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
main
Dhruba Borthakur 11 years ago
parent 87d6eb2f6b
commit f1a60e5c3e
  1. 2
      db/db_test.cc
  2. 2
      include/rocksdb/memtablerep.h
  3. 4
      util/vectorrep.cc

@ -335,7 +335,7 @@ class DBTest {
options.memtable_factory.reset(new UnsortedRepFactory); options.memtable_factory.reset(new UnsortedRepFactory);
break; break;
case kVectorRep: case kVectorRep:
options.memtable_factory.reset(new VectorRepFactory); options.memtable_factory.reset(new VectorRepFactory(100));
break; break;
case kUniversalCompaction: case kUniversalCompaction:
options.compaction_style = kCompactionStyleUniversal; options.compaction_style = kCompactionStyleUniversal;

@ -152,7 +152,7 @@ class MemTableRepFactory {
// Parameters: // Parameters:
// count: Passed to the constructor of the underlying std::vector of each // count: Passed to the constructor of the underlying std::vector of each
// VectorRep. On initialization, the underlying array will be at least count // VectorRep. On initialization, the underlying array will be at least count
// size. // bytes reserved for usage.
class VectorRepFactory : public MemTableRepFactory { class VectorRepFactory : public MemTableRepFactory {
const size_t count_; const size_t count_;
public: public:

@ -123,10 +123,10 @@ size_t VectorRep::ApproximateMemoryUsage() {
} }
VectorRep::VectorRep(const KeyComparator& compare, Arena* arena, size_t count) VectorRep::VectorRep(const KeyComparator& compare, Arena* arena, size_t count)
: bucket_(new Bucket(count)), : bucket_(new Bucket()),
immutable_(false), immutable_(false),
sorted_(false), sorted_(false),
compare_(compare) { } compare_(compare) { bucket_.get()->reserve(count); }
VectorRep::Iterator::Iterator(class VectorRep* vrep, VectorRep::Iterator::Iterator(class VectorRep* vrep,
std::shared_ptr<std::vector<const char*>> bucket, std::shared_ptr<std::vector<const char*>> bucket,

Loading…
Cancel
Save