Avoid to get manifest file size when recovering from it. (#6369)
Summary: Right now RocksDB gets manifest file size before recovering from it. The information is available in LogReader. Use it instead to prevent one file system call. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6369 Test Plan: Run all existing tests Differential Revision: D19714872 fbshipit-source-id: 0144be324d403c99e3da875ea2feccc8f64e883d
This commit is contained in:
parent
637e64b9ac
commit
69c8614815
@ -2277,6 +2277,41 @@ TEST_F(DBTest, SnapshotFiles) {
|
||||
dbfull()->DisableFileDeletions();
|
||||
} while (ChangeCompactOptions());
|
||||
}
|
||||
|
||||
TEST_F(DBTest, ReadonlyDBGetLiveManifestSize) {
|
||||
do {
|
||||
Options options = CurrentOptions();
|
||||
options.level0_file_num_compaction_trigger = 2;
|
||||
DestroyAndReopen(options);
|
||||
|
||||
ASSERT_OK(Put("foo", "bar"));
|
||||
ASSERT_OK(Flush());
|
||||
ASSERT_OK(Put("foo", "bar"));
|
||||
ASSERT_OK(Flush());
|
||||
ASSERT_OK(dbfull()->TEST_WaitForCompact());
|
||||
|
||||
Close();
|
||||
ASSERT_OK(ReadOnlyReopen(options));
|
||||
|
||||
uint64_t manifest_size = 0;
|
||||
std::vector<std::string> files;
|
||||
dbfull()->GetLiveFiles(files, &manifest_size);
|
||||
|
||||
for (const std::string& f : files) {
|
||||
uint64_t number = 0;
|
||||
FileType type;
|
||||
if (ParseFileName(f.substr(1), &number, &type)) {
|
||||
if (type == kDescriptorFile) {
|
||||
uint64_t size_on_disk;
|
||||
env_->GetFileSize(dbname_ + "/" + f, &size_on_disk);
|
||||
ASSERT_EQ(manifest_size, size_on_disk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Close();
|
||||
} while (ChangeCompactOptions());
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_F(DBTest, PurgeInfoLogs) {
|
||||
|
@ -93,6 +93,10 @@ class Reader {
|
||||
|
||||
uint64_t GetLogNumber() const { return log_number_; }
|
||||
|
||||
size_t GetReadOffset() const {
|
||||
return static_cast<size_t>(end_of_buffer_offset_);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Logger> info_log_;
|
||||
const std::unique_ptr<SequentialFileReader> file_;
|
||||
|
@ -4403,12 +4403,6 @@ Status VersionSet::Recover(
|
||||
new SequentialFileReader(std::move(manifest_file), manifest_path,
|
||||
db_options_->log_readahead_size));
|
||||
}
|
||||
uint64_t current_manifest_file_size;
|
||||
s = fs_->GetFileSize(manifest_path, IOOptions(), ¤t_manifest_file_size,
|
||||
nullptr);
|
||||
if (!s.ok()) {
|
||||
return s;
|
||||
}
|
||||
|
||||
std::unordered_map<uint32_t, std::unique_ptr<BaseReferencedVersionBuilder>>
|
||||
builders;
|
||||
@ -4429,6 +4423,7 @@ Status VersionSet::Recover(
|
||||
builders.insert(
|
||||
std::make_pair(0, std::unique_ptr<BaseReferencedVersionBuilder>(
|
||||
new BaseReferencedVersionBuilder(default_cfd))));
|
||||
uint64_t current_manifest_file_size = 0;
|
||||
VersionEditParams version_edit_params;
|
||||
{
|
||||
VersionSet::LogReporter reporter;
|
||||
@ -4441,6 +4436,8 @@ Status VersionSet::Recover(
|
||||
s = ReadAndRecover(&reader, &read_buffer, cf_name_to_options,
|
||||
column_families_not_found, builders,
|
||||
&version_edit_params, db_id);
|
||||
current_manifest_file_size = reader.GetReadOffset();
|
||||
assert(current_manifest_file_size != 0);
|
||||
}
|
||||
|
||||
if (s.ok()) {
|
||||
|
Loading…
Reference in New Issue
Block a user