2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/memtablerep.h"
|
2013-07-23 21:42:27 +00:00
|
|
|
#include "db/memtable.h"
|
|
|
|
#include "db/skiplist.h"
|
|
|
|
|
|
|
|
namespace leveldb {
|
2013-08-23 06:10:02 +00:00
|
|
|
namespace {
|
2013-07-23 21:42:27 +00:00
|
|
|
class SkipListRep : public MemTableRep {
|
|
|
|
SkipList<const char*, MemTableRep::KeyComparator&> skip_list_;
|
|
|
|
public:
|
Make arena block size configurable
Summary:
Add an option for arena block size, default value 4096 bytes. Arena will allocate blocks with such size.
I am not sure about passing parameter to skiplist in the new virtualized framework, though I talked to Jim a bit. So add Jim as reviewer.
Test Plan:
new unit test, I am running db_test.
For passing paramter from configured option to Arena, I tried tests like:
TEST(DBTest, Arena_Option) {
std::string dbname = test::TmpDir() + "/db_arena_option_test";
DestroyDB(dbname, Options());
DB* db = nullptr;
Options opts;
opts.create_if_missing = true;
opts.arena_block_size = 1000000; // tested 99, 999999
Status s = DB::Open(opts, dbname, &db);
db->Put(WriteOptions(), "a", "123");
}
and printed some debug info. The results look good. Any suggestion for such a unit-test?
Reviewers: haobo, dhruba, emayanke, jpaton
Reviewed By: dhruba
CC: leveldb, zshao
Differential Revision: https://reviews.facebook.net/D11799
2013-07-31 19:42:23 +00:00
|
|
|
explicit SkipListRep(MemTableRep::KeyComparator& compare, Arena* arena)
|
|
|
|
: skip_list_(compare, arena) {
|
|
|
|
}
|
2013-07-23 21:42:27 +00:00
|
|
|
|
|
|
|
// Insert key into the list.
|
|
|
|
// REQUIRES: nothing that compares equal to key is currently in the list.
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual void Insert(const char* key) override {
|
2013-07-23 21:42:27 +00:00
|
|
|
skip_list_.Insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true iff an entry that compares equal to key is in the list.
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual bool Contains(const char* key) const override {
|
2013-07-23 21:42:27 +00:00
|
|
|
return skip_list_.Contains(key);
|
|
|
|
}
|
|
|
|
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual size_t ApproximateMemoryUsage() override {
|
|
|
|
// All memory is allocated through arena; nothing to report here
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~SkipListRep() override { }
|
2013-07-23 21:42:27 +00:00
|
|
|
|
|
|
|
// Iteration over the contents of a skip list
|
|
|
|
class Iterator : public MemTableRep::Iterator {
|
|
|
|
SkipList<const char*, MemTableRep::KeyComparator&>::Iterator iter_;
|
|
|
|
public:
|
|
|
|
// Initialize an iterator over the specified list.
|
|
|
|
// The returned iterator is not valid.
|
|
|
|
explicit Iterator(
|
|
|
|
const SkipList<const char*, MemTableRep::KeyComparator&>* list
|
|
|
|
) : iter_(list) { }
|
|
|
|
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual ~Iterator() override { }
|
2013-07-23 21:42:27 +00:00
|
|
|
|
|
|
|
// Returns true iff the iterator is positioned at a valid node.
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual bool Valid() const override {
|
2013-07-23 21:42:27 +00:00
|
|
|
return iter_.Valid();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the key at the current position.
|
|
|
|
// REQUIRES: Valid()
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual const char* key() const override {
|
2013-07-23 21:42:27 +00:00
|
|
|
return iter_.key();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advances to the next position.
|
|
|
|
// REQUIRES: Valid()
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual void Next() override {
|
2013-07-23 21:42:27 +00:00
|
|
|
iter_.Next();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advances to the previous position.
|
|
|
|
// REQUIRES: Valid()
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual void Prev() override {
|
2013-07-23 21:42:27 +00:00
|
|
|
iter_.Prev();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Advance to the first entry with a key >= target
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual void Seek(const char* target) override {
|
2013-07-23 21:42:27 +00:00
|
|
|
iter_.Seek(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position at the first entry in list.
|
|
|
|
// Final state of iterator is Valid() iff list is not empty.
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual void SeekToFirst() override {
|
2013-07-23 21:42:27 +00:00
|
|
|
iter_.SeekToFirst();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position at the last entry in list.
|
|
|
|
// Final state of iterator is Valid() iff list is not empty.
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual void SeekToLast() override {
|
2013-07-23 21:42:27 +00:00
|
|
|
iter_.SeekToLast();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-23 06:10:02 +00:00
|
|
|
// Unhide default implementations of GetIterator
|
|
|
|
using MemTableRep::GetIterator;
|
2013-07-23 21:42:27 +00:00
|
|
|
|
2013-08-23 06:10:02 +00:00
|
|
|
virtual std::shared_ptr<MemTableRep::Iterator> GetIterator() override {
|
|
|
|
return std::make_shared<SkipListRep::Iterator>(&skip_list_);
|
2013-07-23 21:42:27 +00:00
|
|
|
}
|
|
|
|
};
|
2013-08-23 06:10:02 +00:00
|
|
|
}
|
2013-07-23 21:42:27 +00:00
|
|
|
|
2013-08-23 06:10:02 +00:00
|
|
|
std::shared_ptr<MemTableRep> SkipListFactory::CreateMemTableRep (
|
|
|
|
MemTableRep::KeyComparator& compare, Arena* arena) {
|
|
|
|
return std::shared_ptr<MemTableRep>(new SkipListRep(compare, arena));
|
2013-07-23 21:42:27 +00:00
|
|
|
}
|
|
|
|
|
2013-08-23 06:10:02 +00:00
|
|
|
} // namespace leveldb
|