Skip to content

Commit

Permalink
Merge pull request #3160 from autonomys/avoid-replotting-the-same-sector
Browse files Browse the repository at this point in the history
Avoid replotting the same sector more than once
  • Loading branch information
nazar-pc authored Oct 22, 2024
2 parents 4555261 + a1f796a commit 2f46ae7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/subspace-farmer/src/single_disk_farm/plotting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ where
} = sector_to_plot;
trace!("Preparing to plot sector");

// Inform others that this sector is being modified
{
let mut sectors_being_modified = sectors_being_modified.write().await;
if !sectors_being_modified.insert(sector_index) {
debug!("Skipped sector plotting, it is already in progress");
return PlotSingleSectorResult::Skipped;
}
}

let maybe_old_sector_metadata = sectors_metadata
.read()
.await
Expand Down Expand Up @@ -384,7 +393,6 @@ where
plot_file,
metadata_file,
handlers,
sectors_being_modified,
global_mutex,
progress_receiver,
metrics,
Expand Down Expand Up @@ -492,7 +500,6 @@ async fn plot_single_sector_internal(
plot_file: &Arc<DirectIoFile>,
metadata_file: &Arc<DirectIoFile>,
handlers: &Handlers,
sectors_being_modified: &AsyncRwLock<HashSet<SectorIndex>>,
global_mutex: &AsyncMutex<()>,
mut progress_receiver: mpsc::Receiver<SectorPlottingProgress>,
metrics: &Option<Arc<SingleDiskFarmMetrics>>,
Expand Down Expand Up @@ -569,9 +576,6 @@ async fn plot_single_sector_internal(
}
};

// Inform others that this sector is being modified
sectors_being_modified.write().await.insert(sector_index);

{
// Take mutex briefly to make sure writing is allowed right now
global_mutex.lock().await;
Expand Down

0 comments on commit 2f46ae7

Please sign in to comment.