Skip to content

Commit

Permalink
fix(storage): fix sstable info stripped (#17822)
Browse files Browse the repository at this point in the history
  • Loading branch information
Li0k authored Jul 26, 2024
1 parent 321e8c0 commit 4b40658
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/storage/hummock_sdk/src/key_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ impl KeyRange {
fn end_bound_inf(&self) -> bool {
self.right.is_empty()
}

#[inline]
pub fn inf_key_range(&self) -> bool {
self.start_bound_inf() && self.end_bound_inf()
}
}

pub trait KeyRangeCommon {
Expand Down
62 changes: 40 additions & 22 deletions src/storage/hummock_sdk/src/sstable_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ impl From<PbSstableInfo> for SstableInfo {
object_id: pb_sstable_info.object_id,
sst_id: pb_sstable_info.sst_id,
key_range: {
let pb_keyrange = pb_sstable_info.key_range.unwrap();
KeyRange {
left: pb_keyrange.left.into(),
right: pb_keyrange.right.into(),
right_exclusive: pb_keyrange.right_exclusive,
// Due to the stripped key range, the key range may be `None`
if let Some(pb_keyrange) = pb_sstable_info.key_range {
KeyRange {
left: pb_keyrange.left.into(),
right: pb_keyrange.right.into(),
right_exclusive: pb_keyrange.right_exclusive,
}
} else {
KeyRange::inf()
}
},
file_size: pb_sstable_info.file_size,
Expand All @@ -93,11 +97,14 @@ impl From<&PbSstableInfo> for SstableInfo {
object_id: pb_sstable_info.object_id,
sst_id: pb_sstable_info.sst_id,
key_range: {
let pb_keyrange = pb_sstable_info.key_range.as_ref().unwrap();
KeyRange {
left: pb_keyrange.left.clone().into(),
right: pb_keyrange.right.clone().into(),
right_exclusive: pb_keyrange.right_exclusive,
if let Some(pb_keyrange) = &pb_sstable_info.key_range {
KeyRange {
left: pb_keyrange.left.clone().into(),
right: pb_keyrange.right.clone().into(),
right_exclusive: pb_keyrange.right_exclusive,
}
} else {
KeyRange::inf()
}
},
file_size: pb_sstable_info.file_size,
Expand All @@ -122,12 +129,19 @@ impl From<SstableInfo> for PbSstableInfo {
sst_id: sstable_info.sst_id,
key_range: {
let keyrange = sstable_info.key_range;
let pb_key_range = PbKeyRange {
left: keyrange.left.into(),
right: keyrange.right.into(),
right_exclusive: keyrange.right_exclusive,
};
Some(pb_key_range)
if keyrange.inf_key_range() {
// For empty key range, we don't need to encode it
// Timetravel will use the default key range to stripped the PbSstableInfo
// Note: If new fields are added, using Default to implement stripped may not work, resulting in an increase in encode size.
None
} else {
let pb_key_range = PbKeyRange {
left: keyrange.left.into(),
right: keyrange.right.into(),
right_exclusive: keyrange.right_exclusive,
};
Some(pb_key_range)
}
},

file_size: sstable_info.file_size,
Expand All @@ -151,12 +165,16 @@ impl From<&SstableInfo> for PbSstableInfo {
sst_id: sstable_info.sst_id,
key_range: {
let keyrange = &sstable_info.key_range;
let pb_key_range = PbKeyRange {
left: keyrange.left.to_vec(),
right: keyrange.right.to_vec(),
right_exclusive: keyrange.right_exclusive,
};
Some(pb_key_range)
if keyrange.inf_key_range() {
None
} else {
let pb_key_range = PbKeyRange {
left: keyrange.left.to_vec(),
right: keyrange.right.to_vec(),
right_exclusive: keyrange.right_exclusive,
};
Some(pb_key_range)
}
},

file_size: sstable_info.file_size,
Expand Down

0 comments on commit 4b40658

Please sign in to comment.