Skip to content

Commit

Permalink
fix(agent/core): rebuild space required
Browse files Browse the repository at this point in the history
If a replica is thick then no rebuild space is required..
Ensure we don't overflow if allocated_bytes are larger than
minimum required bytes (although this probably won't happen
now that we short-circuit thick replicas..)

Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Mar 28, 2024
1 parent 69bb8a4 commit 7d196d5
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ pub(crate) fn replica_rebuildable(
/// Calculates the number of bytes required to rebuild this replica up to the given minimum.
/// # Warning: valid only if the current blocks are exactly the same as the healthy replicas.
pub(crate) fn rebuild_space_required(min_allocated_bytes: u64, replica: &Replica) -> u64 {
if !replica.thin {
return 0;
}

let repl_allocated_bytes = replica
.space
.as_ref()
Expand All @@ -194,7 +198,7 @@ pub(crate) fn rebuild_space_required(min_allocated_bytes: u64, replica: &Replica

// we've already allocated some bytes, so take those into account
// did you read the warning above?
let bytes_needed = min_allocated_bytes - repl_allocated_bytes;
let bytes_needed = min_allocated_bytes - repl_allocated_bytes.min(min_allocated_bytes);

// We need sufficient free space for at least the current allocation of other replicas, but
// just this capacity may not be enough as applications may carry on issuing new writes.
Expand Down

0 comments on commit 7d196d5

Please sign in to comment.