]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_kvs: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Wed, 17 Jul 2019 13:17:07 +0000 (21:17 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:20 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/key_value_store/kv_flat_btree_async.cc
src/key_value_store/kv_flat_btree_async.h
src/test/kv_store_bench.cc
src/test/kv_store_bench.h

index 5aec8032e7af0ee883fdeb195c08908235edb61c..66c95f3ff9985a08cbf4f6628c17417ea10d0277 100644 (file)
@@ -243,13 +243,13 @@ int KvFlatBtreeAsync::read_index(const string &key, index_data * idata,
     if (verbose) cout << "\t" << client_name
        << "-read_index: getting index_data for " << key
        << " from cache" << std::endl;
-    icache_lock.Lock();
+    icache_lock.lock();
     if (next_idata != NULL) {
       err = icache.get(key, idata, next_idata);
     } else {
       err = icache.get(key, idata);
     }
-    icache_lock.Unlock();
+    icache_lock.unlock();
 
     if (err == 0) {
       //if (verbose) cout << "CACHE SUCCESS" << std::endl;
@@ -303,9 +303,8 @@ int KvFlatBtreeAsync::read_index(const string &key, index_data * idata,
       }
       return read_index(key, idata, next_idata, force_update);
     }
-    icache_lock.Lock();
+    std::scoped_lock l{icache_lock};
     icache.push(this_idata);
-    icache_lock.Unlock();
   }
   auto b = kvmap.begin()->second.cbegin();
   idata->decode(b);
@@ -315,17 +314,16 @@ int KvFlatBtreeAsync::read_index(const string &key, index_data * idata,
       << ", idata is " << idata->str() << std::endl;
 
   ceph_assert(idata->obj != "");
-  icache_lock.Lock();
+  icache_lock.lock();
   icache.push(key, *idata);
-  icache_lock.Unlock();
+  icache_lock.unlock();
 
   if (next_idata != NULL && idata->kdata.prefix != "1") {
     next_idata->kdata.parse((++kvmap.begin())->first);
     auto nb = (++kvmap.begin())->second.cbegin();
     next_idata->decode(nb);
-    icache_lock.Lock();
+    std::scoped_lock l{icache_lock};
     icache.push(*next_idata);
-    icache_lock.Unlock();
   }
   return err;
 }
@@ -364,9 +362,9 @@ int KvFlatBtreeAsync::split(const index_data &idata) {
 
   //for lower half object
   map<std::string, bufferlist>::const_iterator it = args.odata.omap.begin();
-  client_index_lock.Lock();
+  client_index_lock.lock();
   to_create.push_back(object_data(to_string(client_name, client_index++)));
-  client_index_lock.Unlock();
+  client_index_lock.unlock();
   for (int i = 0; i < k; i++) {
     to_create[0].omap.insert(*it);
     ++it;
@@ -375,11 +373,11 @@ int KvFlatBtreeAsync::split(const index_data &idata) {
   to_create[0].max_kdata = key_data(to_create[0].omap.rbegin()->first);
 
   //for upper half object
-  client_index_lock.Lock();
+  client_index_lock.lock();
   to_create.push_back(object_data(to_create[0].max_kdata,
         args.odata.max_kdata,
         to_string(client_name, client_index++)));
-  client_index_lock.Unlock();
+  client_index_lock.unlock();
   to_create[1].omap.insert(
       ++args.odata.omap.find(to_create[0].omap.rbegin()->first),
       args.odata.omap.end());
@@ -406,7 +404,7 @@ int KvFlatBtreeAsync::split(const index_data &idata) {
   if (verbose) cout << "\t\t" << client_name << "-split: done splitting."
       << std::endl;
   /////END CRITICAL SECTION/////
-  icache_lock.Lock();
+  icache_lock.lock();
   for (vector<delete_data>::iterator it = out_data.to_delete.begin();
       it != out_data.to_delete.end(); ++it) {
     icache.erase(it->max);
@@ -415,7 +413,7 @@ int KvFlatBtreeAsync::split(const index_data &idata) {
       it != out_data.to_create.end(); ++it) {
     icache.push(index_data(*it));
   }
-  icache_lock.Unlock();
+  icache_lock.unlock();
   return err;
 }
 
@@ -533,9 +531,9 @@ int KvFlatBtreeAsync::rebalance(const index_data &idata1,
   }
 
   //this is the high object. it gets created regardless of rebalance or merge.
-  client_index_lock.Lock();
+  client_index_lock.lock();
   string o2w = to_string(client_name, client_index++);
-  client_index_lock.Unlock();
+  client_index_lock.unlock();
   index_data idata;
   vector<object_data> to_create;
   vector<object_data> to_delete;
@@ -569,9 +567,9 @@ int KvFlatBtreeAsync::rebalance(const index_data &idata1,
     map<std::string, bufferlist> write1_map;
     map<std::string, bufferlist> write2_map;
     map<std::string, bufferlist>::iterator it;
-    client_index_lock.Lock();
+    client_index_lock.lock();
     string o1w = to_string(client_name, client_index++);
-    client_index_lock.Unlock();
+    client_index_lock.unlock();
     int target_size_1 = ceil(((int)args1.odata.size + (int)args2.odata.size)
        / 2.0);
     if (args1.odata.max_kdata != idata1.kdata) {
@@ -636,7 +634,7 @@ int KvFlatBtreeAsync::rebalance(const index_data &idata1,
   if (err < 0) {
     return err;
   }
-  icache_lock.Lock();
+  icache_lock.lock();
   for (vector<delete_data>::iterator it = out_data.to_delete.begin();
       it != out_data.to_delete.end(); ++it) {
     icache.erase(it->max);
@@ -645,7 +643,7 @@ int KvFlatBtreeAsync::rebalance(const index_data &idata1,
       it != out_data.to_create.end(); ++it) {
     icache.push(index_data(*it));
   }
-  icache_lock.Unlock();
+  icache_lock.unlock();
   if (verbose) cout << "\t\t" << client_name << "-rebalance: done rebalancing."
       << std::endl;
   /////END CRITICAL SECTION/////
@@ -1922,7 +1920,7 @@ int KvFlatBtreeAsync::set_many(const map<string, bufferlist> &in_map) {
   if (verbose) cout << "\t\t" << client_name << "-split: done splitting."
       << std::endl;
   /////END CRITICAL SECTION/////
-  icache_lock.Lock();
+  std::scoped_lock l{icache_lock};
   for (vector<delete_data>::iterator it = idata.to_delete.begin();
       it != idata.to_delete.end(); ++it) {
     icache.erase(it->max);
@@ -1931,7 +1929,6 @@ int KvFlatBtreeAsync::set_many(const map<string, bufferlist> &in_map) {
       it != idata.to_create.end(); ++it) {
     icache.push(index_data(*it));
   }
-  icache_lock.Unlock();
   return err;
 }
 
index 346e4056cd3ee6e17de21faa73f892e1d773f887..3f1a96b3c71783af558ff84a5bc94b46192de662 100644 (file)
@@ -22,7 +22,7 @@
 #include "include/utime.h"
 #include "include/types.h"
 #include "include/encoding.h"
-#include "common/Mutex.h"
+#include "common/ceph_mutex.h"
 #include "common/Clock.h"
 #include "common/Formatter.h"
 #include "global/global_context.h"
@@ -518,9 +518,9 @@ protected:
   bool verbose;//if true, display lots of debug output
 
   //shared variables protected with mutexes
-  Mutex client_index_lock;
+  ceph::mutex client_index_lock = ceph::make_mutex("client_index_lock");
   int client_index; //names of new objects are client_name.client_index
-  Mutex icache_lock;
+  ceph::mutex icache_lock = ceph::make_mutex("icache_lock");
   IndexCache icache;
   friend struct index_data;
 
@@ -771,9 +771,7 @@ KvFlatBtreeAsync(int k_val, string name, int cache, double cache_r,
     cache_size(cache),
     cache_refresh(cache_r),
     verbose(verb),
-    client_index_lock("client_index_lock"),
     client_index(0),
-    icache_lock("icache_lock"),
     icache(cache)
   {}
 
index 76cc375ea8bae644a98eb08a92415923f49794af..ff9b36872ddb9d1ba4d0bbf9c7bbccfc77645333 100644 (file)
@@ -33,9 +33,7 @@ KvStoreBench::KvStoreBench()
   client_name("admin"),
   verbose(false),
   kvs(NULL),
-  data_lock("data lock"),
   ops_in_flight(0),
-  ops_in_flight_lock("KvStoreBench::ops_in_flight_lock"),
   rados_id("admin"),
   pool_name("rbd"),
   io_ctx_ready(false)
@@ -306,9 +304,9 @@ int KvStoreBench::test_random_insertions() {
 
 void KvStoreBench::aio_callback_timed(int * err, void *arg) {
   timed_args *args = reinterpret_cast<timed_args *>(arg);
-  Mutex * ops_in_flight_lock = &args->kvsb->ops_in_flight_lock;
-  Mutex * data_lock = &args->kvsb->data_lock;
-  Cond * op_avail = &args->kvsb->op_avail;
+  ceph::mutex * ops_in_flight_lock = &args->kvsb->ops_in_flight_lock;
+  ceph::mutex * data_lock = &args->kvsb->data_lock;
+  ceph::condition_variable * op_avail = &args->kvsb->op_avail;
   int *ops_in_flight = &args->kvsb->ops_in_flight;
   if (*err < 0 && *err != -61) {
     cerr << "Error during " << args->op << " operation: " << *err << std::endl;
@@ -318,7 +316,7 @@ void KvStoreBench::aio_callback_timed(int * err, void *arg) {
   double time = args->sw.get_time();
   args->sw.clear();
 
-  data_lock->Lock();
+  data_lock->lock();
   //latency
   args->kvsb->data.latency_jf.open_object_section("latency");
   args->kvsb->data.latency_jf.dump_float(string(1, args->op).c_str(),
@@ -331,12 +329,12 @@ void KvStoreBench::aio_callback_timed(int * err, void *arg) {
       ceph_clock_now());
   args->kvsb->data.throughput_jf.close_section();
 
-  data_lock->Unlock();
+  data_lock->unlock();
 
-  ops_in_flight_lock->Lock();
+  ops_in_flight_lock->lock();
   (*ops_in_flight)--;
-  op_avail->Signal();
-  ops_in_flight_lock->Unlock();
+  op_avail->notify_all();
+  ops_in_flight_lock->unlock();
 
   delete args;
 }
@@ -357,15 +355,11 @@ int KvStoreBench::test_teuthology_aio(next_gen_t distr,
 
   cout << "done waiting. Starting random operations..." << std::endl;
 
-  Mutex::Locker l(ops_in_flight_lock);
+  std::unique_lock l{ops_in_flight_lock};
   for (int i = 0; i < ops; i++) {
     ceph_assert(ops_in_flight <= max_ops_in_flight);
     if (ops_in_flight == max_ops_in_flight) {
-      int err = op_avail.Wait(ops_in_flight_lock);
-      if (err < 0) {
-       ceph_abort();
-       return err;
-      }
+      op_avail.wait(l);
       ceph_assert(ops_in_flight < max_ops_in_flight);
     }
     cout << "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" << i + 1 << " / "
@@ -429,9 +423,7 @@ int KvStoreBench::test_teuthology_aio(next_gen_t distr,
     delete cb_args;
   }
 
-  while(ops_in_flight > 0) {
-    op_avail.Wait(ops_in_flight_lock);
-  }
+  op_avail.wait(l, [this] { return ops_in_flight <= 0; });
 
   print_time_data();
   return err;
index da23c402bc1619178f0c48895986644572c86389..733594b70c5d9ee39035827c16b121ffab057db0 100644 (file)
@@ -18,7 +18,6 @@
 #include "key_value_store/kv_flat_btree_async.h"
 #include "common/Clock.h"
 #include "global/global_context.h"
-#include "common/Mutex.h"
 #include "common/Cond.h"
 
 #include <string>
@@ -117,10 +116,11 @@ protected:
   set<string> key_set;//set of keys already in the data set
   KeyValueStructure * kvs;
   kv_bench_data data;//stores throughput and latency from completed tests
-  Mutex data_lock;
-  Cond op_avail;//signaled when an op completes
+  ceph::mutex data_lock = ceph::make_mutex("data lock");
+  ceph::condition_variable op_avail; // signaled when an op completes
   int ops_in_flight;//number of operations currently in progress
-  Mutex ops_in_flight_lock;
+  ceph::mutex ops_in_flight_lock =
+    ceph::make_mutex("KvStoreBench::ops_in_flight_lock");
   //these are used for cleanup and setup purposes - they are NOT passed to kvs!
   librados::Rados rados;
   string rados_id;