Skip to content

Commit

Permalink
Doubly skiplist for reverse scan (#116)
Browse files Browse the repository at this point in the history
Signed-off-by: Little-Wallace liuwei@pingcap.com

When the iterator read keys in reverse order, each Prev() function cost O(log n) times. So I add prev pointer for every node in skiplist to improve the Prev() function.
  • Loading branch information
Little-Wallace authored and Yi Wu committed Sep 19, 2019
1 parent c142c93 commit eb7c79f
Show file tree
Hide file tree
Showing 6 changed files with 1,207 additions and 46 deletions.
6 changes: 6 additions & 0 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,12 @@ void rocksdb_options_set_memtable_huge_page_size(rocksdb_options_t* opt,
opt->rep.memtable_huge_page_size = v;
}

void rocksdb_options_set_doubly_skip_list_rep(rocksdb_options_t *opt) {
rocksdb::MemTableRepFactory* factory = new rocksdb::DoublySkipListFactory();
opt->rep.memtable_factory.reset(factory);
}


void rocksdb_options_set_hash_skip_list_rep(
rocksdb_options_t *opt, size_t bucket_count,
int32_t skiplist_height, int32_t skiplist_branching_factor) {
Expand Down
1 change: 1 addition & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_skip_list_rep(
rocksdb_options_t*, size_t, int32_t, int32_t);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_hash_link_list_rep(
rocksdb_options_t*, size_t);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_doubly_skip_list_rep(rocksdb_options_t *opt);
extern ROCKSDB_LIBRARY_API void rocksdb_options_set_plain_table_factory(
rocksdb_options_t*, uint32_t, int, double, size_t);

Expand Down
21 changes: 20 additions & 1 deletion include/rocksdb/memtablerep.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,26 @@ class SkipListFactory : public MemTableRepFactory {

bool CanHandleDuplicatedKey() const override { return true; }

private:
private:
const size_t lookahead_;
};

// This uses a doubly skip list to store keys, which is similar to skip list, but optimize for prev seek.
class DoublySkipListFactory : public MemTableRepFactory {
public:
explicit DoublySkipListFactory(size_t lookahead = 0) : lookahead_(lookahead) {}

using MemTableRepFactory::CreateMemTableRep;
virtual MemTableRep* CreateMemTableRep(const MemTableRep::KeyComparator&,
Allocator*, const SliceTransform*,
Logger* logger) override;
const char* Name() const override { return "DoublySkipListFactory"; }

bool IsInsertConcurrentlySupported() const override { return true; }

bool CanHandleDuplicatedKey() const override { return true; }

private:
const size_t lookahead_;
};

Expand Down
Loading

0 comments on commit eb7c79f

Please sign in to comment.