sstable_directory: Load sstable once when sorting

In order to decide which list to put sstable into, the sort_sstable()
first calls get_shards_for_this_sstable() which loads the sstable
anyway. If loaded shards contain only the current one (which is the
common case) sstable is loaded again. In fact, if the sstable happens to
be remote it's loaded anyway to get its open info.

Fix that by loading sstable, then getting shards directly from it.

Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
Pavel Emelyanov
2024-08-13 12:30:38 +03:00
parent 607abe96e8
commit 63f1969e08

View File

@@ -211,18 +211,19 @@ future<foreign_sstable_open_info> sstable_directory::get_open_info_for_this_ssta
future<>
sstable_directory::sort_sstable(sstables::entry_descriptor desc, process_flags flags) {
auto shards = co_await get_shards_for_this_sstable(desc, flags);
auto sst = co_await load_sstable(desc, flags);
auto shards = sst->get_shards_for_this_sstable();
if (shards.size() == 1) {
if (shards[0] == this_shard_id()) {
dirlog.trace("{} identified as a local unshared SSTable", sstable_filename(desc));
_unshared_local_sstables.push_back(co_await load_sstable(std::move(desc), flags));
_unshared_local_sstables.push_back(std::move(sst));
} else {
dirlog.trace("{} identified as a remote unshared SSTable, shard={}", sstable_filename(desc), shards[0]);
_unshared_remote_sstables[shards[0]].push_back(std::move(desc));
}
} else {
dirlog.trace("{} identified as a shared SSTable, shards={}", sstable_filename(desc), shards);
_shared_sstable_info.push_back(co_await get_open_info_for_this_sstable(desc));
_shared_sstable_info.push_back(co_await sst->get_open_info());
}
}