]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
kv/RocksDBStore: no reason to make write_batch using new/delete 11197/head
authorHaomai Wang <haomai@xsky.com>
Wed, 21 Sep 2016 08:20:48 +0000 (16:20 +0800)
committerHaomai Wang <haomai@xsky.com>
Wed, 21 Sep 2016 08:20:48 +0000 (16:20 +0800)
discards new/delete for bat

Signed-off-by: Haomai Wang <haomai@xsky.com>
src/kv/RocksDBStore.cc
src/kv/RocksDBStore.h

index 337f0d005a384c507cdeb2cc85c2616bea16a83f..989a375e5171665c786abb3b75a60ba3f52aa36c 100644 (file)
@@ -367,13 +367,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;
   }
@@ -393,13 +393,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;
   }
@@ -428,12 +428,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,
@@ -443,13 +439,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()));
   }
 }
@@ -457,13 +453,13 @@ 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::rm_single_key(const string &prefix,
                                                         const string &k)
 {
-  bat->SingleDelete(combine_strings(prefix, k));
+  bat.SingleDelete(combine_strings(prefix, k));
 }
 
 void RocksDBStore::RocksDBTransactionImpl::rmkeys_by_prefix(const string &prefix)
@@ -472,7 +468,7 @@ 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()));
   }
 }
 
@@ -485,13 +481,13 @@ void RocksDBStore::RocksDBTransactionImpl::merge(
 
   // 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->Merge(rocksdb::Slice(key),
+    bat.Merge(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->Merge(rocksdb::Slice(key),
+    bat.Merge(rocksdb::Slice(key),
             rocksdb::Slice(val.c_str(), val.length()));
   }
 }
index a4ce5bd15de5f4623f1dd04c6ab7d1d75bef71f6..371ca6ca6dece7eb3b2f9fb10cd0c564ca558084 100644 (file)
@@ -231,11 +231,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,