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] improved list() function
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 12, 2022
1 parent 4a68874 commit dbe376c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
53 changes: 31 additions & 22 deletions src/rgw/motr/gc/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
*/

#include "motr/gc/gc.h"
#include "gc.h"
#include <ctime>

void *MotrGC::GCWorker::entry() {
Expand Down Expand Up @@ -105,27 +105,19 @@ void *MotrGC::GCWorker::entry() {
my_index = (my_index + 1) % motr_gc->max_indices;

// sleep for remaining duration
// if (end_time > current_time) sleep(end_time - current_time);
cv.wait_for(lk, std::chrono::seconds(rgw_gc_processor_period));

} while (! motr_gc->going_down());
uint32_t unutilized_time = (rgw_gc_processor_period - (end_time - start_time));
if (unutilized_time > 0) {
cv.wait_for(lk, std::chrono::seconds(unutilized_time));
}
} while (!motr_gc->going_down());

ldpp_dout(dpp, 0) << __func__ << ": Stop signal called for "
<< gc_thread_prefix << worker_id << dendl;
return nullptr;
}

void MotrGC::initialize() {
// fetch max gc indices from config
uint32_t rgw_gc_max_objs = cct->_conf->rgw_gc_max_objs;
if (rgw_gc_max_objs) {
rgw_gc_max_objs = pow(2, ceil(log2(rgw_gc_max_objs)));
max_indices = static_cast<int>(std::min(rgw_gc_max_objs,
GC_MAX_QUEUES));
}
else {
max_indices = GC_DEFAULT_QUEUES;
}
max_indices = get_max_indices();
index_names.reserve(max_indices);
ldpp_dout(this, 50) << __func__ << ": max_indices = " << max_indices << dendl;
for (uint32_t ind_suf = 0; ind_suf < max_indices; ind_suf++) {
Expand Down Expand Up @@ -188,6 +180,21 @@ bool MotrGC::going_down() {
return down_flag;
}

uint32_t MotrGC::get_max_indices() {
// fetch max gc indices from config
uint32_t rgw_gc_max_objs = cct->_conf->rgw_gc_max_objs;
uint32_t gc_max_indices = 0;
if (rgw_gc_max_objs) {
rgw_gc_max_objs = pow(2, ceil(log2(rgw_gc_max_objs)));
gc_max_indices = static_cast<uint32_t>(std::min(rgw_gc_max_objs,
GC_MAX_QUEUES));
}
else {
gc_max_indices = GC_DEFAULT_QUEUES;
}
return gc_max_indices;
}

int MotrGC::delete_motr_obj_from_gc(motr_gc_obj_info ginfo) {
int rc;
struct m0_op *op = nullptr;
Expand Down Expand Up @@ -335,23 +342,25 @@ int MotrGC::get_locked_gc_index(uint32_t& rand_ind) {
return rc;
}

int MotrGC::list(std::vector<std::unordered_map<std::string, std::string>>& gc_entries) {
int MotrGC::list(std::vector<std::unordered_map<std::string, std::string>> &gc_entries) {
int rc = 0;
int max_entries = 1000;
max_indices = get_max_indices();
for (uint32_t i = 0; i < max_indices; i++) {
std::vector<std::string> keys(max_entries + 1);
std::vector<bufferlist> vals(max_entries + 1);
keys[0] = obj_tag_prefix;
std::string marker = "";
bool truncated = false;
ldout(cct, 70) << "listing entries for " << index_names[i] << dendl;
keys[0] = obj_tag_prefix;
std::string iname = gc_index_prefix + "." + std::to_string(i);
ldout(cct, 70) << "listing entries for " << iname << dendl;
do {
if (!marker.empty())
if (!marker.empty()) {
keys[0] = marker;
rc = store->next_query_by_name(index_names[i], keys, vals,
obj_tag_prefix);
}
rc = store->next_query_by_name(iname, keys, vals, obj_tag_prefix);
if (rc < 0) {
ldpp_dout(this, 0) <<__func__<<": ERROR: NEXT query failed. rc="
ldout(cct, 0) <<__func__<<": ERROR: NEXT query failed. rc="
<< rc << dendl;
return rc;
}
Expand Down
19 changes: 11 additions & 8 deletions src/rgw/motr/gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
const uint32_t GC_DEFAULT_QUEUES = 64;
const uint32_t GC_DEFAULT_COUNT = 256;
const uint32_t GC_MAX_QUEUES = 4096;

static const std::string gc_index_prefix = "motr.rgw.gc";
static const std::string gc_thread_prefix = "motr_gc_";
static const std::string obj_tag_prefix = "0_";
Expand Down Expand Up @@ -71,13 +72,14 @@ struct motr_gc_obj_info {
std::string multipart_iname; // part index name

motr_gc_obj_info() {}
motr_gc_obj_info(std::string _tag, std::string _name, Meta _mobj,
std::time_t _deletion_time, std::uint64_t _size, std::uint64_t _size_actual,
bool _is_multipart, std::string _multipart_iname)
: tag(std::move(_tag)), name(std::move(_name)), mobj(std::move(_mobj)),
deletion_time(std::move(_deletion_time)), size(std::move(_size)),
size_actual(std::move(_size_actual)), is_multipart(std::move(_is_multipart)),
multipart_iname(std::move(_multipart_iname)) {}
motr_gc_obj_info(const std::string& _tag, const std::string& _name, Meta& _mobj,
const std::time_t& _deletion_time, const std::uint64_t& _size,
const std::uint64_t& _size_actual, bool _is_multipart,
const std::string& _multipart_iname)
: tag(_tag), name(_name), mobj(_mobj),
deletion_time(_deletion_time), size(_size),
size_actual(_size_actual), is_multipart(_is_multipart),
multipart_iname(_multipart_iname) {}

void encode(bufferlist &bl) const {
ENCODE_START(12, 2, bl);
Expand Down Expand Up @@ -164,9 +166,10 @@ class MotrGC : public DoutPrefixProvider {
void stop_processor();
bool going_down();

uint32_t get_max_indices();
int enqueue(motr_gc_obj_info obj);
int dequeue(std::string iname, motr_gc_obj_info obj);
int list(std::vector<std::unordered_map<std::string, std::string>>& gc_entries);
int list(std::vector<std::unordered_map<std::string, std::string>> &gc_entries);
int delete_motr_obj_from_gc(motr_gc_obj_info ginfo);
int get_locked_gc_index(uint32_t& rand_ind);

Expand Down
3 changes: 2 additions & 1 deletion src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7816,7 +7816,7 @@ int main(int argc, const char **argv)
ldpp_dout(dpp(), 20) << "Listing GC objects from Motr" << dendl;
std::vector<std::unordered_map<std::string, std::string>> gc_entries;
formatter->open_array_section("entries");
int ret = static_cast<rgw::sal::MotrStore*>(store)->list_gc_objs(dpp(), gc_entries);
int ret = static_cast<rgw::sal::MotrStore*>(store)->list_gc_objs(gc_entries);
if (ret < 0) {
cerr << "ERROR: failed to list objs: " << cpp_strerror(-ret) << std::endl;
return 1;
Expand All @@ -7833,6 +7833,7 @@ int main(int argc, const char **argv)
}
formatter->close_section();
formatter->flush(cout);
exit(0);
#endif

formatter->open_array_section("entries");
Expand Down
7 changes: 4 additions & 3 deletions src/rgw/rgw_sal_motr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4834,13 +4834,14 @@ int MotrStore::store_email_info(const DoutPrefixProvider *dpp, optional_yield y,
return rc;
}

int MotrStore::list_gc_objs(const DoutPrefixProvider *dpp,
std::vector<std::unordered_map<std::string, std::string>>& gc_entries)
int MotrStore::list_gc_objs(std::vector<std::unordered_map<std::string, std::string>>& gc_entries)
{
int rc = motr_gc->list(gc_entries);
auto gc = new MotrGC(cctx, this);
int rc = gc->list(gc_entries);
if (rc < 0) {
ldout(cctx, 0) <<__func__<< ": failed to list gc items: rc=" << rc << dendl;
}
delete gc;
return rc;
}

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 @@ -1125,7 +1125,7 @@ class MotrStore : public Store {
luarocks_path = path;
}

int list_gc_objs(const DoutPrefixProvider *dpp, std::vector<std::unordered_map<std::string, std::string>>& gc_entries);
int list_gc_objs(std::vector<std::unordered_map<std::string, std::string>>& gc_entries);
void close_idx(struct m0_idx *idx) { m0_idx_fini(idx); }
int do_idx_op(struct m0_idx *, enum m0_idx_opcode opcode,
std::vector<uint8_t>& key, std::vector<uint8_t>& val, bool update = false);
Expand Down

0 comments on commit dbe376c

Please sign in to comment.