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

Commit

Permalink
motr_gc: [CORTX-32689] Validate GC for simple object delete API (#393)
Browse files Browse the repository at this point in the history
- Fix issues in locking mechanism.

Signed-off-by: Dattaprasad Govekar <dattaprasad.govekar@seagate.com>

Signed-off-by: Dattaprasad Govekar <dattaprasad.govekar@seagate.com>
  • Loading branch information
DPG17 authored Aug 16, 2022
1 parent eb0414a commit 9155311
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/rgw/motr/gc/gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ int MotrGC::initialize() {
ldout(cct, 0) << "ERROR: GC index creation failed with rc: " << rc << dendl;
break;
}
if (rc == -EEXIST) rc = 0;
index_names.push_back(iname);
}
// Get the max count of objects to be deleted in 1 processing cycle
Expand Down Expand Up @@ -356,19 +357,26 @@ int MotrGC::get_locked_gc_index(uint32_t& rand_ind,
uint32_t& lease_duration) {
int rc = -1;
uint32_t new_index = 0;
std::shared_ptr<MotrSync>& gc_lock = get_lock_instance();

// attempt to lock GC starting with passed in index
for (uint32_t ind = 0; ind < max_indices; ind++) {
new_index = (ind + rand_ind) % max_indices;
// try locking index
std::shared_ptr<MotrSync>& gc_lock = get_lock_instance();
if (gc_lock) {
std::chrono::milliseconds lease_timeout{lease_duration * 1000};
auto tv = ceph::to_timeval(lease_timeout);
utime_t gc_lease_duration;
gc_lease_duration.set_from_timeval(&tv);
std::string iname = index_names[new_index];
// try locking index
rc = gc_lock->lock(iname, MotrLockType::EXCLUSIVE,
gc_lease_duration, caller_id);
if (rc < 0) {
ldout(cct, 10) << "Failed to acquire lock: GC Queue =["<< iname << "]"
<< "caller_id =[" << caller_id << "]" << "rc = " << rc << dendl;
} else {
ldout(cct, 10) << "Acquired lock for GC Queue =["<< iname << "]" << dendl;
}
}
if (rc == 0)
break;
Expand Down
9 changes: 7 additions & 2 deletions src/rgw/motr/sync/motr_sync_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ int MotrLock::unlock(const std::string& lock_name,
int MotrKVLockProvider::initialize(const DoutPrefixProvider* dpp,
rgw::sal::MotrStore* _s,
const std::string& lock_index_name) {
int rc = 0;
_dpp = dpp;
_store = _s;
_lock_index = lock_index_name;
if (!_store || lock_index_name.empty()) {
return -EINVAL;
}
return _store->create_motr_idx_by_name(lock_index_name);
rc = _store->create_motr_idx_by_name(lock_index_name);
if (rc == -EEXIST) rc = 0;
return rc;
}

int MotrLock::check_lock(const std::string& lock_name,
Expand Down Expand Up @@ -193,7 +196,9 @@ std::shared_ptr<MotrSync> g_motr_lock;
std::shared_ptr<MotrSync>& get_lock_instance(
std::unique_ptr<MotrLockProvider>& lock_provider) {
static bool initialize = false;
if (!initialize && !lock_provider) {
std::mutex lock;
std::lock_guard l(lock);
if (!initialize && lock_provider) {
g_motr_lock = std::make_shared<MotrLock>();
g_motr_lock->initialize(lock_provider);
initialize = true;
Expand Down

0 comments on commit 9155311

Please sign in to comment.