This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs-object-store.git
The following commit(s) were added to refs/heads/main by this push:
new d009117 Only read file metadata once in
`LocalFileSystem::read_ranges` (#595)
d009117 is described below
commit d00911715c9faffd97b036740372b6b91d7b018e
Author: Adam Gutglick <[email protected]>
AuthorDate: Thu Jan 8 21:51:39 2026 +0000
Only read file metadata once in `LocalFileSystem::read_ranges` (#595)
---
src/local.rs | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/local.rs b/src/local.rs
index 8f18aa6..961ed12 100644
--- a/src/local.rs
+++ b/src/local.rs
@@ -444,10 +444,10 @@ impl ObjectStore for LocalFileSystem {
let ranges = ranges.to_vec();
maybe_spawn_blocking(move || {
// Vectored IO might be faster
- let (mut file, _) = open_file(&path)?;
+ let (mut file, metadata) = open_file(&path)?;
ranges
.into_iter()
- .map(|r| read_range(&mut file, &path, r))
+ .map(|r| read_range(&mut file, metadata.len(), &path, r))
.collect()
})
.await
@@ -968,15 +968,14 @@ pub(crate) fn chunked_stream(
.boxed()
}
-pub(crate) fn read_range(file: &mut File, path: &PathBuf, range: Range<u64>)
-> Result<Bytes> {
- let file_metadata = file.metadata().map_err(|e| Error::Metadata {
- source: e.into(),
- path: path.to_string_lossy().to_string(),
- })?;
-
+pub(crate) fn read_range(
+ file: &mut File,
+ file_len: u64,
+ path: &PathBuf,
+ range: Range<u64>,
+) -> Result<Bytes> {
// If none of the range is satisfiable we should error, e.g. if the start
offset is beyond the
// extents of the file
- let file_len = file_metadata.len();
if range.start >= file_len {
return Err(Error::InvalidRange {
source: InvalidGetRange::StartTooLarge {