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:
parent
c3ebc75843
commit
3db1ada3bf
@ -242,11 +242,12 @@ TEST_F(DBOptionsTest, WritableFileMaxBufferSize) {
|
|||||||
ASSERT_EQ(unmatch_cnt, 0);
|
ASSERT_EQ(unmatch_cnt, 0);
|
||||||
ASSERT_GE(match_cnt, 11);
|
ASSERT_GE(match_cnt, 11);
|
||||||
|
|
||||||
buffer_size = 512 * 1024;
|
|
||||||
match_cnt = 0;
|
|
||||||
unmatch_cnt = 0;
|
|
||||||
ASSERT_OK(
|
ASSERT_OK(
|
||||||
dbfull()->SetDBOptions({{"writable_file_max_buffer_size", "524288"}}));
|
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,
|
ASSERT_EQ(buffer_size,
|
||||||
dbfull()->GetDBOptions().writable_file_max_buffer_size);
|
dbfull()->GetDBOptions().writable_file_max_buffer_size);
|
||||||
i = 0;
|
i = 0;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "rocksdb/convenience.h"
|
#include "rocksdb/convenience.h"
|
||||||
#include "rocksdb/db.h"
|
#include "rocksdb/db.h"
|
||||||
#include "util/cast_util.h"
|
#include "util/cast_util.h"
|
||||||
|
#include "util/file_reader_writer.h"
|
||||||
#include "util/string_util.h"
|
#include "util/string_util.h"
|
||||||
#include "util/sync_point.h"
|
#include "util/sync_point.h"
|
||||||
|
|
||||||
@ -41,12 +42,16 @@ Status PersistRocksDBOptions(const DBOptions& db_opt,
|
|||||||
return Status::InvalidArgument(
|
return Status::InvalidArgument(
|
||||||
"cf_names.size() and cf_opts.size() must be the same");
|
"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()) {
|
if (!s.ok()) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
unique_ptr<WritableFileWriter> writable;
|
||||||
|
writable.reset(new WritableFileWriter(std::move(wf), EnvOptions(),
|
||||||
|
nullptr /* statistics */));
|
||||||
|
|
||||||
std::string options_file_content;
|
std::string options_file_content;
|
||||||
|
|
||||||
writable->Append(option_file_header + "[" +
|
writable->Append(option_file_header + "[" +
|
||||||
@ -93,8 +98,7 @@ Status PersistRocksDBOptions(const DBOptions& db_opt,
|
|||||||
writable->Append(options_file_content + "\n");
|
writable->Append(options_file_content + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writable->Flush();
|
writable->Sync(true /* use_fsync */);
|
||||||
writable->Fsync();
|
|
||||||
writable->Close();
|
writable->Close();
|
||||||
|
|
||||||
return RocksDBOptionsParser::VerifyRocksDBOptionsFromFile(
|
return RocksDBOptionsParser::VerifyRocksDBOptionsFromFile(
|
||||||
|
Loading…
Reference in New Issue
Block a user