From: Samarah Date: Fri, 6 Feb 2026 18:41:01 +0000 (+0000) Subject: d4n/policy: Remove erase call from update X-Git-Tag: testing/wip-vshankar-testing-20260218.045142~6^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d6c81dce601204b8b0cf04071e678cca701788d8;p=ceph-ci.git d4n/policy: Remove erase call from update Signed-off-by: Samarah --- diff --git a/src/rgw/driver/d4n/d4n_policy.cc b/src/rgw/driver/d4n/d4n_policy.cc index 793c0302916..e9611b82fc8 100644 --- a/src/rgw/driver/d4n/d4n_policy.cc +++ b/src/rgw/driver/d4n/d4n_policy.cc @@ -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; diff --git a/src/test/rgw/test_d4n_filter.cc b/src/test/rgw/test_d4n_filter.cc index 77a27daac25..9523243c783 100755 --- a/src/test/rgw/test_d4n_filter.cc +++ b/src/test/rgw/test_d4n_filter.cc @@ -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 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(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(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 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(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(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 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(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(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(optional_yield{yield});