Skip to content

Commit 8b169e9

Browse files
committed
Merge branch 'master' into columnfamilies
2 parents 928ee23 + 2bad3cb commit 8b169e9

7 files changed

+60
-12
lines changed

db/memtable.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,8 @@ size_t MemTable::CountSuccessiveMergeEntries(const LookupKey& key) {
562562
const char* entry = iter->key();
563563
uint32_t key_length = 0;
564564
const char* iter_key_ptr = GetVarint32Ptr(entry, entry + 5, &key_length);
565-
if (!comparator_.comparator.user_comparator()->Compare(
566-
Slice(iter_key_ptr, key_length - 8), key.user_key()) == 0) {
565+
if (comparator_.comparator.user_comparator()->Compare(
566+
Slice(iter_key_ptr, key_length - 8), key.user_key()) != 0) {
567567
break;
568568
}
569569

db/perf_context_test.cc

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "rocksdb/db.h"
1212
#include "rocksdb/perf_context.h"
13+
#include "rocksdb/slice_transform.h"
14+
#include "rocksdb/memtablerep.h"
1315
#include "util/histogram.h"
1416
#include "util/stop_watch.h"
1517
#include "util/testharness.h"

db/prefix_test.cc

+37
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,43 @@ TEST(PrefixTest, TestResult) {
369369
}
370370
}
371371

372+
TEST(PrefixTest, FullIterator) {
373+
while (NextOptions(1000000)) {
374+
DestroyDB(kDbName, Options());
375+
auto db = OpenDb();
376+
WriteOptions write_options;
377+
378+
std::vector<uint64_t> prefixes;
379+
for (uint64_t i = 0; i < 100; ++i) {
380+
prefixes.push_back(i);
381+
}
382+
std::random_shuffle(prefixes.begin(), prefixes.end());
383+
384+
for (auto prefix : prefixes) {
385+
for (uint64_t i = 0; i < 200; ++i) {
386+
TestKey test_key(prefix, i);
387+
Slice key = TestKeyToSlice(test_key);
388+
ASSERT_OK(db->Put(write_options, key, Slice("0")));
389+
}
390+
}
391+
392+
auto func = [](void* db_void) {
393+
auto db = reinterpret_cast<DB*>(db_void);
394+
std::unique_ptr<Iterator> iter(db->NewIterator(ReadOptions()));
395+
iter->SeekToFirst();
396+
for (int i = 0; i < 3; ++i) {
397+
iter->Next();
398+
}
399+
};
400+
401+
auto env = Env::Default();
402+
for (int i = 0; i < 16; ++i) {
403+
env->StartThread(func, reinterpret_cast<void*>(db.get()));
404+
}
405+
env->WaitForJoin();
406+
}
407+
}
408+
372409
TEST(PrefixTest, DynamicPrefixIterator) {
373410
while (NextOptions(FLAGS_bucket_count)) {
374411
std::cout << "*** Mem table: " << options.memtable_factory->Name()

util/arena.h

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class Arena {
5252
// same size of that allocation.
5353
virtual size_t IrregularBlockNum() const { return irregular_block_num; }
5454

55+
size_t BlockSize() const { return kBlockSize; }
56+
5557
private:
5658
// Number of bytes allocated in one block
5759
const size_t kBlockSize;

util/crc32c.cc

+2
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,11 @@ static inline uint32_t LE_LOAD32(const uint8_t *p) {
291291
return DecodeFixed32(reinterpret_cast<const char*>(p));
292292
}
293293

294+
#ifdef __SSE4_2__
294295
static inline uint64_t LE_LOAD64(const uint8_t *p) {
295296
return DecodeFixed64(reinterpret_cast<const char*>(p));
296297
}
298+
#endif
297299

298300
static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) {
299301
uint32_t c = *l ^ LE_LOAD32(*p);

util/hash_linklist_rep.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ class HashLinkListRep : public MemTableRep {
141141

142142
class FullListIterator : public MemTableRep::Iterator {
143143
public:
144-
explicit FullListIterator(FullList* list)
145-
: iter_(list), full_list_(list) {}
144+
explicit FullListIterator(FullList* list, Arena* arena)
145+
: iter_(list), full_list_(list), arena_(arena) {}
146146

147147
virtual ~FullListIterator() {
148148
}
@@ -196,6 +196,7 @@ class HashLinkListRep : public MemTableRep {
196196
FullList::Iterator iter_;
197197
// To destruct with the iterator.
198198
std::unique_ptr<FullList> full_list_;
199+
std::unique_ptr<Arena> arena_;
199200
std::string tmp_; // For passing to EncodeKey
200201
};
201202

@@ -416,7 +417,9 @@ void HashLinkListRep::Get(const LookupKey& k, void* callback_args,
416417
}
417418

418419
MemTableRep::Iterator* HashLinkListRep::GetIterator() {
419-
auto list = new FullList(compare_, arena_);
420+
// allocate a new arena of similar size to the one currently in use
421+
Arena* new_arena = new Arena(arena_->BlockSize());
422+
auto list = new FullList(compare_, new_arena);
420423
for (size_t i = 0; i < bucket_size_; ++i) {
421424
auto bucket = GetBucket(i);
422425
if (bucket != nullptr) {
@@ -426,7 +429,7 @@ MemTableRep::Iterator* HashLinkListRep::GetIterator() {
426429
}
427430
}
428431
}
429-
return new FullListIterator(list);
432+
return new FullListIterator(list, new_arena);
430433
}
431434

432435
MemTableRep::Iterator* HashLinkListRep::GetPrefixIterator(

util/hash_skiplist_rep.cc

+8-6
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,9 @@ class HashSkipListRep : public MemTableRep {
8181

8282
class Iterator : public MemTableRep::Iterator {
8383
public:
84-
explicit Iterator(Bucket* list, bool own_list = true)
85-
: list_(list),
86-
iter_(list),
87-
own_list_(own_list) {}
84+
explicit Iterator(Bucket* list, bool own_list = true,
85+
Arena* arena = nullptr)
86+
: list_(list), iter_(list), own_list_(own_list), arena_(arena) {}
8887

8988
virtual ~Iterator() {
9089
// if we own the list, we should also delete it
@@ -163,6 +162,7 @@ class HashSkipListRep : public MemTableRep {
163162
// here we track if we own list_. If we own it, we are also
164163
// responsible for it's cleaning. This is a poor man's shared_ptr
165164
bool own_list_;
165+
std::unique_ptr<Arena> arena_;
166166
std::string tmp_; // For passing to EncodeKey
167167
};
168168

@@ -289,7 +289,9 @@ void HashSkipListRep::Get(const LookupKey& k, void* callback_args,
289289
}
290290

291291
MemTableRep::Iterator* HashSkipListRep::GetIterator() {
292-
auto list = new Bucket(compare_, arena_);
292+
// allocate a new arena of similar size to the one currently in use
293+
Arena* new_arena = new Arena(arena_->BlockSize());
294+
auto list = new Bucket(compare_, new_arena);
293295
for (size_t i = 0; i < bucket_size_; ++i) {
294296
auto bucket = GetBucket(i);
295297
if (bucket != nullptr) {
@@ -299,7 +301,7 @@ MemTableRep::Iterator* HashSkipListRep::GetIterator() {
299301
}
300302
}
301303
}
302-
return new Iterator(list);
304+
return new Iterator(list, true, new_arena);
303305
}
304306

305307
MemTableRep::Iterator* HashSkipListRep::GetPrefixIterator(const Slice& prefix) {

0 commit comments

Comments
 (0)