Skip to content

Commit d009117

Browse files
authored
Only read file metadata once in LocalFileSystem::read_ranges (#595)
1 parent 1e32f96 commit d009117

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/local.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@ impl ObjectStore for LocalFileSystem {
444444
let ranges = ranges.to_vec();
445445
maybe_spawn_blocking(move || {
446446
// Vectored IO might be faster
447-
let (mut file, _) = open_file(&path)?;
447+
let (mut file, metadata) = open_file(&path)?;
448448
ranges
449449
.into_iter()
450-
.map(|r| read_range(&mut file, &path, r))
450+
.map(|r| read_range(&mut file, metadata.len(), &path, r))
451451
.collect()
452452
})
453453
.await
@@ -968,15 +968,14 @@ pub(crate) fn chunked_stream(
968968
.boxed()
969969
}
970970

971-
pub(crate) fn read_range(file: &mut File, path: &PathBuf, range: Range<u64>) -> Result<Bytes> {
972-
let file_metadata = file.metadata().map_err(|e| Error::Metadata {
973-
source: e.into(),
974-
path: path.to_string_lossy().to_string(),
975-
})?;
976-
971+
pub(crate) fn read_range(
972+
file: &mut File,
973+
file_len: u64,
974+
path: &PathBuf,
975+
range: Range<u64>,
976+
) -> Result<Bytes> {
977977
// If none of the range is satisfiable we should error, e.g. if the start offset is beyond the
978978
// extents of the file
979-
let file_len = file_metadata.len();
980979
if range.start >= file_len {
981980
return Err(Error::InvalidRange {
982981
source: InvalidGetRange::StartTooLarge {

0 commit comments

Comments
 (0)