Browse Source

[2836] Store the address for whole lifetime

Store the named address for the whole lifetime of the zone data updater.
This should be better for performance.
Michal 'vorner' Vaner 12 years ago
parent
commit
29f6d05f66

+ 0 - 10
src/lib/datasrc/memory/zone_data_updater.cc

@@ -417,7 +417,6 @@ ZoneDataUpdater::add(const ConstRRsetPtr& rrset,
 
 
     // Store the address, it may change during growth and the address inside
     // Store the address, it may change during growth and the address inside
     // would get updated.
     // would get updated.
-    mem_sgmt_.setNamedAddress("updater_zone_data", zone_data_);
     bool added = false;
     bool added = false;
     do {
     do {
         try {
         try {
@@ -429,18 +428,9 @@ ZoneDataUpdater::add(const ConstRRsetPtr& rrset,
             zone_data_ =
             zone_data_ =
                 static_cast<ZoneData*>(
                 static_cast<ZoneData*>(
                     mem_sgmt_.getNamedAddress("updater_zone_data"));
                     mem_sgmt_.getNamedAddress("updater_zone_data"));
-        } catch (...) {
-            // In case of other exceptions, they are propagated. But clean up
-            // the temporary address stored there (this is shorter than
-            // RAII class in this case).
-            mem_sgmt_.clearNamedAddress("updater_zone_data");
-            throw;
         }
         }
         // Retry if it didn't add due to the growth
         // Retry if it didn't add due to the growth
     } while (!added);
     } while (!added);
-
-    // Clean up the named address
-    mem_sgmt_.clearNamedAddress("updater_zone_data");
 }
 }
 
 
 } // namespace memory
 } // namespace memory

+ 4 - 1
src/lib/datasrc/memory/zone_data_updater.h

@@ -74,10 +74,13 @@ public:
        zone_name_(zone_name),
        zone_name_(zone_name),
        hash_(NULL),
        hash_(NULL),
        zone_data_(&zone_data)
        zone_data_(&zone_data)
-    {}
+    {
+        mem_sgmt_.setNamedAddress("updater_zone_data", zone_data_);
+    }
 
 
     /// The destructor.
     /// The destructor.
     ~ZoneDataUpdater() {
     ~ZoneDataUpdater() {
+        mem_sgmt_.clearNamedAddress("updater_zone_data");
         delete hash_;
         delete hash_;
     }
     }
 
 

+ 2 - 0
src/lib/datasrc/tests/memory/zone_data_updater_unittest.cc

@@ -92,6 +92,8 @@ protected:
     ~ZoneDataUpdaterTest() {
     ~ZoneDataUpdaterTest() {
         if (updater_) {
         if (updater_) {
             ZoneData::destroy(*mem_sgmt_, updater_->getZoneData(), zclass_);
             ZoneData::destroy(*mem_sgmt_, updater_->getZoneData(), zclass_);
+            // Release the updater, so it frees all memory inside the segment too
+            updater_.reset();
         }
         }
         if (!mem_sgmt_->allMemoryDeallocated()) {
         if (!mem_sgmt_->allMemoryDeallocated()) {
             ADD_FAILURE() << "Memory leak detected";
             ADD_FAILURE() << "Memory leak detected";