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
泰友 committed Mar 27, 2024
1 parent de6d183 commit 5fb77f2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions storage/src/cache/cachedfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,23 @@ 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 {
println!("fucking {:x} {:x}", seg.offset as u64 + start, region.blob_address + region.seg.offset as u64 + region.seg.len as u64);
// Usually seg.offset = 0, for semantic integrity here.
if seg.offset as u64 + start
!= region.blob_address + region.seg.offset as u64 + region.seg.len as u64
{
// Stop append for non-continuous user io segment.
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 @@ -1564,7 +1581,7 @@ mod tests {

let tag = BlobIoTag::User(BlobIoSegment {
offset: 0x1800,
len: 0x1800,
len: 0x800,
});
state
.push(RegionType::CacheFast, 0x1000, 0x2000, tag, None)
Expand All @@ -1581,8 +1598,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 5fb77f2

Please sign in to comment.