Skip to content

GH-38854: [C++] Allow seeking to EOF in GcsRandomAccessFile - #55815

Open
yraivo wants to merge 1 commit into
apache:mainfrom
yraivo:gh-38854-gcsfs-seek-eof
Open

yraivo wants to merge 1 commit into
apache:mainfrom
yraivo:gh-38854-gcsfs-seek-eof

Conversation

@yraivo

@yraivo yraivo commented Nov 27, 2026

Copy link
Copy Markdown

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, 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:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Seeking EOF of GCS File fails via Python

1 participant