Skip to content

Commit

Permalink
Fix accidental deadlock in metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Feb 19, 2024
1 parent df8ba53 commit ccd2067
Showing 1 changed file with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,31 +298,37 @@ impl FarmerMetrics {
// Never called, doesn't make sense
}
SectorState::Plotted => {
let not_plotted_sectors = self.sectors_total.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("state".to_string(), SectorState::NotPlotted.to_string()),
]);
if not_plotted_sectors.get() > 0 {
// Initial plotting
not_plotted_sectors.dec();
} else {
// Separate blocks in because of mutex guard returned by `get_or_create` resulting
// in deadlock otherwise
{
let not_plotted_sectors = self.sectors_total.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("state".to_string(), SectorState::NotPlotted.to_string()),
]);
if not_plotted_sectors.get() > 0 {
// Initial plotting
not_plotted_sectors.dec();
return;
}
}
{
let expired_sectors = self.sectors_total.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("state".to_string(), SectorState::Expired.to_string()),
]);
if expired_sectors.get() > 0 {
// Replaced expired sector
expired_sectors.dec();
} else {
// Replaced about to expire sector
self.sectors_total
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("state".to_string(), SectorState::AboutToExpire.to_string()),
])
.dec();
return;
}
}
// Replaced about to expire sector
self.sectors_total
.get_or_create(&vec![
("farm_id".to_string(), single_disk_farm_id.to_string()),
("state".to_string(), SectorState::AboutToExpire.to_string()),
])
.dec();
}
SectorState::AboutToExpire | SectorState::Expired => {
self.sectors_total
Expand Down

0 comments on commit ccd2067

Please sign in to comment.