tablets: Include pending replica in get_shard()

We need to move get_shard() from tablet_info to tablet_map in order to
have access to transition_info.
This commit is contained in:
Tomasz Grabiec
2023-05-09 11:43:57 +02:00
parent e8dd5e34c3
commit e44e6033d8
3 changed files with 74 additions and 9 deletions

View File

@@ -105,6 +105,23 @@ void tablet_map::set_tablet_transition_info(tablet_id id, tablet_transition_info
_transitions.insert_or_assign(id, std::move(info));
}
std::optional<shard_id> tablet_map::get_shard(tablet_id tid, host_id host) const {
auto&& info = get_tablet_info(tid);
for (auto&& r : info.replicas) {
if (r.host == host) {
return r.shard;
}
}
auto tinfo = get_tablet_transition_info(tid);
if (tinfo && tinfo->pending_replica.host == host) {
return tinfo->pending_replica.shard;
}
return std::nullopt;
}
future<> tablet_map::clear_gently() {
return utils::clear_gently(_tablets);
}

View File

@@ -52,15 +52,6 @@ using tablet_replica_set = utils::small_vector<tablet_replica, 3>;
struct tablet_info {
tablet_replica_set replicas;
std::optional<shard_id> get_shard(host_id host) const {
for (auto&& r : replicas) {
if (r.host == host) {
return r.shard;
}
}
return std::nullopt;
}
bool operator==(const tablet_info&) const = default;
};
@@ -148,6 +139,12 @@ public:
return tablet_id(size_t(t) + 1);
}
/// Returns shard id which is a replica for a given tablet on a given host.
/// If there is no replica on a given host, returns nullopt.
/// If the topology is transitional, also considers the new replica set.
/// The old replica set is preferred in case of ambiguity.
std::optional<shard_id> get_shard(tablet_id, host_id) const;
const tablet_container& tablets() const {
return _tablets;
}