From 3db1ada3bfb08fe208e6726a4ef2d5bb609a85f9 Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Mon, 21 May 2018 16:37:47 -0700 Subject: [PATCH] PersistRocksDBOptions() to use WritableFileWriter Summary: By using WritableFileWriter rather than WritableFile directly, we can buffer multiple Append() calls to one write() file system call, which will be expensive to underlying Env without its own write buffering. Closes https://github.com/facebook/rocksdb/pull/3882 Differential Revision: D8080673 Pulled By: siying fbshipit-source-id: e0db900cb3c178166aa738f3985db65e3ae2cf1b --- db/db_options_test.cc | 7 ++++--- options/options_parser.cc | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/db/db_options_test.cc b/db/db_options_test.cc index 94727da8e..dc7931624 100644 --- a/db/db_options_test.cc +++ b/db/db_options_test.cc @@ -242,11 +242,12 @@ TEST_F(DBOptionsTest, WritableFileMaxBufferSize) { ASSERT_EQ(unmatch_cnt, 0); ASSERT_GE(match_cnt, 11); - buffer_size = 512 * 1024; - match_cnt = 0; - unmatch_cnt = 0; ASSERT_OK( dbfull()->SetDBOptions({{"writable_file_max_buffer_size", "524288"}})); + buffer_size = 512 * 1024; + match_cnt = 0; + unmatch_cnt = 0; // SetDBOptions() will create a WriteableFileWriter + ASSERT_EQ(buffer_size, dbfull()->GetDBOptions().writable_file_max_buffer_size); i = 0; diff --git a/options/options_parser.cc b/options/options_parser.cc index c7a7c6d37..dabefdc7b 100644 --- a/options/options_parser.cc +++ b/options/options_parser.cc @@ -17,6 +17,7 @@ #include "rocksdb/convenience.h" #include "rocksdb/db.h" #include "util/cast_util.h" +#include "util/file_reader_writer.h" #include "util/string_util.h" #include "util/sync_point.h" @@ -41,12 +42,16 @@ Status PersistRocksDBOptions(const DBOptions& db_opt, return Status::InvalidArgument( "cf_names.size() and cf_opts.size() must be the same"); } - std::unique_ptr writable; + std::unique_ptr wf; - Status s = env->NewWritableFile(file_name, &writable, EnvOptions()); + Status s = env->NewWritableFile(file_name, &wf, EnvOptions()); if (!s.ok()) { return s; } + unique_ptr writable; + writable.reset(new WritableFileWriter(std::move(wf), EnvOptions(), + nullptr /* statistics */)); + std::string options_file_content; writable->Append(option_file_header + "[" + @@ -93,8 +98,7 @@ Status PersistRocksDBOptions(const DBOptions& db_opt, writable->Append(options_file_content + "\n"); } } - writable->Flush(); - writable->Fsync(); + writable->Sync(true /* use_fsync */); writable->Close(); return RocksDBOptionsParser::VerifyRocksDBOptionsFromFile(