From 0ea17216fed3ce949bee298d83d22a35b6b8c476 Mon Sep 17 00:00:00 2001 From: Juliusz Stasiewicz Date: Wed, 29 Jan 2020 16:55:17 +0100 Subject: [PATCH] atomic_cell: special rule for printing counter cells Until now, attempts to print counter update cell would end up calling abort() because `atomic_cell_view::value()` has no specialized visitor for `imr::pod::basic_view`, i.e. counter update IMR type. Such visitor is not easy to write if we want to intercept counters only (and not all int64_t values). Anyway, linearized byte representation of counter cell would not be helpful without knowing if it consists of counter shards or counter update (delta) - and this must be known upon `deserialize`. This commit introduces simple approach: it determines cell type on high level (from `atomic_cell_view`) and prints counter contents by `counter_cell_view` or `atomic_cell_view::counter_update_value()`. Fixes #5616 --- atomic_cell.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/atomic_cell.cc b/atomic_cell.cc index 92adfb1e32..30b0aebf50 100644 --- a/atomic_cell.cc +++ b/atomic_cell.cc @@ -21,6 +21,7 @@ #include "atomic_cell.hh" #include "atomic_cell_or_collection.hh" +#include "counters.hh" #include "types.hh" /// LSA mirator for cells with irrelevant type @@ -218,7 +219,9 @@ std::ostream& operator<<(std::ostream& os, const atomic_cell_view& acv) { if (acv.is_live()) { return fmt_print(os, "atomic_cell{{{},ts={:d},expiry={:d},ttl={:d}}}", - to_hex(acv.value().linearize()), + acv.is_counter_update() + ? "counter_update_value=" + to_sstring(acv.counter_update_value()) + : to_hex(acv.value().linearize()), acv.timestamp(), acv.is_live_and_has_ttl() ? acv.expiry().time_since_epoch().count() : -1, acv.is_live_and_has_ttl() ? acv.ttl().count() : 0); @@ -238,8 +241,21 @@ operator<<(std::ostream& os, const atomic_cell_view::printer& acvp) { auto& type = acvp._type; auto& acv = acvp._cell; if (acv.is_live()) { + std::ostringstream cell_value_string_builder; + if (type.is_counter()) { + if (acv.is_counter_update()) { + cell_value_string_builder << "counter_update_value=" << acv.counter_update_value(); + } else { + cell_value_string_builder << "shards: "; + counter_cell_view::with_linearized(acv, [&cell_value_string_builder] (counter_cell_view& ccv) { + cell_value_string_builder << ::join(", ", ccv.shards()); + }); + } + } else { + cell_value_string_builder << type.to_string(acv.value().linearize()); + } return fmt_print(os, "atomic_cell{{{},ts={:d},expiry={:d},ttl={:d}}}", - type.to_string(acv.value().linearize()), + cell_value_string_builder.str(), acv.timestamp(), acv.is_live_and_has_ttl() ? acv.expiry().time_since_epoch().count() : -1, acv.is_live_and_has_ttl() ? acv.ttl().count() : 0);