storage_service, tablets: Move get_leaving_replica() to tablets.cc
For better encapsulation of tablet-specific code.
This commit is contained in:
@@ -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<tablet_replica> 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);
|
||||
|
||||
@@ -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().
|
||||
|
||||
Reference in New Issue
Block a user