]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
multiget: fix memory issues due to vector auto resizing (#5279)
authorZhongyi Xie <xiez@fb.com>
Fri, 3 May 2019 22:55:48 +0000 (15:55 -0700)
committeranand76 <anand76@devvm1373.frc2.facebook.com>
Fri, 24 May 2019 20:19:06 +0000 (13:19 -0700)
Summary:
This PR fixes three memory issues found by ASAN
* in db_stress, the key vector for MultiGet is created using `emplace_back` which could potentially invalidates references to the underlying storage (vector<string>) due to auto resizing. Fix by calling reserve in advance.
* Similar issue in construction of GetContext autovector in version_set.cc
* In multiget_context.h use T[] specialization for unique_ptr that holds a char array
Pull Request resolved: https://github.com/facebook/rocksdb/pull/5279

Differential Revision: D15202893

Pulled By: miasantreble

fbshipit-source-id: 14cc2cda0ed64d29f2a1e264a6bfdaa4294ee75d

db/version_set.cc
table/multiget_context.h
tools/db_stress.cc

index fdc07fee0e5695b2636fa04107624cba81e8c322..a8e6ff232bce91e2499dedc5ffb8d2af831a9f1c 100644 (file)
@@ -1758,7 +1758,11 @@ void Version::MultiGet(const ReadOptions& read_options, MultiGetRange* range,
         iter->value, nullptr, &(iter->merge_context),
         &iter->max_covering_tombstone_seq, this->env_, &iter->seq,
         merge_operator_ ? &pinned_iters_mgr : nullptr, callback, is_blob);
-    iter->get_context = &get_ctx.back();
+  }
+  int get_ctx_index = 0;
+  for (auto iter = range->begin(); iter != range->end();
+       ++iter, get_ctx_index++) {
+    iter->get_context = &(get_ctx[get_ctx_index]);
   }
 
   MultiGetRange file_picker_range(*range, range->begin(), range->end());
index d3a8d09463b064c2615f3f705d1356a6cb63c24b..c9e682fad4b754b2bb0d75a045cd8623cf981277 100644 (file)
@@ -123,7 +123,7 @@ class MultiGetContext {
   KeyContext** sorted_keys_;
   size_t num_keys_;
   uint64_t value_mask_;
-  std::unique_ptr<char> lookup_key_heap_buf;
+  std::unique_ptr<char[]> lookup_key_heap_buf;
   LookupKey* lookup_key_ptr_;
 
  public:
index 97755fe962a42edc2e98c06a4f201133ed24fa66..db324da60d6f4b39928a3c940badfe81e0668c27 100644 (file)
@@ -3057,6 +3057,8 @@ class NonBatchedOpsStressTest : public StressTest {
     size_t num_keys = rand_keys.size();
     std::vector<std::string> key_str;
     std::vector<Slice> keys;
+    key_str.reserve(num_keys);
+    keys.reserve(num_keys);
     std::vector<PinnableSlice> values(num_keys);
     std::vector<Status> statuses(num_keys);
     ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]];
@@ -3615,6 +3617,8 @@ class BatchedOpsStressTest : public StressTest {
       ReadOptions readoptionscopy = readoptions;
       readoptionscopy.snapshot = db_->GetSnapshot();
       std::vector<std::string> key_str;
+      key_str.reserve(num_keys);
+      key_slices.reserve(num_keys);
       std::string from_db;
       ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]];
 
@@ -3888,6 +3892,8 @@ class AtomicFlushStressTest : public StressTest {
     int num_keys = rand_keys.size();
     std::vector<std::string> key_str;
     std::vector<Slice> keys;
+    keys.reserve(num_keys);
+    key_str.reserve(num_keys);
     std::vector<PinnableSlice> values(num_keys);
     std::vector<Status> statuses(num_keys);
     ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]];