]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
d4n/policy: Remove erase call from update 66484/head
authorSamarah <samarah.uriarte@ibm.com>
Fri, 6 Feb 2026 18:41:01 +0000 (18:41 +0000)
committerSamarah Uriarte <samarah.uriarte@ibm.com>
Tue, 10 Feb 2026 15:59:30 +0000 (15:59 +0000)
Signed-off-by: Samarah <samarah.uriarte@ibm.com>
src/rgw/driver/d4n/d4n_policy.cc
src/test/rgw/test_d4n_filter.cc

index 793c0302916c6a3f70eee89a3da32277cd08e46f..e9611b82fc807c94b0306450c3348c208cf4f91d 100644 (file)
@@ -415,16 +415,15 @@ bool LFUDAPolicy::update_refcount_if_key_exists(const DoutPrefixProvider* dpp, c
   refcount = entry->refcount;
   ldpp_dout(dpp, 20) << "LFUDAPolicy::" << __func__ << "(): old refcount is: " << refcount << dendl;
   if (op == RefCount::INCR) {
-    refcount += 1; 
-  }
-  if (op == RefCount::DECR) {
-    if (refcount > 1) {
+    refcount += 1;
+  } else if (op == RefCount::DECR) {
+    if (refcount > 0) {
       refcount -= 1;
     }
   }
   (*entry->handle)->refcount = refcount;
+  entries_heap.update(entry->handle);
   ldpp_dout(dpp, 20) << "LFUDAPolicy::" << __func__ << "(): updated refcount is: " << (*entry->handle)->refcount << dendl;
-       entries_heap.update(entry->handle);
 
   return true;
 }
@@ -476,12 +475,23 @@ void LFUDAPolicy::update(const DoutPrefixProvider* dpp, const std::string& key,
   } else if (entry) {
     is_dirty = entry->dirty;
   }
-  _erase(dpp, key, y);
   ldpp_dout(dpp, 10) << "LFUDAPolicy::" << __func__ << "(): updated refcount is: " << refcount << dendl;
-  LFUDAEntry* e = new LFUDAEntry(key, offset, len, version, is_dirty, refcount, localWeight);
-  handle_type handle = entries_heap.push(e);
-  e->set_handle(handle);
-  entries_map.emplace(key, e);
+
+  if (entry) {
+    entry->key = key;
+    entry->offset = offset;
+    entry->len = len;
+    entry->version = version;
+    entry->dirty = is_dirty;
+    entry->refcount = refcount;
+    entry->localWeight = localWeight;
+    entries_heap.update(entry->handle, entry);
+  } else {
+    LFUDAEntry* e = new LFUDAEntry(key, offset, len, version, is_dirty, refcount, localWeight);
+    handle_type handle = entries_heap.push(e);
+    e->set_handle(handle);
+    entries_map.emplace(key, e);
+  }
 
   if (updateLocalWeight) {
     int ret = -1;
index 77a27daac255039d620959bfb7f5105bc3c71508..9523243c783055da5982eeace1e693f045e36259 100755 (executable)
@@ -1974,7 +1974,7 @@ TEST_F(D4NFilterFixture, CopyReplaceObjectWrite)
 TEST_F(D4NFilterFixture, DeleteObjectWrite)
 {
   env->cct->_conf->d4n_writecache_enabled = true;
-  env->cct->_conf->rgw_d4n_cache_cleaning_interval = 0;
+  env->cct->_conf->rgw_d4n_cache_cleaning_interval = 1;
   const std::string testName = "DeleteObjectWrite";
   std::string version;
  
@@ -2012,10 +2012,12 @@ TEST_F(D4NFilterFixture, DeleteObjectWrite)
     std::unique_ptr<rgw::sal::Object::DeleteOp> del_op = obj->get_delete_op();
     EXPECT_EQ(del_op->delete_obj(env->dpp, optional_yield{yield}, rgw::sal::FLAG_LOG_OP), 0);
 
+    std::string key = TEST_BUCKET + testName + "#" + version + "#" + TEST_OBJ + testName; 
+    d4nFilter->get_policy_driver()->get_cache_policy()->update_refcount_if_key_exists(env->dpp, key, rgw::d4n::RefCount::DECR, optional_yield{yield});
     dynamic_cast<rgw::d4n::LFUDAPolicy*>(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(null_yield);
   }, rethrow);
 
-  io.run_for(std::chrono::seconds(2)); // Allow cleaning cycle to complete
+  io.run_for(std::chrono::seconds(3)); // Allow cleaning cycle to complete
 
   net::spawn(io, [this, &testName, &version] (net::yield_context yield) {
     dynamic_cast<rgw::d4n::LFUDAPolicy*>(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(optional_yield{yield});
@@ -3026,8 +3028,8 @@ TEST_F(D4NFilterFixture, CopyReplaceVersionedObjectWrite)
 TEST_F(D4NFilterFixture, DeleteVersionedObjectWrite)
 {
   env->cct->_conf->d4n_writecache_enabled = true;
-  env->cct->_conf->rgw_d4n_cache_cleaning_interval = 0;
-  const std::string testName = "DeleteVersionedObjectRead";
+  env->cct->_conf->rgw_d4n_cache_cleaning_interval = 1;
+  const std::string testName = "DeleteVersionedObjectWrite";
   const std::string bucketName = "/tmp/d4n_filter_tests/dbstore-default_ns.1";
   std::string version, instance;
  
@@ -3080,10 +3082,14 @@ TEST_F(D4NFilterFixture, DeleteVersionedObjectWrite)
     std::unique_ptr<rgw::sal::Object::DeleteOp> del_op_suspended = objSuspended->get_delete_op();
     EXPECT_EQ(del_op_suspended->delete_obj(env->dpp, optional_yield{yield}, rgw::sal::FLAG_LOG_OP), 0);
 
+    d4nFilter->get_policy_driver()->get_cache_policy()->update_refcount_if_key_exists(env->dpp, 
+                                     url_encode(bucketName, true) + "#" + instance + "#" + TEST_OBJ + testName, rgw::d4n::RefCount::DECR, optional_yield{yield});
+    d4nFilter->get_policy_driver()->get_cache_policy()->update_refcount_if_key_exists(env->dpp, 
+                                     url_encode(bucketName, true) + "#" + version + "#" + TEST_OBJ + testName, rgw::d4n::RefCount::DECR, optional_yield{yield});
     dynamic_cast<rgw::d4n::LFUDAPolicy*>(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(null_yield);
   }, rethrow);
 
-  io.run_for(std::chrono::seconds(2)); // Allow cleaning cycle to complete
+  io.run_for(std::chrono::seconds(3)); // Allow cleaning cycle to complete
 
   net::spawn(io, [this, &testName, &bucketName, &version, &instance] (net::yield_context yield) {
     dynamic_cast<rgw::d4n::LFUDAPolicy*>(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(optional_yield{yield});
@@ -3216,7 +3222,7 @@ TEST_F(D4NFilterFixture, SimpleDeleteBeforeCleaning)
 TEST_F(D4NFilterFixture, VersionedDeleteBeforeCleaning)
 {
   env->cct->_conf->d4n_writecache_enabled = true;
-  env->cct->_conf->rgw_d4n_cache_cleaning_interval = 0;
+  env->cct->_conf->rgw_d4n_cache_cleaning_interval = 1;
   const std::string testName = "VersionedDeleteBeforeCleaning";
   const std::string bucketName = "/tmp/d4n_filter_tests/dbstore-default_ns.1";
   std::vector<std::string> instances;
@@ -3278,10 +3284,12 @@ TEST_F(D4NFilterFixture, VersionedDeleteBeforeCleaning)
     EXPECT_EQ(objEnabled->get_instance(), instances[0]); // Next latest version
 
     objEnabled->set_instance(instances[0]);
+    d4nFilter->get_policy_driver()->get_cache_policy()->update_refcount_if_key_exists(env->dpp, 
+                                     url_encode(bucketName, true) + "#" + instances[1] + "#" + TEST_OBJ + testName, rgw::d4n::RefCount::DECR, optional_yield{yield});
     dynamic_cast<rgw::d4n::LFUDAPolicy*>(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(null_yield);
   }, rethrow);
 
-  io.run_for(std::chrono::seconds(2)); // Allow cleaning cycle to complete
+  io.run_for(std::chrono::seconds(3)); // Allow cleaning cycle to complete
 
   net::spawn(io, [this, &testName, &bucketName, &instances] (net::yield_context yield) {
     dynamic_cast<rgw::d4n::LFUDAPolicy*>(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(optional_yield{yield});