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.
This commit is contained in:
Tomasz Grabiec
2018-02-16 18:23:38 +01:00
parent 5320705300
commit bee875fa7d
3 changed files with 15 additions and 12 deletions

View File

@@ -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<rows_entry>();
auto i = _rows.erase_and_dispose(_rows.begin(), std::prev(_rows.end()), current_deleter<rows_entry>());
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;

View File

@@ -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<partition_version>(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<partition_version>(mutation_partition::make_incomplete(s))
: current_allocator().construct<partition_version>(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);

View File

@@ -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().