Skip to content

Commit

Permalink
Prevent piece from being stored in caches of multiple farms at the sa…
Browse files Browse the repository at this point in the history
…me time
  • Loading branch information
nazar-pc committed Nov 19, 2023
1 parent 36f334e commit 6b1a665
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions crates/subspace-farmer/src/piece_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,34 @@ where
};

// Find plot in which there is a place for new piece to be stored
for (disk_farm_index, cache) in caches.iter_mut().enumerate() {
let Some(offset) = cache.free_offsets.pop() else {
continue;
};
if !caches
.iter_mut()
.enumerate()
.any(|(disk_farm_index, cache)| {
let Some(offset) = cache.free_offsets.pop() else {
return false;
};

if let Err(error) = cache.backend.write_piece(offset, piece_index, &piece) {
error!(
%error,
%disk_farm_index,
%piece_index,
%offset,
"Failed to write piece into cache"
);
continue;
}
cache
.stored_pieces
.insert(RecordKey::from(piece_index.to_multihash()), offset);
if let Err(error) = cache.backend.write_piece(offset, piece_index, &piece) {
error!(
%error,
%disk_farm_index,
%piece_index,
%offset,
"Failed to write piece into cache"
);
return false;
}
cache
.stored_pieces
.insert(RecordKey::from(piece_index.to_multihash()), offset);
true
})
{
error!(
%piece_index,
"Failed to store piece in cache, there was no space"
);
}

downloaded_pieces_count += 1;
Expand Down

0 comments on commit 6b1a665

Please sign in to comment.