diff --git a/locator/tablets.cc b/locator/tablets.cc index 8889f74447..b05e332d3e 100644 --- a/locator/tablets.cc +++ b/locator/tablets.cc @@ -75,6 +75,20 @@ tablet_transition_info::tablet_transition_info(tablet_transition_stage stage, ta , reads(get_selector_for_reads(stage)) { } +tablet_replica get_leaving_replica(const tablet_info& tinfo, const tablet_transition_info& trinfo) { + std::unordered_set leaving(tinfo.replicas.begin(), tinfo.replicas.end()); + for (auto&& r : trinfo.next) { + leaving.erase(r); + } + if (leaving.empty()) { + throw std::runtime_error(format("No leaving replicas")); + } + if (leaving.size() > 1) { + throw std::runtime_error(format("More than one leaving replica")); + } + return *leaving.begin(); +} + const tablet_map& tablet_metadata::get_tablet_map(table_id id) const { try { return _tablets.at(id); diff --git a/locator/tablets.hh b/locator/tablets.hh index 9032645e00..4948a7be9e 100644 --- a/locator/tablets.hh +++ b/locator/tablets.hh @@ -168,6 +168,9 @@ struct tablet_transition_info { bool operator==(const tablet_transition_info&) const = default; }; +// Returns the leaving replica for a given transition. +tablet_replica get_leaving_replica(const tablet_info&, const tablet_transition_info&); + /// Stores information about tablets of a single table. /// /// The map contains a constant number of tablets, tablet_count(). diff --git a/service/storage_service.cc b/service/storage_service.cc index 7257cd1bf9..f17e7c4d42 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -5611,21 +5611,6 @@ future<> storage_service::update_fence_version(token_metadata::version_t new_ver }); } -static -locator::tablet_replica get_leaving_replica(const locator::tablet_info& tinfo, const locator::tablet_transition_info& trinfo) { - std::unordered_set leaving(tinfo.replicas.begin(), tinfo.replicas.end()); - for (auto&& r : trinfo.next) { - leaving.erase(r); - } - if (leaving.empty()) { - throw std::runtime_error(format("No leaving replicas")); - } - if (leaving.size() > 1) { - throw std::runtime_error(format("More than one leaving replica")); - } - return *leaving.begin(); -} - inet_address storage_service::host2ip(locator::host_id host) { auto ip = _group0->address_map().find(raft::server_id(host.uuid())); if (!ip) { @@ -5660,7 +5645,7 @@ future<> storage_service::stream_tablet(locator::global_tablet_id tablet) { auto& tinfo = tmap.get_tablet_info(tablet.tablet); auto range = tmap.get_token_range(tablet.tablet); - locator::tablet_replica leaving_replica = get_leaving_replica(tinfo, *trinfo); + locator::tablet_replica leaving_replica = locator::get_leaving_replica(tinfo, *trinfo); if (leaving_replica.host == tm->get_my_id()) { // The algorithm doesn't work with tablet migration within the same node because // it assumes there is only one tablet replica, picked by the sharder, on local node.