git-hulk commented on code in PR #3342:
URL: https://github.com/apache/kvrocks/pull/3342#discussion_r2708154172
##########
src/storage/storage.cc:
##########
@@ -802,12 +802,27 @@ StatusOr<int> Storage::IngestSST(const std::string
&sst_dir, const rocksdb::Inge
return 0;
}
- std::unordered_map<ColumnFamilyID, std::vector<std::string>> cf_files;
+ // Group files by column family and build ingestion arguments atomically
Review Comment:
@ltagliamonte-dd I have one nit suggestion. It would be more concise and
easier to read by refactoring the for-loop to the following:
1. Group SST files by the column family id;
2. Build the ingest args with grouped SST files.
```C++
const auto &column_families = ColumnFamilyConfigs::ListAllColumnFamilies();
std::unordered_map<ColumnFamilyID, std::vector<std::string>>
column_family_files;
for (const auto &file : sst_files) {
auto iter = std::find_if(column_families.begin(), column_families.end(),
[&file](const auto &cf) { return
file.find(cf.Name()) != std::string::npos; });
if (iter == column_families.end()) {
return {Status::NotOK, fmt::format("SST file '{}' does not match any
known column family name", file)};
}
column_family_files[iter->Id()].push_back(file);
}
std::vector<rocksdb::IngestExternalFileArg> ingest_args;
ingest_args.reserve(column_family_files.size());
for (auto &[cf_id, files] : column_family_files) {
rocksdb::IngestExternalFileArg arg;
arg.column_family = GetCFHandle(cf_id);
arg.external_files = std::move(files);
arg.options = ingest_options;
ingest_args.push_back(std::move(arg));
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]