Reserve vector in advance to avoid resizing in GetLiveFilesMetaData (#12554)

Summary:
As title

Pull Request resolved: https://github.com/facebook/rocksdb/pull/12554

Test Plan: Existing CI

Reviewed By: ajkr

Differential Revision: D56252201

Pulled By: jaykorean

fbshipit-source-id: 06211555a54ce5e6bf656b81109022494e6787ea
This commit is contained in:
Jay Huh 2024-04-17 11:01:06 -07:00 committed by Facebook GitHub Bot
parent 3bbacda9b1
commit 02ea0d6367
1 changed files with 14 additions and 0 deletions

View File

@ -7137,6 +7137,20 @@ Status VersionSet::GetMetadataForFile(uint64_t number, int* filelevel,
}
void VersionSet::GetLiveFilesMetaData(std::vector<LiveFileMetaData>* metadata) {
if (!metadata) {
return;
}
assert(metadata);
size_t count = 0;
for (auto cfd : *column_family_set_) {
if (cfd->IsDropped() || !cfd->initialized()) {
continue;
}
for (int level = 0; level < cfd->NumberLevels(); level++) {
count += cfd->current()->storage_info()->LevelFiles(level).size();
}
}
metadata->reserve(count);
for (auto cfd : *column_family_set_) {
if (cfd->IsDropped() || !cfd->initialized()) {
continue;