Skip to content

Commit 858babd

Browse files
committed
[runtime/utils/buffer/write] skip sync if unnecessary
1 parent 7e7fcca commit 858babd

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

runtime/src/utils/buffer/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,13 @@ mod tests {
14911491
let blob = RangeSyncBlob::new();
14921492
let writer = Write::from_pooler(&context, blob.clone(), 0, NZUsize!(8));
14931493

1494+
// A fresh writer has no buffered bytes or prior plain blob mutation, so sync is a no-op.
1495+
writer.sync().await.unwrap();
1496+
let (durable, full_syncs, range_syncs) = blob.snapshot();
1497+
assert!(durable.is_empty());
1498+
assert_eq!(full_syncs, 0);
1499+
assert_eq!(range_syncs, 0);
1500+
14941501
// The write remains entirely buffered, so sync can make just this range durable.
14951502
writer.write_at(0, b"abc").await.unwrap();
14961503
writer.sync().await.unwrap();
@@ -1500,6 +1507,13 @@ mod tests {
15001507
assert_eq!(durable.as_slice(), b"abc");
15011508
assert_eq!(full_syncs, 0);
15021509
assert_eq!(range_syncs, 1);
1510+
1511+
// The prior sync used write_at_sync, so there is still no pending full-sync barrier.
1512+
writer.sync().await.unwrap();
1513+
let (durable, full_syncs, range_syncs) = blob.snapshot();
1514+
assert_eq!(durable.as_slice(), b"abc");
1515+
assert_eq!(full_syncs, 0);
1516+
assert_eq!(range_syncs, 1);
15031517
});
15041518
}
15051519

@@ -1521,6 +1535,13 @@ mod tests {
15211535
assert_eq!(full_syncs, 1);
15221536
assert_eq!(range_syncs, 0);
15231537

1538+
// With no new writes, sync has no work left.
1539+
writer.sync().await.unwrap();
1540+
let (durable, full_syncs, range_syncs) = blob.snapshot();
1541+
assert_eq!(durable.as_slice(), b"abcdefg");
1542+
assert_eq!(full_syncs, 1);
1543+
assert_eq!(range_syncs, 0);
1544+
15241545
// After the full sync, the next buffer-only write can use range sync again.
15251546
writer.write_at(7, b"h").await.unwrap();
15261547
writer.sync().await.unwrap();

runtime/src/utils/buffer/write.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ impl<B: Blob> Write<B> {
240240
state.needs_sync = false;
241241
return Ok(());
242242
}
243+
244+
if !state.needs_sync {
245+
return Ok(());
246+
}
247+
243248
self.blob.sync().await?;
244249
state.needs_sync = false;
245250
Ok(())

0 commit comments

Comments
 (0)