From 9155311648dfbcd2c5688dc8d06031a3b9b8e82b Mon Sep 17 00:00:00 2001 From: Dattaprasad Govekar Date: Tue, 16 Aug 2022 18:51:45 +0530 Subject: [PATCH] motr_gc: [CORTX-32689] Validate GC for simple object delete API (#393) - Fix issues in locking mechanism. Signed-off-by: Dattaprasad Govekar Signed-off-by: Dattaprasad Govekar --- src/rgw/motr/gc/gc.cc | 12 ++++++++++-- src/rgw/motr/sync/motr_sync_impl.cc | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/rgw/motr/gc/gc.cc b/src/rgw/motr/gc/gc.cc index 576c4ede41c4e..20f4251e268e9 100644 --- a/src/rgw/motr/gc/gc.cc +++ b/src/rgw/motr/gc/gc.cc @@ -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 @@ -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& 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& 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; diff --git a/src/rgw/motr/sync/motr_sync_impl.cc b/src/rgw/motr/sync/motr_sync_impl.cc index 831f6c7a11b4e..67e18f96f6844 100644 --- a/src/rgw/motr/sync/motr_sync_impl.cc +++ b/src/rgw/motr/sync/motr_sync_impl.cc @@ -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, @@ -193,7 +196,9 @@ std::shared_ptr g_motr_lock; std::shared_ptr& get_lock_instance( std::unique_ptr& 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(); g_motr_lock->initialize(lock_provider); initialize = true;