From f1a60e5c3e75688d2bc728771cc3c8dd8ffb20fe Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Tue, 24 Sep 2013 22:23:19 -0700 Subject: [PATCH] The vector rep implementation was segfaulting because of incorrect initialization of vector. Summary: The constructor for Vector memtable has a parameter called 'count' that specifies the capacity of the vector to be reserved at allocation time. It was incorrectly used to initialize the size of the vector. Test Plan: Enhanced db_test. Reviewers: haobo, xjin, emayanke Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D13083 --- db/db_test.cc | 2 +- include/rocksdb/memtablerep.h | 2 +- util/vectorrep.cc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/db_test.cc b/db/db_test.cc index 6802e4a34..1db529c44 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -335,7 +335,7 @@ class DBTest { options.memtable_factory.reset(new UnsortedRepFactory); break; case kVectorRep: - options.memtable_factory.reset(new VectorRepFactory); + options.memtable_factory.reset(new VectorRepFactory(100)); break; case kUniversalCompaction: options.compaction_style = kCompactionStyleUniversal; diff --git a/include/rocksdb/memtablerep.h b/include/rocksdb/memtablerep.h index a2cb63f8f..209249837 100644 --- a/include/rocksdb/memtablerep.h +++ b/include/rocksdb/memtablerep.h @@ -152,7 +152,7 @@ class MemTableRepFactory { // Parameters: // count: Passed to the constructor of the underlying std::vector of each // VectorRep. On initialization, the underlying array will be at least count -// size. +// bytes reserved for usage. class VectorRepFactory : public MemTableRepFactory { const size_t count_; public: diff --git a/util/vectorrep.cc b/util/vectorrep.cc index 8770f60b9..744c9304c 100644 --- a/util/vectorrep.cc +++ b/util/vectorrep.cc @@ -123,10 +123,10 @@ size_t VectorRep::ApproximateMemoryUsage() { } VectorRep::VectorRep(const KeyComparator& compare, Arena* arena, size_t count) - : bucket_(new Bucket(count)), + : bucket_(new Bucket()), immutable_(false), sorted_(false), - compare_(compare) { } + compare_(compare) { bucket_.get()->reserve(count); } VectorRep::Iterator::Iterator(class VectorRep* vrep, std::shared_ptr> bucket,