mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-12 19:02:12 +00:00
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 <bhalevy@scylladb.com>
This commit is contained in:
@@ -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<api::timestamp_type> min_timestamp;
|
||||
min_tracker<int32_t> min_local_deletion_time;
|
||||
min_tracker<int32_t> min_ttl;
|
||||
|
||||
public:
|
||||
encoding_stats_collector()
|
||||
: min_timestamp(api::max_timestamp)
|
||||
, min_local_deletion_time(std::numeric_limits<int32_t>::max())
|
||||
, min_ttl(std::numeric_limits<int32_t>::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() };
|
||||
}
|
||||
};
|
||||
|
||||
41
memtable.hh
41
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<api::timestamp_type> timestamp;
|
||||
min_tracker<int32_t> min_local_deletion_time;
|
||||
min_tracker<int32_t> min_ttl;
|
||||
max_tracker<api::timestamp_type> 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<int32_t>::max())
|
||||
, min_ttl(std::numeric_limits<int32_t>::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() {
|
||||
|
||||
Reference in New Issue
Block a user