From a5dfb457452113e6969752b6f1c1b7ef2138e6a5 Mon Sep 17 00:00:00 2001 From: Samarah Date: Wed, 18 Jun 2025 19:06:51 +0000 Subject: [PATCH] rgw/d4n: Add shutdown calls to unit tests and save yield in filter Signed-off-by: Samarah --- src/rgw/driver/d4n/d4n_policy.h | 13 ++++++------ src/rgw/driver/d4n/rgw_sal_d4n.cc | 6 ++++-- src/rgw/driver/d4n/rgw_sal_d4n.h | 2 ++ src/test/rgw/test_d4n_filter.cc | 33 +++++++++++++++++++++++++++++-- src/test/rgw/test_d4n_policy.cc | 2 +- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/rgw/driver/d4n/d4n_policy.h b/src/rgw/driver/d4n/d4n_policy.h index 96275701a88d2..a2b0d6508cb92 100644 --- a/src/rgw/driver/d4n/d4n_policy.h +++ b/src/rgw/driver/d4n/d4n_policy.h @@ -182,9 +182,10 @@ class LFUDAPolicy : public CachePolicy { int delete_data_blocks(const DoutPrefixProvider* dpp, LFUDAObjEntry* e, optional_yield y); public: - LFUDAPolicy(std::shared_ptr& conn, rgw::cache::CacheDriver* cacheDriver) : CachePolicy(), - conn(conn), - cacheDriver(cacheDriver) + LFUDAPolicy(std::shared_ptr& conn, rgw::cache::CacheDriver* cacheDriver, optional_yield y) : CachePolicy(), + y(y), + conn(conn), + cacheDriver(cacheDriver) { blockDir = new BlockDirectory{conn}; objDir = new ObjectDirectory{conn}; @@ -207,7 +208,6 @@ class LFUDAPolicy : public CachePolicy { virtual void update(const DoutPrefixProvider* dpp, const std::string& key, uint64_t offset, uint64_t len, const std::string& version, bool dirty, uint8_t op, optional_yield y, std::string& restore_val=empty) override; virtual bool erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y) override; virtual bool _erase(const DoutPrefixProvider* dpp, const std::string& key, optional_yield y); - void save_y(optional_yield y) { this->y = y; } virtual void update_dirty_object(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool deleteMarker, uint64_t size, double creationTime, const rgw_user& user, const std::string& etag, const std::string& bucket_name, const std::string& bucket_id, const rgw_obj_key& obj_key, uint8_t op, optional_yield y, std::string& restore_val=empty) override; @@ -221,6 +221,7 @@ class LFUDAPolicy : public CachePolicy { } return it->second.first; } + void save_y(optional_yield y) { this->y = y; } }; class LRUPolicy : public CachePolicy { @@ -258,10 +259,10 @@ class PolicyDriver { CachePolicy* cachePolicy; public: - PolicyDriver(std::shared_ptr& conn, rgw::cache::CacheDriver* cacheDriver, const std::string& _policyName) : policyName(_policyName) + PolicyDriver(std::shared_ptr& conn, rgw::cache::CacheDriver* cacheDriver, const std::string& _policyName, optional_yield y) : policyName(_policyName) { if (policyName == "lfuda") { - cachePolicy = new LFUDAPolicy(conn, cacheDriver); + cachePolicy = new LFUDAPolicy(conn, cacheDriver, y); } else if (policyName == "lru") { cachePolicy = new LRUPolicy(cacheDriver); } diff --git a/src/rgw/driver/d4n/rgw_sal_d4n.cc b/src/rgw/driver/d4n/rgw_sal_d4n.cc index 257803c6d3cf8..288775c78b166 100644 --- a/src/rgw/driver/d4n/rgw_sal_d4n.cc +++ b/src/rgw/driver/d4n/rgw_sal_d4n.cc @@ -37,7 +37,8 @@ static inline Object* nextObject(Object* t) } D4NFilterDriver::D4NFilterDriver(Driver* _next, boost::asio::io_context& io_context) : FilterDriver(_next), - io_context(io_context) + io_context(io_context), + y(null_yield) { rgw::cache::Partition partition_info; partition_info.location = g_conf()->rgw_d4n_l1_datacache_persistent_path; @@ -60,7 +61,8 @@ int D4NFilterDriver::initialize(CephContext *cct, const DoutPrefixProvider *dpp) bucketDir = std::make_unique(conn); policyDriver = std::make_unique(conn, cacheDriver.get(), - "lfuda"); + "lfuda", + this->y); std::string address = cct->_conf->rgw_d4n_address; config cfg; diff --git a/src/rgw/driver/d4n/rgw_sal_d4n.h b/src/rgw/driver/d4n/rgw_sal_d4n.h index f844dc73d5fec..d091ede2b7312 100644 --- a/src/rgw/driver/d4n/rgw_sal_d4n.h +++ b/src/rgw/driver/d4n/rgw_sal_d4n.h @@ -60,6 +60,7 @@ class D4NFilterDriver : public FilterDriver { std::unique_ptr bucketDir; std::unique_ptr policyDriver; boost::asio::io_context& io_context; + optional_yield y; public: D4NFilterDriver(Driver* _next, boost::asio::io_context& io_context); @@ -84,6 +85,7 @@ class D4NFilterDriver : public FilterDriver { rgw::d4n::BlockDirectory* get_block_dir() { return blockDir.get(); } rgw::d4n::BucketDirectory* get_bucket_dir() { return bucketDir.get(); } rgw::d4n::PolicyDriver* get_policy_driver() { return policyDriver.get(); } + void save_y(optional_yield y) { this->y = y; } void shutdown() override; }; diff --git a/src/test/rgw/test_d4n_filter.cc b/src/test/rgw/test_d4n_filter.cc index 6f1649eb345d4..f43a8f56b2021 100755 --- a/src/test/rgw/test_d4n_filter.cc +++ b/src/test/rgw/test_d4n_filter.cc @@ -141,7 +141,7 @@ class D4NFilterFixture: public ::testing::Test { } void init_driver(net::yield_context yield) { - dynamic_cast(d4nFilter->get_policy_driver()->get_cache_policy())->save_y(optional_yield{yield}); + d4nFilter->save_y(optional_yield{yield}); driver->initialize(env->cct.get(), env->dpp); ASSERT_NE(driver, nullptr); @@ -342,6 +342,7 @@ TEST_F(D4NFilterFixture, PutObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -410,6 +411,7 @@ TEST_F(D4NFilterFixture, GetObjectRead) testFile.close(); conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -520,6 +522,7 @@ TEST_F(D4NFilterFixture, CopyNoneObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -606,6 +609,7 @@ TEST_F(D4NFilterFixture, CopyMergeObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -692,6 +696,7 @@ TEST_F(D4NFilterFixture, CopyReplaceObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -762,6 +767,7 @@ TEST_F(D4NFilterFixture, DeleteObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -801,6 +807,7 @@ TEST_F(D4NFilterFixture, PutVersionedObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -886,6 +893,7 @@ TEST_F(D4NFilterFixture, GetVersionedObjectRead) testFile.close(); conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1024,6 +1032,7 @@ TEST_F(D4NFilterFixture, CopyNoneVersionedObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1162,6 +1171,7 @@ TEST_F(D4NFilterFixture, CopyMergeVersionedObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1300,6 +1310,7 @@ TEST_F(D4NFilterFixture, CopyReplaceVersionedObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1390,6 +1401,7 @@ TEST_F(D4NFilterFixture, DeleteVersionedObjectRead) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1504,9 +1516,10 @@ TEST_F(D4NFilterFixture, PutObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); - + io.run(); } @@ -1576,6 +1589,7 @@ TEST_F(D4NFilterFixture, GetObjectWrite) testFile.close(); conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1697,6 +1711,7 @@ TEST_F(D4NFilterFixture, CopyNoneObjectWrite) testFile.close(); conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1818,6 +1833,7 @@ TEST_F(D4NFilterFixture, CopyMergeObjectWrite) testFile.close(); conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -1939,6 +1955,7 @@ TEST_F(D4NFilterFixture, CopyReplaceObjectWrite) testFile.close(); conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -2019,6 +2036,7 @@ TEST_F(D4NFilterFixture, DeleteObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -2175,6 +2193,7 @@ TEST_F(D4NFilterFixture, PutVersionedObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -2325,6 +2344,7 @@ TEST_F(D4NFilterFixture, GetVersionedObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -2545,6 +2565,7 @@ TEST_F(D4NFilterFixture, CopyNoneVersionedObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -2765,6 +2786,7 @@ TEST_F(D4NFilterFixture, CopyMergeVersionedObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -2985,6 +3007,7 @@ TEST_F(D4NFilterFixture, CopyReplaceVersionedObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -3089,6 +3112,7 @@ TEST_F(D4NFilterFixture, DeleteVersionedObjectWrite) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -3174,6 +3198,7 @@ TEST_F(D4NFilterFixture, SimpleDeleteBeforeCleaning) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -3285,6 +3310,7 @@ TEST_F(D4NFilterFixture, VersionedDeleteBeforeCleaning) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -3337,6 +3363,7 @@ TEST_F(D4NFilterFixture, SimpleDeleteAfterCleaning) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -3433,6 +3460,7 @@ TEST_F(D4NFilterFixture, VersionedDeleteAfterCleaning) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); @@ -3475,6 +3503,7 @@ TEST_F(D4NFilterFixture, ListObjectVersions) conn->cancel(); testBucket->remove(env->dpp, true, optional_yield{yield}); + driver->shutdown(); DriverDestructor driver_destructor(static_cast(driver)); }, rethrow); diff --git a/src/test/rgw/test_d4n_policy.cc b/src/test/rgw/test_d4n_policy.cc index eb1f6f42c8a82..f0e29030f88b1 100644 --- a/src/test/rgw/test_d4n_policy.cc +++ b/src/test/rgw/test_d4n_policy.cc @@ -72,7 +72,7 @@ class LFUDAPolicyFixture : public ::testing::Test { conn = std::make_shared(net::make_strand(io)); rgw::cache::Partition partition_info{ .location = "RedisCache", .size = 1000 }; cacheDriver = new rgw::cache::RedisDriver{io, partition_info}; - policyDriver = new rgw::d4n::PolicyDriver(conn, cacheDriver, "lfuda"); + policyDriver = new rgw::d4n::PolicyDriver(conn, cacheDriver, "lfuda", null_yield); dir = new rgw::d4n::BlockDirectory{conn}; ASSERT_NE(dir, nullptr); -- 2.39.5