diff --git a/librocksdb_sys/crocksdb/c.cc b/librocksdb_sys/crocksdb/c.cc index ea58d546f..e1aabe9e7 100644 --- a/librocksdb_sys/crocksdb/c.cc +++ b/librocksdb_sys/crocksdb/c.cc @@ -40,6 +40,7 @@ #include "rocksdb/rate_limiter.h" #include "rocksdb/slice_transform.h" #include "rocksdb/sst_dump_tool.h" +#include "rocksdb/sst_file_manager.h" #include "rocksdb/sst_file_reader.h" #include "rocksdb/sst_partitioner.h" #include "rocksdb/statistics.h" @@ -147,6 +148,7 @@ using rocksdb::Slice; using rocksdb::SliceParts; using rocksdb::SliceTransform; using rocksdb::Snapshot; +using rocksdb::SstFileManager; using rocksdb::SstFileReader; using rocksdb::SstFileWriter; using rocksdb::SstPartitioner; @@ -356,6 +358,9 @@ struct crocksdb_sequential_file_t { struct crocksdb_ingestexternalfileoptions_t { IngestExternalFileOptions rep; }; +struct crocksdb_sstfilemanager_t { + shared_ptr rep; +}; struct crocksdb_sstfilereader_t { SstFileReader* rep; }; @@ -4770,6 +4775,26 @@ crocksdb_env_t* crocksdb_file_system_inspected_env_create( return result; } +crocksdb_sstfilemanager_t* crocksdb_sstfilemanager_create(crocksdb_env_t* env) { + auto manager = new crocksdb_sstfilemanager_t; + manager->rep.reset(NewSstFileManager(env->rep)); + return manager; +} + +void crocksdb_sstfilemanager_destroy(crocksdb_sstfilemanager_t* file_manager) { + delete file_manager; +} + +uint64_t crocksdb_sstfilemanager_get_total_size( + crocksdb_sstfilemanager_t* file_manager) { + return file_manager->rep->GetTotalSize(); +} + +void crocksdb_options_set_sstfilemanager( + crocksdb_options_t* opt, crocksdb_sstfilemanager_t* file_manager) { + opt->rep.sst_file_manager = file_manager->rep; +} + crocksdb_sstfilereader_t* crocksdb_sstfilereader_create( const crocksdb_options_t* io_options) { auto reader = new crocksdb_sstfilereader_t; diff --git a/librocksdb_sys/crocksdb/crocksdb/c.h b/librocksdb_sys/crocksdb/crocksdb/c.h index 7e8bce09f..b06b67fa0 100644 --- a/librocksdb_sys/crocksdb/crocksdb/c.h +++ b/librocksdb_sys/crocksdb/crocksdb/c.h @@ -119,6 +119,7 @@ typedef struct crocksdb_envoptions_t crocksdb_envoptions_t; typedef struct crocksdb_sequential_file_t crocksdb_sequential_file_t; typedef struct crocksdb_ingestexternalfileoptions_t crocksdb_ingestexternalfileoptions_t; +typedef struct crocksdb_sstfilemanager_t crocksdb_sstfilemanager_t; typedef struct crocksdb_sstfilereader_t crocksdb_sstfilereader_t; typedef struct crocksdb_sstfilewriter_t crocksdb_sstfilewriter_t; typedef struct crocksdb_externalsstfileinfo_t crocksdb_externalsstfileinfo_t; @@ -1894,6 +1895,20 @@ extern C_ROCKSDB_LIBRARY_API crocksdb_env_t* crocksdb_file_system_inspected_env_create(crocksdb_env_t*, crocksdb_file_system_inspector_t*); +/* SstFileManager */ + +extern C_ROCKSDB_LIBRARY_API crocksdb_sstfilemanager_t* +crocksdb_sstfilemanager_create(crocksdb_env_t* env); + +extern C_ROCKSDB_LIBRARY_API void crocksdb_sstfilemanager_destroy( + crocksdb_sstfilemanager_t* file_manager); + +extern C_ROCKSDB_LIBRARY_API uint64_t +crocksdb_sstfilemanager_get_total_size(crocksdb_sstfilemanager_t* file_manager); + +extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_sst_filemanager( + crocksdb_options_t* opt, crocksdb_sstfilemanager_t* file_manager); + /* SstFile */ extern C_ROCKSDB_LIBRARY_API crocksdb_sstfilereader_t* diff --git a/librocksdb_sys/src/lib.rs b/librocksdb_sys/src/lib.rs index 67a034689..fff7717c7 100644 --- a/librocksdb_sys/src/lib.rs +++ b/librocksdb_sys/src/lib.rs @@ -92,6 +92,8 @@ pub struct DBCheckpoint(c_void); #[repr(C)] pub struct EnvOptions(c_void); #[repr(C)] +pub struct SstFileManager(c_void); +#[repr(C)] pub struct SstFileReader(c_void); #[repr(C)] pub struct SstFileWriter(c_void); @@ -2045,6 +2047,15 @@ extern "C" { inspector: *mut DBFileSystemInspectorInstance, ) -> *mut DBEnv; + // SstFileManager + pub fn crocksdb_sstfilemanager_create(env: *const DBEnv) -> *mut SstFileManager; + pub fn crocksdb_sstfilemanager_destroy(file_manager: *mut SstFileManager); + pub fn crocksdb_sstfilemanager_get_total_size(file_manager: *const SstFileManager) -> u64; + pub fn crocksdb_options_set_sstfilemanager( + options: *mut Options, + file_manager: *const SstFileManager, + ); + // SstFileReader pub fn crocksdb_sstfilereader_create(io_options: *const Options) -> *mut SstFileReader; diff --git a/src/lib.rs b/src/lib.rs index 2d6fc4074..c169dbcc4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,6 +70,7 @@ pub use rocksdb_options::{ RateLimiter, ReadOptions, RestoreOptions, Statistics, WriteBufferManager, WriteOptions, }; pub use slice_transform::SliceTransform; +pub use sst_file_manager::SstFileManager; pub use sst_partitioner::{ SstPartitioner, SstPartitionerContext, SstPartitionerFactory, SstPartitionerRequest, }; @@ -100,6 +101,7 @@ mod perf_context; pub mod rocksdb; pub mod rocksdb_options; mod slice_transform; +pub mod sst_file_manager; pub mod sst_partitioner; mod table_filter; mod table_properties; diff --git a/src/rocksdb_options.rs b/src/rocksdb_options.rs index 32a73ae8f..2b167e1c8 100644 --- a/src/rocksdb_options.rs +++ b/src/rocksdb_options.rs @@ -44,6 +44,7 @@ use table_properties_collector_factory::{ new_table_properties_collector_factory, TablePropertiesCollectorFactory, }; use titan::TitanDBOptions; +use SstFileManager; use TablePropertiesCollector; #[derive(Default, Debug)] @@ -1236,6 +1237,12 @@ impl DBOptions { } } + pub fn set_sst_file_manager(&mut self, file_manager: &SstFileManager) { + unsafe { + crocksdb_ffi::crocksdb_options_set_sstfilemanager(self.inner, file_manager.inner); + } + } + pub fn get_rate_limiter(&self) -> Option { let limiter = unsafe { crocksdb_ffi::crocksdb_options_get_ratelimiter(self.inner) }; if limiter.is_null() { diff --git a/src/sst_file_manager.rs b/src/sst_file_manager.rs new file mode 100644 index 000000000..5279ba4cc --- /dev/null +++ b/src/sst_file_manager.rs @@ -0,0 +1,20 @@ +use crocksdb_ffi; +use librocksdb_sys::DBEnv; + +pub struct SstFileManager { + pub(crate) inner: *mut crocksdb_ffi::SstFileManager, +} + +impl SstFileManager { + pub fn new(env: *const DBEnv) -> SstFileManager { + unsafe { + SstFileManager { + inner: crocksdb_ffi::crocksdb_sstfilemanager_create(env), + } + } + } + + pub fn get_total_size(&self) -> u64 { + unsafe { crocksdb_ffi::crocksdb_sstfilemanager_get_total_size(self.inner) } + } +}