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

Fix sector plotting getting stuck #3041

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading