Skip to content

Commit

Permalink
fix(metrics): only remove metrics when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
iwanbk committed Nov 18, 2024
1 parent c5f1fba commit 5354d33
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions zstor/src/actors/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,13 @@ impl Handler<SetDataBackendInfo> for MetricsActor {
if let Some(info) = msg.info {
self.data_zdbs.insert(msg.ci, info);
} else {
self.data_zdbs.remove(&msg.ci);
self.removed_zdbs.push((msg.ci, BackendType::Data));
let v = self.data_zdbs.remove(&msg.ci);
// when the zdb is down, backend actors always send a None info
// in this case we should remove the zdb from the metrics *only* if it was present.
// Otherwise we will do unnecessary work and the `removed_zdbs` list will exploded
if v.is_some() {
self.removed_zdbs.push((msg.ci, BackendType::Data));
}
}
}
}
Expand All @@ -322,8 +327,13 @@ impl Handler<SetMetaBackendInfo> for MetricsActor {
if let Some(info) = msg.info {
self.meta_zdbs.insert(msg.ci, info);
} else {
self.meta_zdbs.remove(&msg.ci);
self.removed_zdbs.push((msg.ci, BackendType::Meta));
let v = self.meta_zdbs.remove(&msg.ci);
// when the zdb is down, backend actors always send a None info
// in this case we should remove the zdb from the metrics *only* if it was present.
// Otherwise we will do unnecessary work and the `removed_zdbs` list will exploded
if v.is_some() {
self.removed_zdbs.push((msg.ci, BackendType::Meta));
}
}
}
}
Expand Down

0 comments on commit 5354d33

Please sign in to comment.