diff --git a/mutation_partition.cc b/mutation_partition.cc index 8e8114d5cb..fcbdec0adc 100644 --- a/mutation_partition.cc +++ b/mutation_partition.cc @@ -352,12 +352,11 @@ stop_iteration mutation_partition::apply_monotonically(const schema& s, mutation src_e.set_continuous(false); if (tracker) { tracker->on_remove(*i); - i->_lru_link.swap_nodes(src_e._lru_link); // Newer evictable versions store complete rows - i->_row = std::move(src_e._row); + i->replace_with(std::move(src_e)); } else { memory::on_alloc_point(); - i->_row.apply_monotonically(s, std::move(src_e._row)); + i->apply_monotonically(s, std::move(src_e)); } ++app_stats.row_hits; p_i = p._rows.erase_and_dispose(p_i, del); @@ -1593,6 +1592,11 @@ rows_entry::rows_entry(rows_entry&& o) noexcept } } +void rows_entry::replace_with(rows_entry&& o) noexcept { + _lru_link.swap_nodes(o._lru_link); + _row = std::move(o._row); +} + row::row(const schema& s, column_kind kind, const row& o) : _type(o._type) , _size(o._size) diff --git a/mutation_partition.hh b/mutation_partition.hh index e1c3e709e3..67e21e39e2 100644 --- a/mutation_partition.hh +++ b/mutation_partition.hh @@ -1025,7 +1025,6 @@ class cache_tracker; class rows_entry { using lru_link_type = bi::list_member_hook>; - friend class cache_tracker; friend class size_calculator; intrusive_set_external_comparator_member_hook _link; clustering_key _key; @@ -1042,8 +1041,13 @@ class rows_entry { bool _last_dummy : 1; flags() : _before_ck(0), _after_ck(0), _continuous(true), _dummy(false), _last_dummy(false) { } } _flags{}; - friend class mutation_partition; public: + using container_type = intrusive_set_external_comparator; + using lru_type = bi::list, + bi::constant_time_size>; // we need this to have bi::auto_unlink on hooks. + + void unlink_from_lru() noexcept { _lru_link.unlink(); } struct last_dummy_tag {}; explicit rows_entry(clustering_key&& key) : _key(std::move(key)) @@ -1103,6 +1107,8 @@ public: bool is_last_dummy() const { return _flags._last_dummy; } void set_dummy(bool value) { _flags._dummy = value; } void set_dummy(is_dummy value) { _flags._dummy = bool(value); } + void replace_with(rows_entry&& other) noexcept; + void apply(row_tombstone t) { _row.apply(t); } @@ -1231,8 +1237,7 @@ struct mutation_application_stats { // in the doc in partition_version.hh. class mutation_partition final { public: - using rows_type = intrusive_set_external_comparator; - friend class rows_entry; + using rows_type = rows_entry::container_type; friend class size_calculator; private: tombstone _tombstone; diff --git a/row_cache.cc b/row_cache.cc index 0c6c2d1b8b..5da85599d1 100644 --- a/row_cache.cc +++ b/row_cache.cc @@ -156,9 +156,9 @@ void cache_tracker::clear() { } void cache_tracker::touch(rows_entry& e) { - if (e._lru_link.is_linked()) { // last dummy may not be linked if evicted. - _lru.erase(_lru.iterator_to(e)); - } + // last dummy may not be linked if evicted, but + // the unlink_from_lru() handles it + e.unlink_from_lru(); _lru.push_front(e); } @@ -176,10 +176,6 @@ void cache_tracker::on_partition_erase() noexcept { allocator().invalidate_references(); } -void cache_tracker::unlink(rows_entry& row) noexcept { - row._lru_link.unlink(); -} - void cache_tracker::on_partition_merge() noexcept { ++_stats.partition_merges; } @@ -1106,7 +1102,7 @@ void row_cache::unlink_from_lru(const dht::decorated_key& dk) { if (i != _partitions.end()) { for (partition_version& pv : i->partition().versions_from_oldest()) { for (rows_entry& row : pv.partition().clustered_rows()) { - _tracker.unlink(row); + row.unlink_from_lru(); } } } @@ -1243,7 +1239,7 @@ void rows_entry::on_evicted(cache_tracker& tracker) noexcept { // so don't remove it, just unlink from the LRU. // That dummy is linked in the LRU, because there may be partitions // with no regular rows, and we need to track them. - _lru_link.unlink(); + unlink_from_lru(); } else { ++it; it->set_continuous(false); diff --git a/row_cache.hh b/row_cache.hh index c1753fe71b..0b5c44dbb0 100644 --- a/row_cache.hh +++ b/row_cache.hh @@ -155,10 +155,7 @@ public: // Tracks accesses and performs eviction of cache entries. class cache_tracker final { public: - using lru_type = bi::list, - bi::constant_time_size>; // we need this to have bi::auto_unlink on hooks. -public: + using lru_type = rows_entry::lru_type; friend class row_cache; friend class cache::read_context; friend class cache::autoupdating_underlying_reader; @@ -216,7 +213,6 @@ public: void insert(partition_version&) noexcept; void insert(rows_entry&) noexcept; void on_remove(rows_entry&) noexcept; - void unlink(rows_entry&) noexcept; void clear_continuity(cache_entry& ce) noexcept; void on_partition_erase() noexcept; void on_partition_merge() noexcept;