Preserve frequency hash across remove/add cycles, handle counter wrap-around

Co-authored-by: tgrabiec <283695+tgrabiec@users.noreply.github.com>
Agent-Logs-Url: https://github.com/scylladb/scylladb/sessions/c799b7fa-d908-448a-9c0c-9cd231864f31
This commit is contained in:
copilot-swe-agent[bot]
2026-03-22 23:59:19 +00:00
parent ba9122a374
commit f9f7b282fc

View File

@@ -158,7 +158,16 @@ private:
}
void assign_frequency_hash(evictable& e) noexcept {
e._frequency_hash = ++_next_hash;
// Only assign a new hash if the entry doesn't have one yet.
// Re-added entries (after remove()) keep their existing hash
// to preserve frequency tracking across remove/add cycles.
if (e._frequency_hash == 0) {
// Skip 0 on wrap-around to keep it as the "unassigned" sentinel.
if (++_next_hash == 0) {
++_next_hash;
}
e._frequency_hash = _next_hash;
}
}
void record_access(const evictable& e) noexcept {