Skip to content

[Improvement] Avoid an unnecessary S3 PUT when opening a data file - #1465

Open
ZENOTME wants to merge 5 commits into
apache:mainfrom
ZENOTME:codex/skip-s3-directory-marker
Open

ZENOTME wants to merge 5 commits into
apache:mainfrom
ZENOTME:codex/skip-s3-directory-marker

Conversation

@ZENOTME

@ZENOTME ZENOTME commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Closes #1464. Avoid an extra S3 PUT when opening a data file.

Brief change log

Remove the explicit mkdirs() calls from the append and primary-key data writers. OpenDAL’s local filesystem writer already creates missing parent directories when it opens a file. The S3 writer can write the object directly, so removing mkdirs() avoids a separate PUT for the directory marker. Custom OpenDAL operators that require parent directories should create them in their own write path.

Tests

Add a regression test that writes append and primary-key Parquet files into fresh buckets through a custom FileIO provider backed by OpenDAL FS. It verifies that the files exist and that neither writer requests the bucket directory separately.

@ZENOTME ZENOTME changed the title fix(io): skip S3 directory markers when opening data files [Improvement] Avoid an unnecessary S3 PUT when opening a data file Nov 19, 2026
@ZENOTME
ZENOTME force-pushed the codex/skip-s3-directory-marker branch 9 times, most recently from b795f49 to 2ea74d4 Compare November 20, 2026 02:17
.new_file_name(&self.data_file_prefix, &self.file_format);
let location = self.paths.new_path(&file_name)?;
let bucket_dir = location.parent();
self.file_io.mkdirs(&format!("{bucket_dir}/")).await?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we skip mkdirs() for S3 in FileIO and keep it for backends that need it? I tested a FileIOProvider backed by OpenDAL WebDAV with automatic parent creation disabled. Both append and primary-key writes to a new bucket-0 failed with HTTP 409 during prepare_commit(). The same writes passed after explicitly creating the bucket directory.

Could we also add a regression test that checks both S3 write paths produce a Parquet file without sending a directory marker PUT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that each operator handles parent directories as needed. E.g. FsWriter::create() calls ensure_write_abs_path(), which creates missing parent directories. The WebDAV writer does the same by default in WebdavWriter::write_once().

Is there a use case for disabling automatic directory creation when the WebDAV server requires the parent to exist, or is the concern mainly backward compatibility with providers that rely on Paimon to create it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly backward compatibility. I don’t have a concrete use case for that WebDAV setup. I used it to reproduce what happens when a custom provider relies on Paimon to create the bucket directory.

I’m fine with leaving parent directory creation to the operator and documenting that in FileIOProvider. @JingsongLi does that match what you’d expect from FileIOProvider?

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding an S3 directory-marker PUT per data file has end-to-end value. DataFusion unit and native MERGE tests passed. The isolated provider regression below passed on the base and failed on the PR head.

.new_file_name(&self.data_file_prefix, &self.file_format);
let location = self.paths.new_path(&file_name)?;
let bucket_dir = location.parent();
self.file_io.mkdirs(&format!("{bucket_dir}/")).await?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Keep parent creation for providers that require it

This removes the directory creation step for every FileIO, including existing custom FileIOProviders. I used a public TableWrite with a provider backed by a hierarchical OpenDAL filesystem that requires the parent directory before resolving a Parquet file. Writing the first row of a fresh partition and bucket prepared a real Parquet file on 589e7743. On 2ea74d4d it fails because pt=a%2Fb/bucket-0 does not exist. The KV writer drops the same prerequisite.

Keep the current behavior for provider-backed or unclassified storage. Skip the marker only for backends known to create parents on write or accept object keys without directories.

@JingsongLi JingsongLi Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reran the original strict-provider reproduction on the current head b285e577 merged into main (86cd12c7). The first append to the fresh pt=a%2Fb/bucket-0 still fails with Data file parent must exist. The new default is true, but resolve_for_write calls self.resolve(path) before checking it. A provider that needs the directory before resolving the child Parquet path returns early, so its create_dir is never reached.

Please resolve and create the logical parent before resolving the file for providers that require it, or keep the conditional mkdirs before opening the file in both data writers. The local HTTP S3 probe passed for append and primary-key files and observed no directory-marker PUTs, so the fast path is working.

Keeping the check at the data-writer boundary also avoids a separate I/O regression. With the documented SharedStorage S3 provider, ConsumerManager::reset already creates consumer/ before writing its checkpoint. Applying the new default in every OutputFile writer repeats the marker PUT for that metadata write. The current OpenDAL S3 operator implements create_dir as a marker write, so this changes the reset path from two PUTs to three for existing providers.

Comment thread crates/paimon/src/io/file_io.rs Outdated
/// require parent directories to exist before writing. Providers backed by
/// object stores or operators that create missing parent directories on
/// write may return `false` to avoid extra directory marker requests.
fn requires_parent_dir_for_write(&self) -> bool {

@JingsongLi JingsongLi Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reference system for this interface? It looks a bit odd. Can we avoid introducing it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed commit b909c78 removing requires_parent_dir_for_write() from FileIOProvider completely. This implements Option 2 below (preserving backward compatibility without changing any public trait). I'd also like to share Option 1 in case we prefer to simplify further:

Option 2 (Implemented in the latest push — no public API change, keeps backward compatibility):

  • Removed requires_parent_dir_for_write() from pub trait FileIOProvider.
  • Moved the flag to a crate-internal field on FileIOBackend::Provider / FileSource::Provider: built-in Storage backends (except CustomFs and Memory) and internal providers (RESTTokenFileIO, FuseFileIO) inherit the backend's behavior via a pub(crate) helper (with_internal_provider), while external custom FileIOProviders and CustomFs keep the conservative pre-write parent-directory creation path.

Option 1 (Simpler alternative — delegate parent directory creation to the OpenDAL Operator):

  • Drop pre-write parent directory creation in OutputFile::resolve_for_write() completely (no backend special-casing), and document on FileIOProvider that resolving/opening a file for writing should not require callers to call mkdirs() first (updating the memory empty-directory assertion in consumer_manager tests if needed).
  • Why Option 1 is worth considering:
    1. Clearer layering (I/O / operator responsibility, aligned with OpenDAL and iceberg-rust): Whether a backend needs missing parent directories before creating a file is a storage-service detail, not a table-format or writer concern. OpenDAL's hierarchical services already handle this inside their write paths (FsWriter::create via ensure_write_abs_path, HdfsCore via ensure_parent_dir, HdfsNative via HDFS create_parent = true, and WebdavWriter via webdav_mkcol by default), while object stores don't need directory markers. iceberg-rust follows the same model and delegates OutputFile::writer() directly to OpenDAL Operator::writer() without calling create_dir.
    2. Questionable precondition on FileIOProvider::create(path): Guaranteeing that callers have already created the parent directory before calling FileIOProvider::create(path) is not a necessary or intended semantic of FileIOProvider::create(path) — it is meant to resolve an (Operator, relative_path) for a URI, not to rely on physical parent directories already existing. Maintaining this implicit precondition forces resolve_for_write() to split the logical parent URI, call provider.create(parent/), and issue create_dir before even resolving the target file path. Is this implicit semantic really worth maintaining?
    3. Consistent behavior for external object-store providers: Without a public trait knob, Option 2 has an inherent asymmetry — built-in S3 / RESTTokenFileIO skip directory-marker PUTs, whereas an external custom S3 FileIOProvider (like SharedS3Provider) still pays for an extra directory-marker PUT on every write. Option 1 gives both built-in and external providers the same behavior with much less code.

If you'd like to keep strict backward compatibility for existing custom FileIOProviders, the current push (Option 2) is ready as-is. If you prefer the cleaner Option 1 contract, I'm happy to simplify it accordingly.

@ZENOTME
ZENOTME force-pushed the codex/skip-s3-directory-marker branch from 8e80ce4 to b909c78 Compare November 24, 2026 05:07
@ZENOTME
ZENOTME force-pushed the codex/skip-s3-directory-marker branch from b909c78 to 6f2a36c Compare November 24, 2026 06:52

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the native S3 directory-marker PUT has a concrete write-path benefit. On 6f2a36ca integrated with d557fb13, 282 selected FileIO, S3, managed BLOB and REST tests passed. An additional public FileIO regression passed on main and failed on this head.

let path = path.trim_end_matches('/');
match path.rsplit_once('/') {
Some((parent, _)) if !parent.is_empty() && !parent.ends_with(":/") => {
Some(resolve_provider(provider.as_ref(), &format!("{parent}/")).await?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Preserve the ability to write a provider-mapped object directly

Every public FileIOProvider now resolves a separate parent URI before writing the requested file. A provider can map the exact requested object to an operator without having a directory route. I exercised FileIO::new_output(...).write(...) with an object that the provider resolves and a backend that writes it directly. The write succeeds on main. Here it fails with the unmapped parent URI before the object is resolved. Keep the existing direct-write contract for generic providers. Use explicit parent creation at call sites that require it, or make the extra directory operation an explicit backend capability.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement] Avoid an unnecessary S3 PUT when opening a data file

3 participants