Skip to content

Commit

Permalink
Merge pull request #3140 from autonomys/fix-storing-in-memory-sector-…
Browse files Browse the repository at this point in the history
…metadata

Make sure sector metadata is stored in memory in the correct order during initial plotting
  • Loading branch information
nazar-pc authored Oct 17, 2024
2 parents 8692ee2 + f7c24da commit 11d1762
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions crates/subspace-farmer/src/single_disk_farm/plotting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ where
maybe_sector_plotting_result = maybe_wait_futures_ordered(&mut sectors_being_plotted).fuse() => {
process_plotting_result(
maybe_sector_plotting_result?,
sectors_metadata,
sectors_being_modified,
&mut metadata_header,
Arc::clone(&sector_plotting_options.metadata_file)
).await?;
Expand All @@ -175,6 +177,8 @@ where
maybe_sector_plotting_result = maybe_wait_futures_ordered(&mut sectors_being_plotted).fuse() => {
process_plotting_result(
maybe_sector_plotting_result?,
sectors_metadata,
sectors_being_modified,
&mut metadata_header,
Arc::clone(&sector_plotting_options.metadata_file)
).await?;
Expand All @@ -187,15 +191,32 @@ where

async fn process_plotting_result(
sector_plotting_result: SectorPlottingResult,
sectors_metadata: &AsyncRwLock<Vec<SectorMetadataChecksummed>>,
sectors_being_modified: &AsyncRwLock<HashSet<SectorIndex>>,
metadata_header: &mut PlotMetadataHeader,
metadata_file: Arc<DirectIoFile>,
) -> Result<(), PlottingError> {
let SectorPlottingResult {
sector_index,
sector_metadata,
replotting,
last_queued,
} = sector_plotting_result;

let sector_index = sector_metadata.sector_index;

{
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 @@ -238,7 +259,7 @@ enum PlotSingleSectorResult<F> {
}

struct SectorPlottingResult {
sector_index: SectorIndex,
sector_metadata: SectorMetadataChecksummed,
replotting: bool,
last_queued: bool,
}
Expand Down Expand Up @@ -454,22 +475,8 @@ 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 11d1762

Please sign in to comment.