Skip to content

Commit

Permalink
fix(market): clean up provider_sectors when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed May 16, 2024
1 parent a0e34d2 commit 88fda7f
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions actors/market/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ impl State {
) -> Result<(), ActorError> {
let mut provider_sectors = self.load_provider_sectors(store)?;
for (provider, sector_deal_ids) in provider_sector_deal_ids {
let mut flush = false;
let mut sector_deals = load_provider_sector_deals(store, &provider_sectors, *provider)?;
for (sector_number, deals_to_remove) in sector_deal_ids {
let existing_deal_ids = sector_deals
Expand All @@ -662,20 +663,46 @@ impl State {
// pretty fast.
// Loading into a HashSet could be an improvement for large collections of deals
// in a single sector being removed at one time.
let new_deals = existing_deal_ids
let new_deals: Vec<_> = existing_deal_ids
.iter()
.filter(|deal_id| !deals_to_remove.contains(*deal_id))
.cloned()
.collect();

sector_deals
.set(sector_number, new_deals)
flush = true;

if new_deals.is_empty() {
sector_deals.delete(sector_number).with_context_code(
ExitCode::USR_ILLEGAL_STATE,
|| {
format!(
"failed to delete sector deals for {} {}",
provider, sector_number
)
},
)?;
} else {
sector_deals.set(sector_number, new_deals).with_context_code(
ExitCode::USR_ILLEGAL_STATE,
|| {
format!(
"failed to set sector deals for {} {}",
provider, sector_number
)
},
)?;
}
}
}
if flush {
if sector_deals.is_empty() {
provider_sectors
.delete(provider)
.with_context_code(ExitCode::USR_ILLEGAL_STATE, || {
format!("failed to set sector deals for {} {}", provider, sector_number)
format!("failed to delete sector deals for {}", provider)
})?;
}
save_provider_sector_deals(&mut provider_sectors, *provider, &mut sector_deals)?;
}
save_provider_sector_deals(&mut provider_sectors, *provider, &mut sector_deals)?;
}
self.save_provider_sectors(&mut provider_sectors)?;
Ok(())
Expand Down

0 comments on commit 88fda7f

Please sign in to comment.