From 1df256221c69bede3f2727075ff288a41ca9d6f9 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 19 Jan 2024 12:08:42 +0100 Subject: [PATCH] tablets: Extract get_new_replicas() which works on migraiton request Now we have a single place which translates tablet migration request to new replicas. Will be reused in other places. --- locator/tablets.cc | 4 ++++ locator/tablets.hh | 3 +++ service/storage_service.cc | 2 +- test/boost/tablets_test.cc | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/locator/tablets.cc b/locator/tablets.cc index 21109ac815..b684a5d3b2 100644 --- a/locator/tablets.cc +++ b/locator/tablets.cc @@ -107,6 +107,10 @@ tablet_replica get_leaving_replica(const tablet_info& tinfo, const tablet_transi return *leaving.begin(); } +tablet_replica_set get_new_replicas(const tablet_info& tinfo, const tablet_migration_info& mig) { + return replace_replica(tinfo.replicas, mig.src, mig.dst); +} + 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 883d78f9b0..6421e3dd54 100644 --- a/locator/tablets.hh +++ b/locator/tablets.hh @@ -209,6 +209,9 @@ struct tablet_migration_info { locator::tablet_replica dst; }; +/// Returns the replica set which will become the replica set of the tablet after executing a given tablet transition. +tablet_replica_set get_new_replicas(const tablet_info&, const tablet_migration_info&); + /// Describes streaming required for a given tablet transition. struct tablet_migration_streaming_info { std::unordered_set read_from; diff --git a/service/storage_service.cc b/service/storage_service.cc index 5d0b77810f..7d16d7d1ef 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -2044,7 +2044,7 @@ class topology_coordinator : public endpoint_lifecycle_subscriber { } out.emplace_back( replica::tablet_mutation_builder(guard.write_timestamp(), mig.tablet.table) - .set_new_replicas(last_token, replace_replica(tmap.get_tablet_info(mig.tablet.tablet).replicas, mig.src, mig.dst)) + .set_new_replicas(last_token, locator::get_new_replicas(tmap.get_tablet_info(mig.tablet.tablet), mig)) .set_stage(last_token, locator::tablet_transition_stage::allow_write_both_read_old) .set_transition(last_token, mig.kind) .build()); diff --git a/test/boost/tablets_test.cc b/test/boost/tablets_test.cc index 59bcc6bdd2..c321320cf4 100644 --- a/test/boost/tablets_test.cc +++ b/test/boost/tablets_test.cc @@ -617,7 +617,7 @@ tablet_transition_info migration_to_transition_info(const tablet_migration_info& return tablet_transition_info { tablet_transition_stage::allow_write_both_read_old, mig.kind, - replace_replica(ti.replicas, mig.src, mig.dst), + get_new_replicas(ti, mig), mig.dst }; }