Skip to content

[core] Refactor sort compact to produce COMPACT commits#8566

Closed
hbgstc123 wants to merge 2 commits into
apache:masterfrom
hbgstc123:fix_sort_compact
Closed

[core] Refactor sort compact to produce COMPACT commits#8566
hbgstc123 wants to merge 2 commits into
apache:masterfrom
hbgstc123:fix_sort_compact

Conversation

@hbgstc123

Copy link
Copy Markdown

Purpose

Follow up on #7595 per this review comment: sort compact should not be modeled as an OVERWRITE commit with extra base-snapshot handling. Instead, it should produce a normal COMPACT commit so the existing commit protocol can perform compact validation and conflict detection.

This PR fixes the concurrent-write data loss risk in sort compact by refactoring Flink/Spark sort compact to:

  1. Write sorted output in write-only mode.
  2. Rewrite the written append commit messages into CompactIncrement messages.
  3. Commit them through the normal compact commit path.

No new overwritePartition(baseSnapshotId) APIs or special overwrite conflict logic are introduced.

Tests

Core

  • SortCompactCommitMessageRewriterTest
    • rewrite to compact messages
    • multi-bucket / cross-bucket rewrite
    • deletion-vector cleanup
    • hash-dynamic hash-index cleanup
    • snapshot sequence range preservation
    • inline compaction rejection
    • compact commit success detection, including expired snapshot gaps
  • ConflictDetectionTest
  • KeyValueTableReadSequenceTest
  • IncrementalDiffSplitReadTest
  • PrimaryKeyTableRawFileSplitReadProviderTest

Flink

  • SortCompactCommitterTest
  • SortCompactSinkWriteTest
  • SortCompactActionForAppendTableITCase
    • latest snapshot kind is COMPACT
    • concurrent append between read and commit does not lose data
  • SortCompactActionForDynamicBucketITCase
  • CommitterOperatorTest
  • FlinkSourceBuilderTest

Spark

  • SortCompactSparkCommitTest
  • CompactProcedureTestBase updated to expect COMPACT

Rewrite sort compact writes into COMPACT commits instead of OVERWRITE,
preserve sequence ordering and hash-index consistency across Flink/Spark,
and make commit-success detection safe when post-commit steps fail.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove unused imports and correct import ordering so CI licensing and build checks pass.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hbgstc123 hbgstc123 closed this Jul 11, 2026
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