Skip to content

Commit

Permalink
fix: move sst meta offset to the end of the object (risingwavelabs#8524)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzxa21 authored Mar 14, 2023
1 parent d49a4c5 commit 0c53349
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/storage/src/hummock/sstable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl SstableMeta {
/// | smallest key len (4B) | smallest key |
/// | largest key len (4B) | largest key |
/// | range-tombstone 0 | ... | range-tombstone M-1 |
/// | file offset of this meta block (8B) |
/// | checksum (8B) | version (4B) | magic (4B) |
/// ```
pub fn encode_to_bytes(&self) -> Vec<u8> {
Expand All @@ -299,11 +300,11 @@ impl SstableMeta {
buf.put_u32_le(self.key_count);
put_length_prefixed_slice(buf, &self.smallest_key);
put_length_prefixed_slice(buf, &self.largest_key);
buf.put_u64_le(self.meta_offset);
buf.put_u32_le(self.range_tombstone_list.len() as u32);
for tombstone in &self.range_tombstone_list {
tombstone.encode(buf);
}
buf.put_u64_le(self.meta_offset);
let checksum = xxhash64_checksum(&buf[start_offset..]);
buf.put_u64_le(checksum);
buf.put_u32_le(VERSION);
Expand Down Expand Up @@ -340,13 +341,13 @@ impl SstableMeta {
let key_count = buf.get_u32_le();
let smallest_key = get_length_prefixed_slice(buf);
let largest_key = get_length_prefixed_slice(buf);
let meta_offset = buf.get_u64_le();
let range_del_count = buf.get_u32_le() as usize;
let mut range_tombstone_list = Vec::with_capacity(range_del_count);
for _ in 0..range_del_count {
let tombstone = DeleteRangeTombstone::decode(buf);
range_tombstone_list.push(tombstone);
}
let meta_offset = buf.get_u64_le();

Ok(Self {
block_metas,
Expand Down

0 comments on commit 0c53349

Please sign in to comment.