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

Stop zeroing buffers in the local file storage. #4712

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion quickwit/quickwit-storage/src/file_descriptor_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ impl SplitFile {
use std::os::unix::fs::FileExt;
let file = self.clone();
let buf = tokio::task::spawn_blocking(move || {
let mut buf = vec![0u8; range.len()];
let mut buf = Vec::with_capacity(range.len());
#[allow(clippy::uninit_vec)]
unsafe {
buf.set_len(range.len());
}
file.0.file.read_exact_at(&mut buf, range.start as u64)?;
io::Result::Ok(buf)
})
Expand Down
7 changes: 5 additions & 2 deletions quickwit/quickwit-storage/src/local_file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,15 @@ impl Storage for LocalFileStorage {
let full_path = self.full_path(path)?;
tokio::task::spawn_blocking(move || {
use std::io::{Read, Seek};

// we run these io in a spawn_blocking so there is no scheduling delay between each
// step, as there would be if using tokio async File.
let mut file = std::fs::File::open(full_path)?;
file.seek(SeekFrom::Start(range.start as u64))?;
let mut content_bytes: Vec<u8> = vec![0u8; range.len()];
let mut content_bytes: Vec<u8> = Vec::with_capacity(range.len());
#[allow(clippy::uninit_vec)]
unsafe {
content_bytes.set_len(range.len());
}
file.read_exact(&mut content_bytes)?;
Ok(OwnedBytes::new(content_bytes))
})
Expand Down
Loading