mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-29 19:21:01 +00:00
Merge "utils: minor fixes in the loading_cache class" from Vlad
"This series aims to fix the "serving invalid (old) values" issue in the loading_cache (issue #2590) by arming the timer with a period that equals min(expire, refresh). We are still trying to optimize the main case where 'expire' is significantly longer than 'refresh' period. We don't want to add any additional logic in the fast path and this series gives the immediate solution for the issue above while not adding any additional CPU cycle to the fast path." * 'loading_cache_short_expired-v2' of https://github.com/vladzcloudius/scylla: utils::loading_cache: arm the timer with a period equal to min(_expire, _update) utils::loading_cache: make a timer use a loading_cache_clock_type clock as a source
This commit is contained in:
@@ -182,8 +182,9 @@ public:
|
||||
throw exceptions::configuration_exception("loading_cache: caching is enabled but refresh period and/or max_size are zero");
|
||||
}
|
||||
|
||||
_timer_period = std::min(_expiry, _refresh);
|
||||
_timer.set_callback([this] { on_timer(); });
|
||||
_timer.arm(_refresh);
|
||||
_timer.arm(_timer_period);
|
||||
}
|
||||
|
||||
~loading_cache() {
|
||||
@@ -364,7 +365,7 @@ private:
|
||||
return now();
|
||||
}).finally([this, timer_start_tp] {
|
||||
_logger.trace("on_timer(): rearming");
|
||||
_timer.arm(timer_start_tp + _refresh);
|
||||
_timer.arm(timer_start_tp + _timer_period);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -376,9 +377,10 @@ private:
|
||||
size_t _max_size;
|
||||
std::chrono::milliseconds _expiry;
|
||||
std::chrono::milliseconds _refresh;
|
||||
loading_cache_clock_type::duration _timer_period;
|
||||
logging::logger& _logger;
|
||||
std::function<future<Tp>(const Key&)> _load;
|
||||
timer<lowres_clock> _timer;
|
||||
timer<loading_cache_clock_type> _timer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user