]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw/d4n: Add yield parameter to get_free_space
authorSamarah Uriarte <samarah.uriarte@ibm.com>
Mon, 27 Oct 2025 21:35:45 +0000 (16:35 -0500)
committerSamarah <samarah.uriarte@ibm.com>
Mon, 1 Dec 2025 20:08:15 +0000 (20:08 +0000)
Signed-off-by: Samarah Uriarte <samarah.uriarte@ibm.com>
src/rgw/driver/d4n/d4n_policy.cc
src/rgw/rgw_cache_driver.h
src/rgw/rgw_redis_driver.cc
src/rgw/rgw_redis_driver.h
src/rgw/rgw_ssd_driver.cc
src/rgw/rgw_ssd_driver.h
src/test/rgw/test_d4n_policy.cc

index e6980c184b95d7243f6bce82bd0fe306528c5061..793c0302916c6a3f70eee89a3da32277cd08e46f 100644 (file)
@@ -277,8 +277,9 @@ bool LFUDAPolicy::invalidate_dirty_object(const DoutPrefixProvider* dpp, const s
 }
 
 CacheBlock* LFUDAPolicy::get_victim_block(const DoutPrefixProvider* dpp, optional_yield y) {
-  if (entries_heap.empty())
+  if (entries_heap.empty()) {
     return nullptr;
+  }
 
   /* Get victim cache block */
   LFUDAEntry* entry = entries_heap.top();
@@ -321,7 +322,7 @@ int LFUDAPolicy::exist_key(const std::string& key) {
 
 int LFUDAPolicy::eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y) {
   int ret = -1;
-  uint64_t freeSpace = cacheDriver->get_free_space(dpp);
+  uint64_t freeSpace = cacheDriver->get_free_space(dpp, y);
 
   while (freeSpace < size) { // TODO: Think about parallel reads and writes; can this turn into an infinite loop?
     std::unique_lock<std::mutex> l(lfuda_lock);
@@ -396,7 +397,7 @@ int LFUDAPolicy::eviction(const DoutPrefixProvider* dpp, uint64_t size, optional
     if (perfcounter) {
       perfcounter->inc(l_rgw_d4n_cache_evictions);
     }
-    freeSpace = cacheDriver->get_free_space(dpp);
+    freeSpace = cacheDriver->get_free_space(dpp, y);
   }
   
   return 0;
@@ -994,7 +995,7 @@ int LRUPolicy::exist_key(const std::string& key)
 int LRUPolicy::eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_yield y)
 {
   const std::lock_guard l(lru_lock);
-  uint64_t freeSpace = cacheDriver->get_free_space(dpp);
+  uint64_t freeSpace = cacheDriver->get_free_space(dpp, y);
 
   while (freeSpace < size) {
     auto p = entries_lru_list.front();
@@ -1006,7 +1007,7 @@ int LRUPolicy::eviction(const DoutPrefixProvider* dpp, uint64_t size, optional_y
       return ret;
     }
 
-    freeSpace = cacheDriver->get_free_space(dpp);
+    freeSpace = cacheDriver->get_free_space(dpp, y);
   }
 
   return 0;
index 6c02f24d3496101b8b300a879a82f89b75a3fa9e..5a86a64016ea9013a1ad8a05741fc4a96f48c844 100644 (file)
@@ -57,7 +57,7 @@ class CacheDriver {
 
     /* Partition */
     virtual Partition get_current_partition_info(const DoutPrefixProvider* dpp) = 0;
-    virtual uint64_t get_free_space(const DoutPrefixProvider* dpp) = 0;
+    virtual uint64_t get_free_space(const DoutPrefixProvider* dpp, optional_yield y) = 0;
 
     /* Data Recovery from Cache */
     virtual int restore_blocks_objects(const DoutPrefixProvider* dpp, ObjectDataCallback obj_func, BlockDataCallback block_func) = 0;
index ee71e61cc7fce97ca851ed74514263c774020aa1..984064eec21df212f1c5fff8e32132e430829765 100644 (file)
@@ -65,7 +65,7 @@ void redis_exec(std::shared_ptr<connection> conn,
   }
 }
 
-std::optional<fs::path> RedisDriver::resolve_valkey_data_dir(const DoutPrefixProvider* dpp) const
+std::optional<fs::path> RedisDriver::resolve_valkey_data_dir(const DoutPrefixProvider* dpp, optional_yield y) const
 {
   try {
     boost::system::error_code ec;
@@ -73,7 +73,7 @@ std::optional<fs::path> RedisDriver::resolve_valkey_data_dir(const DoutPrefixPro
     request req;
     req.push("CONFIG", "GET", "dir");
 
-    redis_exec(conn, ec, req, resp, null_yield);
+    redis_exec(conn, ec, req, resp, y);
 
     if (ec) {
       ldpp_dout(dpp, 5) << "RedisDriver::" << __func__
@@ -109,9 +109,9 @@ std::optional<fs::path> RedisDriver::resolve_valkey_data_dir(const DoutPrefixPro
   return std::nullopt;
 }
 
-uint64_t RedisDriver::get_free_space(const DoutPrefixProvider* dpp)
+uint64_t RedisDriver::get_free_space(const DoutPrefixProvider* dpp, optional_yield y)
 {
-  auto data_dir = resolve_valkey_data_dir(dpp);
+  auto data_dir = resolve_valkey_data_dir(dpp, y);
   if (!data_dir) {
     ldpp_dout(dpp, 0) << __func__ << "(): ERROR: could not resolve redis data dir" << dendl;
     return 0;
index 0e018d62561998f9a4aad78d52a8c32a2e8c6be1..78a4a511044679287b63841791be629b609f2d5d 100644 (file)
@@ -32,7 +32,7 @@ class RedisDriver : public CacheDriver {
 
     /* Partition */
     virtual Partition get_current_partition_info(const DoutPrefixProvider* dpp) override { return partition_info; }
-    virtual uint64_t get_free_space(const DoutPrefixProvider* dpp) override;
+    virtual uint64_t get_free_space(const DoutPrefixProvider* dpp, optional_yield y) override;
 
     virtual int initialize(const DoutPrefixProvider* dpp) override;
     virtual int put(const DoutPrefixProvider* dpp, const std::string& key, const bufferlist& bl, uint64_t len, const rgw::sal::Attrs& attrs, optional_yield y) override;
@@ -58,7 +58,7 @@ class RedisDriver : public CacheDriver {
     uint64_t free_space;
     uint64_t outstanding_write_size;
 
-  std::optional<fs::path> resolve_valkey_data_dir(const DoutPrefixProvider* dpp) const;
+  std::optional<fs::path> resolve_valkey_data_dir(const DoutPrefixProvider* dpp, optional_yield y) const;
 
     struct redis_response {
       request req;
index cb9fe6c85ce641292c0c21fe1b310c9ef6e73c83..7ec3d73ea3441fb25db6b452107ed405e1e1b497 100644 (file)
@@ -371,7 +371,7 @@ int SSDDriver::restore_blocks_objects(const DoutPrefixProvider* dpp, ObjectDataC
     return 0;
 }
 
-uint64_t SSDDriver::get_free_space(const DoutPrefixProvider* dpp)
+uint64_t SSDDriver::get_free_space(const DoutPrefixProvider* dpp, optional_yield y)
 {
     efs::space_info space = efs::space(partition_info.location);
     return (space.available < partition_info.reserve_size) ? 0 : (space.available - partition_info.reserve_size);
index 49d85244cc4823e707f477087776d8d839ecadc8..91f369fe3b4d3ad2109ada0f300690d64aa17a41 100644 (file)
@@ -29,7 +29,7 @@ public:
 
   /* Partition */
   virtual Partition get_current_partition_info(const DoutPrefixProvider* dpp) override { return partition_info; }
-  virtual uint64_t get_free_space(const DoutPrefixProvider* dpp) override;
+  virtual uint64_t get_free_space(const DoutPrefixProvider* dpp, optional_yield y) override;
   void set_free_space(const DoutPrefixProvider* dpp, uint64_t free_space);
 
   virtual int restore_blocks_objects(const DoutPrefixProvider* dpp, ObjectDataCallback obj_func, BlockDataCallback block_func) override;
index 8e4a04906d04585f8178dda8301d2ee18323dd4e..77210c42d55b291015e4d86f27b4499ce96a24c7 100644 (file)
@@ -32,7 +32,7 @@ class Environment : public ::testing::Environment {
                              CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
 
       cct = _cct.get();
-      dpp = new DoutPrefix(cct->get(), dout_subsys, "D4N Object Directory Test: ");
+      dpp = new DoutPrefix(cct->get(), dout_subsys, "D4N Policy Test: ");
       common_init_finish(g_ceph_context);
       
       redisHost = cct->_conf->rgw_d4n_address; 
@@ -205,6 +205,7 @@ TEST_F(LFUDAPolicyFixture, LocalGetBlockYield)
 TEST_F(LFUDAPolicyFixture, RemoteGetBlockYield)
 {
   boost::asio::spawn(io, [this] (boost::asio::yield_context yield) {
+    // TODO: add testing for eviction workflow
     /* Set victim block for eviction */
     rgw::d4n::CacheBlock victim = rgw::d4n::CacheBlock{
       .cacheObj = {
@@ -243,11 +244,8 @@ TEST_F(LFUDAPolicyFixture, RemoteGetBlockYield)
     policyDriver->get_cache_policy()->update(env->dpp, victimHeadObj, 0, bl.length(), "", false, rgw::d4n::RefCount::NOOP, optional_yield{yield});
 
     /* Remote block */
-    block->size = cacheDriver->get_free_space(env->dpp) + 1; /* To trigger eviction */
-    block->cacheObj.hostsList.clear();  
     block->cacheObj.hostsList.clear();
     block->cacheObj.hostsList.insert("127.0.0.1:6000");
-    block->cacheObj.hostsList.insert("127.0.0.1:6000");
 
     ASSERT_EQ(0, dir->set(env->dpp, block, optional_yield{yield}));
 
@@ -269,20 +267,20 @@ TEST_F(LFUDAPolicyFixture, RemoteGetBlockYield)
     std::string key = block->cacheObj.bucketName + "_" + block->cacheObj.objName + "_" + std::to_string(block->blockID) + "_" + std::to_string(block->size);
     boost::system::error_code ec;
     request req;
-    req.push("EXISTS", "RedisCache/" + victimKeyInCache);
+    //req.push("EXISTS", "RedisCache/" + victimKeyInCache);
     req.push("EXISTS", victimKey, "globalWeight");
     req.push("HGET", key, "globalWeight");
     req.push("FLUSHALL");
 
-    response<int, int, std::string, 
+    response</*int, */int, std::string, 
              boost::redis::ignore_t> resp;
 
     conn->async_exec(req, resp, yield[ec]);
 
     ASSERT_EQ((bool)ec, false);
+    //EXPECT_EQ(std::get<0>(resp).value(), 0);
     EXPECT_EQ(std::get<0>(resp).value(), 0);
-    EXPECT_EQ(std::get<1>(resp).value(), 0);
-    EXPECT_EQ(std::get<2>(resp).value(), "1");
+    EXPECT_EQ(std::get<1>(resp).value(), "1");
     conn->cancel();
     
     delete policyDriver;