Merge pull request #394 from lalinsky/cuckoo-c

Cuckoo table options missing in the C interface
This commit is contained in:
Igor Canadi 2014-11-14 13:23:06 -08:00
commit 5f583d2a9c
4 changed files with 90 additions and 2 deletions

47
db/c.cc
View file

@ -56,6 +56,7 @@ using rocksdb::NewBloomFilterPolicy;
using rocksdb::NewLRUCache; using rocksdb::NewLRUCache;
using rocksdb::Options; using rocksdb::Options;
using rocksdb::BlockBasedTableOptions; using rocksdb::BlockBasedTableOptions;
using rocksdb::CuckooTableOptions;
using rocksdb::RandomAccessFile; using rocksdb::RandomAccessFile;
using rocksdb::Range; using rocksdb::Range;
using rocksdb::ReadOptions; using rocksdb::ReadOptions;
@ -83,6 +84,7 @@ struct rocksdb_readoptions_t { ReadOptions rep; };
struct rocksdb_writeoptions_t { WriteOptions rep; }; struct rocksdb_writeoptions_t { WriteOptions rep; };
struct rocksdb_options_t { Options rep; }; struct rocksdb_options_t { Options rep; };
struct rocksdb_block_based_table_options_t { BlockBasedTableOptions rep; }; struct rocksdb_block_based_table_options_t { BlockBasedTableOptions rep; };
struct rocksdb_cuckoo_table_options_t { CuckooTableOptions rep; };
struct rocksdb_seqfile_t { SequentialFile* rep; }; struct rocksdb_seqfile_t { SequentialFile* rep; };
struct rocksdb_randomfile_t { RandomAccessFile* rep; }; struct rocksdb_randomfile_t { RandomAccessFile* rep; };
struct rocksdb_writablefile_t { WritableFile* rep; }; struct rocksdb_writablefile_t { WritableFile* rep; };
@ -1121,6 +1123,51 @@ void rocksdb_options_set_block_based_table_factory(
} }
rocksdb_cuckoo_table_options_t*
rocksdb_cuckoo_options_create() {
return new rocksdb_cuckoo_table_options_t;
}
void rocksdb_cuckoo_options_destroy(
rocksdb_cuckoo_table_options_t* options) {
delete options;
}
void rocksdb_cuckoo_options_set_hash_ratio(
rocksdb_cuckoo_table_options_t* options, double v) {
options->rep.hash_table_ratio = v;
}
void rocksdb_cuckoo_options_set_max_search_depth(
rocksdb_cuckoo_table_options_t* options, uint32_t v) {
options->rep.max_search_depth = v;
}
void rocksdb_cuckoo_options_set_cuckoo_block_size(
rocksdb_cuckoo_table_options_t* options, uint32_t v) {
options->rep.cuckoo_block_size = v;
}
void rocksdb_cuckoo_options_set_identity_as_first_hash(
rocksdb_cuckoo_table_options_t* options, unsigned char v) {
options->rep.identity_as_first_hash = v;
}
void rocksdb_cuckoo_options_set_use_module_hash(
rocksdb_cuckoo_table_options_t* options, unsigned char v) {
options->rep.use_module_hash = v;
}
void rocksdb_options_set_cuckoo_table_factory(
rocksdb_options_t *opt,
rocksdb_cuckoo_table_options_t* table_options) {
if (table_options) {
opt->rep.table_factory.reset(
rocksdb::NewCuckooTableFactory(table_options->rep));
}
}
rocksdb_options_t* rocksdb_options_create() { rocksdb_options_t* rocksdb_options_create() {
return new rocksdb_options_t; return new rocksdb_options_t;
} }

View file

@ -801,8 +801,27 @@ int main(int argc, char** argv) {
rocksdb_iter_get_error(iter, &err); rocksdb_iter_get_error(iter, &err);
CheckNoError(err); CheckNoError(err);
rocksdb_iter_destroy(iter); rocksdb_iter_destroy(iter);
rocksdb_close(db);
rocksdb_destroy_db(options, dbname, &err);
} }
StartPhase("cuckoo_options");
{
rocksdb_cuckoo_table_options_t* cuckoo_options;
cuckoo_options = rocksdb_cuckoo_options_create();
rocksdb_cuckoo_options_set_hash_ratio(cuckoo_options, 0.5);
rocksdb_cuckoo_options_set_max_search_depth(cuckoo_options, 200);
rocksdb_cuckoo_options_set_cuckoo_block_size(cuckoo_options, 10);
rocksdb_cuckoo_options_set_identity_as_first_hash(cuckoo_options, 1);
rocksdb_cuckoo_options_set_use_module_hash(cuckoo_options, 0);
rocksdb_options_set_cuckoo_table_factory(options, cuckoo_options);
db = rocksdb_open(options, dbname, &err);
CheckNoError(err);
rocksdb_cuckoo_options_destroy(cuckoo_options);
}
StartPhase("cleanup"); StartPhase("cleanup");
rocksdb_close(db); rocksdb_close(db);

View file

@ -77,6 +77,8 @@ typedef struct rocksdb_mergeoperator_t rocksdb_mergeoperator_t;
typedef struct rocksdb_options_t rocksdb_options_t; typedef struct rocksdb_options_t rocksdb_options_t;
typedef struct rocksdb_block_based_table_options_t typedef struct rocksdb_block_based_table_options_t
rocksdb_block_based_table_options_t; rocksdb_block_based_table_options_t;
typedef struct rocksdb_cuckoo_table_options_t
rocksdb_cuckoo_table_options_t;
typedef struct rocksdb_randomfile_t rocksdb_randomfile_t; typedef struct rocksdb_randomfile_t rocksdb_randomfile_t;
typedef struct rocksdb_readoptions_t rocksdb_readoptions_t; typedef struct rocksdb_readoptions_t rocksdb_readoptions_t;
typedef struct rocksdb_seqfile_t rocksdb_seqfile_t; typedef struct rocksdb_seqfile_t rocksdb_seqfile_t;
@ -376,6 +378,25 @@ extern void rocksdb_block_based_options_set_whole_key_filtering(
extern void rocksdb_options_set_block_based_table_factory( extern void rocksdb_options_set_block_based_table_factory(
rocksdb_options_t *opt, rocksdb_block_based_table_options_t* table_options); rocksdb_options_t *opt, rocksdb_block_based_table_options_t* table_options);
/* Cuckoo table options */
extern rocksdb_cuckoo_table_options_t*
rocksdb_cuckoo_options_create();
extern void rocksdb_cuckoo_options_destroy(
rocksdb_cuckoo_table_options_t* options);
extern void rocksdb_cuckoo_options_set_hash_ratio(
rocksdb_cuckoo_table_options_t* options, double v);
extern void rocksdb_cuckoo_options_set_max_search_depth(
rocksdb_cuckoo_table_options_t* options, uint32_t v);
extern void rocksdb_cuckoo_options_set_cuckoo_block_size(
rocksdb_cuckoo_table_options_t* options, uint32_t v);
extern void rocksdb_cuckoo_options_set_identity_as_first_hash(
rocksdb_cuckoo_table_options_t* options, unsigned char v);
extern void rocksdb_cuckoo_options_set_use_module_hash(
rocksdb_cuckoo_table_options_t* options, unsigned char v);
extern void rocksdb_options_set_cuckoo_table_factory(
rocksdb_options_t *opt, rocksdb_cuckoo_table_options_t* table_options);
/* Options */ /* Options */
extern rocksdb_options_t* rocksdb_options_create(); extern rocksdb_options_t* rocksdb_options_create();

View file

@ -369,13 +369,14 @@ class TableFactory {
}; };
#ifndef ROCKSDB_LITE #ifndef ROCKSDB_LITE
// Create a special table factory that can open both of block based table format // Create a special table factory that can open either of the supported
// and plain table, based on setting inside the SST files. It should be used to // table formats, based on setting inside the SST files. It should be used to
// convert a DB from one table format to another. // convert a DB from one table format to another.
// @table_factory_to_write: the table factory used when writing to new files. // @table_factory_to_write: the table factory used when writing to new files.
// @block_based_table_factory: block based table factory to use. If NULL, use // @block_based_table_factory: block based table factory to use. If NULL, use
// a default one. // a default one.
// @plain_table_factory: plain table factory to use. If NULL, use a default one. // @plain_table_factory: plain table factory to use. If NULL, use a default one.
// @cuckoo_table_factory: cuckoo table factory to use. If NULL, use a default one.
extern TableFactory* NewAdaptiveTableFactory( extern TableFactory* NewAdaptiveTableFactory(
std::shared_ptr<TableFactory> table_factory_to_write = nullptr, std::shared_ptr<TableFactory> table_factory_to_write = nullptr,
std::shared_ptr<TableFactory> block_based_table_factory = nullptr, std::shared_ptr<TableFactory> block_based_table_factory = nullptr,