From bee875fa7d3e695ecdd64c1071a687633b6819c2 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Fri, 16 Feb 2018 18:23:38 +0100 Subject: [PATCH] cache: Ensure all evictable partition_versions have a dummy after all rows Every evictable version will have a dummy entry at the end so that it can be tracked in the LRU. It is also needed to allow old versions to stay around (with tombstones and static rows) after all rows are evicted. Such versions must be fully discontinuous, and we need some entry to mark that. --- mutation_partition.cc | 14 +++++--------- partition_version.cc | 8 +++++++- partition_version.hh | 5 +++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/mutation_partition.cc b/mutation_partition.cc index eec1ab6899..8aff61b741 100644 --- a/mutation_partition.cc +++ b/mutation_partition.cc @@ -2123,17 +2123,13 @@ clustering_interval_set mutation_partition::get_continuity(const schema& s, is_c } void mutation_partition::evict(cache_tracker& tracker) noexcept { - if (!_rows.empty()) { - // We need to keep the last entry to mark the range containing all evicted rows as discontinuous. - // No rows would mean it is continuous. + { + assert(!_rows.empty()); + auto del = current_deleter(); auto i = _rows.erase_and_dispose(_rows.begin(), std::prev(_rows.end()), current_deleter()); rows_entry& e = *i; - e._flags._before_ck = false; - e._flags._after_ck = true; - e._flags._dummy = true; - e._flags._last_dummy = true; - e._flags._continuous = false; - e._row = {}; + assert(e.is_last_dummy()); + e.set_continuous(false); } _row_tombstones.clear(); _static_row_continuous = false; diff --git a/partition_version.cc b/partition_version.cc index 76bea643ac..940b1b52cc 100644 --- a/partition_version.cc +++ b/partition_version.cc @@ -241,7 +241,13 @@ void partition_entry::set_version(partition_version* new_version) } partition_version& partition_entry::add_version(const schema& s, cache_tracker* tracker) { - auto new_version = current_allocator().construct(mutation_partition(s.shared_from_this())); + // Every evictable version must have a dummy entry at the end so that + // it can be tracked in the LRU. It is also needed to allow old versions + // to stay around (with tombstones and static rows) after fully evicted. + // Such versions must be fully discontinuous, and thus have a dummy at the end. + auto new_version = tracker + ? current_allocator().construct(mutation_partition::make_incomplete(s)) + : current_allocator().construct(mutation_partition(s.shared_from_this())); new_version->partition().set_static_row_continuous(_version->partition().static_row_continuous()); new_version->insert_before(*_version); set_version(new_version); diff --git a/partition_version.hh b/partition_version.hh index b32525e05c..a26feb628e 100644 --- a/partition_version.hh +++ b/partition_version.hh @@ -131,8 +131,9 @@ // this assumption to make calculation of the union of intervals on merging // easier. // -// Continuity after the last entry in a version is assumed to be discontinuous -// for evictable entries. +// versions of evictable entries always have a dummy entry at position_in_partition::after_all_clustered_rows(). +// This is needed so that they can be always made fully discontinuous by eviction, and because +// we need a way to link partitions with no rows into the LRU. // // Snapshots of evictable entries always have a row entry at // position_in_partition::after_all_clustered_rows().