diff --git a/db/c.cc b/db/c.cc index 935a297f107354c34c81f4f734ae0d1495f232ac..0a8e0700eee19b0ef330427d2822fdcce23ea68d 100644 --- a/db/c.cc +++ b/db/c.cc @@ -51,6 +51,7 @@ using rocksdb::Status; using rocksdb::WritableFile; using rocksdb::WriteBatch; using rocksdb::WriteOptions; +using rocksdb::LiveFileMetaData; using std::shared_ptr; @@ -70,6 +71,7 @@ struct rocksdb_writablefile_t { WritableFile* rep; }; struct rocksdb_filelock_t { FileLock* rep; }; struct rocksdb_logger_t { shared_ptr rep; }; struct rocksdb_cache_t { shared_ptr rep; }; +struct rocksdb_livefiles_t { std::vector rep; }; struct rocksdb_comparator_t : public Comparator { void* state_; @@ -435,6 +437,19 @@ void rocksdb_approximate_sizes( delete[] ranges; } +void rocksdb_delete_file( + rocksdb_t* db, + const char* name) { + db->rep->DeleteFile(name); +} + +const rocksdb_livefiles_t* rocksdb_livefiles( + rocksdb_t* db) { + rocksdb_livefiles_t* result = new rocksdb_livefiles_t; + db->rep->GetLiveFilesMetaData(&result->rep); + return result; +} + void rocksdb_compact_range( rocksdb_t* db, const char* start_key, size_t start_key_len, @@ -537,6 +552,10 @@ void rocksdb_writebatch_clear(rocksdb_writebatch_t* b) { b->rep.Clear(); } +int rocksdb_writebatch_count(rocksdb_writebatch_t* b) { + return b->rep.Count(); +} + void rocksdb_writebatch_put( rocksdb_writebatch_t* b, const char* key, size_t klen, @@ -581,6 +600,11 @@ void rocksdb_writebatch_iterate( b->rep.Iterate(&handler); } +const char* rocksdb_writebatch_data(rocksdb_writebatch_t* b, size_t* size) { + *size = b->rep.GetDataSize(); + return b->rep.Data().c_str(); +} + rocksdb_options_t* rocksdb_options_create() { return new rocksdb_options_t; } @@ -983,7 +1007,6 @@ DB::GetSortedWalFiles DB::GetLatestSequenceNumber DB::GetUpdatesSince DB::DeleteFile -DB::GetLiveFilesMetaData DB::GetDbIdentity DB::RunManualCompaction custom cache @@ -1304,4 +1327,61 @@ void rocksdb_universal_compaction_options_destroy( delete uco; } +void rocksdb_options_set_min_level_to_compress(rocksdb_options_t* opt, int level) { + if (level >= 0) { + assert(level <= opt->rep.num_levels); + opt->rep.compression_per_level.resize(opt->rep.num_levels); + for (int i = 0; i < level; i++) { + opt->rep.compression_per_level[i] = rocksdb::kNoCompression; + } + for (int i = level; i < opt->rep.num_levels; i++) { + opt->rep.compression_per_level[i] = opt->rep.compression; + } + } +} + +int rocksdb_livefiles_count( + const rocksdb_livefiles_t* lf) { + return lf->rep.size(); +} + +const char* rocksdb_livefiles_name( + const rocksdb_livefiles_t* lf, + int index) { + return lf->rep[index].name.c_str(); +} + +int rocksdb_livefiles_level( + const rocksdb_livefiles_t* lf, + int index) { + return lf->rep[index].level; +} + +size_t rocksdb_livefiles_size( + const rocksdb_livefiles_t* lf, + int index) { + return lf->rep[index].size; +} + +const char* rocksdb_livefiles_smallestkey( + const rocksdb_livefiles_t* lf, + int index, + size_t* size) { + *size = lf->rep[index].smallestkey.size(); + return lf->rep[index].smallestkey.data(); +} + +const char* rocksdb_livefiles_largestkey( + const rocksdb_livefiles_t* lf, + int index, + size_t* size) { + *size = lf->rep[index].largestkey.size(); + return lf->rep[index].largestkey.data(); +} + +extern void rocksdb_livefiles_destroy( + const rocksdb_livefiles_t* lf) { + delete lf; +} + } // end extern "C" diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index 91efed37fdd02ec1e59e95443381411ed399ed97..62be94fe489431726913289137d7999feb56b4c1 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -74,6 +74,7 @@ typedef struct rocksdb_writablefile_t rocksdb_writablefile_t; typedef struct rocksdb_writebatch_t rocksdb_writebatch_t; typedef struct rocksdb_writeoptions_t rocksdb_writeoptions_t; typedef struct rocksdb_universal_compaction_options_t rocksdb_universal_compaction_options_t; +typedef struct rocksdb_livefiles_t rocksdb_livefiles_t; /* DB operations */ @@ -148,6 +149,13 @@ extern void rocksdb_compact_range( const char* start_key, size_t start_key_len, const char* limit_key, size_t limit_key_len); +extern void rocksdb_delete_file( + rocksdb_t* db, + const char* name); + +extern const rocksdb_livefiles_t* rocksdb_livefiles( + rocksdb_t* db); + extern void rocksdb_flush( rocksdb_t* db, const rocksdb_flushoptions_t* options, @@ -192,6 +200,7 @@ extern void rocksdb_iter_get_error(const rocksdb_iterator_t*, char** errptr); extern rocksdb_writebatch_t* rocksdb_writebatch_create(); extern void rocksdb_writebatch_destroy(rocksdb_writebatch_t*); extern void rocksdb_writebatch_clear(rocksdb_writebatch_t*); +extern int rocksdb_writebatch_count(rocksdb_writebatch_t*); extern void rocksdb_writebatch_put( rocksdb_writebatch_t*, const char* key, size_t klen, @@ -208,6 +217,7 @@ extern void rocksdb_writebatch_iterate( void* state, void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*deleted)(void*, const char* k, size_t klen)); +extern const char* rocksdb_writebatch_data(rocksdb_writebatch_t*, size_t *size); /* Options */ @@ -336,6 +346,12 @@ 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_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); + +extern void rocksdb_options_set_min_level_to_compress(rocksdb_options_t* opt, int level); + extern void rocksdb_options_set_memtable_prefix_bloom_bits( rocksdb_options_t*, uint32_t); extern void rocksdb_options_set_memtable_prefix_bloom_probes( @@ -508,6 +524,28 @@ extern void rocksdb_universal_compaction_options_set_stop_style( extern void rocksdb_universal_compaction_options_destroy( rocksdb_universal_compaction_options_t*); +extern int rocksdb_livefiles_count( + const rocksdb_livefiles_t*); +extern const char* rocksdb_livefiles_name( + const rocksdb_livefiles_t*, + int index); +extern int rocksdb_livefiles_level( + const rocksdb_livefiles_t*, + int index); +extern size_t rocksdb_livefiles_size( + const rocksdb_livefiles_t*, + int index); +extern const char* rocksdb_livefiles_smallestkey( + const rocksdb_livefiles_t*, + int index, + size_t* size); +extern const char* rocksdb_livefiles_largestkey( + const rocksdb_livefiles_t*, + int index, + size_t* size); +extern void rocksdb_livefiles_destroy( + const rocksdb_livefiles_t*); + #ifdef __cplusplus } /* end extern "C" */ #endif