Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic SstFileManager functionality #791

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions librocksdb_sys/crocksdb/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -356,6 +358,9 @@ struct crocksdb_sequential_file_t {
struct crocksdb_ingestexternalfileoptions_t {
IngestExternalFileOptions rep;
};
struct crocksdb_sstfilemanager_t {
shared_ptr<SstFileManager> rep;
};
struct crocksdb_sstfilereader_t {
SstFileReader* rep;
};
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions librocksdb_sys/crocksdb/crocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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*
Expand Down
11 changes: 11 additions & 0 deletions librocksdb_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<RateLimiter> {
let limiter = unsafe { crocksdb_ffi::crocksdb_options_get_ratelimiter(self.inner) };
if limiter.is_null() {
Expand Down
20 changes: 20 additions & 0 deletions src/sst_file_manager.rs
Original file line number Diff line number Diff line change
@@ -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) }
}
}