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

Revert #734 and port stats_persist_period_sec and disable_manual_compaction #735

Merged
merged 3 commits into from
Feb 2, 2023
Merged
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
24 changes: 13 additions & 11 deletions librocksdb_sys/crocksdb/c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,14 @@ void crocksdb_continue_bg_work(crocksdb_t* db) {
db->rep->ContinueBackgroundWork();
}

void crocksdb_disable_manual_compaction(crocksdb_t* db) {
db->rep->DisableManualCompaction();
}

void crocksdb_enable_manual_compaction(crocksdb_t* db) {
db->rep->EnableManualCompaction();
}

crocksdb_t* crocksdb_open_column_families(
const crocksdb_options_t* db_options, const char* name,
int num_column_families, const char** column_family_names,
Expand Down Expand Up @@ -2133,11 +2141,6 @@ void crocksdb_options_set_wal_bytes_per_sync(crocksdb_options_t* opt,
opt->rep.wal_bytes_per_sync = v;
}

void crocksdb_options_set_disable_periodic_work_scheduler(
crocksdb_options_t* opt, unsigned char v) {
opt->rep.disable_periodic_work_scheduler = v;
}

static BlockBasedTableOptions* get_block_based_table_options(
crocksdb_options_t* opt) {
if (opt && opt->rep.table_factory != nullptr) {
Expand Down Expand Up @@ -3034,6 +3037,11 @@ void crocksdb_options_set_stats_dump_period_sec(crocksdb_options_t* opt,
opt->rep.stats_dump_period_sec = v;
}

void crocksdb_options_set_stats_persist_period_sec(crocksdb_options_t* opt,
uint32_t v) {
opt->rep.stats_persist_period_sec = v;
}

void crocksdb_options_set_advise_random_on_open(crocksdb_options_t* opt,
unsigned char v) {
opt->rep.advise_random_on_open = v;
Expand Down Expand Up @@ -5856,12 +5864,6 @@ void crocksdb_compact_files_cf(crocksdb_t* db,
SaveError(errptr, s);
}

void crocksdb_do_periodic_work(crocksdb_t* db, int work_type, char** errptr) {
auto s =
db->rep->DoPeriodicWork(static_cast<DB::PeriodicWorkType>(work_type));
SaveError(errptr, s);
}

/* PerfContext */

int crocksdb_get_perf_level(void) {
Expand Down
14 changes: 7 additions & 7 deletions librocksdb_sys/crocksdb/crocksdb/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_close(crocksdb_t* db);
extern C_ROCKSDB_LIBRARY_API void crocksdb_pause_bg_work(crocksdb_t* db);
extern C_ROCKSDB_LIBRARY_API void crocksdb_continue_bg_work(crocksdb_t* db);

extern C_ROCKSDB_LIBRARY_API void crocksdb_disable_manual_compaction(
crocksdb_t* db);
extern C_ROCKSDB_LIBRARY_API void crocksdb_enable_manual_compaction(
crocksdb_t* db);

extern C_ROCKSDB_LIBRARY_API void crocksdb_put(
crocksdb_t* db, const crocksdb_writeoptions_t* options, const char* key,
size_t keylen, const char* val, size_t vallen, char** errptr);
Expand Down Expand Up @@ -1303,6 +1308,8 @@ crocksdb_options_set_skip_log_error_on_recovery(crocksdb_options_t*,
unsigned char);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_stats_dump_period_sec(
crocksdb_options_t*, unsigned int);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_stats_persist_period_sec(
crocksdb_options_t*, uint32_t);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_advise_random_on_open(
crocksdb_options_t*, unsigned char);
extern C_ROCKSDB_LIBRARY_API void
Expand Down Expand Up @@ -1385,9 +1392,6 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_max_subcompactions(
crocksdb_options_t*, uint32_t);
extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_wal_bytes_per_sync(
crocksdb_options_t*, uint64_t);
extern C_ROCKSDB_LIBRARY_API void
crocksdb_options_set_disable_periodic_work_scheduler(crocksdb_options_t*,
unsigned char);

enum {
crocksdb_tolerate_corrupted_tail_records_recovery = 0,
Expand Down Expand Up @@ -2277,10 +2281,6 @@ extern C_ROCKSDB_LIBRARY_API void
crocksdb_compaction_options_set_max_subcompactions(
crocksdb_compaction_options_t*, int);

extern C_ROCKSDB_LIBRARY_API void crocksdb_do_periodic_work(crocksdb_t*,
int work_type,
char** errptr);

extern C_ROCKSDB_LIBRARY_API void crocksdb_compact_files_cf(
crocksdb_t*, crocksdb_column_family_handle_t*,
crocksdb_compaction_options_t*, const char** input_file_names,
Expand Down
19 changes: 4 additions & 15 deletions librocksdb_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,6 @@ pub enum DBTableFileCreationReason {
Misc = 3,
}

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(C)]
pub enum DBPeriodicWorkType {
FlushInfoLog = 0,
DumpStats = 1,
PersistStats = 2,
}

/// # Safety
///
/// ptr must point to a valid CStr value
Expand Down Expand Up @@ -868,7 +860,6 @@ extern "C" {
pub fn crocksdb_options_set_wal_recovery_mode(options: *mut Options, mode: DBRecoveryMode);
pub fn crocksdb_options_set_max_subcompactions(options: *mut Options, v: u32);
pub fn crocksdb_options_set_wal_bytes_per_sync(options: *mut Options, v: u64);
pub fn crocksdb_options_set_disable_periodic_work_scheduler(options: *mut Options, v: bool);

pub fn crocksdb_options_set_statistics(options: *mut Options, statistics: *mut DBStatistics);
pub fn crocksdb_options_get_statistics(options: *mut Options) -> *mut DBStatistics;
Expand Down Expand Up @@ -903,7 +894,9 @@ extern "C" {
standard_deviation: *mut c_double,
max: *mut c_double,
) -> bool;

pub fn crocksdb_options_set_stats_dump_period_sec(options: *mut Options, v: usize);
pub fn crocksdb_options_set_stats_persist_period_sec(options: *mut Options, v: u32);
pub fn crocksdb_options_set_num_levels(options: *mut Options, v: c_int);
pub fn crocksdb_options_get_num_levels(options: *mut Options) -> c_int;
pub fn crocksdb_options_set_db_log_dir(options: *mut Options, path: *const c_char);
Expand Down Expand Up @@ -1201,6 +1194,8 @@ extern "C" {
pub fn crocksdb_close(db: *mut DBInstance);
pub fn crocksdb_pause_bg_work(db: *mut DBInstance);
pub fn crocksdb_continue_bg_work(db: *mut DBInstance);
pub fn crocksdb_disable_manual_compaction(db: *mut DBInstance);
pub fn crocksdb_enable_manual_compaction(db: *mut DBInstance);
pub fn crocksdb_destroy_db(options: *const Options, path: *const c_char, err: *mut *mut c_char);
pub fn crocksdb_repair_db(options: *const Options, path: *const c_char, err: *mut *mut c_char);
// Merge
Expand Down Expand Up @@ -2530,12 +2525,6 @@ extern "C" {
errptr: *mut *mut c_char,
);

pub fn crocksdb_do_periodic_work(
db: *mut DBInstance,
work_type: DBPeriodicWorkType,
errptr: *mut *mut c_char,
);

pub fn crocksdb_get_perf_level() -> c_int;
pub fn crocksdb_set_perf_level(level: c_int);
pub fn crocksdb_create_perf_flags() -> *mut DBPerfFlags;
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub use file_system::FileSystemInspector;
pub use librocksdb_sys::{
self as crocksdb_ffi, new_bloom_filter, ChecksumType, CompactionPriority, CompactionReason,
DBBackgroundErrorReason, DBBottommostLevelCompaction, DBCompactionStyle, DBCompressionType,
DBEntryType, DBInfoLogLevel, DBPeriodicWorkType, DBRateLimiterMode, DBRecoveryMode,
DBEntryType, DBInfoLogLevel, DBRateLimiterMode, DBRecoveryMode,
DBSstPartitionerResult as SstPartitionerResult, DBStatisticsHistogramType,
DBStatisticsTickerType, DBStatusPtr, DBTableFileCreationReason, DBTitanDBBlobRunMode,
DBValueType, IndexType, PrepopulateBlockCache, WriteStallCondition,
Expand Down
33 changes: 13 additions & 20 deletions src/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crocksdb_ffi::{
DBTitanDBOptions, DBWriteBatch,
};
use libc::{self, c_char, c_int, c_void, size_t};
use librocksdb_sys::{DBMemoryAllocator, DBPeriodicWorkType};
use librocksdb_sys::DBMemoryAllocator;
use metadata::ColumnFamilyMetaData;
use rocksdb_options::{
CColumnFamilyDescriptor, ColumnFamilyDescriptor, ColumnFamilyOptions, CompactOptions,
Expand Down Expand Up @@ -821,6 +821,18 @@ impl DB {
}
}

pub fn disable_manual_compaction(&self) {
unsafe {
crocksdb_ffi::crocksdb_disable_manual_compaction(self.inner);
}
}

pub fn enable_manual_compaction(&self) {
unsafe {
crocksdb_ffi::crocksdb_enable_manual_compaction(self.inner);
}
}

pub fn path(&self) -> &str {
&self.path
}
Expand Down Expand Up @@ -2041,13 +2053,6 @@ impl DB {
Ok(())
}
}

pub fn do_periodic_work(&self, work_type: DBPeriodicWorkType) -> Result<(), String> {
unsafe {
ffi_try!(crocksdb_do_periodic_work(self.inner, work_type));
Ok(())
}
}
}

impl Writable for DB {
Expand Down Expand Up @@ -3835,16 +3840,4 @@ mod test {
)
.unwrap();
}

#[test]
fn test_offload_periodic_work() {
let path = tempdir_with_prefix("_rust_rocksdb_test_offload_periodic_work");
let mut opts = DBOptions::new();
opts.create_if_missing(true);
opts.create_missing_column_families(true);
opts.disable_periodic_work_scheduler(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
db.do_periodic_work(DBPeriodicWorkType::FlushInfoLog)
.unwrap();
}
}
12 changes: 6 additions & 6 deletions src/rocksdb_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,12 @@ impl DBOptions {
}
}

pub fn set_stats_persist_period_sec(&mut self, n: u32) {
unsafe {
crocksdb_ffi::crocksdb_options_set_stats_persist_period_sec(self.inner, n);
}
}

pub fn set_db_log_dir(&mut self, path: &str) {
let path = CString::new(path.as_bytes()).unwrap();
unsafe {
Expand Down Expand Up @@ -1328,12 +1334,6 @@ impl DBOptions {
Some(CStr::from_ptr(memtable_name).to_str().unwrap())
}
}

pub fn disable_periodic_work_scheduler(&self, v: bool) {
unsafe {
crocksdb_ffi::crocksdb_options_set_disable_periodic_work_scheduler(self.inner, v);
}
}
}

pub struct ColumnFamilyOptions {
Expand Down