Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure that a new offset file ends with the zero data file length #8770

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions crates/storage/nippy-jar/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,19 @@ impl<H: NippyJarHeader> NippyJarWriter<H> {
}

let mut offsets_file = OpenOptions::new().read(true).write(true).open(offsets)?;
if is_created {
let mut buf = Vec::with_capacity(1 + OFFSET_SIZE_BYTES as usize);

// First byte of the offset file is the size of one offset in bytes
offsets_file.write_all(&[OFFSET_SIZE_BYTES])?;
offsets_file.seek(SeekFrom::End(0))?;
// First byte of the offset file is the size of one offset in bytes
buf.write_all(&[OFFSET_SIZE_BYTES])?;

// The last offset should always represent the data file len, which is 0 on
// creation.
buf.write_all(&[0; OFFSET_SIZE_BYTES as usize])?;

offsets_file.write_all(&buf)?;
offsets_file.seek(SeekFrom::End(0))?;
}

Ok((data_file, offsets_file, is_created))
}
Expand Down
Loading