cache_hitrate_calculator: wait for ongoing calculation to complete during stop

Currently stop returns ready future immediately. This is not a problem
since calculation loop holds a shared pointer to the local service, so
it will not be destroyed until calculation completes and global database
object db, that also used by the calculation, is never destroyed. But the
later is just a workaround for a shutdown sequence that cannot handle
it and will be changed one day. Make cache hitrate calculation service
ready for it.

Message-Id: <20190422113538.GR21208@scylladb.com>
This commit is contained in:
Gleb Natapov
2019-04-22 14:35:38 +03:00
committed by Avi Kivity
parent 64c2aa8f9b
commit c6b3b9ff13
2 changed files with 3 additions and 2 deletions

View File

@@ -35,6 +35,7 @@ class cache_hitrate_calculator : public seastar::async_sharded_service<cache_hit
timer<lowres_clock> _timer;
bool _stopped = false;
float _diff = 0;
future<> _done = make_ready_future();
future<lowres_clock::duration> recalculate_hitrates();
void recalculate_timer();

View File

@@ -93,7 +93,7 @@ cache_hitrate_calculator::cache_hitrate_calculator(seastar::sharded<database>& d
{}
void cache_hitrate_calculator::recalculate_timer() {
recalculate_hitrates().then_wrapped([p = shared_from_this()] (future<lowres_clock::duration> f) {
_done = recalculate_hitrates().then_wrapped([p = shared_from_this()] (future<lowres_clock::duration> f) {
lowres_clock::duration d;
if (f.failed()) {
d = std::chrono::milliseconds(2000);
@@ -184,7 +184,7 @@ future<lowres_clock::duration> cache_hitrate_calculator::recalculate_hitrates()
future<> cache_hitrate_calculator::stop() {
_timer.cancel();
_stopped = true;
return make_ready_future<>();
return std::move(_done);
}