Skip to content

Commit

Permalink
test/rgw: Correct RedisDriver keys and add checks for cache blocks after
Browse files Browse the repository at this point in the history
write

Signed-off-by: Samarah <[email protected]>
  • Loading branch information
Samarah committed Nov 14, 2024
1 parent a56d947 commit 9e0bd2f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/test/rgw/test_d4n_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LFUDAPolicyFixture : public ::testing::Test {
.hostsList = { env->redisHost }
},
.blockID = 0,
.version = "",
.version = "version",
.deleteMarker = false,
.size = bl.length(),
.globalWeight = 0
Expand Down Expand Up @@ -99,7 +99,7 @@ class LFUDAPolicyFixture : public ::testing::Test {
}

std::string build_index(std::string bucketName, std::string oid, uint64_t offset, uint64_t size) {
return bucketName + "_" + oid + "_" + std::to_string(offset) + "_" + std::to_string(size);
return bucketName + "#" + oid + "#" + std::to_string(offset) + "#" + std::to_string(size);
}

int lfuda(const DoutPrefixProvider* dpp, rgw::d4n::CacheBlock* block, rgw::cache::CacheDriver* cacheDriver, optional_yield y) {
Expand Down Expand Up @@ -169,7 +169,7 @@ TEST_F(LFUDAPolicyFixture, LocalGetBlockYield)
dynamic_cast<rgw::d4n::LFUDAPolicy*>(policyDriver->get_cache_policy())->save_y(optional_yield{yield});
policyDriver->get_cache_policy()->init(env->cct, env->dpp, io, driver);

std::string key = block->cacheObj.bucketName + "_" + block->cacheObj.objName + "_" + std::to_string(block->blockID) + "_" + std::to_string(block->size);
std::string key = block->cacheObj.bucketName + "#" + block->cacheObj.objName + "#" + std::to_string(block->blockID) + "#" + std::to_string(block->size);
ASSERT_EQ(0, cacheDriver->put(env->dpp, key, bl, bl.length(), attrs, optional_yield{yield}));
policyDriver->get_cache_policy()->update(env->dpp, key, 0, bl.length(), "", false, rgw::d4n::REFCOUNT_NOOP, optional_yield{yield});

Expand All @@ -179,7 +179,7 @@ TEST_F(LFUDAPolicyFixture, LocalGetBlockYield)

boost::system::error_code ec;
request req;
req.push("HGET", "RedisCache/testBucket_testName_0_0", RGW_CACHE_ATTR_LOCAL_WEIGHT);
req.push("HGET", "RedisCache/testBucket#testName#0#0", RGW_CACHE_ATTR_LOCAL_WEIGHT);
req.push("FLUSHALL");

response<std::string, boost::redis::ignore_t> resp;
Expand Down Expand Up @@ -210,7 +210,7 @@ TEST_F(LFUDAPolicyFixture, RemoteGetBlockYield)
.hostsList = { env->redisHost }
},
.blockID = 0,
.version = "",
.version = "version",
.deleteMarker = false,
.size = bl.length(),
.globalWeight = 5,
Expand All @@ -229,8 +229,14 @@ TEST_F(LFUDAPolicyFixture, RemoteGetBlockYield)

ASSERT_EQ(0, dir->set(env->dpp, &victim, optional_yield{yield}));
std::string victimKey = victim.cacheObj.bucketName + "_version_" + victim.cacheObj.objName + "_" + std::to_string(victim.blockID) + "_" + std::to_string(victim.size);
ASSERT_EQ(0, cacheDriver->put(env->dpp, victimKey, bl, bl.length(), attrs, optional_yield{yield}));
policyDriver->get_cache_policy()->update(env->dpp, victimKey, 0, bl.length(), "", false, rgw::d4n::REFCOUNT_NOOP, optional_yield{yield});
std::string victimKeyInCache = victim.cacheObj.bucketName + "#version#" + victim.cacheObj.objName + "#" + std::to_string(victim.blockID) + "#" + std::to_string(victim.size);
ASSERT_EQ(0, cacheDriver->put(env->dpp, victimKeyInCache, bl, bl.length(), attrs, optional_yield{yield}));
policyDriver->get_cache_policy()->update(env->dpp, victimKeyInCache, 0, bl.length(), "", false, rgw::d4n::REFCOUNT_NOOP, optional_yield{yield});

/* Set head blocks */
std::string victimHeadObj = victim.cacheObj.bucketName + "#version#" + victim.cacheObj.objName + "#0#0";
ASSERT_EQ(0, cacheDriver->put(env->dpp, victimHeadObj, bl, bl.length(), attrs, optional_yield{yield}));
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 */
Expand Down Expand Up @@ -258,12 +264,12 @@ 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/" + victimKey);
req.push("EXISTS", "RedisCache/" + victimKeyInCache);
req.push("EXISTS", victimKey, "globalWeight");
req.push("HGET", key, "globalWeight");
req.push("FLUSHALL");

response<int, int, std::string, std::string,
response<int, int, std::string,
boost::redis::ignore_t> resp;

conn->async_exec(req, resp, yield[ec]);
Expand Down

0 comments on commit 9e0bd2f

Please sign in to comment.