replica: devirtualize storage_group_of()

can be made private to tablet_storage_group_manager.

Signed-off-by: Raphael S. Carvalho <raphaelsc@scylladb.com>
This commit is contained in:
Raphael S. Carvalho
2024-06-12 11:29:46 -03:00
parent c752bda0a2
commit 9c1d3bcc02
3 changed files with 18 additions and 27 deletions

View File

@@ -273,7 +273,6 @@ public:
virtual compaction_group& compaction_group_for_key(partition_key_view key, const schema_ptr& s) const noexcept = 0;
virtual compaction_group& compaction_group_for_sstable(const sstables::shared_sstable& sst) const noexcept = 0;
virtual std::pair<size_t, locator::tablet_range_side> storage_group_of(dht::token) const = 0;
virtual size_t log2_storage_groups() const = 0;
virtual storage_group* storage_group_for_token(dht::token) const noexcept = 0;

View File

@@ -589,8 +589,7 @@ private:
// that were previously split.
future<> handle_tablet_split_completion(size_t old_tablet_count, const locator::tablet_map& new_tmap);
// Select a compaction group from a given token.
std::pair<size_t, locator::tablet_range_side> storage_group_of(dht::token token) const noexcept;
// Select a storage group from a given token.
storage_group* storage_group_for_token(dht::token token) const noexcept;
// FIXME: Cannot return nullptr, signature can be changed to return storage_group&.
storage_group* storage_group_for_id(size_t i) const;

View File

@@ -615,9 +615,6 @@ public:
compaction_group& compaction_group_for_sstable(const sstables::shared_sstable& sst) const noexcept override {
return get_compaction_group();
}
std::pair<size_t, locator::tablet_range_side> storage_group_of(dht::token) const override {
return {0, locator::tablet_range_side{}};
}
size_t log2_storage_groups() const override {
return 0;
}
@@ -676,6 +673,23 @@ private:
size_t tablet_id_for_token(dht::token t) const noexcept {
return tablet_map().get_tablet_id(t).value();
}
std::pair<size_t, locator::tablet_range_side> storage_group_of(dht::token t) const {
auto [id, side] = tablet_map().get_tablet_id_and_range_side(t);
auto idx = id.value();
#ifndef SCYLLA_BUILD_MODE_RELEASE
if (idx >= tablet_count()) {
on_fatal_internal_error(tlogger, format("storage_group_of: index out of range: idx={} size_log2={} size={} token={}",
idx, log2_storage_groups(), tablet_count(), t));
}
auto* sg = storage_group_for_id(idx);
if (!t.is_minimum() && !t.is_maximum() && sg && !sg->token_range().contains(t, dht::token_comparator())) {
on_fatal_internal_error(tlogger, format("storage_group_of: storage_group idx={} range={} does not contain token={}",
idx, sg->token_range(), t));
}
#endif
return { idx, side };
}
public:
tablet_storage_group_manager(table& t, const locator::effective_replication_map& erm)
: _t(t)
@@ -706,22 +720,6 @@ public:
compaction_group& compaction_group_for_key(partition_key_view key, const schema_ptr& s) const noexcept override;
compaction_group& compaction_group_for_sstable(const sstables::shared_sstable& sst) const noexcept override;
std::pair<size_t, locator::tablet_range_side> storage_group_of(dht::token t) const override {
auto [id, side] = tablet_map().get_tablet_id_and_range_side(t);
auto idx = id.value();
#ifndef SCYLLA_BUILD_MODE_RELEASE
if (idx >= tablet_count()) {
on_fatal_internal_error(tlogger, format("storage_group_of: index out of range: idx={} size_log2={} size={} token={}",
idx, log2_storage_groups(), tablet_count(), t));
}
auto* sg = storage_group_for_id(idx);
if (!t.is_minimum() && !t.is_maximum() && sg && !sg->token_range().contains(t, dht::token_comparator())) {
on_fatal_internal_error(tlogger, format("storage_group_of: storage_group idx={} range={} does not contain token={}",
idx, sg->token_range(), t));
}
#endif
return { idx, side };
}
size_t log2_storage_groups() const override {
return log2ceil(tablet_map().tablet_count());
}
@@ -902,11 +900,6 @@ compaction_group* table::get_compaction_group(size_t id) const noexcept {
return storage_group_for_id(id)->main_compaction_group().get();
}
std::pair<size_t, locator::tablet_range_side>
table::storage_group_of(dht::token token) const noexcept {
return _sg_manager->storage_group_of(token);
}
storage_group* table::storage_group_for_token(dht::token token) const noexcept {
return _sg_manager->storage_group_for_token(token);
}