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
This commit is contained in:
Siying Dong 2018-05-21 16:37:47 -07:00 committed by Facebook Github Bot
parent c3ebc75843
commit 3db1ada3bf
2 changed files with 12 additions and 7 deletions

View File

@ -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;

View File

@ -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<WritableFile> writable;
std::unique_ptr<WritableFile> wf;
Status s = env->NewWritableFile(file_name, &writable, EnvOptions());
Status s = env->NewWritableFile(file_name, &wf, EnvOptions());
if (!s.ok()) {
return s;
}
unique_ptr<WritableFileWriter> 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(