Refactor with VersionBuilder (#8706)
Summary: Introduce a new function to save sst files. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8706 Reviewed By: jay-zhuang Differential Revision: D30544242 Pulled By: riversand963 fbshipit-source-id: 554755852daff7ae1c7864b0029f51b27099ee09
This commit is contained in:
parent
7ddc096d7d
commit
2bc914094d
@ -856,18 +856,32 @@ class VersionBuilder::Rep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the current state in *vstorage.
|
void MaybeAddFile(VersionStorageInfo* vstorage, int level, FileMetaData* f) {
|
||||||
Status SaveTo(VersionStorageInfo* vstorage) {
|
const uint64_t file_number = f->fd.GetNumber();
|
||||||
Status s = CheckConsistency(base_vstorage_);
|
|
||||||
if (!s.ok()) {
|
const auto& level_state = levels_[level];
|
||||||
return s;
|
|
||||||
}
|
const auto& del_files = level_state.deleted_files;
|
||||||
|
const auto del_it = del_files.find(file_number);
|
||||||
s = CheckConsistency(vstorage);
|
|
||||||
if (!s.ok()) {
|
if (del_it != del_files.end()) {
|
||||||
return s;
|
// f is to-be-deleted table file
|
||||||
|
vstorage->RemoveCurrentStats(f);
|
||||||
|
} else {
|
||||||
|
const auto& add_files = level_state.added_files;
|
||||||
|
const auto add_it = add_files.find(file_number);
|
||||||
|
|
||||||
|
// Note: if the file appears both in the base version and in the added
|
||||||
|
// list, the added FileMetaData supersedes the one in the base version.
|
||||||
|
if (add_it != add_files.end() && add_it->second != f) {
|
||||||
|
vstorage->RemoveCurrentStats(f);
|
||||||
|
} else {
|
||||||
|
vstorage->AddFile(level, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SaveSSTFilesTo(VersionStorageInfo* vstorage) {
|
||||||
for (int level = 0; level < num_levels_; level++) {
|
for (int level = 0; level < num_levels_; level++) {
|
||||||
const auto& cmp = (level == 0) ? level_zero_cmp_ : level_nonzero_cmp_;
|
const auto& cmp = (level == 0) ? level_zero_cmp_ : level_nonzero_cmp_;
|
||||||
// Merge the set of added files with the set of pre-existing files.
|
// Merge the set of added files with the set of pre-existing files.
|
||||||
@ -909,6 +923,21 @@ class VersionBuilder::Rep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the current state in *vstorage.
|
||||||
|
Status SaveTo(VersionStorageInfo* vstorage) {
|
||||||
|
Status s = CheckConsistency(base_vstorage_);
|
||||||
|
if (!s.ok()) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = CheckConsistency(vstorage);
|
||||||
|
if (!s.ok()) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveSSTFilesTo(vstorage);
|
||||||
|
|
||||||
SaveBlobFilesTo(vstorage);
|
SaveBlobFilesTo(vstorage);
|
||||||
|
|
||||||
@ -1017,31 +1046,6 @@ class VersionBuilder::Rep {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MaybeAddFile(VersionStorageInfo* vstorage, int level, FileMetaData* f) {
|
|
||||||
const uint64_t file_number = f->fd.GetNumber();
|
|
||||||
|
|
||||||
const auto& level_state = levels_[level];
|
|
||||||
|
|
||||||
const auto& del_files = level_state.deleted_files;
|
|
||||||
const auto del_it = del_files.find(file_number);
|
|
||||||
|
|
||||||
if (del_it != del_files.end()) {
|
|
||||||
// f is to-be-deleted table file
|
|
||||||
vstorage->RemoveCurrentStats(f);
|
|
||||||
} else {
|
|
||||||
const auto& add_files = level_state.added_files;
|
|
||||||
const auto add_it = add_files.find(file_number);
|
|
||||||
|
|
||||||
// Note: if the file appears both in the base version and in the added
|
|
||||||
// list, the added FileMetaData supersedes the one in the base version.
|
|
||||||
if (add_it != add_files.end() && add_it->second != f) {
|
|
||||||
vstorage->RemoveCurrentStats(f);
|
|
||||||
} else {
|
|
||||||
vstorage->AddFile(level, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VersionBuilder::VersionBuilder(const FileOptions& file_options,
|
VersionBuilder::VersionBuilder(const FileOptions& file_options,
|
||||||
|
Loading…
Reference in New Issue
Block a user