This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch release/0.12
in repository https://gitbox.apache.org/repos/asf/arrow-rs-object-store.git
The following commit(s) were added to refs/heads/release/0.12 by this push:
new 21ea104 [release/0.12] Backport #595 - only read file metadata once
in `LocalFileSystem::get_ranges` (#596)
21ea104 is described below
commit 21ea104bcf97278a0fc90e7c7c1ab352437a163d
Author: Adam Gutglick <[email protected]>
AuthorDate: Thu Jan 8 21:51:51 2026 +0000
[release/0.12] Backport #595 - only read file metadata once in
`LocalFileSystem::get_ranges` (#596)
Co-authored-by: Andrew Lamb <[email protected]>
---
src/local.rs | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/local.rs b/src/local.rs
index 3404bc8..e67206d 100644
--- a/src/local.rs
+++ b/src/local.rs
@@ -428,8 +428,8 @@ impl ObjectStore for LocalFileSystem {
async fn get_range(&self, location: &Path, range: Range<u64>) ->
Result<Bytes> {
let path = self.path_to_filesystem(location)?;
maybe_spawn_blocking(move || {
- let (mut file, _) = open_file(&path)?;
- read_range(&mut file, &path, range)
+ let (mut file, metadata) = open_file(&path)?;
+ read_range(&mut file, metadata.len(), &path, range)
})
.await
}
@@ -439,10 +439,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
@@ -899,15 +899,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 {