From: Samarah Date: Fri, 29 Sep 2023 13:35:57 +0000 (+0000) Subject: d4n/policy: Update policy to use block name X-Git-Tag: testing/wip-batrick-testing-20240411.154038~45^2~46 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8328330fb533faaea4c6650f1018907141c60265;p=ceph-ci.git d4n/policy: Update policy to use block name Signed-off-by: Samarah --- diff --git a/src/rgw/driver/d4n/d4n_directory.h b/src/rgw/driver/d4n/d4n_directory.h index 2ad56f0f619..e71e2774bb8 100644 --- a/src/rgw/driver/d4n/d4n_directory.h +++ b/src/rgw/driver/d4n/d4n_directory.h @@ -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 conn; - - std::string build_index(CacheBlock* block); }; } } // namespace rgw::d4n diff --git a/src/rgw/driver/d4n/d4n_policy.cc b/src/rgw/driver/d4n/d4n_policy.cc index a7d68f84591..4453e5ec48b 100644 --- a/src/rgw/driver/d4n/d4n_policy.cc +++ b/src/rgw/driver/d4n/d4n_policy.cc @@ -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(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 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; } diff --git a/src/rgw/driver/d4n/d4n_policy.h b/src/rgw/driver/d4n/d4n_policy.h index 2b9ac5cea32..713aa78c890 100644 --- a/src/rgw/driver/d4n/d4n_policy.h +++ b/src/rgw/driver/d4n/d4n_policy.h @@ -139,6 +139,7 @@ class PolicyDriver { int init(); CachePolicy* get_cache_policy() { return cachePolicy; } + std::string get_policy_name() { return policyName; } }; } } // namespace rgw::d4n diff --git a/src/rgw/driver/d4n/rgw_sal_d4n.cc b/src/rgw/driver/d4n/rgw_sal_d4n.cc index 8da78b28035..059c3112619 100644 --- a/src/rgw/driver/d4n/rgw_sal_d4n.cc +++ b/src/rgw/driver/d4n/rgw_sal_d4n.cc @@ -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 diff --git a/src/test/rgw/test_d4n_policy.cc b/src/test/rgw/test_d4n_policy.cc index e73cf3fe003..ce2fde244bf 100644 --- a/src/test/rgw/test_d4n_policy.cc +++ b/src/test/rgw/test_d4n_policy.cc @@ -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 */