std::string oid_in_cache = key;
if (dirty == true) {
- oid_in_cache = "D_" + key;
+ oid_in_cache = DIRTY_BLOCK_PREFIX + key;
}
if (!restore_val.empty()) {
erase_dirty_object(dpp, e->key, null_yield);
}
- std::string prefix = e->bucket_id + "_" + e->version + "_" + c_obj->get_name();
+ std::string prefix = url_encode(e->bucket_id) + CACHE_DELIM + url_encode(e->version) + CACHE_DELIM + url_encode(c_obj->get_name());
off_t lst = e->size;
off_t fst = 0;
off_t ofs = 0;
rgw::sal::DataProcessor* filter = processor.get();
- std::string head_oid_in_cache = "D_" + prefix;
+ std::string head_oid_in_cache = DIRTY_BLOCK_PREFIX + prefix;
std::string new_head_oid_in_cache = prefix;
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;
}
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 = "D_" + prefix + "_" + std::to_string(fst) + "_" + std::to_string(cur_len);
+ std::string oid_in_cache = DIRTY_BLOCK_PREFIX + prefix + 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);
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 = "D_" + prefix + "_" + std::to_string(fst) + "_" + std::to_string(cur_len);
+ std::string oid_in_cache = DIRTY_BLOCK_PREFIX + prefix + 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 + "_" + std::to_string(fst) + "_" + std::to_string(cur_len);
+ 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
std::string key = get_cache_block_prefix(dest_object, dest_version, false);
std::string head_oid_in_cache;
if (dirty) {
- head_oid_in_cache = std::format("{}{}","D_", key); //same as key, as there is no len or offset attached to head oid in cache
+ head_oid_in_cache = std::format("{}{}",DIRTY_BLOCK_PREFIX, key); //same as key, as there is no len or offset attached to head oid in cache
} else {
head_oid_in_cache = key;
}
return ret;
}
if (dirty) {
- std::string object_key = dest_object->get_bucket()->get_bucket_id() + "_" + dest_object->get_oid();
- driver->get_policy_driver()->get_cache_policy()->update_dirty_object(dpp, object_key, dest_version, true, this->get_size(), creationTime, std::get<rgw_user>(dest_object->get_bucket()->get_owner()), *etag, dest_object->get_bucket()->get_name(), dest_object->get_bucket()->get_bucket_id(), dest_object->get_key(), y);
+ driver->get_policy_driver()->get_cache_policy()->update_dirty_object(dpp, key, dest_version, true, this->get_size(), creationTime, std::get<rgw_user>(dest_object->get_bucket()->get_owner()), *etag, dest_object->get_bucket()->get_name(), dest_object->get_bucket()->get_bucket_id(), dest_object->get_key(), y);
}
}
}
std::string key = get_key_in_cache(get_cache_block_prefix(this, version, false), std::to_string(fst), std::to_string(cur_len));
std::string key_in_cache;
if (dirty) {
- key_in_cache = std::format("{}{}","D_", key);
+ key_in_cache = std::format("{}{}",DIRTY_BLOCK_PREFIX, key);
} else {
key_in_cache = key;
}
dest_block.cacheObj.hostsList.insert(dpp->get_cct()->_conf->rgw_d4n_l1_datacache_address);
dest_block.version = dest_version;
dest_block.cacheObj.dirty = true;
- std::string prefix = get_cache_block_prefix(source->dest_object, dest_version, false);
std::string key = get_key_in_cache(get_cache_block_prefix(source->dest_object, dest_version, false), std::to_string(ofs), std::to_string(len));
- std::string dest_oid_in_cache = std::format("{}{}","D_", key);
+ std::string dest_oid_in_cache = std::format("{}{}",DIRTY_BLOCK_PREFIX, key);
auto ret = source->driver->get_policy_driver()->get_cache_policy()->eviction(dpp, dest_block.size, y);
if (ret == 0) {
rgw::sal::Attrs attrs;
ldpp_dout(dpp, 20) << "D4NFilterObject::iterate:: " << __func__ << "(): READ FROM CACHE: block is dirty = " << block.cacheObj.dirty << dendl;
if (block.cacheObj.dirty == true) {
- key = "D_" + oid_in_cache; // we keep track of dirty data in the cache for the metadata failure case
+ key = DIRTY_BLOCK_PREFIX + oid_in_cache; // we keep track of dirty data in the cache for the metadata failure case
ldpp_dout(dpp, 20) << "D4NFilterObject::iterate:: " << __func__ << "(): READ FROM CACHE: key=" << key << " data is Dirty." << dendl;
}
if ((part_len != chunk_size) && source->driver->get_policy_driver()->get_cache_policy()->exist_key(oid_in_cache) > 0) {
// Read From Cache
if (block.cacheObj.dirty == true){
- key = "D_" + oid_in_cache; //we keep track of dirty data in the cache for the metadata failure case
+ key = DIRTY_BLOCK_PREFIX + oid_in_cache;
}
ldpp_dout(dpp, 20) << "D4NFilterObject::iterate:: " << __func__ << "(): " << __LINE__ << ": READ FROM CACHE: block dirty =" << block.cacheObj.dirty << dendl;
bl_rem.claim_append(bl_copy);
if (bl_rem.length() == rgw_max_chunk_size) {
- std::string oid = get_key_in_cache(prefix, std::to_string(adjusted_start_ofs), std::to_string(bl_rem.length()));
+ std::string oid = prefix + CACHE_DELIM + std::to_string(adjusted_start_ofs) + CACHE_DELIM + std::to_string(bl_rem.length());
if (!filter->get_policy_driver()->get_cache_policy()->exist_key(oid)) {
block.blockID = adjusted_start_ofs;
block.size = bl_rem.length();
if (source->dest_object && source->dest_bucket) {
D4NFilterObject* d4n_dest_object = dynamic_cast<D4NFilterObject*>(source->dest_object);
std::string dest_version = d4n_dest_object->get_object_version();
- std::string dest_oid = get_key_in_cache(dest_prefix, std::to_string(adjusted_start_ofs), std::to_string(bl_rem.length()));
+ std::string dest_oid = dest_prefix + CACHE_DELIM + std::to_string(adjusted_start_ofs) + CACHE_DELIM + std::to_string(bl_rem.length());
dest_block.blockID = adjusted_start_ofs;
dest_block.size = bl_rem.length();
auto ret = filter->get_policy_driver()->get_cache_policy()->eviction(dpp, dest_block.size, *y);
}
if (block.cacheObj.dirty)
- prefix = "D_" + prefix;
+ prefix = DIRTY_BLOCK_PREFIX + prefix;
std::string oid_in_cache = get_key_in_cache(prefix, std::to_string(fst), std::to_string(cur_len));
if (!objDirty) { // object written to backend
return next->delete_obj(dpp, y, flags);
} else {
- std::string object_key = source->get_bucket()->get_bucket_id() + "_" + source->get_oid();
- if (!(ret = source->driver->get_policy_driver()->get_cache_policy()->erase_dirty_object(dpp, object_key, y))) {
+ std::string key = policy_prefix;
+ if (!(ret = source->driver->get_policy_driver()->get_cache_policy()->erase_dirty_object(dpp, key, y))) {
ldpp_dout(dpp, 0) << "Failed to delete policy object entry for: " << source->get_name() << ", ret=" << ret << dendl;
return -ENOENT;
} else {
return next->process(std::move(data), offset);
} else {
rgw::sal::Attrs attrs;
- std::string oid = prefix + "_" + std::to_string(ofs);
- std::string key = "D_" + oid + "_" + std::to_string(bl_len);
- std::string oid_in_cache = oid + "_" + std::to_string(bl_len);
+ std::string oid = prefix + CACHE_DELIM + std::to_string(ofs);
+ std::string key = DIRTY_BLOCK_PREFIX + oid + CACHE_DELIM + std::to_string(bl_len);
+ std::string oid_in_cache = oid + CACHE_DELIM + std::to_string(bl_len);
dirty = true;
ret = driver->get_policy_driver()->get_cache_policy()->eviction(dpp, bl.length(), y);
if (ret == 0) {
std::string head_oid_in_cache;
//same as key, as there is no len or offset attached to head oid in cache
if (dirty) {
- head_oid_in_cache = std::format("{}{}","D_", key);;
+ head_oid_in_cache = std::format("{}{}",DIRTY_BLOCK_PREFIX, key);;
} else {
head_oid_in_cache = key;
}
return ret;
}
if (dirty) {
- //using object oid here so that version is automatically picked for versioned buckets, and for non-versioned buckets the old version is replaced by the latest version
- std::string object_key = obj->get_bucket()->get_bucket_id() + "_" + obj->get_oid();
auto creationTime = ceph::real_clock::to_time_t(object->get_mtime());
- ldpp_dout(dpp, 16) << "D4NFilterWriter::" << __func__ << "(): object_key=" << object_key << dendl;
- driver->get_policy_driver()->get_cache_policy()->update_dirty_object(dpp, object_key, version, dirty, accounted_size, creationTime, std::get<rgw_user>(obj->get_bucket()->get_owner()), objEtag, obj->get_bucket()->get_name(), obj->get_bucket()->get_bucket_id(), obj->get_key(), y);
+ ldpp_dout(dpp, 16) << "D4NFilterWriter::" << __func__ << "(): key=" << key << dendl;
+ driver->get_policy_driver()->get_cache_policy()->update_dirty_object(dpp, key, version, dirty, accounted_size, creationTime, std::get<rgw_user>(obj->get_bucket()->get_owner()), objEtag, obj->get_bucket()->get_name(), obj->get_bucket()->get_bucket_id(), obj->get_key(), y);
}
} else { //if get_cache_driver()->put()
ldpp_dout(dpp, 0) << "D4NFilterWriter::" << __func__ << "(): put failed for head_oid_in_cache, ret=" << ret << dendl;
inline std::string get_cache_block_prefix(rgw::sal::Object* object, const std::string& version, bool is_dirty)
{
if (is_dirty) {
- //return "D_" + object->get_bucket()->get_bucket_id() + "_" + version + "_" + object->get_name();
- return fmt::format("{}{}{}{}{}{}", "D_", object->get_bucket()->get_bucket_id(), "_", version, "_", object->get_name());
+ return fmt::format("{}{}{}{}{}{}", DIRTY_BLOCK_PREFIX, object->get_bucket()->get_bucket_id(), CACHE_DELIM, version, CACHE_DELIM, object->get_name());
} else {
- //return object->get_bucket()->get_bucket_id() + "_" + version + "_" + object->get_name();
- return fmt::format("{}{}{}{}{}", object->get_bucket()->get_bucket_id(), "_", version, "_", object->get_name());
+ return fmt::format("{}{}{}{}{}", object->get_bucket()->get_bucket_id(), CACHE_DELIM, version, CACHE_DELIM, object->get_name());
}
}
inline std::string get_key_in_cache(const std::string& prefix, const std::string& offset, const std::string& len)
{
- return fmt::format("{}{}{}{}{}", prefix, "_", offset, "_", len);
+ return fmt::format("{}{}{}{}{}", prefix, CACHE_DELIM, offset, CACHE_DELIM, len);
}
using boost::redis::connection;
constexpr char RGW_CACHE_ATTR_SOURC_ZONE[] = "user.rgw.source_zone";
constexpr char RGW_CACHE_ATTR_LOCAL_WEIGHT[] = "user.rgw.localWeight";
+constexpr char DIRTY_BLOCK_PREFIX[] = "D#";
+constexpr char CACHE_DELIM = '#';
+
namespace rgw { namespace cache {
typedef std::function<void(const DoutPrefixProvider* dpp, const std::string& key, const std::string& version, bool dirty, uint64_t size,
namespace rgw { namespace cache {
+static inline std::string get_file_path(const std::string& location, const std::string& key)
+{
+ return location + "/" + key;
+}
+
int SSDDriver::initialize(const DoutPrefixProvider* dpp)
{
if(partition_info.location.back() != '/') {
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): filename: " << file_name << dendl;
try {
std::stringstream ss(file_name);
- while (std::getline(ss, part, '_')) {
+ while (std::getline(ss, part, CACHE_DELIM)) {
parts.push_back(part);
}
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): parts.size(): " << parts.size() << dendl;
std::string key = file_name;
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): file_name: " << file_name << dendl;
- std::string version = parts[1];
+ std::string version = url_decode(parts[1]);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): version: " << version << dendl;
uint64_t offset = 0, len = 0;
}
//dirty blocks - "D", bucket_id, version, object_name in head block and offset, len in data blocks
if ((parts.size() == 4 || parts.size() == 6) && parts[0] == "D") {
- std::string prefix = "D_";
+ std::string prefix = DIRTY_BLOCK_PREFIX;
if (file_name.starts_with(prefix)) {
std::string key = file_name.substr(prefix.length());
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): key: " << key << dendl;
bool dirty = true;
- std::string bucket_id = parts[1];
+ std::string bucket_id = url_decode(parts[1]);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): bucket_id: " << bucket_id << dendl;
- std::string version = parts[2];
+ std::string version = url_decode(parts[2]);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): version: " << version << dendl;
- std::string obj_name = parts[3];
+ std::string obj_name = url_decode(parts[3]);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): obj_name: " << obj_name << dendl;
uint64_t len = 0, offset = 0;
int SSDDriver::get(const DoutPrefixProvider* dpp, const std::string& key, off_t offset, uint64_t len, bufferlist& bl, rgw::sal::Attrs& attrs, optional_yield y)
{
char buffer[len];
- std::string location = partition_info.location + "/" + url_encode(key, true);
-
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << __func__ << "(): location=" << location << dendl;
FILE *cache_file = nullptr;
int r = 0;
int SSDDriver::append_data(const DoutPrefixProvider* dpp, const::std::string& key, const bufferlist& bl_data, optional_yield y)
{
bufferlist src = bl_data;
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << __func__ << "(): location=" << location << dendl;
FILE *cache_file = nullptr;
auto p = Op::create(ex, handler);
auto& op = p->user_data;
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
int ret = op.prepare_libaio_read_op(dpp, location, read_ofs, read_len, p.get());
auto p = Op::create(ex, handler);
auto& op = p->user_data;
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
int r = 0;
int SSDDriver::delete_data(const DoutPrefixProvider* dpp, const::std::string& key, optional_yield y)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
if (!efs::remove(location)) {
ldpp_dout(dpp, 0) << "ERROR: delete_data::remove has failed to remove the file: " << location << dendl;
int SSDDriver::rename(const DoutPrefixProvider* dpp, const::std::string& oldKey, const::std::string& newKey, optional_yield y)
{
- std::string location = partition_info.location;
-
- int ret = std::rename((location + "/" + url_encode(oldKey, true)).c_str(), (location + "/" + url_encode(newKey, true)).c_str());
+ std::string old_file_path = get_file_path(partition_info.location, oldKey);
+ std::string new_file_path = get_file_path(partition_info.location, newKey);
+ int ret = std::rename(old_file_path.c_str(), new_file_path.c_str());
if (ret < 0) {
- ldpp_dout(dpp, 0) << "SSDDriver: ERROR: failed to rename the file: " << location + "/" + url_encode(oldKey, true) << dendl;
+ ldpp_dout(dpp, 0) << "SSDDriver: ERROR: failed to rename the file: " << old_file_path << dendl;
return ret;
}
int SSDDriver::AsyncWriteRequest::prepare_libaio_write_op(const DoutPrefixProvider *dpp, bufferlist& bl, unsigned int len, std::string key, std::string cache_location)
{
- std::string location = cache_location + "/" + url_encode(key, true);
+ std::string location = get_file_path(cache_location, key);
int r = 0;
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): Write To Cache, location=" << location << dendl;
cb.reset(new struct aiocb);
efs::space_info space = efs::space(partition_info.location);
op.priv_data->set_free_space(op.dpp, space.available);
- std::string new_path = partition_info.location + "/" + url_encode(op.key, true);
- std::string old_path = partition_info.location + "/" + url_encode(op.temp_key, true);
-
+ std::string new_path = get_file_path(partition_info.location, op.key);
+ std::string old_path = get_file_path(partition_info.location, op.temp_key);
ldpp_dout(op.dpp, 20) << "INFO: AsyncWriteRequest::libaio_write_yield_cb: temp_key: " << op.temp_key << dendl;
ret = std::rename(old_path.c_str(), new_path.c_str());
int SSDDriver::update_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
for (auto& it : attrs) {
int SSDDriver::delete_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& del_attrs, optional_yield y)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
for (auto& it : del_attrs) {
int SSDDriver::get_attrs(const DoutPrefixProvider* dpp, const std::string& key, rgw::sal::Attrs& attrs, optional_yield y)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
char namebuf[64 * 1024];
int SSDDriver::set_attrs(const DoutPrefixProvider* dpp, const std::string& key, const rgw::sal::Attrs& attrs, optional_yield y)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
for (auto& [attr_name, attr_val_bl] : attrs) {
int SSDDriver::get_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, std::string& attr_val, optional_yield y)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): get_attr: key: " << attr_name << dendl;
int SSDDriver::set_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name, const std::string& attr_val, optional_yield y)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): set_attr: key: " << attr_name << " val: " << attr_val << dendl;
int SSDDriver::delete_attr(const DoutPrefixProvider* dpp, const std::string& key, const std::string& attr_name)
{
- std::string location = partition_info.location + "/" + url_encode(key, true);
+ std::string location = get_file_path(partition_info.location, key);
ldpp_dout(dpp, 20) << "SSDCache: " << __func__ << "(): location=" << location << dendl;
auto ret = removexattr(location.c_str(), attr_name.c_str());