]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kv/RocksDBStore: no reason to make write_batch using new/delete
authorHaomai Wang <haomai@xsky.com>
Wed, 21 Sep 2016 08:20:48 +0000 (16:20 +0800)
committerJosh Durgin <jdurgin@redhat.com>
Wed, 4 Apr 2018 14:12:43 +0000 (10:12 -0400)
discards new/delete for bat

Signed-off-by: Haomai Wang <haomai@xsky.com>
(cherry picked from commit 79a6611c0aa2c5b16435fad53268dd29a8541188)

Conflicts:
src/kv/RocksDBStore.cc (trivial)

src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index a2dd90a8aac70f9706f0c77cdd2e958c33e56d96..017c4e03498550c86afdcfca16dd2ee90bed1449 100644 (file)
@@ -324,13 +324,13 @@ int RocksDBStore::submit_transaction(KeyValueDB::Transaction t)
   woptions.disableWAL = disableWAL;
   lgeneric_subdout(cct, rocksdb, 30) << __func__;
   RocksWBHandler bat_txc;
-  _t->bat->Iterate(&bat_txc);
+  _t->bat.Iterate(&bat_txc);
   *_dout << " Rocksdb transaction: " << bat_txc.seen << dendl;
   
-  rocksdb::Status s = db->Write(woptions, _t->bat);
+  rocksdb::Status s = db->Write(woptions, &_t->bat);
   if (!s.ok()) {
     RocksWBHandler rocks_txc;
-    _t->bat->Iterate(&rocks_txc);
+    _t->bat.Iterate(&rocks_txc);
     derr << __func__ << " error: " << s.ToString() << " code = " << s.code()
          << " Rocksdb transaction: " << rocks_txc.seen << dendl;
   }
@@ -350,13 +350,13 @@ int RocksDBStore::submit_transaction_sync(KeyValueDB::Transaction t)
   woptions.disableWAL = disableWAL;
   lgeneric_subdout(cct, rocksdb, 30) << __func__;
   RocksWBHandler bat_txc;
-  _t->bat->Iterate(&bat_txc);
+  _t->bat.Iterate(&bat_txc);
   *_dout << " Rocksdb transaction: " << bat_txc.seen << dendl;
 
-  rocksdb::Status s = db->Write(woptions, _t->bat);
+  rocksdb::Status s = db->Write(woptions, &_t->bat);
   if (!s.ok()) {
     RocksWBHandler rocks_txc;
-    _t->bat->Iterate(&rocks_txc);
+    _t->bat.Iterate(&rocks_txc);
     derr << __func__ << " error: " << s.ToString() << " code = " << s.code()
          << " Rocksdb transaction: " << rocks_txc.seen << dendl;
   }
@@ -385,12 +385,8 @@ int RocksDBStore::get_info_log_level(string info_log_level)
 RocksDBStore::RocksDBTransactionImpl::RocksDBTransactionImpl(RocksDBStore *_db)
 {
   db = _db;
-  bat = new rocksdb::WriteBatch();
-}
-RocksDBStore::RocksDBTransactionImpl::~RocksDBTransactionImpl()
-{
-  delete bat;
 }
+
 void RocksDBStore::RocksDBTransactionImpl::set(
   const string &prefix,
   const string &k,
@@ -400,13 +396,13 @@ void RocksDBStore::RocksDBTransactionImpl::set(
 
   // bufferlist::c_str() is non-constant, so we can't call c_str()
   if (to_set_bl.is_contiguous() && to_set_bl.length() > 0) {
-    bat->Put(rocksdb::Slice(key),
+    bat.Put(rocksdb::Slice(key),
             rocksdb::Slice(to_set_bl.buffers().front().c_str(),
                            to_set_bl.length()));
   } else {
     // make a copy
     bufferlist val = to_set_bl;
-    bat->Put(rocksdb::Slice(key),
+    bat.Put(rocksdb::Slice(key),
             rocksdb::Slice(val.c_str(), val.length()));
   }
 }
@@ -414,7 +410,7 @@ void RocksDBStore::RocksDBTransactionImpl::set(
 void RocksDBStore::RocksDBTransactionImpl::rmkey(const string &prefix,
                                                 const string &k)
 {
-  bat->Delete(combine_strings(prefix, k));
+  bat.Delete(combine_strings(prefix, k));
 }
 
 void RocksDBStore::RocksDBTransactionImpl::rmkeys_by_prefix(const string &prefix)
@@ -423,10 +419,11 @@ void RocksDBStore::RocksDBTransactionImpl::rmkeys_by_prefix(const string &prefix
   for (it->seek_to_first();
        it->valid();
        it->next()) {
-    bat->Delete(combine_strings(prefix, it->key()));
+    bat.Delete(combine_strings(prefix, it->key()));
   }
 }
 
+ew/delete
 int RocksDBStore::get(
     const string &prefix,
     const std::set<string> &keys,
index 654c51c105c2aa1e079877c7b09962336c594e0f..8cd657c96cd53ce3d9c1f06149e8d6df90f5c5af 100644 (file)
@@ -230,11 +230,10 @@ public:
 
   class RocksDBTransactionImpl : public KeyValueDB::TransactionImpl {
   public:
-    rocksdb::WriteBatch *bat;
+    rocksdb::WriteBatch bat;
     RocksDBStore *db;
 
     explicit RocksDBTransactionImpl(RocksDBStore *_db);
-    ~RocksDBTransactionImpl();
     void set(
       const string &prefix,
       const string &k,