From 45c7ce1377b19df185069cf75195bfe4bd80ed5d Mon Sep 17 00:00:00 2001 From: zhangjinpeng1987 Date: Wed, 7 Dec 2016 17:44:35 -0800 Subject: [PATCH] CompactRangeOptions C API Summary: Add C API for CompactRangeOptions. Closes https://github.com/facebook/rocksdb/pull/1596 Differential Revision: D4252339 Pulled By: yiwu-arbug fbshipit-source-id: f768f93 --- db/c.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++ db/c_test.c | 13 ++++++++++++ include/rocksdb/c.h | 24 ++++++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/db/c.cc b/db/c.cc index 15c3c9807..49eca765f 100644 --- a/db/c.cc +++ b/db/c.cc @@ -104,6 +104,9 @@ struct rocksdb_readoptions_t { }; struct rocksdb_writeoptions_t { WriteOptions rep; }; struct rocksdb_options_t { Options rep; }; +struct rocksdb_compactoptions_t { + CompactRangeOptions rep; +}; struct rocksdb_block_based_table_options_t { BlockBasedTableOptions rep; }; struct rocksdb_cuckoo_table_options_t { CuckooTableOptions rep; }; struct rocksdb_seqfile_t { SequentialFile* rep; }; @@ -976,6 +979,30 @@ void rocksdb_compact_range_cf( (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); } +void rocksdb_compact_range_opt(rocksdb_t* db, rocksdb_compactoptions_t* opt, + const char* start_key, size_t start_key_len, + const char* limit_key, size_t limit_key_len) { + Slice a, b; + db->rep->CompactRange( + opt->rep, + // Pass nullptr Slice if corresponding "const char*" is nullptr + (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), + (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); +} + +void rocksdb_compact_range_cf_opt(rocksdb_t* db, + rocksdb_column_family_handle_t* column_family, + rocksdb_compactoptions_t* opt, + const char* start_key, size_t start_key_len, + const char* limit_key, size_t limit_key_len) { + Slice a, b; + db->rep->CompactRange( + opt->rep, column_family->rep, + // Pass nullptr Slice if corresponding "const char*" is nullptr + (start_key ? (a = Slice(start_key, start_key_len), &a) : nullptr), + (limit_key ? (b = Slice(limit_key, limit_key_len), &b) : nullptr)); +} + void rocksdb_flush( rocksdb_t* db, const rocksdb_flushoptions_t* options, @@ -2185,6 +2212,28 @@ void rocksdb_writeoptions_disable_WAL(rocksdb_writeoptions_t* opt, int disable) opt->rep.disableWAL = disable; } +rocksdb_compactoptions_t* rocksdb_compactoptions_create() { + return new rocksdb_compactoptions_t; +} + +void rocksdb_compactoptions_destroy(rocksdb_compactoptions_t* opt) { + delete opt; +} + +void rocksdb_compactoptions_set_exclusive_manual_compaction( + rocksdb_compactoptions_t* opt, unsigned char v) { + opt->rep.exclusive_manual_compaction = v; +} + +void rocksdb_compactoptions_set_change_level(rocksdb_compactoptions_t* opt, + unsigned char v) { + opt->rep.change_level = v; +} + +void rocksdb_compactoptions_set_target_level(rocksdb_compactoptions_t* opt, + int n) { + opt->rep.target_level = n; +} rocksdb_flushoptions_t* rocksdb_flushoptions_create() { return new rocksdb_flushoptions_t; diff --git a/db/c_test.c b/db/c_test.c index 0260ec3fa..120fd23b7 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -288,6 +288,7 @@ int main(int argc, char** argv) { rocksdb_cache_t* cache; rocksdb_env_t* env; rocksdb_options_t* options; + rocksdb_compactoptions_t* coptions; rocksdb_block_based_table_options_t* table_options; rocksdb_readoptions_t* roptions; rocksdb_writeoptions_t* woptions; @@ -344,6 +345,9 @@ int main(int argc, char** argv) { woptions = rocksdb_writeoptions_create(); rocksdb_writeoptions_set_sync(woptions, 1); + coptions = rocksdb_compactoptions_create(); + rocksdb_compactoptions_set_exclusive_manual_compaction(coptions, 1); + StartPhase("destroy"); rocksdb_destroy_db(options, dbname, &err); Free(&err); @@ -425,6 +429,14 @@ int main(int argc, char** argv) { rocksdb_compact_range(db, "a", 1, "z", 1); CheckGet(db, roptions, "foo", "hello"); + StartPhase("compactallopt"); + rocksdb_compact_range_opt(db, coptions, NULL, 0, NULL, 0); + CheckGet(db, roptions, "foo", "hello"); + + StartPhase("compactrangeopt"); + rocksdb_compact_range_opt(db, coptions, "a", 1, "z", 1); + CheckGet(db, roptions, "foo", "hello"); + StartPhase("writebatch"); { rocksdb_writebatch_t* wb = rocksdb_writebatch_create(); @@ -1040,6 +1052,7 @@ int main(int argc, char** argv) { rocksdb_block_based_options_destroy(table_options); rocksdb_readoptions_destroy(roptions); rocksdb_writeoptions_destroy(woptions); + rocksdb_compactoptions_destroy(coptions); rocksdb_cache_destroy(cache); rocksdb_comparator_destroy(cmp); rocksdb_env_destroy(env); diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index fddf3e076..1c5bdb278 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -90,6 +90,7 @@ typedef struct rocksdb_iterator_t rocksdb_iterator_t; typedef struct rocksdb_logger_t rocksdb_logger_t; typedef struct rocksdb_mergeoperator_t rocksdb_mergeoperator_t; typedef struct rocksdb_options_t rocksdb_options_t; +typedef struct rocksdb_compactoptions_t rocksdb_compactoptions_t; typedef struct rocksdb_block_based_table_options_t rocksdb_block_based_table_options_t; typedef struct rocksdb_cuckoo_table_options_t @@ -315,6 +316,15 @@ extern ROCKSDB_LIBRARY_API void rocksdb_compact_range_cf( const char* start_key, size_t start_key_len, const char* limit_key, size_t limit_key_len); +extern ROCKSDB_LIBRARY_API void rocksdb_compact_range_opt( + rocksdb_t* db, rocksdb_compactoptions_t* opt, const char* start_key, + size_t start_key_len, const char* limit_key, size_t limit_key_len); + +extern ROCKSDB_LIBRARY_API void rocksdb_compact_range_cf_opt( + rocksdb_t* db, rocksdb_column_family_handle_t* column_family, + rocksdb_compactoptions_t* opt, const char* start_key, size_t start_key_len, + const char* limit_key, size_t limit_key_len); + extern ROCKSDB_LIBRARY_API void rocksdb_delete_file(rocksdb_t* db, const char* name); @@ -861,6 +871,20 @@ extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_set_sync( extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_disable_WAL( rocksdb_writeoptions_t* opt, int disable); +/* Compact range options */ + +extern ROCKSDB_LIBRARY_API rocksdb_compactoptions_t* +rocksdb_compactoptions_create(); +extern ROCKSDB_LIBRARY_API void rocksdb_compactoptions_destroy( + rocksdb_compactoptions_t*); +extern ROCKSDB_LIBRARY_API void +rocksdb_compactoptions_set_exclusive_manual_compaction( + rocksdb_compactoptions_t*, unsigned char); +extern ROCKSDB_LIBRARY_API void rocksdb_compactoptions_set_change_level( + rocksdb_compactoptions_t*, unsigned char); +extern ROCKSDB_LIBRARY_API void rocksdb_compactoptions_set_target_level( + rocksdb_compactoptions_t*, int); + /* Flush options */ extern ROCKSDB_LIBRARY_API rocksdb_flushoptions_t*