Skip to content

Commit

Permalink
fix: bad read by wrong data region
Browse files Browse the repository at this point in the history
    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: 泰友 <cuichengxu.ccx@antgroup.com>
  • Loading branch information
泰友 authored and imeoer committed Jun 18, 2024
1 parent 64dddd2 commit 7cf2d4a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions storage/src/cache/cachedfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,20 @@ impl FileIoMergeState {
tag: BlobIoTag,
chunk: Option<Arc<dyn BlobChunkInfo>>,
) -> Result<()> {
// Make sure user io of same region continuous
if !self.regions.is_empty() && self.joinable(region_type) {
let region = &self.regions[self.regions.len() - 1];
if !region.seg.is_empty() && tag.is_user_io() {
if let BlobIoTag::User(ref seg) = tag {
if seg.offset as u64 + start
!= region.blob_address + region.seg.offset as u64 + region.seg.len as u64
{
self.commit();
}
}
}
}

if self.regions.is_empty() || !self.joinable(region_type) {
self.regions.push(Region::new(region_type));
self.last_region_joinable = true;
Expand Down Expand Up @@ -1793,7 +1807,7 @@ mod tests {

let tag = BlobIoTag::User(BlobIoSegment {
offset: 0x1800,
len: 0x1800,
len: 0x800,
});
state
.push(RegionType::CacheFast, 0x1000, 0x2000, tag, None)
Expand All @@ -1810,8 +1824,8 @@ mod tests {
assert_eq!(state.regions.len(), 1);

let tag = BlobIoTag::User(BlobIoSegment {
offset: 0x0000,
len: 0x2000,
offset: 0x0001,
len: 0x1fff,
});
state
.push(RegionType::CacheSlow, 0x5000, 0x2000, tag, None)
Expand Down

0 comments on commit 7cf2d4a

Please sign in to comment.