From f3fbfdaa379ac9df19b17da2f214dbaef910d865 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 24 Mar 2023 17:00:27 +0100 Subject: [PATCH] db: tablets: Add printers Example: TRACE 2023-03-30 12:06:33,918 [shard 0] tablets - Read tablet metadata: { 8cd5b560-cee2-11ed-9cd5-7f37187f2167: { [0]: last_token=-6917529027641081857, replicas={4fe5c4d5-7030-4ddd-8117-ba22c29f4f57:0}, [1]: last_token=-4611686018427387905, replicas={3160b965-1925-4677-884b-c761e2bf4272:0}, [2]: last_token=-2305843009213693953, replicas={3160b965-1925-4677-884b-c761e2bf4272:0}, [3]: last_token=-1, replicas={4fe5c4d5-7030-4ddd-8117-ba22c29f4f57:0}, [4]: last_token=2305843009213693951, replicas={3160b965-1925-4677-884b-c761e2bf4272:0}, [5]: last_token=4611686018427387903, replicas={4fe5c4d5-7030-4ddd-8117-ba22c29f4f57:0}, [6]: last_token=6917529027641081855, replicas={4fe5c4d5-7030-4ddd-8117-ba22c29f4f57:0}, [7]: last_token=9223372036854775807, replicas={3160b965-1925-4677-884b-c761e2bf4272:0} } } --- locator/tablets.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ locator/tablets.hh | 3 +++ 2 files changed, 45 insertions(+) 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&); }; }