locator: Wrap replication_strategy_config_options into replication_strategy_params
When replication strategy class is created caller parr const reference on the config options which is, in turn, a map<string, string>. In the future r.s. classes will need to get "scylla specific" info along with legacy options and this patch prepares for that by passing more generic params argument into constructor. Currently the only inhabitant of the new params is the legacy options. Signed-off-by: Pavel Emelyanov <xemul@scylladb.com>
This commit is contained in:
@@ -34,16 +34,15 @@ static endpoint_set resolve_endpoints(const host_id_set& host_ids, const token_m
|
||||
logging::logger rslogger("replication_strategy");
|
||||
|
||||
abstract_replication_strategy::abstract_replication_strategy(
|
||||
const replication_strategy_config_options& config_options,
|
||||
replication_strategy_params params,
|
||||
replication_strategy_type my_type)
|
||||
: _config_options(config_options)
|
||||
: _config_options(params.options)
|
||||
, _my_type(my_type) {}
|
||||
|
||||
abstract_replication_strategy::ptr_type abstract_replication_strategy::create_replication_strategy(const sstring& strategy_name, const replication_strategy_config_options& config_options) {
|
||||
try {
|
||||
return create_object<abstract_replication_strategy,
|
||||
const replication_strategy_config_options&>
|
||||
(strategy_name, config_options);
|
||||
replication_strategy_params params(config_options);
|
||||
return create_object<abstract_replication_strategy, replication_strategy_params>(strategy_name, std::move(params));
|
||||
} catch (const no_such_class& e) {
|
||||
throw exceptions::configuration_exception(e.what());
|
||||
}
|
||||
@@ -75,7 +74,7 @@ future<endpoint_set> abstract_replication_strategy::calculate_natural_ips(const
|
||||
|
||||
using strategy_class_registry = class_registry<
|
||||
locator::abstract_replication_strategy,
|
||||
const locator::replication_strategy_config_options&>;
|
||||
replication_strategy_params>;
|
||||
|
||||
sstring abstract_replication_strategy::to_qualified_class_name(std::string_view strategy_class_name) {
|
||||
return strategy_class_registry::to_qualified_class_name(strategy_class_name);
|
||||
|
||||
@@ -49,6 +49,10 @@ enum class replication_strategy_type {
|
||||
using can_yield = utils::can_yield;
|
||||
|
||||
using replication_strategy_config_options = std::map<sstring, sstring>;
|
||||
struct replication_strategy_params {
|
||||
const replication_strategy_config_options& options;
|
||||
explicit replication_strategy_params(const replication_strategy_config_options& o) noexcept : options(o) {}
|
||||
};
|
||||
|
||||
using replication_map = std::unordered_map<token, inet_address_vector_replica_set>;
|
||||
|
||||
@@ -91,7 +95,7 @@ public:
|
||||
using ptr_type = seastar::shared_ptr<abstract_replication_strategy>;
|
||||
|
||||
abstract_replication_strategy(
|
||||
const replication_strategy_config_options& config_options,
|
||||
replication_strategy_params params,
|
||||
replication_strategy_type my_type);
|
||||
|
||||
// Evaluates to true iff calculate_natural_endpoints
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
namespace locator {
|
||||
|
||||
everywhere_replication_strategy::everywhere_replication_strategy(const replication_strategy_config_options& config_options) :
|
||||
abstract_replication_strategy(config_options, replication_strategy_type::everywhere_topology) {
|
||||
everywhere_replication_strategy::everywhere_replication_strategy(replication_strategy_params params) :
|
||||
abstract_replication_strategy(params, replication_strategy_type::everywhere_topology) {
|
||||
_natural_endpoints_depend_on_token = false;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ size_t everywhere_replication_strategy::get_replication_factor(const token_metad
|
||||
return tm.sorted_tokens().empty() ? 1 : tm.count_normal_token_owners();
|
||||
}
|
||||
|
||||
using registry = class_registrator<abstract_replication_strategy, everywhere_replication_strategy, const replication_strategy_config_options&>;
|
||||
using registry = class_registrator<abstract_replication_strategy, everywhere_replication_strategy, replication_strategy_params>;
|
||||
static registry registrator("org.apache.cassandra.locator.EverywhereStrategy");
|
||||
static registry registrator_short_name("EverywhereStrategy");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
namespace locator {
|
||||
class everywhere_replication_strategy : public abstract_replication_strategy {
|
||||
public:
|
||||
everywhere_replication_strategy(const replication_strategy_config_options& config_options);
|
||||
everywhere_replication_strategy(replication_strategy_params params);
|
||||
|
||||
virtual future<host_id_set> calculate_natural_endpoints(const token& search_token, const token_metadata& tm) const override;
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
namespace locator {
|
||||
|
||||
local_strategy::local_strategy(const replication_strategy_config_options& config_options) :
|
||||
abstract_replication_strategy(config_options, replication_strategy_type::local) {
|
||||
local_strategy::local_strategy(replication_strategy_params params) :
|
||||
abstract_replication_strategy(params, replication_strategy_type::local) {
|
||||
_natural_endpoints_depend_on_token = false;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ size_t local_strategy::get_replication_factor(const token_metadata&) const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
using registry = class_registrator<abstract_replication_strategy, local_strategy, const replication_strategy_config_options&>;
|
||||
using registry = class_registrator<abstract_replication_strategy, local_strategy, replication_strategy_params>;
|
||||
static registry registrator("org.apache.cassandra.locator.LocalStrategy");
|
||||
static registry registrator_short_name("LocalStrategy");
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ using token = dht::token;
|
||||
|
||||
class local_strategy : public abstract_replication_strategy {
|
||||
public:
|
||||
local_strategy(const replication_strategy_config_options& config_options);
|
||||
local_strategy(replication_strategy_params params);
|
||||
virtual ~local_strategy() {};
|
||||
virtual size_t get_replication_factor(const token_metadata&) const override;
|
||||
|
||||
|
||||
@@ -29,9 +29,8 @@ struct hash<locator::endpoint_dc_rack> {
|
||||
|
||||
namespace locator {
|
||||
|
||||
network_topology_strategy::network_topology_strategy(
|
||||
const replication_strategy_config_options& config_options) :
|
||||
abstract_replication_strategy(config_options,
|
||||
network_topology_strategy::network_topology_strategy(replication_strategy_params params) :
|
||||
abstract_replication_strategy(params,
|
||||
replication_strategy_type::network_topology) {
|
||||
auto opts = _config_options;
|
||||
process_tablet_options(*this, opts);
|
||||
@@ -332,7 +331,7 @@ future<tablet_map> network_topology_strategy::allocate_tablets_for_new_table(sch
|
||||
co_return tablets;
|
||||
}
|
||||
|
||||
using registry = class_registrator<abstract_replication_strategy, network_topology_strategy, const replication_strategy_config_options&>;
|
||||
using registry = class_registrator<abstract_replication_strategy, network_topology_strategy, replication_strategy_params>;
|
||||
static registry registrator("org.apache.cassandra.locator.NetworkTopologyStrategy");
|
||||
static registry registrator_short_name("NetworkTopologyStrategy");
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ namespace locator {
|
||||
class network_topology_strategy : public abstract_replication_strategy
|
||||
, public tablet_aware_replication_strategy {
|
||||
public:
|
||||
network_topology_strategy(
|
||||
const replication_strategy_config_options& config_options);
|
||||
network_topology_strategy(replication_strategy_params params);
|
||||
|
||||
virtual size_t get_replication_factor(const token_metadata&) const override {
|
||||
return _rep_factor;
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
namespace locator {
|
||||
|
||||
simple_strategy::simple_strategy(const replication_strategy_config_options& config_options) :
|
||||
abstract_replication_strategy(config_options, replication_strategy_type::simple) {
|
||||
simple_strategy::simple_strategy(replication_strategy_params params) :
|
||||
abstract_replication_strategy(params, replication_strategy_type::simple) {
|
||||
for (auto& config_pair : _config_options) {
|
||||
auto& key = config_pair.first;
|
||||
auto& val = config_pair.second;
|
||||
@@ -79,7 +79,7 @@ std::optional<std::unordered_set<sstring>>simple_strategy::recognized_options(co
|
||||
return {{ "replication_factor" }};
|
||||
}
|
||||
|
||||
using registry = class_registrator<abstract_replication_strategy, simple_strategy, const replication_strategy_config_options&>;
|
||||
using registry = class_registrator<abstract_replication_strategy, simple_strategy, replication_strategy_params>;
|
||||
static registry registrator("org.apache.cassandra.locator.SimpleStrategy");
|
||||
static registry registrator_short_name("SimpleStrategy");
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace locator {
|
||||
|
||||
class simple_strategy : public abstract_replication_strategy {
|
||||
public:
|
||||
simple_strategy(const replication_strategy_config_options& config_options);
|
||||
simple_strategy(replication_strategy_params params);
|
||||
virtual ~simple_strategy() {};
|
||||
virtual size_t get_replication_factor(const token_metadata& tm) const override;
|
||||
virtual void validate_options(const gms::feature_service&) const override;
|
||||
|
||||
@@ -642,13 +642,13 @@ static void test_equivalence(const shared_token_metadata& stm, const locator::to
|
||||
using network_topology_strategy::calculate_natural_endpoints;
|
||||
};
|
||||
|
||||
my_network_topology_strategy nts(
|
||||
my_network_topology_strategy nts(replication_strategy_params(
|
||||
boost::copy_range<std::map<sstring, sstring>>(
|
||||
datacenters
|
||||
| boost::adaptors::transformed(
|
||||
[](const std::pair<sstring, size_t>& p) {
|
||||
return std::make_pair(p.first, to_sstring(p.second));
|
||||
})));
|
||||
}))));
|
||||
|
||||
const token_metadata& tm = *stm.get();
|
||||
for (size_t i = 0; i < 1000; ++i) {
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace {
|
||||
mutable_vnode_erm_ptr create_erm(mutable_token_metadata_ptr tmptr, replication_strategy_config_options opts = {}) {
|
||||
dc_rack_fn get_dc_rack_fn = get_dc_rack;
|
||||
tmptr->update_topology_change_info(get_dc_rack_fn).get();
|
||||
auto strategy = seastar::make_shared<Strategy>(std::move(opts));
|
||||
auto strategy = seastar::make_shared<Strategy>(replication_strategy_params(opts));
|
||||
return calculate_effective_replication_map(std::move(strategy), tmptr).get0();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user