Skip to content

[spark] Introduce multi-batch compaction for append tables - #11436

Open
lilei1128 wants to merge 1 commit into
apache:masterfrom
lilei1128:spark-append-compact-batches-container
Open

lilei1128 wants to merge 1 commit into
apache:masterfrom
lilei1128:spark-append-compact-batches-container

Conversation

@lilei1128

Copy link
Copy Markdown
Contributor

Purpose

Spark sys.compact previously compacted at most compaction.file-num-limit
candidate files per call for unaware-bucket append tables, so tables with many
small files required repeated calls.

Introduce compaction.multi-batch.enabled (default: false). When enabled, one
call keeps scanning from the starting snapshot and plans/commits one batch at a
time until all candidates are processed:

  • compaction.file-num-limit bounds candidate files scanned per batch, not the
    files committed at once. Candidates can accumulate across batches, and only
    batches that produce compaction tasks are committed.
  • Each batch commits separately, so completed batches survive a failure in a
    later batch. Concurrent file replacement or deletion-vector changes are
    rejected by commit conflict detection.
  • Snapshot, partition, consumer and tag expiration triggered by the call is
    deferred until all batches finish. A failure during the final cleanup may
    fail the CALL, but committed batches are not rolled back.
  • The coordinator is pinned to the starting snapshot, so appends committed
    afterwards are left for a later call.

Add TableCommitImpl.expireOnCommit(boolean) to defer automatic expiration,
and document the new option and its semantics.

Tests

  • AppendOnlyTableCompactionTest#testLaterBatchRejectsConcurrentCompaction:
    verifies a later batch fails with a file deletion conflict whether the
    rewrite starts before or after a concurrent commit replaces its inputs,
    without changing data or the latest snapshot.
  • TableCommitTest#testExpireSnapshotsOnCommit: verifies automatic expiration
    can be disabled per commit while explicit expiration and write-only behavior
    are preserved.
  • CompactProcedureTestBase:
    • single-batch default and dynamic disable, including a first batch with no
      task;
    • multi-batch across limits 1/2, with and without write-only;
    • deferred expiration after a post-commit callback failure;
    • partition filter, deletion vectors, and partition_idle_time.

@lilei1128
lilei1128 force-pushed the spark-append-compact-batches-container branch from 0df44a5 to 5d1436c Compare November 25, 2026 08:21
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.

1 participant