token_metadata: topology_change_info: change field types to token_metadata_ptr

In subsequent commits we'll need the following api for token_metadata:
  token_metadata(token_metadata2_ptr);
  get_new() -> token_metadata2*
where token_metadata2 is the new version of token_metadata,
based on host_id.

In other words:
* token_metadata knows the new version of itself and returns a pointer
to it through get_new()
* token_metadata can be constructed based solely on the new version,
without its own implementation. In this case the only method we can
use on it is get_new.

This allows to pass token_metadata2 to API's with token_metadata in method
signature, if these APIs are known to only use the get_new method on the
passed token_metadata.

And back to topology_change_info - if we got it from the new token_metadata
we want to be able to construct token_metadata from token_metadata2 contained
in it, and this requires it to be a ptr, not value.
This commit is contained in:
Petr Gusev
2023-11-23 14:40:18 +04:00
parent f21f23483c
commit 2f137776c3
3 changed files with 11 additions and 11 deletions

View File

@@ -373,7 +373,7 @@ future<mutable_vnode_effective_replication_map_ptr> calculate_effective_replicat
const auto token = all_tokens[i];
auto current_endpoints = co_await rs->calculate_natural_endpoints(token, base_token_metadata);
auto target_endpoints = co_await rs->calculate_natural_endpoints(token, topology_changes->target_token_metadata);
auto target_endpoints = co_await rs->calculate_natural_endpoints(token, *topology_changes->target_token_metadata);
auto add_mapping = [&](ring_mapping& target, std::unordered_set<inet_address>&& endpoints) {
using interval = ring_mapping::interval_type;

View File

@@ -796,8 +796,8 @@ future<> token_metadata_impl::update_topology_change_info(dc_rack_fn& get_dc_rac
std::sort(begin(all_tokens), end(all_tokens));
auto prev_value = std::move(_topology_change_info);
_topology_change_info.emplace(token_metadata(std::move(target_token_metadata)),
base_token_metadata ? std::optional(token_metadata(std::move(base_token_metadata))): std::nullopt,
_topology_change_info.emplace(make_token_metadata_ptr(std::move(target_token_metadata)),
base_token_metadata ? make_token_metadata_ptr(std::move(base_token_metadata)): nullptr,
std::move(all_tokens),
_read_new);
co_await utils::clear_gently(prev_value);
@@ -844,10 +844,10 @@ std::map<token, inet_address> token_metadata_impl::get_normal_and_bootstrapping_
return ret;
}
topology_change_info::topology_change_info(token_metadata target_token_metadata_,
std::optional<token_metadata> base_token_metadata_,
std::vector<dht::token> all_tokens_,
token_metadata::read_new_t read_new_)
topology_change_info::topology_change_info(token_metadata_ptr target_token_metadata_,
token_metadata_ptr base_token_metadata_,
std::vector<dht::token> all_tokens_,
token_metadata::read_new_t read_new_)
: target_token_metadata(std::move(target_token_metadata_))
, base_token_metadata(std::move(base_token_metadata_))
, all_tokens(std::move(all_tokens_))

View File

@@ -290,13 +290,13 @@ private:
};
struct topology_change_info {
token_metadata target_token_metadata;
std::optional<token_metadata> base_token_metadata;
token_metadata_ptr target_token_metadata;
token_metadata_ptr base_token_metadata;
std::vector<dht::token> all_tokens;
token_metadata::read_new_t read_new;
topology_change_info(token_metadata target_token_metadata_,
std::optional<token_metadata> base_token_metadata_,
topology_change_info(token_metadata_ptr target_token_metadata_,
token_metadata_ptr base_token_metadata_,
std::vector<dht::token> all_tokens_,
token_metadata::read_new_t read_new_);
future<> clear_gently();