]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Fix accidental object copy in transactions
authoragiardullo <agiardullo@fb.com>
Wed, 30 Sep 2015 00:00:16 +0000 (17:00 -0700)
committeragiardullo <agiardullo@fb.com>
Wed, 30 Sep 2015 18:37:27 +0000 (11:37 -0700)
Summary: Should have used auto& instead of auto.  Also needed to change the code a bit due to const correctness.

Test Plan: unit tests

Reviewers: sdong, igor, yoshinorim, yhchiang

Reviewed By: yhchiang

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D47787

utilities/transactions/transaction_base.cc
utilities/transactions/transaction_impl.cc

index a93006b29ec851cbab43307748cddff97c379136..373121b890cb59fbe6c8a97c518b13388c1bcd4e 100644 (file)
@@ -77,7 +77,7 @@ Status TransactionBaseImpl::RollbackToSavePoint() {
     assert(s.ok());
 
     // Rollback any keys that were tracked since the last savepoint
-    auto key_map = GetTrackedKeysSinceSavePoint();
+    const TransactionKeyMap* key_map = GetTrackedKeysSinceSavePoint();
     assert(key_map);
     for (auto& key_map_iter : *key_map) {
       uint32_t column_family_id = key_map_iter.first;
index 6202970bd0508d9ee9a003e999cb11a5304ce708..c2a93cf33dc1de1ad9a2b424feea1a35420190d4 100644 (file)
@@ -126,7 +126,7 @@ void TransactionImpl::Rollback() { Clear(); }
 
 Status TransactionImpl::RollbackToSavePoint() {
   // Unlock any keys locked since last transaction
-  auto keys = GetTrackedKeysSinceSavePoint();
+  const TransactionKeyMap* keys = GetTrackedKeysSinceSavePoint();
   if (keys) {
     txn_db_impl_->UnLock(this, keys);
   }
@@ -227,18 +227,26 @@ Status TransactionImpl::TryLock(ColumnFamilyHandle* column_family,
   // TODO(agiardullo): could optimize by supporting shared txn locks in the
   // future
   bool check_snapshot = !untracked;
-
-  // lock this key if this transactions hasn't already locked it
   SequenceNumber tracked_seqno = kMaxSequenceNumber;
-  auto tracked_keys = GetTrackedKeys();
-  auto iter = tracked_keys[cfh_id].find(key_str);
-  if (iter == tracked_keys[cfh_id].end()) {
+
+  // Lookup whether this key has already been locked by this transaction
+  const auto& tracked_keys = GetTrackedKeys();
+  const auto tracked_keys_cf = tracked_keys.find(cfh_id);
+  if (tracked_keys_cf == tracked_keys.end()) {
     previously_locked = false;
+  } else {
+    auto iter = tracked_keys_cf->second.find(key_str);
+    if (iter == tracked_keys_cf->second.end()) {
+      previously_locked = false;
+    } else {
+      previously_locked = true;
+      tracked_seqno = iter->second;
+    }
+  }
 
+  // lock this key if this transactions hasn't already locked it
+  if (!previously_locked) {
     s = txn_db_impl_->TryLock(this, cfh_id, key_str);
-  } else {
-    previously_locked = true;
-    tracked_seqno = iter->second;
   }
 
   if (s.ok()) {