dht: Rename dht::shard_of() to dht::static_shard_of()

This is in order to prevent new incorrect uses of dht::shard_of() to
be accidentally added. Also, makes sure that all current uses are
caught by the compiler and require an explicit rename.
This commit is contained in:
Tomasz Grabiec
2023-05-16 23:38:36 +02:00
parent 21198e8470
commit 29cbdb812b
8 changed files with 11 additions and 8 deletions

View File

@@ -135,7 +135,7 @@ static std::vector<sstring> get_keyspaces(const schema& s, const replica::databa
return boost::copy_range<std::vector<sstring>>(
range.slice(keyspaces, std::move(cmp)) | boost::adaptors::filtered([&s] (const auto& ks) {
// If this is a range query, results are divided between shards by the partition key (keyspace_name).
return shard_of(s, dht::get_token(s,
return dht::static_shard_of(s, dht::get_token(s,
partition_key::from_single_value(s, utf8_type->decompose(ks))))
== this_shard_id();
})

View File

@@ -28,7 +28,7 @@ void virtual_table::set_cell(row& cr, const bytes& column_name, data_value value
}
bool virtual_table::this_shard_owns(const dht::decorated_key& dk) const {
return dht::shard_of(*_s, dk.token()) == this_shard_id();
return dht::static_shard_of(*_s, dk.token()) == this_shard_id();
}
bool virtual_table::contains_key(const dht::partition_range& pr, const dht::decorated_key& dk) const {

View File

@@ -182,7 +182,7 @@ std::ostream& operator<<(std::ostream& out, const i_partitioner& p) {
return out << "}";
}
unsigned shard_of(const schema& s, const token& t) {
unsigned static_shard_of(const schema& s, const token& t) {
return s.get_sharder().shard_of(t);
}

View File

@@ -620,7 +620,10 @@ public:
};
std::ostream& operator<<(std::ostream& out, partition_ranges_view v);
unsigned shard_of(const schema&, const token&);
// Returns the owning shard number for vnode-based replication strategies.
// Use table::shard_of() for the general case.
unsigned static_shard_of(const schema&, const token&);
inline decorated_key decorate_key(const schema& s, const partition_key& key) {
return s.get_partitioner().decorate_key(s, key);
}

View File

@@ -38,7 +38,7 @@ public:
{}
future<> consume(partition_start&& ps) {
_current_shard = dht::shard_of(*_schema, ps.key().token());
_current_shard = dht::static_shard_of(*_schema, ps.key().token()); // FIXME: Use table sharder
if (!_shards[_current_shard]) {
_shards[_current_shard] = shard_writer(_schema, _permit, _consumer);
}

View File

@@ -777,7 +777,7 @@ public:
}
shard_id shard_of(dht::token t) const {
return _erm ? _erm->shard_of(*_schema, t)
: dht::shard_of(*_schema, t); // for tests.
: dht::static_shard_of(*_schema, t); // for tests.
}
// Applies given mutation to this column family
// The mutation is always upgraded to current schema.

View File

@@ -100,7 +100,7 @@ static generated_table create_test_table(
keys.emplace_back(mut.decorated_key());
compacted_frozen_mutations.emplace_back(freeze(mut.compacted()));
(void)with_gate(write_gate, [&] {
return smp::submit_to(dht::shard_of(*schema, mut.decorated_key().token()), [&env, gs = global_schema_ptr(schema), mut = freeze(mut)] () mutable {
return smp::submit_to(dht::static_shard_of(*schema, mut.decorated_key().token()), [&env, gs = global_schema_ptr(schema), mut = freeze(mut)] () mutable {
return env.local_db().apply(gs.get(), std::move(mut), {}, db::commitlog_force_sync::no, db::no_timeout);
});
});

View File

@@ -65,7 +65,7 @@ std::vector<dht::decorated_key> generate_partition_keys(size_t n, schema_ptr s,
s->partition_key_type()->types(),
[s, shard, tokens = std::set<dht::token>()] (const partition_key& pkey) mutable -> std::optional<dht::decorated_key> {
auto dkey = dht::decorate_key(*s, pkey);
if (shard && *shard != dht::shard_of(*s, dkey.token())) {
if (shard && *shard != dht::static_shard_of(*s, dkey.token())) {
return {};
}
if (!tokens.insert(dkey.token()).second) {