Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
rgw: [CORTX-32688] updated logic for listing gc objects
Browse files Browse the repository at this point in the history
Signed-off-by: Jeet Jain <jeet.jain@seagate.com>
  • Loading branch information
jjxsg committed Aug 9, 2022
2 parents 41ebaec + 238130f commit ccc74ed
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 55 deletions.
10 changes: 6 additions & 4 deletions src/rgw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,12 @@ set(radosgw_admin_srcs
rgw_sync_checkpoint.cc
rgw_orphan.cc)
add_executable(radosgw-admin ${radosgw_admin_srcs})
target_include_directories(radosgw-admin PRIVATE "/usr/include/motr")
target_compile_options(radosgw-admin PRIVATE "-Wno-attributes")
target_compile_definitions(radosgw-admin
PRIVATE "M0_EXTERN=extern" "M0_INTERNAL=")
if(WITH_RADOSGW_MOTR)
target_include_directories(radosgw-admin PRIVATE "/usr/include/motr")
target_compile_options(radosgw-admin PRIVATE "-Wno-attributes")
target_compile_definitions(radosgw-admin
PRIVATE "M0_EXTERN=extern" "M0_INTERNAL=")
endif()
target_link_libraries(radosgw-admin ${rgw_libs} librados
cls_rgw_client cls_otp_client cls_lock_client cls_refcount_client
cls_log_client cls_timeindex_client neorados_cls_fifo
Expand Down
100 changes: 57 additions & 43 deletions src/rgw/motr/gc/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,48 @@ void *MotrGC::GCWorker::entry() {
iname = motr_gc->index_names[my_index];
ldpp_dout(dpp, 10) << __func__ << ": " << gc_thread_prefix
<< worker_id << " Working on GC Queue: " << iname << dendl;
// time based while loop
do {
bufferlist bl;
std::vector<std::string>keys(motr_gc->max_count + 1);
std::vector<bufferlist>vals(motr_gc->max_count + 1);
uint32_t rgw_gc_obj_min_wait = cct->_conf->rgw_gc_obj_min_wait;
rc = motr_gc->store->next_query_by_name(iname,
keys, vals, obj_exp_time_prefix);
if (rc < 0) {
// In case of failure, worker will keep retrying till end_time
ldpp_dout(dpp, 0) <<__func__<<": ERROR: NEXT query failed. rc=" << rc << dendl;
}

bufferlist bl;
std::vector<std::string> keys(motr_gc->max_count + 1);
std::vector<bufferlist> vals(motr_gc->max_count + 1);
uint32_t rgw_gc_obj_min_wait = cct->_conf->rgw_gc_obj_min_wait;
rc = motr_gc->store->next_query_by_name(iname,
keys, vals, obj_tag_prefix);
ldpp_dout(dpp, 0) <<__func__<<": next_query_by_name() rc=" << rc << dendl;
if (rc < 0) {
// In case of failure, worker will keep retrying till end_time
ldpp_dout(dpp, 0) <<__func__<<": ERROR: NEXT query failed. rc=" << rc << dendl;
continue;
}

// fetch entries as per defined in rgw_gc_max_trim_chunk from index iname
for (uint32_t j = 0; j < motr_gc->max_count && !keys[j].empty(); j++) {
bufferlist::const_iterator blitr = vals[j].cbegin();
motr_gc_obj_info ginfo;
ginfo.decode(blitr);
// check if the object is ready for deletion
if(ginfo.deletion_time + rgw_gc_obj_min_wait < std::time(nullptr)) {
// delete motr object
rc = motr_gc->delete_motr_obj_from_gc(ginfo);
if (rc < 0) {
ldpp_dout(dpp, 0) << "ERROR: Motr obj deletion failed for "
<< ginfo.tag << " with rc: " << rc << dendl;
continue; // should continue deletion for next objects
}
// delete entry from GC queue
rc = motr_gc->dequeue(iname, ginfo);
processed_count++;
}
// Exit the loop if required work is complete
if (processed_count >= motr_gc->max_count) break;
// fetch entries as per defined in rgw_gc_max_trim_chunk from index iname
for (uint32_t j = 0; j < motr_gc->max_count && !keys[j].empty(); j++) {
bufferlist::const_iterator blitr = vals[j].cbegin();
motr_gc_obj_info ginfo;
ginfo.decode(blitr);
// Check if the object is ready for deletion
if(ginfo.deletion_time + rgw_gc_obj_min_wait > std::time(nullptr)) {
// No more expired object for deletion
break;
}
// delete motr object
rc = motr_gc->delete_motr_obj_from_gc(ginfo);
if (rc < 0) {
ldpp_dout(dpp, 0) << "ERROR: Motr obj deletion failed for "
<< ginfo.tag << " with rc: " << rc << dendl;
continue; // should continue deletion for next objects
}
// delete entry from GC queue
rc = motr_gc->dequeue(iname, ginfo);
processed_count++;

// Update current time
current_time = std::time(nullptr);
} while (current_time < end_time && !motr_gc->going_down()
&& processed_count < motr_gc->max_count);
// Exit the loop if required work is complete
if (processed_count >= motr_gc->max_count
|| current_time > end_time || motr_gc->going_down())
break;
}
// unlock the GC queue
}
my_index = (my_index + 1) % motr_gc->max_indices;
Expand Down Expand Up @@ -178,10 +182,10 @@ int MotrGC::delete_motr_obj_from_gc(motr_gc_obj_info ginfo) {
snprintf(fid_str, ARRAY_SIZE(fid_str), U128X_F, U128_P(&ginfo.mobj.oid));

if (!ginfo.mobj.oid.u_hi || !ginfo.mobj.oid.u_lo) {
ldout(cct, 20) <<__func__<< ": invalid motr object oid=" << fid_str << dendl;
ldout(cct, 0) <<__func__<< ": invalid motr object oid=" << fid_str << dendl;
return -EINVAL;
}
ldout(cct, 20) <<__func__<< ": deleting motr object oid=" << fid_str << dendl;
ldout(cct, 10) <<__func__<< ": deleting motr object oid=" << fid_str << dendl;

// Open the object.
if (ginfo.mobj.layout_id == 0) {
Expand Down Expand Up @@ -220,6 +224,7 @@ int MotrGC::delete_motr_obj_from_gc(motr_gc_obj_info ginfo) {
op = nullptr;
mobj->ob_entity.en_flags |= M0_ENF_META;
rc = m0_entity_delete(&mobj->ob_entity, &op);
ldout(cct, 20) <<__func__<< ": m0_entity_delete() rc=" << rc << dendl;
if (rc != 0) {
ldout(cct, 0) <<__func__<< ": ERROR: m0_entity_delete() failed. rc=" << rc << dendl;
return rc;
Expand All @@ -232,13 +237,16 @@ int MotrGC::delete_motr_obj_from_gc(motr_gc_obj_info ginfo) {
m0_op_free(op);

if (rc < 0) {
ldout(cct, 0) <<__func__<< ": ERROR: failed to open motr object for deletion. rc=" << rc << dendl;
ldout(cct, 0) <<__func__<< ": ERROR: failed to open motr object for deletion. rc="
<< rc << dendl;
return rc;
}
if (mobj != nullptr) {
m0_obj_fini(mobj);
delete mobj; mobj = nullptr;
}
ldout(cct, 10) <<__func__<< ": deleted motr object oid="
<< fid_str << " for tag=" << ginfo.tag << dendl;
return 0;
}

Expand All @@ -258,7 +266,6 @@ int MotrGC::enqueue(motr_gc_obj_info obj) {
M0_IC_PUT, key1, bl);
if (rc < 0)
return rc;

// push {0_ObjTag: motr_gc_obj_info} to the gc queue.📥
rc = store->do_idx_op_by_name(index_names[enqueue_index],
M0_IC_PUT, key2, bl);
Expand All @@ -280,15 +287,21 @@ int MotrGC::enqueue(motr_gc_obj_info obj) {
int MotrGC::dequeue(std::string iname, motr_gc_obj_info obj) {
int rc;
bufferlist bl;
rc = store->do_idx_op_by_name(iname, M0_IC_DEL, obj.tag, bl);
std::string tag_key = obj_tag_prefix + obj.tag;
std::string expiry_time_key = obj_exp_time_prefix +
std::to_string(obj.deletion_time + cct->_conf->rgw_gc_obj_min_wait);
rc = store->do_idx_op_by_name(iname, M0_IC_DEL, tag_key, bl);
if (rc < 0) {
ldout(cct, 0) << "ERROR: failed to delete tag entry "<<obj.tag<<" rc: " << rc << dendl;
ldout(cct, 0) << "ERROR: failed to delete tag entry "
<< tag_key << " rc: " << rc << dendl;
}
rc = store->do_idx_op_by_name(
iname, M0_IC_DEL, std::to_string(obj.deletion_time), bl);
ldout(cct, 10) << "Deleted tag entry "<< tag_key << dendl;
rc = store->do_idx_op_by_name(iname, M0_IC_DEL, expiry_time_key, bl);
if (rc < 0 && rc != -EEXIST) {
ldout(cct, 0) << "ERROR: failed to delete time entry "<<obj.deletion_time<<" rc: " << rc << dendl;
ldout(cct, 0) << "ERROR: failed to delete time entry "
<< expiry_time_key << " rc: " << rc << dendl;
}
ldout(cct, 10) << "Deleted time entry "<< expiry_time_key << dendl;
return rc;
}

Expand All @@ -304,6 +317,7 @@ int MotrGC::get_locked_gc_index(uint32_t& rand_ind) {
if (rc == 0)
break;
}
rc = 0; // remove this line after lock implementation
rand_ind = new_index;
return rc;
}
Expand Down
10 changes: 6 additions & 4 deletions src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ extern "C" {
#include "rgw_bucket_sync.h"
#include "rgw_sync_checkpoint.h"
#include "rgw_lua.h"

#ifdef WITH_RADOSGW_MOTR
#include "rgw_sal_motr.h"
#endif

#include "services/svc_sync_modules.h"
#include "services/svc_cls.h"
Expand Down Expand Up @@ -236,7 +239,6 @@ void usage()
cout << " usage clear reset all the usage stats for the cluster\n";
cout << " gc list dump expired garbage collection objects (specify\n";
cout << " --include-all to list all entries, including unexpired)\n";
cout << " gc list-motr dump expired garbage collection objects for motr backend\n";
cout << " gc process manually process garbage (specify\n";
cout << " --include-all to process all entries, including unexpired)\n";
cout << " lc list list all bucket lifecycle progress\n";
Expand Down Expand Up @@ -7819,12 +7821,12 @@ int main(int argc, const char **argv)
cerr << "ERROR: failed to list objs: " << cpp_strerror(-ret) << std::endl;
return 1;
}
for (auto iter = gc_entries.begin(); iter != gc_entries.end(); ++iter){
std::unordered_map<std::string, std::string>& ginfo = *iter;
for (auto iter = gc_entries.begin(); iter != gc_entries.end(); ++iter) {
std::unordered_map<std::string, std::string> &ginfo = *iter;
formatter->open_object_section("");
formatter->dump_string("tag", ginfo["tag"]);
formatter->dump_string("name", ginfo["name"]);
formatter->dump_string("deletion_time", ginfo["deletion_time"]);
formatter->dump_string("deletion_time", ginfo["deletion_time"]);
formatter->dump_string("size", ginfo["size"]);
formatter->dump_string("size_actual", ginfo["size_actual"]);
formatter->close_section();
Expand Down
8 changes: 5 additions & 3 deletions src/rgw/rgw_sal_motr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1705,9 +1705,6 @@ int MotrObject::fetch_obj_entry_and_key(const DoutPrefixProvider* dpp, rgw_bucke

int MotrObject::set_obj_attrs(const DoutPrefixProvider* dpp, RGWObjectCtx* rctx, Attrs* setattrs, Attrs* delattrs, optional_yield y, rgw_obj* target_obj)
{
// TODO : Set tags for multipart objects
if (this->category == RGWObjCategory::MultiMeta)
return 0;

rgw_bucket_dir_entry ent;
string bname, key;
Expand Down Expand Up @@ -3242,6 +3239,11 @@ int MotrObject::get_bucket_dir_ent(const DoutPrefixProvider *dpp, rgw_bucket_dir
key.set(ent.key);
obj_key = key.name + '\a' + key.instance;

// Set the instance value as "null" to show
// the VersionId field in the GET/HEAD object response
if (this->get_key().have_null_instance())
ent.key.instance = "null";

// Put into the cache
this->store->get_obj_meta_cache()->put(dpp, obj_key, bl);

Expand Down
2 changes: 1 addition & 1 deletion src/rgw/rgw_sal_motr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ class MotrStore : public Store {
int store_access_key(const DoutPrefixProvider *dpp, optional_yield y, MotrAccessKey access_key);
int delete_access_key(const DoutPrefixProvider *dpp, optional_yield y, std::string access_key);
int store_email_info(const DoutPrefixProvider *dpp, optional_yield y, MotrEmailInfo& email_info);

int init_metadata_cache(const DoutPrefixProvider *dpp, CephContext *cct);
MotrMetaCache* get_obj_meta_cache() {return obj_meta_cache;}
MotrMetaCache* get_user_cache() {return user_cache;}
Expand Down

0 comments on commit ccc74ed

Please sign in to comment.