From 3949731de3dd0bee48babba23006e3829fc82343 Mon Sep 17 00:00:00 2001 From: Duarte Nunes Date: Tue, 27 Apr 2021 14:55:34 -0700 Subject: [PATCH] Add WAL flush API to C client (#8226) Summary: The C client is missing the`manual_wal_flush` option and the `flush_wal` API. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8226 Reviewed By: ajkr Differential Revision: D28000869 Pulled By: jay-zhuang fbshipit-source-id: ed44937e7e7e75bc0dfa870a14147fbeef0c38f8 --- db/c.cc | 13 +++++++++++++ db/c_test.c | 6 ++++++ include/rocksdb/c.h | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/db/c.cc b/db/c.cc index 345449b726..64ff26646e 100644 --- a/db/c.cc +++ b/db/c.cc @@ -1512,6 +1512,10 @@ void rocksdb_flush_cf( SaveError(errptr, db->rep->Flush(options->rep, column_family->rep)); } +void rocksdb_flush_wal(rocksdb_t* db, unsigned char sync, char** errptr) { + SaveError(errptr, db->rep->FlushWAL(sync)); +} + void rocksdb_disable_file_deletions( rocksdb_t* db, char** errptr) { @@ -3479,6 +3483,15 @@ unsigned char rocksdb_options_get_atomic_flush(rocksdb_options_t* opt) { return opt->rep.atomic_flush; } +void rocksdb_options_set_manual_wal_flush(rocksdb_options_t* opt, + unsigned char manual_wal_flush) { + opt->rep.manual_wal_flush = manual_wal_flush; +} + +unsigned char rocksdb_options_get_manual_wal_flush(rocksdb_options_t* opt) { + return opt->rep.manual_wal_flush; +} + rocksdb_ratelimiter_t* rocksdb_ratelimiter_create( int64_t rate_bytes_per_sec, int64_t refill_period_us, diff --git a/db/c_test.c b/db/c_test.c index 58a0340585..0b1f22b542 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -1279,6 +1279,9 @@ int main(int argc, char** argv) { CheckPinGetCF(db, roptions, handles[1], "box", "c"); rocksdb_writebatch_destroy(wb); + rocksdb_flush_wal(db, 1, &err); + CheckNoError(err); + const char* keys[3] = { "box", "box", "barfooxx" }; const rocksdb_column_family_handle_t* get_handles[3] = { handles[0], handles[1], handles[1] }; const size_t keys_sizes[3] = { 3, 3, 8 }; @@ -1762,6 +1765,9 @@ int main(int argc, char** argv) { rocksdb_options_set_atomic_flush(o, 1); CheckCondition(1 == rocksdb_options_get_atomic_flush(o)); + rocksdb_options_set_manual_wal_flush(o, 1); + CheckCondition(1 == rocksdb_options_get_manual_wal_flush(o)); + /* Blob Options */ rocksdb_options_set_enable_blob_files(o, 1); CheckCondition(1 == rocksdb_options_get_enable_blob_files(o)); diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index a83d59cbf0..1b19be2c48 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -539,6 +539,10 @@ extern ROCKSDB_LIBRARY_API void rocksdb_flush_cf( rocksdb_t* db, const rocksdb_flushoptions_t* options, rocksdb_column_family_handle_t* column_family, char** errptr); +extern ROCKSDB_LIBRARY_API void rocksdb_flush_wal(rocksdb_t* db, + unsigned char sync, + char** errptr); + extern ROCKSDB_LIBRARY_API void rocksdb_disable_file_deletions(rocksdb_t* db, char** errptr); @@ -1417,6 +1421,10 @@ extern ROCKSDB_LIBRARY_API void rocksdb_options_set_row_cache( extern ROCKSDB_LIBRARY_API void rocksdb_options_add_compact_on_deletion_collector_factory( rocksdb_options_t*, size_t window_size, size_t num_dels_trigger); +extern ROCKSDB_LIBRARY_API void rocksdb_options_set_manual_wal_flush( + rocksdb_options_t* opt, unsigned char); +extern ROCKSDB_LIBRARY_API unsigned char rocksdb_options_get_manual_wal_flush( + rocksdb_options_t* opt); /* RateLimiter */ extern ROCKSDB_LIBRARY_API rocksdb_ratelimiter_t* rocksdb_ratelimiter_create(