yraivo opened a new pull request, #55815: URL: https://github.com/apache/arrow/pull/55815
### Rationale for this change `GcsRandomAccessFile::Seek(position)` immediately opens a GCS read stream with `gcs::ReadFromOffset(position)`. When seeking to the end of a non-empty object (`position == size`, e.g. `f.seek(0, os.SEEK_END)` in Python or via `fsspec` / `pyarrow.dataset` as in #44438), GCS rejects the byte range starting at EOF with `OUT_OF_RANGE` (`416 Request range not satisfiable`). Also, `closed()`, `Tell()`, `Close()`, and `Abort()` all called `InitializeStream()`, which opened a sequential read stream from offset 0 even when the caller only queried state, closed the file, or read via `ReadAt()`. ### What changes are included in this PR? * Track `offset_` and `closed_` explicitly on `GcsRandomAccessFile` so sequential read streams are only opened when `Read()` needs bytes before EOF. * Validate `Seek(position)` bounds (`0 <= position <= size`) and reset `stream_` instead of issuing an immediate range request; return `Status::Invalid` on negative or past-EOF positions without changing the current position. * Return `0` / an empty `Buffer` directly from `Read()` when `nbytes == 0` or when positioned at EOF (`offset_ == size`, including empty objects). ### Are these changes tested? Yes, added `GcsIntegrationTest.OpenInputFileSeekToEnd` and `GcsIntegrationTest.OpenInputFileEmpty` in `cpp/src/arrow/filesystem/gcsfs_test.cc` and ran `arrow-gcsfs-test` against `storage-testbench`. ### Are there any user-facing changes? Seeking to EOF (`Seek(GetSize())` / `f.seek(0, os.SEEK_END)`) on GCS input files now succeeds instead of failing with `ArrowInvalid` (`OUT_OF_RANGE`). If the object is deleted after opening, a valid seek now succeeds and the next read reports the error. ### Was AI used for this PR? In accordance to the [AI generation guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code), please disclose below whether and how AI was used in this PR. Used AI coding tools to help draft the `GcsRandomAccessFile` state changes and unit tests. I reviewed, built, and tested all changes locally against `storage-testbench`. **PR code and description written by:** - [x] Human - [x] AI **Reviewed before submission by:** - [x] Human - [x] AI - [ ] Not reviewed * GitHub Issue: Closes #38854 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
