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
main
zhangjinpeng1987 8 years ago committed by Facebook Github Bot
parent 2c2ba68247
commit 45c7ce1377
  1. 49
      db/c.cc
  2. 13
      db/c_test.c
  3. 24
      include/rocksdb/c.h

@ -104,6 +104,9 @@ struct rocksdb_readoptions_t {
}; };
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_compactoptions_t {
CompactRangeOptions 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_cuckoo_table_options_t { CuckooTableOptions rep; };
struct rocksdb_seqfile_t { SequentialFile* 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)); (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( void rocksdb_flush(
rocksdb_t* db, rocksdb_t* db,
const rocksdb_flushoptions_t* options, const rocksdb_flushoptions_t* options,
@ -2185,6 +2212,28 @@ void rocksdb_writeoptions_disable_WAL(rocksdb_writeoptions_t* opt, int disable)
opt->rep.disableWAL = 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() { rocksdb_flushoptions_t* rocksdb_flushoptions_create() {
return new rocksdb_flushoptions_t; return new rocksdb_flushoptions_t;

@ -288,6 +288,7 @@ int main(int argc, char** argv) {
rocksdb_cache_t* cache; rocksdb_cache_t* cache;
rocksdb_env_t* env; rocksdb_env_t* env;
rocksdb_options_t* options; rocksdb_options_t* options;
rocksdb_compactoptions_t* coptions;
rocksdb_block_based_table_options_t* table_options; rocksdb_block_based_table_options_t* table_options;
rocksdb_readoptions_t* roptions; rocksdb_readoptions_t* roptions;
rocksdb_writeoptions_t* woptions; rocksdb_writeoptions_t* woptions;
@ -344,6 +345,9 @@ int main(int argc, char** argv) {
woptions = rocksdb_writeoptions_create(); woptions = rocksdb_writeoptions_create();
rocksdb_writeoptions_set_sync(woptions, 1); rocksdb_writeoptions_set_sync(woptions, 1);
coptions = rocksdb_compactoptions_create();
rocksdb_compactoptions_set_exclusive_manual_compaction(coptions, 1);
StartPhase("destroy"); StartPhase("destroy");
rocksdb_destroy_db(options, dbname, &err); rocksdb_destroy_db(options, dbname, &err);
Free(&err); Free(&err);
@ -425,6 +429,14 @@ int main(int argc, char** argv) {
rocksdb_compact_range(db, "a", 1, "z", 1); rocksdb_compact_range(db, "a", 1, "z", 1);
CheckGet(db, roptions, "foo", "hello"); 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"); StartPhase("writebatch");
{ {
rocksdb_writebatch_t* wb = rocksdb_writebatch_create(); 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_block_based_options_destroy(table_options);
rocksdb_readoptions_destroy(roptions); rocksdb_readoptions_destroy(roptions);
rocksdb_writeoptions_destroy(woptions); rocksdb_writeoptions_destroy(woptions);
rocksdb_compactoptions_destroy(coptions);
rocksdb_cache_destroy(cache); rocksdb_cache_destroy(cache);
rocksdb_comparator_destroy(cmp); rocksdb_comparator_destroy(cmp);
rocksdb_env_destroy(env); rocksdb_env_destroy(env);

@ -90,6 +90,7 @@ typedef struct rocksdb_iterator_t rocksdb_iterator_t;
typedef struct rocksdb_logger_t rocksdb_logger_t; typedef struct rocksdb_logger_t rocksdb_logger_t;
typedef struct rocksdb_mergeoperator_t rocksdb_mergeoperator_t; 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_compactoptions_t rocksdb_compactoptions_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 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, const char* start_key, size_t start_key_len, const char* limit_key,
size_t limit_key_len); 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, extern ROCKSDB_LIBRARY_API void rocksdb_delete_file(rocksdb_t* db,
const char* name); 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( extern ROCKSDB_LIBRARY_API void rocksdb_writeoptions_disable_WAL(
rocksdb_writeoptions_t* opt, int disable); 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 */ /* Flush options */
extern ROCKSDB_LIBRARY_API rocksdb_flushoptions_t* extern ROCKSDB_LIBRARY_API rocksdb_flushoptions_t*

Loading…
Cancel
Save