]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/objectstore: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Sun, 7 Jul 2019 04:43:04 +0000 (12:43 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:19 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/test/objectstore/Allocator_bench.cc
src/test/objectstore/Allocator_test.cc
src/test/objectstore/FileStoreTracker.cc
src/test/objectstore/FileStoreTracker.h
src/test/objectstore/TestObjectStoreState.h
src/test/objectstore/store_test.cc
src/test/objectstore/test_kv.cc

index 50fbb1e410ac17c0ea9b8c3627a35084eccac59e..21c8312d4111ce80ab9cf7d10b3d202933fb7d64 100644 (file)
@@ -8,7 +8,6 @@
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
 
-#include "common/Mutex.h"
 #include "common/Cond.h"
 #include "common/errno.h"
 #include "include/stringify.h"
index 6ebd0f2906eb37a8a3a5d76ad06fbdde08675728..7528022dd3304a497aed8eda8853fbacd40af1a6 100644 (file)
@@ -8,7 +8,6 @@
 #include <boost/scoped_ptr.hpp>
 #include <gtest/gtest.h>
 
-#include "common/Mutex.h"
 #include "common/Cond.h"
 #include "common/errno.h"
 #include "include/stringify.h"
index dfaa88d1fef2ccd7497d73deec137ffbc69dad0f..880d26dfe9f23c5f352827a2159b683db6e35230 100644 (file)
@@ -4,7 +4,6 @@
 #include <iostream>
 #include <boost/scoped_ptr.hpp>
 #include "include/Context.h"
-#include "common/Mutex.h"
 
 class OnApplied : public Context {
   FileStoreTracker *tracker;
@@ -83,7 +82,7 @@ void FileStoreTracker::submit_transaction(Transaction &t)
 void FileStoreTracker::write(const pair<coll_t, string> &obj,
                             OutTransaction *out)
 {
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   std::cerr << "Writing " << obj << std::endl;
   ObjectContents contents = get_current_content(obj);
 
@@ -113,7 +112,7 @@ void FileStoreTracker::remove(const pair<coll_t, string> &obj,
                              OutTransaction *out)
 {
   std::cerr << "Deleting " << obj << std::endl;
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   ObjectContents old_contents = get_current_content(obj);
   if (!old_contents.exists())
     return;
@@ -126,7 +125,7 @@ void FileStoreTracker::remove(const pair<coll_t, string> &obj,
 void FileStoreTracker::clone_range(const pair<coll_t, string> &from,
                                   const pair<coll_t, string> &to,
                                   OutTransaction *out) {
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   std::cerr << "CloningRange " << from << " to " << to << std::endl;
   ceph_assert(from.first == to.first);
   ObjectContents from_contents = get_current_content(from);
@@ -157,7 +156,7 @@ void FileStoreTracker::clone_range(const pair<coll_t, string> &from,
 void FileStoreTracker::clone(const pair<coll_t, string> &from,
                             const pair<coll_t, string> &to,
                             OutTransaction *out) {
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   std::cerr << "Cloning " << from << " to " << to << std::endl;
   ceph_assert(from.first == to.first);
   if (from.second == to.second) {
@@ -272,7 +271,7 @@ void _clean_forward(const pair<coll_t, string> &obj,
 
 void FileStoreTracker::verify(const coll_t &coll, const string &obj,
                              bool on_start) {
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   std::cerr << "Verifying " << make_pair(coll, obj) << std::endl;
 
   pair<uint64_t, uint64_t> valid_reads = get_valid_reads(make_pair(coll, obj));
@@ -402,7 +401,7 @@ void clear_obsolete(const pair<coll_t, string> &obj,
 
 void FileStoreTracker::committed(const pair<coll_t, string> &obj,
                                 uint64_t seq) {
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   ObjStatus status = get_obj_status(obj, db);
   ceph_assert(status.last_committed < seq);
   status.last_committed = seq;
@@ -414,7 +413,7 @@ void FileStoreTracker::committed(const pair<coll_t, string> &obj,
 
 void FileStoreTracker::applied(const pair<coll_t, string> &obj,
                               uint64_t seq) {
-  Mutex::Locker l(lock);
+  std::lock_guard l{lock};
   std::cerr << "Applied " << obj << " version " << seq << std::endl;
   ObjStatus status = get_obj_status(obj, db);
   ceph_assert(status.last_applied < seq);
index d422d1cf1444c410ccbb54ffebae95311cbf178f..90c456250ce5d42a68c216f17a10232a7fce844f 100644 (file)
@@ -8,13 +8,13 @@
 #include <boost/scoped_ptr.hpp>
 #include <list>
 #include <map>
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 
 class FileStoreTracker {
   const static uint64_t SIZE = 4 * 1024;
   ObjectStore *store;
   KeyValueDB *db;
-  Mutex lock;
+  ceph::mutex lock = ceph::make_mutex("Tracker Lock");
   uint64_t restart_seq;
 
   struct OutTransaction {
@@ -24,7 +24,7 @@ class FileStoreTracker {
 public:
   FileStoreTracker(ObjectStore *store, KeyValueDB *db)
     : store(store), db(db),
-      lock("Tracker Lock"), restart_seq(0) {}
+      restart_seq(0) {}
 
   class Transaction {
     class Op {
index 4383808891c4ba18a70a4d946d2aacc326dc8b79..360f434fbae970c7fa077b4e95a0d4e5248b093d 100644 (file)
@@ -70,8 +70,8 @@ public:
 
   int m_max_in_flight;
   std::atomic<int> m_in_flight = { 0 };
-  Mutex m_finished_lock;
-  Cond m_finished_cond;
+  ceph::mutex m_finished_lock = ceph::make_mutex("Finished Lock");
+  ceph::condition_variable m_finished_cond;
 
   void rebuild_id_vec() {
     m_collections_ids.clear();
@@ -82,15 +82,15 @@ public:
   }
 
   void wait_for_ready() {
-    Mutex::Locker locker(m_finished_lock);
-    while ((m_max_in_flight > 0) && (m_in_flight >= m_max_in_flight))
-      m_finished_cond.Wait(m_finished_lock);
+    std::unique_lock locker{m_finished_lock};
+    m_finished_cond.wait(locker, [this] {
+      return m_max_in_flight <= 0 || m_in_flight < m_max_in_flight;
+    });
   }
 
   void wait_for_done() {
-    Mutex::Locker locker(m_finished_lock);
-    while (m_in_flight)
-      m_finished_cond.Wait(m_finished_lock);
+    std::unique_lock locker{m_finished_lock};
+    m_finished_cond.wait(locker, [this] { return m_in_flight == 0; });
   }
 
   void set_max_in_flight(int max) {
@@ -112,7 +112,7 @@ public:
  public:
   explicit TestObjectStoreState(ObjectStore *store) :
     m_next_coll_nr(0), m_num_objs_per_coll(10), m_num_objects(0),
-    m_max_in_flight(0), m_finished_lock("Finished Lock"), m_next_pool(2) {
+    m_max_in_flight(0), m_next_pool(2) {
     m_store.reset(store);
   }
   ~TestObjectStoreState() { 
@@ -147,9 +147,9 @@ public:
     explicit C_OnFinished(TestObjectStoreState *state) : m_state(state) { }
 
     void finish(int r) override {
-      Mutex::Locker locker(m_state->m_finished_lock);
+      std::lock_guard locker{m_state->m_finished_lock};
       m_state->dec_in_flight();
-      m_state->m_finished_cond.Signal();
+      m_state->m_finished_cond.notify_all();
 
     }
   };
index 7ace015352f6311fb9d24b8322d057e1d5fe2315..d534b493fabb1f79eb6ea8b2d142af909ed251b2 100644 (file)
@@ -32,7 +32,7 @@
 #include "include/Context.h"
 #include "common/ceph_argparse.h"
 #include "global/global_init.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "common/Cond.h"
 #include "common/errno.h"
 #include "include/stringify.h"
@@ -3667,8 +3667,8 @@ public:
   ObjectStore *store;
   ObjectStore::CollectionHandle ch;
 
-  Mutex lock;
-  Cond cond;
+  ceph::mutex lock = ceph::make_mutex("State lock");
+  ceph::condition_variable cond;
 
   struct EnterExit {
     const char *msg;
@@ -3688,7 +3688,7 @@ public:
       : state(state), hoid(hoid) {}
 
     void finish(int r) override {
-      Mutex::Locker locker(state->lock);
+      std::lock_guard locker{state->lock};
       EnterExit ee("onreadable finish");
       ASSERT_TRUE(state->in_flight_objects.count(hoid));
       ASSERT_EQ(r, 0);
@@ -3696,12 +3696,12 @@ public:
       if (state->contents.count(hoid))
         state->available_objects.insert(hoid);
       --(state->in_flight);
-      state->cond.Signal();
+      state->cond.notify_all();
 
       bufferlist r2;
       r = state->store->read(state->ch, hoid, 0, state->contents[hoid].data.length(), r2);
       ceph_assert(bl_eq(state->contents[hoid].data, r2));
-      state->cond.Signal();
+      state->cond.notify_all();
     }
   };
 
@@ -3715,7 +3715,7 @@ public:
       : state(state), oid(oid), noid(noid) {}
 
     void finish(int r) override {
-      Mutex::Locker locker(state->lock);
+      std::lock_guard locker{state->lock};
       EnterExit ee("stash finish");
       ASSERT_TRUE(state->in_flight_objects.count(oid));
       ASSERT_EQ(r, 0);
@@ -3728,7 +3728,7 @@ public:
        state->ch, noid, 0,
        state->contents[noid].data.length(), r2);
       ceph_assert(bl_eq(state->contents[noid].data, r2));
-      state->cond.Signal();
+      state->cond.notify_all();
     }
   };
 
@@ -3742,7 +3742,7 @@ public:
       : state(state), oid(oid), noid(noid) {}
 
     void finish(int r) override {
-      Mutex::Locker locker(state->lock);
+      std::lock_guard locker{state->lock};
       EnterExit ee("clone finish");
       ASSERT_TRUE(state->in_flight_objects.count(oid));
       ASSERT_EQ(r, 0);
@@ -3755,7 +3755,7 @@ public:
       bufferlist r2;
       r = state->store->read(state->ch, noid, 0, state->contents[noid].data.length(), r2);
       ceph_assert(bl_eq(state->contents[noid].data, r2));
-      state->cond.Signal();
+      state->cond.notify_all();
     }
   };
 
@@ -3786,8 +3786,7 @@ public:
                         unsigned alignment)
     : cid(cid), write_alignment(alignment), max_object_len(max_size),
       max_write_len(max_write), in_flight(0), object_gen(gen),
-      rng(rng), store(store),
-      lock("State lock") {}
+      rng(rng), store(store) {}
 
   int init() {
     ObjectStore::Transaction t;
@@ -3818,9 +3817,10 @@ public:
     store->statfs(&stat);
   }
 
-  ghobject_t get_uniform_random_object() {
-    while (in_flight >= max_in_flight || available_objects.empty())
-      cond.Wait(lock);
+  ghobject_t get_uniform_random_object(std::unique_lock<ceph::mutex>& locker) {
+    cond.wait(locker, [this] {
+      return in_flight < max_in_flight && !available_objects.empty();
+    });
     boost::uniform_int<> choose(0, available_objects.size() - 1);
     int index = choose(*rng);
     set<ghobject_t>::iterator i = available_objects.begin();
@@ -3829,15 +3829,13 @@ public:
     return ret;
   }
 
-  void wait_for_ready() {
-    while (in_flight >= max_in_flight)
-      cond.Wait(lock);
+  void wait_for_ready(std::unique_lock<ceph::mutex>& locker) {
+    cond.wait(locker, [this] { return in_flight < max_in_flight; });
   }
 
   void wait_for_done() {
-    Mutex::Locker locker(lock);
-    while (in_flight)
-      cond.Wait(lock);
+    std::unique_lock locker{lock};
+    cond.wait(locker, [this] { return in_flight == 0; });
   }
 
   bool can_create() {
@@ -3903,11 +3901,11 @@ public:
   }
 
   int touch() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("touch");
     if (!can_create())
       return -ENOSPC;
-    wait_for_ready();
+    wait_for_ready(locker);
     ghobject_t new_obj = object_gen->create_object(rng);
     available_objects.erase(new_obj);
     ObjectStore::Transaction t;
@@ -3928,18 +3926,18 @@ public:
   }
 
   int stash() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("stash");
     if (!can_unlink())
       return -ENOENT;
     if (!can_create())
       return -ENOSPC;
-    wait_for_ready();
+    wait_for_ready(locker);
 
     ghobject_t old_obj;
     int max = 20;
     do {
-      old_obj = get_uniform_random_object();
+      old_obj = get_uniform_random_object(locker);
     } while (--max && !contents[old_obj].data.length());
     available_objects.erase(old_obj);
     ghobject_t new_obj = old_obj;
@@ -3960,18 +3958,18 @@ public:
   }
 
   int clone() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("clone");
     if (!can_unlink())
       return -ENOENT;
     if (!can_create())
       return -ENOSPC;
-    wait_for_ready();
+    wait_for_ready(locker);
 
     ghobject_t old_obj;
     int max = 20;
     do {
-      old_obj = get_uniform_random_object();
+      old_obj = get_uniform_random_object(locker);
     } while (--max && !contents[old_obj].data.length());
     available_objects.erase(old_obj);
     ghobject_t new_obj = object_gen->create_object(rng);
@@ -3993,25 +3991,25 @@ public:
   }
 
   int clone_range() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("clone_range");
     if (!can_unlink())
       return -ENOENT;
     if (!can_create())
       return -ENOSPC;
-    wait_for_ready();
+    wait_for_ready(locker);
 
     ghobject_t old_obj;
     int max = 20;
     do {
-      old_obj = get_uniform_random_object();
+      old_obj = get_uniform_random_object(locker);
     } while (--max && !contents[old_obj].data.length());
     bufferlist &srcdata = contents[old_obj].data;
     if (srcdata.length() == 0) {
       return 0;
     }
     available_objects.erase(old_obj);
-    ghobject_t new_obj = get_uniform_random_object();
+    ghobject_t new_obj = get_uniform_random_object(locker);
     available_objects.erase(new_obj);
 
     boost::uniform_int<> u1(0, max_object_len - max_write_len);
@@ -4075,13 +4073,13 @@ public:
 
 
   int write() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("write");
     if (!can_unlink())
       return -ENOENT;
-    wait_for_ready();
+    wait_for_ready(locker);
 
-    ghobject_t new_obj = get_uniform_random_object();
+    ghobject_t new_obj = get_uniform_random_object(locker);
     available_objects.erase(new_obj);
     ObjectStore::Transaction t;
 
@@ -4123,13 +4121,13 @@ public:
   }
 
   int truncate() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("truncate");
     if (!can_unlink())
       return -ENOENT;
-    wait_for_ready();
+    wait_for_ready(locker);
 
-    ghobject_t obj = get_uniform_random_object();
+    ghobject_t obj = get_uniform_random_object(locker);
     available_objects.erase(obj);
     ObjectStore::Transaction t;
 
@@ -4157,13 +4155,13 @@ public:
   }
 
   int zero() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("zero");
     if (!can_unlink())
       return -ENOENT;
-    wait_for_ready();
+    wait_for_ready(locker);
 
-    ghobject_t new_obj = get_uniform_random_object();
+    ghobject_t new_obj = get_uniform_random_object(locker);
     available_objects.erase(new_obj);
     ObjectStore::Transaction t;
 
@@ -4210,13 +4208,13 @@ public:
     bufferlist expected;
     int r;
     {
-      Mutex::Locker locker(lock);
+      std::unique_lock locker{lock};
       EnterExit ee("read locked");
       if (!can_unlink())
         return ;
-      wait_for_ready();
+      wait_for_ready(locker);
 
-      obj = get_uniform_random_object();
+      obj = get_uniform_random_object(locker);
       expected = contents[obj].data;
     }
     bufferlist bl, result;
@@ -4240,13 +4238,13 @@ public:
   }
 
   int setattrs() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("setattrs");
     if (!can_unlink())
       return -ENOENT;
-    wait_for_ready();
+    wait_for_ready(locker);
 
-    ghobject_t obj = get_uniform_random_object();
+    ghobject_t obj = get_uniform_random_object(locker);
     available_objects.erase(obj);
     ObjectStore::Transaction t;
 
@@ -4292,15 +4290,15 @@ public:
     ghobject_t obj;
     map<string, bufferlist> expected;
     {
-      Mutex::Locker locker(lock);
+      std::unique_lock locker{lock};
       EnterExit ee("getattrs locked");
       if (!can_unlink())
         return ;
-      wait_for_ready();
+      wait_for_ready(locker);
 
       int retry = 10;
       do {
-        obj = get_uniform_random_object();
+        obj = get_uniform_random_object(locker);
         if (!--retry)
           return ;
       } while (contents[obj].attrs.empty());
@@ -4323,15 +4321,15 @@ public:
     int retry;
     map<string, bufferlist> expected;
     {
-      Mutex::Locker locker(lock);
+      std::unique_lock locker{lock};
       EnterExit ee("getattr locked");
       if (!can_unlink())
         return ;
-      wait_for_ready();
+      wait_for_ready(locker);
 
       retry = 10;
       do {
-        obj = get_uniform_random_object();
+        obj = get_uniform_random_object(locker);
         if (!--retry)
           return ;
       } while (contents[obj].attrs.empty());
@@ -4352,16 +4350,16 @@ public:
   }
 
   int rmattr() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("rmattr");
     if (!can_unlink())
       return -ENOENT;
-    wait_for_ready();
+    wait_for_ready(locker);
 
     ghobject_t obj;
     int retry = 10;
     do {
-      obj = get_uniform_random_object();
+      obj = get_uniform_random_object(locker);
       if (!--retry)
         return 0;
     } while (contents[obj].attrs.empty());
@@ -4387,10 +4385,9 @@ public:
   }
 
   void fsck(bool deep) {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("fsck");
-    while (in_flight)
-      cond.Wait(lock);
+    cond.wait(locker, [this] { return in_flight == 0; });
     ch.reset();
     store->umount();
     int r = store->fsck(deep);
@@ -4400,10 +4397,9 @@ public:
   }
 
   void scan() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("scan");
-    while (in_flight)
-      cond.Wait(lock);
+    cond.wait(locker, [this] { return in_flight == 0; });
     vector<ghobject_t> objects;
     set<ghobject_t> objects_set, objects_set2;
     ghobject_t next, current;
@@ -4463,11 +4459,11 @@ public:
     ghobject_t hoid;
     uint64_t expected;
     {
-      Mutex::Locker locker(lock);
+      std::unique_lock locker{lock};
       EnterExit ee("stat lock1");
       if (!can_unlink())
         return ;
-      hoid = get_uniform_random_object();
+      hoid = get_uniform_random_object(locker);
       in_flight_objects.insert(hoid);
       available_objects.erase(hoid);
       ++in_flight;
@@ -4479,21 +4475,21 @@ public:
     ceph_assert((uint64_t)buf.st_size == expected);
     ASSERT_TRUE((uint64_t)buf.st_size == expected);
     {
-      Mutex::Locker locker(lock);
+      std::lock_guard locker{lock};
       EnterExit ee("stat lock2");
       --in_flight;
-      cond.Signal();
+      cond.notify_all();
       in_flight_objects.erase(hoid);
       available_objects.insert(hoid);
     }
   }
 
   int unlink() {
-    Mutex::Locker locker(lock);
+    std::unique_lock locker{lock};
     EnterExit ee("unlink");
     if (!can_unlink())
       return -ENOENT;
-    ghobject_t to_remove = get_uniform_random_object();
+    ghobject_t to_remove = get_uniform_random_object(locker);
     ObjectStore::Transaction t;
     t.remove(cid, to_remove);
     ++in_flight;
@@ -4506,7 +4502,7 @@ public:
   }
 
   void print_internal_state() {
-    Mutex::Locker locker(lock);
+    std::lock_guard locker{lock};
     cerr << "available_objects: " << available_objects.size()
         << " in_flight_objects: " << in_flight_objects.size()
         << " total objects: " << in_flight_objects.size() + available_objects.size()
index 16881bcb044ccb98f528af7af251018f00b7857a..6633b67a0fd6b13c8ea7cb0b6cc4a8374b43f526 100644 (file)
@@ -21,7 +21,6 @@
 #include "include/Context.h"
 #include "common/ceph_argparse.h"
 #include "global/global_init.h"
-#include "common/Mutex.h"
 #include "common/Cond.h"
 #include "common/errno.h"
 #include "include/stringify.h"