Skip to content

Commit

Permalink
Merge #1597
Browse files Browse the repository at this point in the history
1597: fix(rebuild/partial): set bits for written blks only r=tiagolobocastro a=tiagolobocastro

The blk used to calculate the end segment was offset by 1 which can lead to rebuilding more data than the one which was actually written into. Example, if we write 1 blk to offset 4, then we only need to rebuild offset 4, and not offset 5 (4 + 1).

Co-authored-by: Tiago Castro <tiagolobocastro@gmail.com>
  • Loading branch information
mayastor-bors and tiagolobocastro committed Feb 29, 2024
2 parents 6359093 + 5489802 commit 091e7da
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion io-engine/src/core/segment_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ impl SegmentMap {
assert_ne!(self.num_blocks, 0);

let start_seg = self.lbn_to_seg(lbn);
let end_seg = self.lbn_to_seg(lbn + lbn_cnt);
// when `lbn_cnt` is 1 means we write only the `lbn` blk, not `lbn` + 1
let end_seg = self.lbn_to_seg(lbn + lbn_cnt - 1);
for i in start_seg ..= end_seg {
self.segments.set(i, value);
}
Expand Down
39 changes: 39 additions & 0 deletions io-engine/tests/nexus_rebuild_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,45 @@ async fn nexus_partial_rebuild_offline_online() {

// check that 3 segments were rebuilt.
assert_eq!(hist[0].blocks_transferred, 3 * SEG_BLK);

// Offline the replica.
nex_0
.offline_child_replica_wait(&repl_0, Duration::from_secs(1))
.await
.unwrap();

let children = nex_0.get_nexus().await.unwrap().children;
assert_eq!(children[0].state(), ChildState::Degraded);
assert_eq!(children[0].state_reason(), ChildStateReason::ByClient);

validate_replicas(&vec![repl_0.clone(), repl_1.clone()]).await;

test_write_to_nexus(
&nex_0,
DataSize::from_kb_blocks(0, 0),
3,
DataSize::from_kb(64),
)
.await
.unwrap();

// Bring the child online. That will trigger partial rebuild.
nex_0.online_child_replica(&repl_0).await.unwrap();
nex_0
.wait_children_online(std::time::Duration::from_secs(10))
.await
.unwrap();

validate_replicas(&vec![repl_0.clone(), repl_1.clone()]).await;

let hist = nex_0.get_rebuild_history().await.unwrap();
assert_eq!(hist.len(), 2);
assert_eq!(hist[1].child_uri, repl_0.shared_uri());
assert_eq!(hist[1].src_uri, repl_1.shared_uri());
assert!(hist[1].is_partial);

// check that 3 segments were rebuilt.
assert_eq!(hist[1].blocks_transferred, 3 * SEG_BLK);
}

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
Expand Down

0 comments on commit 091e7da

Please sign in to comment.