From 9e67649fe5ba00a56a67692a449d39af2168bd3c Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Thu, 31 Oct 2024 19:38:11 +0200 Subject: [PATCH] utils: loading_cache: tighten clock sampling Sample the clock once to avoid the filter returning different results. Range algorithms may use multiple passes, so it's better to return consistent results. Closes scylladb/scylladb#21400 --- utils/loading_cache.hh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/loading_cache.hh b/utils/loading_cache.hh index e7c40b2aee..11ff2345ce 100644 --- a/utils/loading_cache.hh +++ b/utils/loading_cache.hh @@ -658,11 +658,12 @@ private: // Future is waited on indirectly in `stop()` (via `_timer_reads_gate`). // FIXME: error handling (void)with_gate(_timer_reads_gate, [this] { + auto now = loading_cache_clock_type::now(); auto to_reload = std::array({&_unprivileged_lru_list, &_lru_list}) | std::views::transform([] (auto* list_ptr) -> decltype(auto) { return *list_ptr; }) | std::views::join - | std::views::filter([this] (ts_value_lru_entry& lru_entry) { - return lru_entry.timestamped_value().loaded() + _cfg.refresh < loading_cache_clock_type::now(); + | std::views::filter([this, now] (ts_value_lru_entry& lru_entry) { + return lru_entry.timestamped_value().loaded() + _cfg.refresh < now; }) | std::views::transform([] (ts_value_lru_entry& lru_entry) { return lru_entry.timestamped_value_ptr();