]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
d4n/policy: Update policy to use block name
authorSamarah <samarah.uriarte@ibm.com>
Fri, 29 Sep 2023 13:35:57 +0000 (13:35 +0000)
committerPritha Srivastava <prsrivas@redhat.com>
Tue, 2 Apr 2024 15:54:51 +0000 (21:24 +0530)
Signed-off-by: Samarah <samarah.uriarte@ibm.com>
src/rgw/driver/d4n/d4n_directory.h
src/rgw/driver/d4n/d4n_policy.cc
src/rgw/driver/d4n/d4n_policy.h
src/rgw/driver/d4n/rgw_sal_d4n.cc
src/test/rgw/test_d4n_policy.cc

index 2ad56f0f61993f9b64932ee17d4415eabb85ddd7..e71e2774bb88ca468681441d2fe494350227d89d 100644 (file)
@@ -116,11 +116,10 @@ class BlockDirectory: public Directory {
     int del(CacheBlock* block, optional_yield y);
     int update_field(CacheBlock* block, std::string field, std::string value, optional_yield y);
     int remove_host(CacheBlock* block, std::string value, optional_yield y);
+    std::string build_index(CacheBlock* block);
 
   private:
     std::shared_ptr<connection> conn;
-
-    std::string build_index(CacheBlock* block);
 };
 
 } } // namespace rgw::d4n
index a7d68f845919c4cfb2aacf1d66179738e8f413d3..4453e5ec48bea31a72ca1ed01243067201c36581 100644 (file)
@@ -149,7 +149,6 @@ int LFUDAPolicy::get_min_avg_weight(optional_yield y) {
   }
 
   if (!std::get<0>(resp).value()) {
-    // Is int_max what we want here? -Sam
     if (set_min_avg_weight(0, dir->cct->_conf->rgw_local_cache_address, y)) { /* Initialize minimum average weight */
       return 0;
     } else {
@@ -182,10 +181,13 @@ CacheBlock LFUDAPolicy::find_victim(const DoutPrefixProvider* dpp, rgw::cache::C
                              [](const auto& l, const auto& r) { return l.second->localWeight < r.second->localWeight; });
 
   /* Get victim cache block */
+  std::string key = it->second->key;
   CacheBlock victim;
-  victim.cacheObj.objName = it->second->key;
-  victim.cacheObj.bucketName = cacheNode->get_attr(dpp, victim.cacheObj.objName, "bucket_name", y); // generalize for other cache backends -Sam
-  victim.blockID = 0; // find way to get ID -Sam 
+
+  victim.cacheObj.bucketName = key.substr(0, key.find('_')); 
+  key.erase(0, key.find('_') + 1);
+  victim.cacheObj.objName = key.substr(0, key.find('_'));
+  victim.blockID = boost::lexical_cast<uint64_t>(key.substr(key.find('_') + 1, key.length()));
 
   if (dir->get(&victim, y) < 0) {
     return {};
@@ -213,8 +215,8 @@ int LFUDAPolicy::get_block(const DoutPrefixProvider* dpp, CacheBlock* block, rgw
   response<std::string> resp;
   int age = get_age(y);
 
-  if (exist_key(block->cacheObj.objName, y)) { /* Local copy */
-    auto it = entries_map.find(block->cacheObj.objName); // change to block name eventually -Sam
+  if (exist_key(dir->build_index(block), y)) { /* Local copy */
+    auto it = entries_map.find(dir->build_index(block));
     it->second->localWeight += age;
     return cacheNode->set_attr(dpp, block->cacheObj.objName, "localWeight", std::to_string(it->second->localWeight), y);
   } else {
@@ -266,7 +268,7 @@ uint64_t LFUDAPolicy::eviction(const DoutPrefixProvider* dpp, rgw::cache::CacheD
     return 0; /* Return zero for failure */
   }
 
-  auto it = entries_map.find(victim.cacheObj.objName); // change to block name eventually -Sam
+  auto it = entries_map.find(dir->build_index(&victim));
   if (it == entries_map.end()) {
     return 0;
   }
index 2b9ac5cea32c157f0fcbaf274fc347354e57f64e..713aa78c890c9df53289d8f48e4421f8eb7b1eb2 100644 (file)
@@ -139,6 +139,7 @@ class PolicyDriver {
 
     int init();
     CachePolicy* get_cache_policy() { return cachePolicy; }
+    std::string get_policy_name() { return policyName; }
 };
 
 } } // namespace rgw::d4n
index 8da78b280358416ab7b9a89625acda8f72f8c7e8..059c3112619982ffedd878acfb632cc0dc4df216 100644 (file)
@@ -263,7 +263,7 @@ int D4NFilterObject::get_obj_attrs(optional_yield y, const DoutPrefixProvider* d
     this->get_obj_state(dpp, &astate, y);
 
     for (auto it = attrs.begin(); it != attrs.end(); ++it) {
-      if (it->second.length() > 0) { // or return? -Sam
+      if (it->second.length() > 0) {
        if (it->first == "mtime") {
          parse_time(it->second.c_str(), &astate->mtime);
          attrs.erase(it->first);
@@ -574,6 +574,12 @@ int D4NFilterObject::D4NFilterReadOp::iterate(const DoutPrefixProvider* dpp, int
     ldpp_dout(dpp, 20) << "D4NFilterObject::iterate:: " << __func__ << "(): READ FROM CACHE: oid=" << oid_in_cache << " length to read is: " << len_to_read << " part num: " << start_part_num << 
     " read_ofs: " << read_ofs << " part len: " << part_len << dendl;
 
+    /* Build base block for inserting in LFUDA */
+    rgw::d4n::CacheBlock block;
+    block.blockID = ofs;
+    block.cacheObj.objName = source->get_key().get_oid();
+    block.cacheObj.bucketName = source->get_bucket()->get_name();
+
     if (source->driver->get_policy_driver()->get_cache_policy()->exist_key(oid_in_cache, y)) { 
       // Read From Cache
       auto completed = source->driver->get_cache_driver()->get_async(dpp, y, aio.get(), oid_in_cache, read_ofs, len_to_read, cost, id); 
@@ -697,7 +703,7 @@ int D4NFilterObject::D4NFilterReadOp::D4NFilterGetCB::handle_data(bufferlist& bl
     block.cacheObj.objName = source->get_key().get_oid();
     block.cacheObj.bucketName = source->get_bucket()->get_name();
     block.cacheObj.creationTime = 0;
-    block.cacheObj.dirty = false;
+    block.cacheObj.dirty = false;// update hostsList since may overwrite existing hosts -Sam
     block.cacheObj.hostsList.push_back(blockDir->cct->_conf->rgw_local_cache_address); // Is the entire object getting stored in the local cache as well or only blocks? -Sam
 
     if (bl.length() > 0 && last_part) { // if bl = bl_rem has data and this is the last part, write it to cache
index e73cf3fe003fac06e6305e4aeea5d81ea0e1bdf6..ce2fde244bf8143c4eec825e37f11073c325aa7c 100644 (file)
@@ -111,6 +111,12 @@ TEST_F(LFUDAPolicyFixture, LocalGetBlockYield)
 {
   spawn::spawn(io, [this] (spawn::yield_context yield) {
     ASSERT_EQ(0, cacheDriver->put(env->dpp, key, bl, bl.length(), attrs, optional_yield{io, yield}));
+
+    rgw::d4n::CacheBlock temp;
+    temp.blockID = 0;
+    temp.cacheObj.objName = "testName";
+    temp.cacheObj.bucketName = "testBucket";
+    std::string key = dir->build_index(&temp);
     policyDriver->get_cache_policy()->insert(env->dpp, key, 0, bl.length(), "", cacheDriver, optional_yield{io, yield});
 
     /* Change cache age for testing purposes */
@@ -177,7 +183,8 @@ TEST_F(LFUDAPolicyFixture, RemoteGetBlockYield)
 
     ASSERT_EQ(0, dir->set(&victim, optional_yield{io, yield}));
     ASSERT_EQ(0, cacheDriver->put(env->dpp, victim.cacheObj.objName, bl, bl.length(), attrs, optional_yield{io, yield}));
-    policyDriver->get_cache_policy()->insert(env->dpp, victim.cacheObj.objName, 0, bl.length(), "", cacheDriver, optional_yield{io, yield});
+    std::string key = dir->build_index(&victim);
+    policyDriver->get_cache_policy()->insert(env->dpp, key, 0, bl.length(), "", cacheDriver, optional_yield{io, yield});
 
     /* Remote block */
     block->size = cacheDriver->get_free_space(env->dpp) + 1; /* To trigger eviction */