From e2c4d2d60a7008f8ed32ff7be2a991e777f4e51d Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Wed, 16 Jan 2019 17:05:16 +0200 Subject: [PATCH] memtable: extract encoding_stats_collector base class to encoding_stats header file To be used also by compaction. Refs #3971 Signed-off-by: Benny Halevy --- encoding_stats.hh | 31 +++++++++++++++++++++++++++++++ memtable.hh | 41 +++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/encoding_stats.hh b/encoding_stats.hh index e0c3fa40c8..cd886fd8df 100644 --- a/encoding_stats.hh +++ b/encoding_stats.hh @@ -22,6 +22,7 @@ #pragma once #include "timestamp.hh" +#include "utils/extremum_tracking.hh" // Stores statistics on all the updates done to a memtable // The collected statistics are used for flushing memtable to the disk @@ -49,3 +50,33 @@ struct encoding_stats { int32_t min_local_deletion_time = deletion_time_epoch; int32_t min_ttl = ttl_epoch; }; + +class encoding_stats_collector { +private: + min_tracker min_timestamp; + min_tracker min_local_deletion_time; + min_tracker min_ttl; + +public: + encoding_stats_collector() + : min_timestamp(api::max_timestamp) + , min_local_deletion_time(std::numeric_limits::max()) + , min_ttl(std::numeric_limits::max()) + {} + + void update_timestamp(api::timestamp_type ts) { + min_timestamp.update(ts); + } + + void update_local_deletion_time(int32_t local_deletion_time) { + min_local_deletion_time.update(local_deletion_time); + } + + void update_ttl(int32_t ttl) { + min_ttl.update(ttl); + } + + encoding_stats get() const { + return { min_timestamp.get(), min_local_deletion_time.get(), min_ttl.get() }; + } +}; diff --git a/memtable.hh b/memtable.hh index 3db3af8ede..fecfa1beee 100644 --- a/memtable.hh +++ b/memtable.hh @@ -143,39 +143,36 @@ private: mutation_source_opt _underlying; uint64_t _flushed_memory = 0; - class encoding_stats_collector { + class memtable_encoding_stats_collector : public encoding_stats_collector { private: - min_max_tracker timestamp; - min_tracker min_local_deletion_time; - min_tracker min_ttl; + max_tracker max_timestamp; void update_timestamp(api::timestamp_type ts) { if (ts != api::missing_timestamp) { - timestamp.update(ts); + encoding_stats_collector::update_timestamp(ts); + max_timestamp.update(ts); } } public: - encoding_stats_collector() - : timestamp(api::max_timestamp, 0) - , min_local_deletion_time(std::numeric_limits::max()) - , min_ttl(std::numeric_limits::max()) + memtable_encoding_stats_collector() + : max_timestamp(0) {} void update(atomic_cell_view cell) { update_timestamp(cell.timestamp()); if (cell.is_live_and_has_ttl()) { - min_ttl.update(cell.ttl().count()); - min_local_deletion_time.update(cell.expiry().time_since_epoch().count()); + update_ttl(cell.ttl().count()); + update_local_deletion_time(cell.expiry().time_since_epoch().count()); } else if (!cell.is_live()) { - min_local_deletion_time.update(cell.deletion_time().time_since_epoch().count()); + update_local_deletion_time(cell.deletion_time().time_since_epoch().count()); } } void update(tombstone tomb) { if (tomb) { update_timestamp(tomb.timestamp); - min_local_deletion_time.update(tomb.deletion_time.time_since_epoch().count()); + update_local_deletion_time(tomb.deletion_time.time_since_epoch().count()); } } @@ -210,11 +207,11 @@ private: update_timestamp(marker.timestamp()); if (!marker.is_missing()) { if (!marker.is_live()) { - min_ttl.update(sstables::expired_liveness_ttl); - min_local_deletion_time.update(marker.deletion_time().time_since_epoch().count()); + update_ttl(sstables::expired_liveness_ttl); + update_local_deletion_time(marker.deletion_time().time_since_epoch().count()); } else if (marker.is_expiring()) { - min_ttl.update(marker.ttl().count()); - min_local_deletion_time.update(marker.expiry().time_since_epoch().count()); + update_ttl(marker.ttl().count()); + update_local_deletion_time(marker.expiry().time_since_epoch().count()); } } } @@ -238,12 +235,8 @@ private: } } - encoding_stats get() const { - return { timestamp.min(), min_local_deletion_time.get(), min_ttl.get() }; - } - - api::timestamp_type max_timestamp() const { - return timestamp.max(); + api::timestamp_type get_max_timestamp() const { + return max_timestamp.get(); } } _stats_collector; @@ -300,7 +293,7 @@ public: } api::timestamp_type get_max_timestamp() const { - return _stats_collector.max_timestamp(); + return _stats_collector.get_max_timestamp(); } mutation_cleaner& cleaner() {