Files
scylladb/locator/simple_strategy.cc
Avi Kivity fcb8d040e8 treewide: use Software Package Data Exchange (SPDX) license identifiers
Instead of lengthy blurbs, switch to single-line, machine-readable
standardized (https://spdx.dev) license identifiers. The Linux kernel
switched long ago, so there is strong precedent.

Three cases are handled: AGPL-only, Apache-only, and dual licensed.
For the latter case, I chose (AGPL-3.0-or-later and Apache-2.0),
reasoning that our changes are extensive enough to apply our license.

The changes we applied mechanically with a script, except to
licenses/README.md.

Closes #9937
2022-01-18 12:15:18 +01:00

83 lines
2.4 KiB
C++

/*
* Copyright (C) 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <algorithm>
#include <seastar/core/coroutine.hh>
#include <seastar/coroutine/maybe_yield.hh>
#include "simple_strategy.hh"
#include "utils/class_registrator.hh"
#include <boost/algorithm/string.hpp>
#include "utils/sequenced_set.hh"
namespace locator {
simple_strategy::simple_strategy(snitch_ptr& snitch, const replication_strategy_config_options& config_options) :
abstract_replication_strategy(snitch, config_options, replication_strategy_type::simple) {
for (auto& config_pair : config_options) {
auto& key = config_pair.first;
auto& val = config_pair.second;
if (boost::iequals(key, "replication_factor")) {
validate_replication_factor(val);
_replication_factor = std::stol(val);
break;
}
}
}
future<inet_address_vector_replica_set> simple_strategy::calculate_natural_endpoints(const token& t, const token_metadata& tm) const {
const std::vector<token>& tokens = tm.sorted_tokens();
if (tokens.empty()) {
co_return inet_address_vector_replica_set();
}
size_t replicas = _replication_factor;
utils::sequenced_set<inet_address> endpoints;
endpoints.reserve(replicas);
for (auto& token : tm.ring_range(t)) {
if (endpoints.size() == replicas) {
break;
}
auto ep = tm.get_endpoint(token);
assert(ep);
endpoints.push_back(*ep);
co_await coroutine::maybe_yield();
}
co_return boost::copy_range<inet_address_vector_replica_set>(endpoints.get_vector());
}
size_t simple_strategy::get_replication_factor(const token_metadata&) const {
return _replication_factor;
}
void simple_strategy::validate_options() const {
auto it = _config_options.find("replication_factor");
if (it == _config_options.end()) {
throw exceptions::configuration_exception("SimpleStrategy requires a replication_factor strategy option.");
}
validate_replication_factor(it->second);
}
std::optional<std::set<sstring>>simple_strategy::recognized_options(const topology&) const {
return {{ "replication_factor" }};
}
using registry = class_registrator<abstract_replication_strategy, simple_strategy, snitch_ptr&, const replication_strategy_config_options&>;
static registry registrator("org.apache.cassandra.locator.SimpleStrategy");
static registry registrator_short_name("SimpleStrategy");
}