Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hotkey): collector can be terminated by timeout #625

Merged
merged 15 commits into from
Oct 22, 2020
21 changes: 10 additions & 11 deletions src/server/hotkey_collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ void hotkey_collector::analyse_data()
{
switch (_state.load()) {
case hotkey_collector_state::COARSE_DETECTING:
terminate_if_timeout();
_internal_collector->analyse_data();
if (terminate_if_timeout()) {
_internal_collector->analyse_data();
}
return;
default:
return;
Expand All @@ -100,9 +101,9 @@ void hotkey_collector::on_start_detect(dsn::replication::detect_hotkey_response
return;
case hotkey_collector_state::FINISHED:
resp.err = dsn::ERR_INVALID_STATE;
hint = fmt::format("{} hotkey result has been found, you can send a stop rpc to "
"restart hotkey detection",
dsn::enum_to_string(_hotkey_type));
hint = fmt::format(
"{} hotkey result has been found, you can send a stop rpc to restart hotkey detection",
dsn::enum_to_string(_hotkey_type));
dwarn_replica(hint);
return;
case hotkey_collector_state::STOPPED:
Expand Down Expand Up @@ -138,17 +139,15 @@ void hotkey_collector::terminate()
_collector_start_time = 0;
}

void hotkey_collector::terminate_if_timeout()
bool hotkey_collector::terminate_if_timeout()
{
if (_collector_start_time == 0) {
return;
}
if (dsn_now_s() >= _collector_start_time + FLAGS_max_seconds_to_detect_hotkey) {
ddebug_replica("hotkey collector work time is exhausted but no hotkey has been found");
terminate();
return;
return false;
}
};
return true;
Smityz marked this conversation as resolved.
Show resolved Hide resolved
}

} // namespace server
} // namespace pegasus
2 changes: 1 addition & 1 deletion src/server/hotkey_collector.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class hotkey_collector : public dsn::replication::replica_base
void on_start_detect(dsn::replication::detect_hotkey_response &resp);
void on_stop_detect(dsn::replication::detect_hotkey_response &resp);
void terminate();
void terminate_if_timeout();
bool terminate_if_timeout();

std::atomic<hotkey_collector_state> _state;
const dsn::replication::hotkey_type::type _hotkey_type;
Expand Down