From 38dc5ef45fa7720557903c5852d99a5d3f597a6a Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Mon, 31 Mar 2014 08:28:06 +0200 Subject: [PATCH] [C-API] added the possiblity to create a HashSkipList or HashLinkedList to support prefix seeks --- db/c.cc | 20 ++++++++++++++++++++ db/c_test.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ include/rocksdb/c.h | 2 ++ 3 files changed, 68 insertions(+) diff --git a/db/c.cc b/db/c.cc index 9084c4a9a..2e55c0ea1 100644 --- a/db/c.cc +++ b/db/c.cc @@ -983,6 +983,26 @@ void rocksdb_options_set_memtable_prefix_bloom_probes( opt->rep.memtable_prefix_bloom_probes = v; } +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) { + static rocksdb::MemTableRepFactory* factory = 0; + if (!factory) { + factory = rocksdb::NewHashSkipListRepFactory( + bucket_count, skiplist_height, skiplist_branching_factor); + } + opt->rep.memtable_factory.reset(factory); +} + +void rocksdb_options_set_hash_link_list_rep( + rocksdb_options_t *opt, size_t bucket_count) { + static rocksdb::MemTableRepFactory* factory = 0; + if (!factory) { + factory = rocksdb::NewHashLinkListRepFactory(bucket_count); + } + opt->rep.memtable_factory.reset(factory); +} + void rocksdb_options_set_max_successive_merges( rocksdb_options_t* opt, size_t v) { opt->rep.max_successive_merges = v; diff --git a/db/c_test.c b/db/c_test.c index f17e37128..d8fa8eddb 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -433,6 +433,52 @@ int main(int argc, char** argv) { } + StartPhase("prefix"); + { + // Create new database + rocksdb_close(db); + rocksdb_destroy_db(options, dbname, &err); + + rocksdb_options_set_filter_policy(options, rocksdb_filterpolicy_create_bloom(10)); + rocksdb_options_set_prefix_extractor(options, rocksdb_slicetransform_create_fixed_prefix(3)); + rocksdb_options_set_hash_skip_list_rep(options, 50000, 4, 4); + + db = rocksdb_open(options, dbname, &err); + CheckNoError(err); + + rocksdb_put(db, woptions, "foo1", 4, "foo", 3, &err); + CheckNoError(err); + rocksdb_put(db, woptions, "foo2", 4, "foo", 3, &err); + CheckNoError(err); + rocksdb_put(db, woptions, "foo3", 4, "foo", 3, &err); + CheckNoError(err); + rocksdb_put(db, woptions, "bar1", 4, "bar", 3, &err); + CheckNoError(err); + rocksdb_put(db, woptions, "bar2", 4, "bar", 3, &err); + CheckNoError(err); + rocksdb_put(db, woptions, "bar3", 4, "bar", 3, &err); + CheckNoError(err); + + rocksdb_readoptions_set_prefix_seek(roptions, 1); + + rocksdb_iterator_t* iter = rocksdb_create_iterator(db, roptions); + CheckCondition(!rocksdb_iter_valid(iter)); + + rocksdb_iter_seek(iter, "bar", 3); + rocksdb_iter_get_error(iter, &err); + CheckNoError(err); + CheckCondition(rocksdb_iter_valid(iter)); + + CheckIter(iter, "bar1", "bar"); + rocksdb_iter_next(iter); + CheckIter(iter, "bar2", "bar"); + rocksdb_iter_next(iter); + CheckIter(iter, "bar3", "bar"); + rocksdb_iter_get_error(iter, &err); + CheckNoError(err); + rocksdb_iter_destroy(iter); + } + StartPhase("cleanup"); rocksdb_close(db); rocksdb_options_destroy(options); diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index 23c63f24f..a6bc90085 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -346,6 +346,8 @@ extern void rocksdb_options_set_delete_obsolete_files_period_micros( extern void rocksdb_options_set_source_compaction_factor(rocksdb_options_t*, int); extern void rocksdb_options_prepare_for_bulk_load(rocksdb_options_t*); extern void rocksdb_options_set_memtable_vector_rep(rocksdb_options_t*); +extern void rocksdb_options_set_hash_skip_list_rep(rocksdb_options_t*, size_t, int32_t, int32_t); +extern void rocksdb_options_set_hash_link_list_rep(rocksdb_options_t*, size_t); extern void rocksdb_options_set_max_bytes_for_level_base(rocksdb_options_t* opt, uint64_t n); extern void rocksdb_options_set_stats_dump_period_sec(rocksdb_options_t* opt, unsigned int sec);