dht: auto_refreshing_sharder.hh: don't include database.hh
database.hh is a heavyweight include file with a lot of fan-in. auto_refreshing_sharder.hh has a lot of fan out. The combination means a large dependency load. Deinline the class and use forward declarations to avoid the #include. There is no expected performance impact because all the functions are virtual. Ref #1 Note: this shouldn't belong in dht, but be injected by a higher layer, but this isn't addressed by the patch. Closes scylladb/scylladb#21768
This commit is contained in:
committed by
Tomasz Grabiec
parent
7e2875d648
commit
f744007e13
@@ -8,7 +8,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "replica/database.hh"
|
||||
#include "dht/sharder.hh"
|
||||
#include "locator/abstract_replication_strategy.hh"
|
||||
|
||||
#include <seastar/core/abort_source.hh>
|
||||
#include <seastar/core/shared_ptr.hh>
|
||||
|
||||
namespace replica {
|
||||
class table;
|
||||
}
|
||||
|
||||
namespace dht {
|
||||
|
||||
@@ -27,41 +35,19 @@ class auto_refreshing_sharder : public dht::sharder {
|
||||
optimized_optional<seastar::abort_source::subscription> _callback;
|
||||
std::optional<write_replica_set_selector> _sel;
|
||||
private:
|
||||
void refresh() {
|
||||
_erm = _table->get_effective_replication_map();
|
||||
_sharder = &_erm->get_sharder(*_table->schema());
|
||||
_callback = _erm->get_validity_abort_source().subscribe([this] () noexcept {
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
void refresh();
|
||||
public:
|
||||
auto_refreshing_sharder(lw_shared_ptr<replica::table> table, std::optional<write_replica_set_selector> sel = std::nullopt)
|
||||
: _table(std::move(table))
|
||||
, _sel(sel)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
auto_refreshing_sharder(lw_shared_ptr<replica::table> table, std::optional<write_replica_set_selector> sel = std::nullopt);
|
||||
|
||||
virtual ~auto_refreshing_sharder() = default;
|
||||
virtual ~auto_refreshing_sharder();
|
||||
|
||||
virtual unsigned shard_for_reads(const token& t) const override {
|
||||
return _sharder->shard_for_reads(t);
|
||||
}
|
||||
virtual unsigned shard_for_reads(const token& t) const override;
|
||||
|
||||
virtual dht::shard_replica_set shard_for_writes(const token& t, std::optional<write_replica_set_selector> sel) const override {
|
||||
if (!sel) {
|
||||
sel = _sel;
|
||||
}
|
||||
return _sharder->shard_for_writes(t, sel);
|
||||
}
|
||||
virtual dht::shard_replica_set shard_for_writes(const token& t, std::optional<write_replica_set_selector> sel) const override;
|
||||
|
||||
virtual std::optional<dht::shard_and_token> next_shard_for_reads(const dht::token& t) const override {
|
||||
return _sharder->next_shard_for_reads(t);
|
||||
}
|
||||
virtual std::optional<dht::shard_and_token> next_shard_for_reads(const dht::token& t) const override;
|
||||
|
||||
virtual dht::token token_for_next_shard_for_reads(const dht::token& t, shard_id shard, unsigned spans = 1) const override {
|
||||
return _sharder->token_for_next_shard_for_reads(t, shard, spans);
|
||||
}
|
||||
virtual dht::token token_for_next_shard_for_reads(const dht::token& t, shard_id shard, unsigned spans = 1) const override;
|
||||
};
|
||||
|
||||
} // namespace dht
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "i_partitioner.hh"
|
||||
#include "sharder.hh"
|
||||
#include "auto_refreshing_sharder.hh"
|
||||
#include <seastar/core/seastar.hh>
|
||||
#include <seastar/coroutine/maybe_yield.hh>
|
||||
#include "dht/ring_position.hh"
|
||||
@@ -15,6 +16,7 @@
|
||||
#include "utils/assert.hh"
|
||||
#include "utils/class_registrator.hh"
|
||||
#include "sstables/key.hh"
|
||||
#include "replica/database.hh"
|
||||
#include <seastar/core/thread.hh>
|
||||
#include <seastar/core/on_internal_error.hh>
|
||||
#include "utils/log.hh"
|
||||
@@ -492,6 +494,46 @@ std::optional<shard_id> is_single_shard(const dht::sharder& sharder, const schem
|
||||
return shard;
|
||||
}
|
||||
|
||||
auto_refreshing_sharder::auto_refreshing_sharder(lw_shared_ptr<replica::table> table, std::optional<write_replica_set_selector> sel)
|
||||
: _table(std::move(table))
|
||||
, _sel(sel)
|
||||
{
|
||||
refresh();
|
||||
}
|
||||
|
||||
auto_refreshing_sharder::~auto_refreshing_sharder() = default;
|
||||
|
||||
void
|
||||
auto_refreshing_sharder::refresh() {
|
||||
_erm = _table->get_effective_replication_map();
|
||||
_sharder = &_erm->get_sharder(*_table->schema());
|
||||
_callback = _erm->get_validity_abort_source().subscribe([this] () noexcept {
|
||||
refresh();
|
||||
});
|
||||
}
|
||||
|
||||
unsigned auto_refreshing_sharder::shard_for_reads(const token& t) const {
|
||||
return _sharder->shard_for_reads(t);
|
||||
}
|
||||
|
||||
dht::shard_replica_set
|
||||
auto_refreshing_sharder::shard_for_writes(const token& t, std::optional<write_replica_set_selector> sel) const {
|
||||
if (!sel) {
|
||||
sel = _sel;
|
||||
}
|
||||
return _sharder->shard_for_writes(t, sel);
|
||||
}
|
||||
|
||||
std::optional<dht::shard_and_token>
|
||||
auto_refreshing_sharder::next_shard_for_reads(const dht::token& t) const {
|
||||
return _sharder->next_shard_for_reads(t);
|
||||
}
|
||||
|
||||
dht::token
|
||||
auto_refreshing_sharder::token_for_next_shard_for_reads(const dht::token& t, shard_id shard, unsigned spans) const {
|
||||
return _sharder->token_for_next_shard_for_reads(t, shard, spans);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto fmt::formatter<dht::ring_position_view>::format(const dht::ring_position_view& pos, fmt::format_context& ctx) const
|
||||
|
||||
Reference in New Issue
Block a user