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

osd: fix crash caused by divide by zero in heartbeat code #21373

Merged
merged 2 commits into from Apr 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/common/options.cc
Expand Up @@ -2862,7 +2862,8 @@ std::vector<Option> get_global_options() {

Option("osd_heartbeat_interval", Option::TYPE_INT, Option::LEVEL_ADVANCED)
.set_default(6)
.set_description(""),
.set_min_max(1, 86400)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.set_description("Interval (in seconds) between peer pings"),

Option("osd_heartbeat_grace", Option::TYPE_INT, Option::LEVEL_ADVANCED)
.set_default(20)
Expand All @@ -2878,7 +2879,7 @@ std::vector<Option> get_global_options() {

Option("osd_heartbeat_min_size", Option::TYPE_INT, Option::LEVEL_ADVANCED)
.set_default(2000)
.set_description(""),
.set_description("Minimum heartbeat packet size in bytes. Will add dummy payload if heartbeat packet is smaller than this."),

Option("osd_pg_max_concurrent_snap_trims", Option::TYPE_UINT, Option::LEVEL_ADVANCED)
.set_default(2)
Expand Down
9 changes: 8 additions & 1 deletion src/osd/OSD.cc
Expand Up @@ -4690,7 +4690,14 @@ void OSD::heartbeat()

// get CPU load avg
double loadavgs[1];
int n_samples = 86400 / cct->_conf->osd_heartbeat_interval;
int hb_interval = cct->_conf->osd_heartbeat_interval;
int n_samples = 86400;
if (hb_interval > 1) {
n_samples /= hb_interval;
if (n_samples < 1)
n_samples = 1;
}

if (getloadavg(loadavgs, 1) == 1) {
logger->set(l_osd_loadavg, 100 * loadavgs[0]);
daily_loadavg = (daily_loadavg * (n_samples - 1) + loadavgs[0]) / n_samples;
Expand Down