Commit d2cc86c3 authored by arthurprs's avatar arthurprs

add support for db.sync_wal()

parent a3260478
...@@ -1050,6 +1050,12 @@ void crocksdb_flush_cf( ...@@ -1050,6 +1050,12 @@ void crocksdb_flush_cf(
SaveError(errptr, db->rep->Flush(options->rep, column_family->rep)); SaveError(errptr, db->rep->Flush(options->rep, column_family->rep));
} }
void crocksdb_sync_wal(
crocksdb_t* db,
char** errptr) {
SaveError(errptr, db->rep->SyncWAL());
}
void crocksdb_disable_file_deletions( void crocksdb_disable_file_deletions(
crocksdb_t* db, crocksdb_t* db,
char** errptr) { char** errptr) {
......
...@@ -360,6 +360,9 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_flush_cf( ...@@ -360,6 +360,9 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_flush_cf(
crocksdb_t* db, crocksdb_column_family_handle_t* column_family, crocksdb_t* db, crocksdb_column_family_handle_t* column_family,
const crocksdb_flushoptions_t* options, char** errptr); const crocksdb_flushoptions_t* options, char** errptr);
extern C_ROCKSDB_LIBRARY_API void crocksdb_sync_wal(
crocksdb_t* db, char** errptr);
extern C_ROCKSDB_LIBRARY_API void crocksdb_disable_file_deletions(crocksdb_t* db, extern C_ROCKSDB_LIBRARY_API void crocksdb_disable_file_deletions(crocksdb_t* db,
char** errptr); char** errptr);
......
...@@ -581,6 +581,8 @@ extern "C" { ...@@ -581,6 +581,8 @@ extern "C" {
cf: *mut DBCFHandle, cf: *mut DBCFHandle,
options: *const DBFlushOptions, options: *const DBFlushOptions,
err: *mut *mut c_char); err: *mut *mut c_char);
pub fn crocksdb_sync_wal(db: *mut DBInstance,
err: *mut *mut c_char);
pub fn crocksdb_approximate_sizes(db: *mut DBInstance, pub fn crocksdb_approximate_sizes(db: *mut DBInstance,
num_ranges: c_int, num_ranges: c_int,
......
...@@ -744,6 +744,17 @@ impl DB { ...@@ -744,6 +744,17 @@ impl DB {
} }
} }
/// Sync the wal. Note that Write() followed by SyncWAL() is not exactly the
/// same as Write() with sync=true: in the latter case the changes won't be
/// visible until the sync is done.
/// Currently only works if allow_mmap_writes = false in Options.
pub fn sync_wal(&self) -> Result<(), String> {
unsafe {
ffi_try!(crocksdb_sync_wal(self.inner));
Ok(())
}
}
/// Return the approximate file system space used by keys in each ranges. /// Return the approximate file system space used by keys in each ranges.
/// ///
/// Note that the returned sizes measure file system space usage, so /// Note that the returned sizes measure file system space usage, so
......
...@@ -135,6 +135,17 @@ fn test_set_wal_opt() { ...@@ -135,6 +135,17 @@ fn test_set_wal_opt() {
drop(db); drop(db);
} }
#[test]
fn test_sync_wal() {
let path = TempDir::new("_rust_rocksdb_test_sync_wal").expect("");
let mut opts = Options::new();
opts.create_if_missing(true);
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
db.put(b"key", b"value");
db.sync_wal();
drop(db);
}
#[test] #[test]
fn test_create_info_log() { fn test_create_info_log() {
let path = TempDir::new("_rust_rocksdb_test_create_info_log_opt").expect(""); let path = TempDir::new("_rust_rocksdb_test_create_info_log_opt").expect("");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment