Browse Source

[2108] Changed proto of ZoneTable::setZoneData() to return a FindResult

This is so we can differentiate between whether a node was not found
and whether a node was found, but its old data was empty.

We also don't set the node data now when an exact match was not found.
Before it used to set for partial matches too (which was a bug).
Mukund Sivaraman 12 years ago
parent
commit
56afaa4d87

+ 5 - 3
src/lib/datasrc/memory/memory_client.cc

@@ -620,9 +620,11 @@ InMemoryClient::InMemoryClientImpl::load(
         ++zone_count_;
         ++zone_count_;
     }
     }
 
 
-    ZoneData *data = zone_table_->setZoneData(zone_name, holder.release());
-    if (data != NULL) {
-        ZoneData::destroy(local_mem_sgmt_, data, rrclass_);
+    ZoneTable::FindResult fr(zone_table_->setZoneData(zone_name,
+                                                      holder.release()));
+    assert(fr.code == result::SUCCESS);
+    if (fr.zone_data != NULL) {
+        ZoneData::destroy(local_mem_sgmt_, fr.zone_data, rrclass_);
     }
     }
 
 
     return (result.code);
     return (result.code);

+ 5 - 6
src/lib/datasrc/memory/zone_table.cc

@@ -132,19 +132,18 @@ ZoneTable::findZone(const Name& name) const {
     return (FindResult(my_result, node->getData()));
     return (FindResult(my_result, node->getData()));
 }
 }
 
 
-ZoneData*
+ZoneTable::FindResult
 ZoneTable::setZoneData(const Name& name, ZoneData* data)
 ZoneTable::setZoneData(const Name& name, ZoneData* data)
 {
 {
     ZoneTableNode* node(NULL);
     ZoneTableNode* node(NULL);
 
 
     ZoneTableTree::Result result(zones_->find(name, &node));
     ZoneTableTree::Result result(zones_->find(name, &node));
 
 
-    if ((result != ZoneTableTree::EXACTMATCH) &&
-        (result != ZoneTableTree::PARTIALMATCH)) {
-        return (NULL);
+    if (result != ZoneTableTree::EXACTMATCH) {
+        return (FindResult(result::NOTFOUND, NULL));
+    } else {
+        return (FindResult(result::SUCCESS, node->setData(data)));
     }
     }
-
-    return (node->setData(data));
 }
 }
 
 
 } // end of namespace memory
 } // end of namespace memory

+ 3 - 3
src/lib/datasrc/memory/zone_table.h

@@ -191,9 +191,9 @@ public:
     ///
     ///
     /// \param name A domain name for which the zone data is set.
     /// \param name A domain name for which the zone data is set.
     /// \param data The new zone data to set.
     /// \param data The new zone data to set.
-    /// \return A \c ZoneData object containing the old data if the zone
-    /// was found, or \c NULL otherwise.
-    ZoneData* setZoneData(const isc::dns::Name& name, ZoneData* data);
+    /// \return A \c FindResult object containing the old data if the
+    /// zone was found.
+    FindResult setZoneData(const isc::dns::Name& name, ZoneData* data);
 
 
 private:
 private:
     boost::interprocess::offset_ptr<ZoneTableTree> zones_;
     boost::interprocess::offset_ptr<ZoneTableTree> zones_;