Skip to content

GH-32438: [C++] Create target file when OpenAppendStream targets a nonexistent path - #51321

Open
mohammadnaqvi04 wants to merge 1 commit into
apache:mainfrom
mohammadnaqvi04:hdfs-append-nonexistent-file
Open

mohammadnaqvi04 wants to merge 1 commit into
apache:mainfrom
mohammadnaqvi04:hdfs-append-nonexistent-file

Conversation

@mohammadnaqvi04

Copy link
Copy Markdown

Rationale for this change

FileSystem::OpenAppendStream is documented to create the target file if it doesn't already exist. On HDFS this instead raises a not-found error. HadoopFileSystemImpl::OpenWritable always opens in append mode when asked to append, but Hadoop's FileSystem.append() requires the file to already exist, unlike a local append-mode open. See #32438.

What changes are included in this PR?

  • OpenWritable now only sets append mode when the target already exists; otherwise it falls back to a plain create, matching every other backend. Adds an existence check against the NameNode before an append-mode open, since that's the only way to know which mode to request.
  • Removed TestHadoopFileSystemGeneric::allow_append_to_new_file's override to false, seemingly added when HDFS was first wired into the shared filesystem test suite. HDFS now runs the same append-to-new-file check as every other backend.

Are these changes tested?

Yes. With the override removed, TestHadoopFileSystemGeneric.OpenAppendStream fails on the unpatched code with the same not-found error from the issue, and passes with this change, run against the Docker-based HDFS test setup (ci/scripts/integration_hdfs.sh). The rest of the HDFS C++ suite and pyarrow.tests.test_fs pass with no regressions.

Unrelated to this change: ci/scripts/install_minio.sh currently fails for anyone building the CI images locally, since MinIO discontinued the binary distribution it fetches from. I patched around it locally to get a working build. If this is fixed properly upstream and CI behaves differently as a result, I wouldn't have had visibility into that from my local setup.

Are there any user-facing changes?

Yes: appending to a nonexistent file on HDFS now succeeds and creates the file, instead of raising an error.

This PR contains a "Critical Fix". It fixes a case where an operation documented to succeed instead raised an error.

@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #32438 has been automatically assigned in GitHub to PR creator.

@mohammadnaqvi04

Copy link
Copy Markdown
Author

@pitrou Bumping this for whenever you get a chance. Happy to address anything that needs changing!

@mohammadnaqvi04
mohammadnaqvi04 force-pushed the hdfs-append-nonexistent-file branch from 5986fcc to 7e62da7 Compare September 23, 2026 23:46
@mohammadnaqvi04

Copy link
Copy Markdown
Author

I've rebased onto current main to pick up the minio CI fix that was landing while this PR was open. Could someone please approve the workflow runs on the latest push?

@mohammadnaqvi04
mohammadnaqvi04 force-pushed the hdfs-append-nonexistent-file branch from 7e62da7 to 8445861 Compare October 2, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant