Skip to content

Commit

Permalink
Merge pull request #3042 from autonomys/fix-sector-plotting-getting-s…
Browse files Browse the repository at this point in the history
…tuck-backport

Backport: Fix sector plotting getting stuck
  • Loading branch information
nazar-pc authored Sep 20, 2024
2 parents aab8de5 + c39a6f3 commit 84ea07b
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions crates/subspace-farmer/src/single_disk_farm/plotting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ where
process_plotting_result(
maybe_sector_plotting_result?,
&mut metadata_header,
sectors_metadata,
sectors_being_modified,
Arc::clone(&sector_plotting_options.metadata_file)
).await?;
}
Expand All @@ -188,8 +186,6 @@ where
process_plotting_result(
maybe_sector_plotting_result?,
&mut metadata_header,
sectors_metadata,
sectors_being_modified,
Arc::clone(&sector_plotting_options.metadata_file)
).await?;
}
Expand All @@ -202,31 +198,15 @@ where
async fn process_plotting_result(
sector_plotting_result: SectorPlottingResult,
metadata_header: &mut PlotMetadataHeader,
sectors_metadata: &AsyncRwLock<Vec<SectorMetadataChecksummed>>,
sectors_being_modified: &AsyncRwLock<HashSet<SectorIndex>>,
#[cfg(not(windows))] metadata_file: Arc<File>,
#[cfg(windows)] metadata_file: Arc<UnbufferedIoFileWindows>,
) -> Result<(), PlottingError> {
let SectorPlottingResult {
sector_index,
sector_metadata,
replotting,
last_queued,
} = sector_plotting_result;

{
let mut sectors_metadata = sectors_metadata.write().await;
// If exists then we're replotting, otherwise we create sector for the first time
if let Some(existing_sector_metadata) = sectors_metadata.get_mut(sector_index as usize) {
*existing_sector_metadata = sector_metadata;
} else {
sectors_metadata.push(sector_metadata);
}
}

// Inform others that this sector is no longer being modified
sectors_being_modified.write().await.remove(&sector_index);

if sector_index + 1 > metadata_header.plotted_sector_count {
metadata_header.plotted_sector_count = sector_index + 1;

Expand Down Expand Up @@ -270,7 +250,6 @@ enum PlotSingleSectorResult<F> {

struct SectorPlottingResult {
sector_index: SectorIndex,
sector_metadata: SectorMetadataChecksummed,
replotting: bool,
last_queued: bool,
}
Expand Down Expand Up @@ -486,9 +465,22 @@ where
.sector_update
.call_simple(&(sector_index, sector_state));

{
let mut sectors_metadata = sectors_metadata.write().await;
// If exists then we're replotting, otherwise we create sector for the first time
if let Some(existing_sector_metadata) = sectors_metadata.get_mut(sector_index as usize)
{
*existing_sector_metadata = sector_metadata;
} else {
sectors_metadata.push(sector_metadata);
}
}

// Inform others that this sector is no longer being modified
sectors_being_modified.write().await.remove(&sector_index);

Ok(SectorPlottingResult {
sector_index,
sector_metadata,
replotting,
last_queued,
})
Expand Down

0 comments on commit 84ea07b

Please sign in to comment.