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
}
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 {
[](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 {};
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 {
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;
}
int init();
CachePolicy* get_cache_policy() { return cachePolicy; }
+ std::string get_policy_name() { return policyName; }
};
} } // namespace rgw::d4n
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);
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);
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
{
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 */
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 */