diff --git a/locator/tablets.cc b/locator/tablets.cc index baf0ba2851..021389ffcb 100644 --- a/locator/tablets.cc +++ b/locator/tablets.cc @@ -115,4 +115,46 @@ const tablet_transition_info* tablet_map::get_tablet_transition_info(tablet_id i return &i->second; } +std::ostream& operator<<(std::ostream& out, tablet_id id) { + return out << size_t(id); +} + +std::ostream& operator<<(std::ostream& out, const tablet_replica& r) { + return out << r.host << ":" << r.shard; +} + +std::ostream& operator<<(std::ostream& out, const tablet_map& r) { + if (r.tablet_count() == 0) { + return out << "{}"; + } + out << "{"; + bool first = true; + tablet_id tid = r.first_tablet(); + for (auto&& tablet : r._tablets) { + if (!first) { + out << ","; + } + out << format("\n [{}]: last_token={}, replicas={}", tid, r.get_last_token(tid), tablet.replicas); + if (auto tr = r.get_tablet_transition_info(tid)) { + out << format(", new_replicas={}, pending={}", tr->next, tr->pending_replica); + } + first = false; + tid = *r.next_tablet(tid); + } + return out << "\n }"; +} + +std::ostream& operator<<(std::ostream& out, const tablet_metadata& tm) { + out << "{"; + bool first = true; + for (auto&& [id, map] : tm._tablets) { + if (!first) { + out << ","; + } + out << "\n " << id << ": " << map; + first = false; + } + return out << "\n}"; +} + } diff --git a/locator/tablets.hh b/locator/tablets.hh index 019909fbf6..84ff54b6f1 100644 --- a/locator/tablets.hh +++ b/locator/tablets.hh @@ -43,6 +43,7 @@ struct tablet_replica { bool operator==(const tablet_replica&) const = default; }; +std::ostream& operator<<(std::ostream&, tablet_id); std::ostream& operator<<(std::ostream&, const tablet_replica&); using tablet_replica_set = utils::small_vector; @@ -175,6 +176,7 @@ public: // Destroys gently. // The tablet map is not usable after this call and should be destroyed. future<> clear_gently(); + friend std::ostream& operator<<(std::ostream&, const tablet_map&); private: void check_tablet_id(tablet_id) const; }; @@ -209,6 +211,7 @@ public: future<> clear_gently(); public: bool operator==(const tablet_metadata&) const = default; + friend std::ostream& operator<<(std::ostream&, const tablet_metadata&); }; }