Skip to content

Commit

Permalink
rgw/d4n: Remove dirty prefix and make xattr instead
Browse files Browse the repository at this point in the history
Signed-off-by: Samarah <[email protected]>
  • Loading branch information
Samarah committed Nov 4, 2024
1 parent 66c58ca commit 062c198
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 293 deletions.
41 changes: 16 additions & 25 deletions src/rgw/driver/d4n/d4n_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ bool LFUDAPolicy::invalidate_dirty_object(const DoutPrefixProvider* dpp, std::st
if (p->second.second == State::INIT) {
ldpp_dout(dpp, 10) << "LFUDAPolicy::" << __func__ << "(): Setting State::INVALID for key=" << key << dendl;
p->second.second = State::INVALID;
int ret = cacheDriver->set_attr(dpp, DIRTY_BLOCK_PREFIX + key, RGW_CACHE_ATTR_INVALID, "1", y);
int ret = cacheDriver->set_attr(dpp, key, RGW_CACHE_ATTR_INVALID, "1", y);
if (ret < 0) {
ldpp_dout(dpp, 0) << "LFUDAPolicy::" << __func__ << "(): Failed to set xattr, ret=" << ret << dendl;
return false;
Expand Down Expand Up @@ -433,11 +433,6 @@ void LFUDAPolicy::update(const DoutPrefixProvider* dpp, std::string& key, uint64
bool updateLocalWeight = true;
uint64_t refcount = 0;

std::string oid_in_cache = key;
if (dirty == true) {
oid_in_cache = DIRTY_BLOCK_PREFIX + key;
}

if (!restore_val.empty()) {
updateLocalWeight = false;
localWeight = std::stoull(restore_val);
Expand Down Expand Up @@ -473,7 +468,7 @@ void LFUDAPolicy::update(const DoutPrefixProvider* dpp, std::string& key, uint64

if (updateLocalWeight) {
int ret = -1;
if ((ret = cacheDriver->set_attr(dpp, oid_in_cache, RGW_CACHE_ATTR_LOCAL_WEIGHT, std::to_string(localWeight), y)) < 0)
if ((ret = cacheDriver->set_attr(dpp, key, RGW_CACHE_ATTR_LOCAL_WEIGHT, std::to_string(localWeight), y)) < 0)
ldpp_dout(dpp, 0) << "LFUDAPolicy::" << __func__ << "(): CacheDriver set_attr method failed, ret=" << ret << dendl;
}

Expand Down Expand Up @@ -550,20 +545,19 @@ int LFUDAPolicy::delete_data_blocks(const DoutPrefixProvider* dpp, LFUDAObjEntry
}
off_t cur_size = std::min<off_t>(fst + dpp->get_cct()->_conf->rgw_max_chunk_size, lst);
off_t cur_len = cur_size - fst;
std::string prefix = e->key + CACHE_DELIM + std::to_string(fst) + CACHE_DELIM + std::to_string(cur_len);
std::string oid_in_cache = DIRTY_BLOCK_PREFIX + prefix;
std::string oid_in_cache = e->key + CACHE_DELIM + std::to_string(fst) + CACHE_DELIM + std::to_string(cur_len);

int ret = -1;
std::unique_lock<std::mutex> ll(lfuda_lock);
auto it = entries_map.find(prefix);
auto it = entries_map.find(oid_in_cache);
if (it != entries_map.end()) {
if (it->second->refcount > 0) {
return -EBUSY;//better error code?
}
}
ll.unlock();
if ((ret = cacheDriver->delete_data(dpp, oid_in_cache, y)) == 0) { // Sam: do we want del or delete_data here?
if (!(ret = erase(dpp, prefix, y))) {
if (!(ret = erase(dpp, oid_in_cache, y))) {
ldpp_dout(dpp, 0) << "Failed to delete policy entry for: " << oid_in_cache << ", ret=" << ret << dendl;
return -EINVAL;
}
Expand Down Expand Up @@ -638,7 +632,7 @@ void LFUDAPolicy::cleaning(const DoutPrefixProvider* dpp)
continue;
}
ll.unlock();
if ((ret = cacheDriver->delete_data(dpp, DIRTY_BLOCK_PREFIX + e->key, y)) == 0) { // Sam: do we want del or delete_data here?
if ((ret = cacheDriver->delete_data(dpp, e->key, y)) == 0) { // Sam: do we want del or delete_data here?
if (!(ret = erase(dpp, e->key, y))) {
ldpp_dout(dpp, 0) << "Failed to delete head policy entry for: " << e->key << ", ret=" << ret << dendl; // TODO: what must occur during failure?
}
Expand Down Expand Up @@ -696,11 +690,8 @@ void LFUDAPolicy::cleaning(const DoutPrefixProvider* dpp)

ACLOwner owner{c_user->get_id(), c_user->get_display_name()};

std::string prefix = url_encode(e->bucket_id) + CACHE_DELIM + url_encode(e->version) + CACHE_DELIM + url_encode(c_obj->get_name());
std::string head_oid_in_cache = DIRTY_BLOCK_PREFIX + prefix;
std::string new_head_oid_in_cache = prefix;
std::string head_oid_in_cache = url_encode(e->bucket_id) + CACHE_DELIM + url_encode(e->version) + CACHE_DELIM + url_encode(c_obj->get_name());
ldpp_dout(dpp, 10) << __func__ << "(): head_oid_in_cache=" << head_oid_in_cache << dendl;
ldpp_dout(dpp, 10) << __func__ << "(): new_head_oid_in_cache=" << new_head_oid_in_cache << dendl;
int op_ret;
if (e->delete_marker) {
bool null_delete_marker = (c_obj->get_instance() == "null");
Expand Down Expand Up @@ -774,7 +765,7 @@ void LFUDAPolicy::cleaning(const DoutPrefixProvider* dpp)
}
off_t cur_size = std::min<off_t>(fst + dpp->get_cct()->_conf->rgw_max_chunk_size, lst);
off_t cur_len = cur_size - fst;
std::string oid_in_cache = DIRTY_BLOCK_PREFIX + prefix + CACHE_DELIM + std::to_string(fst) + CACHE_DELIM + std::to_string(cur_len);
std::string oid_in_cache = head_oid_in_cache + CACHE_DELIM + std::to_string(fst) + CACHE_DELIM + std::to_string(cur_len);
ldpp_dout(dpp, 10) << __func__ << "(): oid_in_cache=" << oid_in_cache << dendl;
rgw::sal::Attrs attrs;
cacheDriver->get(dpp, oid_in_cache, 0, cur_len, data, attrs, null_yield);
Expand Down Expand Up @@ -827,13 +818,10 @@ void LFUDAPolicy::cleaning(const DoutPrefixProvider* dpp)
off_t cur_size = std::min<off_t>(fst + dpp->get_cct()->_conf->rgw_max_chunk_size, lst);
off_t cur_len = cur_size - fst;

std::string oid_in_cache = DIRTY_BLOCK_PREFIX + prefix + CACHE_DELIM + std::to_string(fst) + CACHE_DELIM + std::to_string(cur_len);
std::string oid_in_cache = head_oid_in_cache + CACHE_DELIM + std::to_string(fst) + CACHE_DELIM + std::to_string(cur_len);
ldpp_dout(dpp, 20) << __func__ << "(): oid_in_cache =" << oid_in_cache << dendl;
std::string new_oid_in_cache = prefix + CACHE_DELIM + std::to_string(fst) + CACHE_DELIM + std::to_string(cur_len);
//Rename block to remove "D" prefix
cacheDriver->rename(dpp, oid_in_cache, new_oid_in_cache, null_yield);
//Update in-memory data structure for each block
this->update(dpp, new_oid_in_cache, 0, 0, e->version, false, 0, y);
this->update(dpp, oid_in_cache, 0, 0, e->version, false, 0, y);

rgw::d4n::CacheBlock block;
block.cacheObj.bucketName = c_obj->get_bucket()->get_bucket_id();
Expand All @@ -848,10 +836,8 @@ void LFUDAPolicy::cleaning(const DoutPrefixProvider* dpp)
} while(fst < lst);
} //end-else if delete_marker

cacheDriver->rename(dpp, head_oid_in_cache, new_head_oid_in_cache, null_yield);

//invoke update() with dirty flag set to false, to update in-memory metadata for head
this->update(dpp, new_head_oid_in_cache, 0, 0, e->version, false, 0, y);
this->update(dpp, head_oid_in_cache, 0, 0, e->version, false, 0, y);

if (null_instance) {
//restore instance for directory data processing in later steps
Expand Down Expand Up @@ -981,6 +967,11 @@ void LFUDAPolicy::cleaning(const DoutPrefixProvider* dpp)
break;
}//end-while (retry)
}

if ((ret = cacheDriver->set_attr(dpp, head_oid_in_cache, RGW_CACHE_ATTR_DIRTY, "0", y)) < 0) {
ldpp_dout(dpp, 0) << __func__ << "(): Failed to update dirty attr in cache, ret=" << op_ret << dendl;
// TODO: continue here?
}
//remove entry from map and queue, erase_dirty_object locks correctly
erase_dirty_object(dpp, e->key, null_yield);
}
Expand Down
Loading

0 comments on commit 062c198

Please sign in to comment.