From a10e8a056d569acf6a52045124e6414ad33bdfcd Mon Sep 17 00:00:00 2001 From: Adam Faulkner Date: Mon, 12 Sep 2016 15:31:42 -0700 Subject: [PATCH] Fix C api memtable rep bugs. (#1328) --- db/c.cc | 36 +++++++++++------------------------- db/c_test.c | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/db/c.cc b/db/c.cc index c9d0a2316..89b392b59 100644 --- a/db/c.cc +++ b/db/c.cc @@ -1783,11 +1783,7 @@ void rocksdb_options_prepare_for_bulk_load(rocksdb_options_t* opt) { } void rocksdb_options_set_memtable_vector_rep(rocksdb_options_t *opt) { - static rocksdb::VectorRepFactory* factory = 0; - if (!factory) { - factory = new rocksdb::VectorRepFactory; - } - opt->rep.memtable_factory.reset(factory); + opt->rep.memtable_factory.reset(new rocksdb::VectorRepFactory); } void rocksdb_options_set_memtable_prefix_bloom_size_ratio( @@ -1803,36 +1799,26 @@ void rocksdb_options_set_memtable_huge_page_size(rocksdb_options_t* opt, 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); - } + rocksdb::MemTableRepFactory* 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); + opt->rep.memtable_factory.reset(rocksdb::NewHashLinkListRepFactory(bucket_count)); } void rocksdb_options_set_plain_table_factory( rocksdb_options_t *opt, uint32_t user_key_len, int bloom_bits_per_key, double hash_table_ratio, size_t index_sparseness) { - static rocksdb::TableFactory* factory = 0; - if (!factory) { - rocksdb::PlainTableOptions options; - options.user_key_len = user_key_len; - options.bloom_bits_per_key = bloom_bits_per_key; - options.hash_table_ratio = hash_table_ratio; - options.index_sparseness = index_sparseness; - - factory = rocksdb::NewPlainTableFactory(options); - } + rocksdb::PlainTableOptions options; + options.user_key_len = user_key_len; + options.bloom_bits_per_key = bloom_bits_per_key; + options.hash_table_ratio = hash_table_ratio; + options.index_sparseness = index_sparseness; + + rocksdb::TableFactory* factory = rocksdb::NewPlainTableFactory(options); opt->rep.table_factory.reset(factory); } diff --git a/db/c_test.c b/db/c_test.c index 7194a843b..0dc3a974c 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -944,6 +944,28 @@ int main(int argc, char** argv) { } } + // Simple sanity check that setting memtable rep works. + StartPhase("memtable_reps"); + { + // Create database with vector memtable. + rocksdb_close(db); + rocksdb_destroy_db(options, dbname, &err); + CheckNoError(err); + + rocksdb_options_set_memtable_vector_rep(options); + db = rocksdb_open(options, dbname, &err); + CheckNoError(err); + + // Create database with hash skiplist memtable. + rocksdb_close(db); + rocksdb_destroy_db(options, dbname, &err); + CheckNoError(err); + + rocksdb_options_set_hash_skip_list_rep(options, 5000, 4, 4); + db = rocksdb_open(options, dbname, &err); + CheckNoError(err); + } + StartPhase("cleanup"); rocksdb_close(db); rocksdb_options_destroy(options); -- GitLab