Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doubly skiplist #377

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions db/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3820,6 +3820,11 @@ size_t rocksdb_options_get_memtable_huge_page_size(rocksdb_options_t* opt) {
return opt->rep.memtable_huge_page_size;
}

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,
Expand Down
2 changes: 2 additions & 0 deletions include/rocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,8 @@ 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, size_t, char,
unsigned char, unsigned char);
Expand Down
21 changes: 21 additions & 0 deletions include/rocksdb/memtablerep.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,27 @@ class SkipListFactory : public MemTableRepFactory {
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:
size_t lookahead_;
};

// This creates MemTableReps that are backed by an std::vector. On iteration,
// the vector is sorted. This is useful for workloads where iteration is very
// rare and writes are generally not issued after reads begin.
Expand Down
Loading
Loading