Merge "Unfriend rows_entry, cache_tracker and mutation_partition" from Pavel Emelyanov
The classes touche private data of each other for no real reason. Putting the interaction behind API makes it easier to track the usage. * xemul/br-unfriends-in-row-cache-2: row cache: Unfriend classes from each other rows_entry: Move container/hooks types declarations rows_entry: Simplify LRU unlink mutation_partition: Define .replace_with method for rows_entry mutation_partition: Use rows_entry::apply_monotonically
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1025,7 +1025,6 @@ class cache_tracker;
|
||||
|
||||
class rows_entry {
|
||||
using lru_link_type = bi::list_member_hook<bi::link_mode<bi::auto_unlink>>;
|
||||
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<rows_entry, &rows_entry::_link>;
|
||||
using lru_type = bi::list<rows_entry,
|
||||
bi::member_hook<rows_entry, rows_entry::lru_link_type, &rows_entry::_lru_link>,
|
||||
bi::constant_time_size<false>>; // 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<rows_entry, &rows_entry::_link>;
|
||||
friend class rows_entry;
|
||||
using rows_type = rows_entry::container_type;
|
||||
friend class size_calculator;
|
||||
private:
|
||||
tombstone _tombstone;
|
||||
|
||||
14
row_cache.cc
14
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);
|
||||
|
||||
@@ -155,10 +155,7 @@ public:
|
||||
// Tracks accesses and performs eviction of cache entries.
|
||||
class cache_tracker final {
|
||||
public:
|
||||
using lru_type = bi::list<rows_entry,
|
||||
bi::member_hook<rows_entry, rows_entry::lru_link_type, &rows_entry::_lru_link>,
|
||||
bi::constant_time_size<false>>; // 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;
|
||||
|
||||
Reference in New Issue
Block a user