]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix unlock of shared lock in RGWDataChangesLog 29538/head
authorCasey Bodley <cbodley@redhat.com>
Wed, 7 Aug 2019 17:55:03 +0000 (13:55 -0400)
committerCasey Bodley <cbodley@redhat.com>
Wed, 7 Aug 2019 18:02:49 +0000 (14:02 -0400)
std::shared_mutex expects a call to unlock_shared() after lock_shared().
use the std::shared_lock guard to make it more obviously correct

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_bucket.cc

index 369cd80da34e378b1005898e46cd030227f1ded4..c6a441e903522bb182fcc1aa189811f36b47b2c5 100644 (file)
@@ -2486,18 +2486,15 @@ void RGWDataChangesLog::ChangesRenewThread::stop()
 void RGWDataChangesLog::mark_modified(int shard_id, const rgw_bucket_shard& bs)
 {
   auto key = bs.get_key();
-  modified_lock.lock_shared();
-  map<int, set<string> >::iterator iter = modified_shards.find(shard_id);
-  if (iter != modified_shards.end()) {
-    set<string>& keys = iter->second;
-    if (keys.find(key) != keys.end()) {
-      modified_lock.unlock();
+  {
+    std::shared_lock rl{modified_lock}; // read lock to check for existence
+    auto shard = modified_shards.find(shard_id);
+    if (shard != modified_shards.end() && shard->second.count(key)) {
       return;
     }
   }
-  modified_lock.unlock();
 
-  std::unique_lock wl{modified_lock};
+  std::unique_lock wl{modified_lock}; // write lock for insertion
   modified_shards[shard_id].insert(key);
 }