Skip to content

Commit aa0236d

Browse files
author
泰友
committed
fix: bad read by wrong data region
User io may involve discontinuous segments in different chunks. Bad read is produced by merging them into continuous one. That is what Region does. This pr separate discontinuous segments into different regions, avoiding merging forcibly. Signed-off-by: 泰友 <[email protected]>
1 parent 8df5d7f commit aa0236d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

storage/src/cache/cachedfile.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,20 @@ impl FileIoMergeState {
16621662
tag: BlobIoTag,
16631663
chunk: Option<Arc<dyn BlobChunkInfo>>,
16641664
) -> Result<()> {
1665+
// Make sure user io of same region continuous
1666+
if !self.regions.is_empty() && self.joinable(region_type) {
1667+
let region = &self.regions[self.regions.len() - 1];
1668+
if !region.seg.is_empty() && tag.is_user_io() {
1669+
if let BlobIoTag::User(ref seg) = tag {
1670+
if seg.offset as u64 + start
1671+
!= region.blob_address + region.seg.offset as u64 + region.seg.len as u64
1672+
{
1673+
self.commit();
1674+
}
1675+
}
1676+
}
1677+
}
1678+
16651679
if self.regions.is_empty() || !self.joinable(region_type) {
16661680
self.regions.push(Region::new(region_type));
16671681
self.last_region_joinable = true;
@@ -1793,7 +1807,7 @@ mod tests {
17931807

17941808
let tag = BlobIoTag::User(BlobIoSegment {
17951809
offset: 0x1800,
1796-
len: 0x1800,
1810+
len: 0x800,
17971811
});
17981812
state
17991813
.push(RegionType::CacheFast, 0x1000, 0x2000, tag, None)
@@ -1810,8 +1824,8 @@ mod tests {
18101824
assert_eq!(state.regions.len(), 1);
18111825

18121826
let tag = BlobIoTag::User(BlobIoSegment {
1813-
offset: 0x0000,
1814-
len: 0x2000,
1827+
offset: 0x0001,
1828+
len: 0x1fff,
18151829
});
18161830
state
18171831
.push(RegionType::CacheSlow, 0x5000, 0x2000, tag, None)

0 commit comments

Comments
 (0)