This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 61de21eee7 [core] Reject concurrent DV compaction in the same bucket 
(#11001)
61de21eee7 is described below

commit 61de21eee7b446f8e892e36fe0ba41a02b7433d3
Author: Jingsong Lee <[email protected]>
AuthorDate: Sun Nov 8 22:54:12 2026 +0800

    [core] Reject concurrent DV compaction in the same bucket (#11001)
---
 docs/docs/concepts/concurrency-control.md          |   5 +
 docs/docs/primary-key-table/compaction.md          |  10 +-
 .../paimon/operation/AbstractFileStoreWrite.java   |  23 +-
 .../paimon/operation/FileStoreCommitImpl.java      |  75 +-
 .../paimon/operation/KeyValueFileStoreWrite.java   |   5 +
 .../paimon/operation/commit/CommitScanner.java     | 105 +++
 .../commit/DataEvolutionChangesProvider.java       |   2 +-
 .../operation/commit/SnapshotConflictChecker.java  | 256 ++++++
 .../paimon/operation/commit/StrictModeChecker.java | 207 -----
 .../org/apache/paimon/postpone/BucketFiles.java    |   8 +-
 .../apache/paimon/table/sink/CommitMessage.java    |   3 +-
 .../PrimaryKeySortedIndexMaintenanceTest.java      |  66 +-
 .../PrimaryKeyDvConcurrentCompactionTest.java      | 928 +++++++++++++++++++++
 .../apache/paimon/postpone/BucketFilesTest.java    |  18 +
 .../apache/paimon/table/sink/TableCommitTest.java  |   2 +-
 .../ChangelogCompactCoordinateOperator.java        |   3 +-
 .../changelog/ChangelogCompactSortOperator.java    |   3 +-
 .../postpone/PostponeBucketCompactSplitSource.java |   5 +-
 .../RemovePostponeBucketFilesOperator.java         |  11 +-
 .../ChangelogCompactCoordinateOperatorTest.java    |  36 +
 .../ChangelogCompactSortOperatorTest.java          |  11 +-
 .../procedure/SparkPostponeCompactProcedure.scala  |   3 +-
 22 files changed, 1482 insertions(+), 303 deletions(-)

diff --git a/docs/docs/concepts/concurrency-control.md 
b/docs/docs/concepts/concurrency-control.md
index cdc1f85d4a..d788008db2 100644
--- a/docs/docs/concepts/concurrency-control.md
+++ b/docs/docs/concepts/concurrency-control.md
@@ -84,6 +84,11 @@ File validation also checks other table invariants. For 
example, primary-key tab
 standard LSM layout reject overlapping key ranges within the same partition, 
bucket, and level
 above level 0. Retrying an unchanged snapshot ID alone cannot fix incompatible 
file changes.
 
+For primary-key tables with fixed bucket routing, deletion vectors, and 
`write-only = false`,
+Paimon rejects concurrent compaction commits from different commit users for 
the same bucket in a
+partition. See
+[Concurrent compaction](../primary-key-table/compaction#concurrent-compaction).
+
 In a streaming job, a failed commit can trigger recovery and a restart. 
Repeated conflicts can
 therefore cause repeated restarts even though the commit validation protects 
the table state.
 
diff --git a/docs/docs/primary-key-table/compaction.md 
b/docs/docs/primary-key-table/compaction.md
index f69c587aa2..b4407790b1 100644
--- a/docs/docs/primary-key-table/compaction.md
+++ b/docs/docs/primary-key-table/compaction.md
@@ -70,12 +70,20 @@ publishes it. MOW batch readers can opt into merging 
pending data with
 For `changelog-producer = lookup`, generated changelogs are also delayed. A 
compactor that cannot
 keep up with sustained input will keep falling behind; relaxing waits does not 
add capacity.
 
+## Concurrent compaction
+
+File-level conflict checks can miss conflicts between concurrent compactions. 
For primary-key
+tables with fixed bucket routing, deletion vectors, and `write-only = false`, 
Paimon therefore
+rejects concurrent compaction commits from different commit users for the same 
bucket in a
+partition. This check allows different buckets to compact independently.
+
 ## Dedicated compaction job
 
 Set `write-only = true` on ingest writers and run a
 [dedicated compaction 
job](../maintenance/dedicated-compaction#dedicated-compaction-job) when
 compaction needs separate resources or multiple writers need a single 
compaction owner.
-Avoid overlapping compaction jobs for the same partition, which can cause 
commit conflicts.
+Avoid overlapping compaction jobs for the same bucket in a partition, which 
can cause commit
+conflicts.
 
 This does not lift [dynamic-bucket](./data-distribution#dynamic-bucket) 
restrictions on concurrent
 writers to the same partition.
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java
index 96c8feb75e..338f6932ce 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/operation/AbstractFileStoreWrite.java
@@ -252,6 +252,7 @@ public abstract class AbstractFileStoreWrite<T> implements 
FileStoreWrite<T> {
         }
 
         List<CommitMessage> result = new ArrayList<>();
+        boolean requiresCompactionBaseline = requiresCompactionBaseline();
 
         Iterator<Map.Entry<BinaryRow, Map<Integer, WriterContainer<T>>>> 
partIter =
                 writers.entrySet().iterator();
@@ -289,7 +290,8 @@ public abstract class AbstractFileStoreWrite<T> implements 
FileStoreWrite<T> {
                                 bucket,
                                 writerContainer.totalBuckets,
                                 newFilesIncrement,
-                                compactIncrement);
+                                compactIncrement,
+                                requiresCompactionBaseline ? 
writerContainer.baseSnapshotId : null);
                 result.add(committable);
 
                 if (committable.isEmpty()) {
@@ -336,6 +338,10 @@ public abstract class AbstractFileStoreWrite<T> implements 
FileStoreWrite<T> {
     // For writers with no conflicts, `commitUser` might be some random value.
     protected abstract Function<WriterContainer<T>, Boolean> 
createWriterCleanChecker();
 
+    protected boolean requiresCompactionBaseline() {
+        return false;
+    }
+
     protected static <T>
             Function<WriterContainer<T>, Boolean> 
createConflictAwareWriterCleanChecker(
                     String commitUser, WriteRestore restore) {
@@ -552,11 +558,17 @@ public abstract class AbstractFileStoreWrite<T> 
implements FileStoreWrite<T> {
         boolean actualIgnorePreviousFiles =
                 ignorePreviousFilesForWriter(
                         partition, bucket, latestSnapshot, 
ignorePreviousFiles);
-        RestoreFiles restored = RestoreFiles.empty();
-        if (!actualIgnorePreviousFiles) {
+        RestoreFiles restored;
+        Snapshot baseSnapshot;
+        if (actualIgnorePreviousFiles) {
+            restored = RestoreFiles.empty();
+            // An overwrite starts from empty files and checks commits made 
after writer creation.
+            baseSnapshot = requiresCompactionBaseline() ? latestSnapshot : 
null;
+        } else {
             restored =
                     scanExistingFileMetas(
                             partition, bucket, expectedTotalBuckets, 
validateNumBuckets);
+            baseSnapshot = restored.snapshot();
         }
 
         DynamicBucketIndexMaintainer indexMaintainer =
@@ -598,14 +610,13 @@ public abstract class AbstractFileStoreWrite<T> 
implements FileStoreWrite<T> {
                         actualIgnorePreviousFiles);
         notifyNewWriter(writer);
 
-        Snapshot previousSnapshot = restored.snapshot();
         return new WriterContainer<>(
                 writer,
                 firstNonNull(restored.totalBuckets(), expectedTotalBuckets),
                 indexMaintainer,
                 dvMaintainer,
                 primaryKeyIndexMaintainer,
-                previousSnapshot == null ? null : previousSnapshot.id());
+                baseSnapshot == null ? null : baseSnapshot.id());
     }
 
     private long writerNumber() {
@@ -766,7 +777,7 @@ public abstract class AbstractFileStoreWrite<T> implements 
FileStoreWrite<T> {
                 @Nullable DynamicBucketIndexMaintainer dynamicBucketMaintainer,
                 @Nullable BucketedDvMaintainer deletionVectorsMaintainer,
                 @Nullable BucketedPrimaryKeyIndexMaintainer 
primaryKeyIndexMaintainer,
-                Long baseSnapshotId) {
+                @Nullable Long baseSnapshotId) {
             this.writer = writer;
             this.totalBuckets = totalBuckets;
             this.dynamicBucketMaintainer = dynamicBucketMaintainer;
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/FileStoreCommitImpl.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/FileStoreCommitImpl.java
index 860835de53..7e7c14da49 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/operation/FileStoreCommitImpl.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/operation/FileStoreCommitImpl.java
@@ -54,12 +54,13 @@ import 
org.apache.paimon.operation.commit.DataEvolutionChangesProvider;
 import 
org.apache.paimon.operation.commit.DataEvolutionRowRangeConflictException;
 import org.apache.paimon.operation.commit.DiscardingCompactChangesProvider;
 import org.apache.paimon.operation.commit.ManifestEntryChanges;
+import org.apache.paimon.operation.commit.PrimaryKeyConflictDetection;
 import org.apache.paimon.operation.commit.RetryCommitResult;
 import 
org.apache.paimon.operation.commit.RetryCommitResult.CommitFailRetryResult;
 import 
org.apache.paimon.operation.commit.RetryCommitResult.ManifestMergeResult;
 import org.apache.paimon.operation.commit.RowIdConflictChecker;
 import 
org.apache.paimon.operation.commit.RowTrackingCommitUtils.RowTrackingAssigned;
-import org.apache.paimon.operation.commit.StrictModeChecker;
+import org.apache.paimon.operation.commit.SnapshotConflictChecker;
 import org.apache.paimon.operation.commit.SuccessCommitResult;
 import org.apache.paimon.operation.metrics.CommitMetrics;
 import org.apache.paimon.operation.metrics.CommitStats;
@@ -110,6 +111,7 @@ import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 import static java.util.Collections.emptyList;
+import static java.util.Collections.emptyMap;
 import static 
org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
 import static org.apache.paimon.format.blob.BlobFileFormat.isBlobFile;
 import static org.apache.paimon.manifest.ManifestEntry.nullableRecordCount;
@@ -167,7 +169,7 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
     private final BucketMode bucketMode;
     private final RetryWaiter retryWaiter;
     private final InternalRowPartitionComputer partitionComputer;
-    @Nullable private final StrictModeChecker strictModeChecker;
+    private final SnapshotConflictChecker snapshotConflictChecker;
     private final ConflictDetection conflictDetection;
     private final CommitCleaner commitCleaner;
 
@@ -227,20 +229,19 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
         this.commitMetrics = null;
         this.statsFileHandler = statsFileHandler;
         this.bucketMode = bucketMode;
-        this.strictModeChecker =
-                options.commitLastSafeSnapshot()
-                        .filter(ignored -> options.commitStrictModeEnabled())
-                        .map(
-                                id ->
-                                        new StrictModeChecker(
-                                                snapshotManager,
-                                                commitUser,
-                                                scanSupplier,
-                                                indexManifestFile,
-                                                options.dataEvolutionEnabled(),
-                                                id))
-                        .orElse(null);
         this.conflictDetection = conflictDetectFactory.create(scanner);
+        this.snapshotConflictChecker =
+                new SnapshotConflictChecker(
+                        snapshotManager,
+                        commitUser,
+                        scanner,
+                        options.dataEvolutionEnabled(),
+                        options.commitLastSafeSnapshot()
+                                .filter(ignored -> 
options.commitStrictModeEnabled())
+                                .orElse(null),
+                        conflictDetection instanceof 
PrimaryKeyConflictDetection
+                                && options.deletionVectorsEnabled()
+                                && !options.writeOnly());
         this.commitCleaner = new CommitCleaner(manifestList, manifestFile, 
indexManifestFile);
     }
 
@@ -347,7 +348,8 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
         int attempts = 0;
 
         List<CommitMessage> commitMessages = committable.fileCommittables();
-        configureRowIdCheckFromMessages(commitMessages);
+        Map<Pair<BinaryRow, Integer>, Long> compactionBaselines =
+                prepareConflictChecks(commitMessages);
         ManifestEntryChanges changes = collectChanges(commitMessages);
         List<ManifestEntry> committedCompactFiles = changes.compactTableFiles;
         Set<Pair<BinaryRow, Integer>> materializedBuckets = 
materializedBuckets(commitMessages);
@@ -391,6 +393,7 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
                                                 changes.appendIndexFiles),
                                         commitKind,
                                         Collections.emptySet()),
+                                emptyMap(),
                                 committable.identifier(),
                                 committable.watermark(),
                                 committable.properties(),
@@ -409,6 +412,7 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
                 attempts +=
                         tryCommit(
                                 compactProvider,
+                                compactionBaselines,
                                 committable.identifier(),
                                 committable.watermark(),
                                 committable.properties(),
@@ -525,7 +529,8 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
         int generatedSnapshot = 0;
         int attempts = 0;
 
-        configureRowIdCheckFromMessages(committable.fileCommittables());
+        Map<Pair<BinaryRow, Integer>, Long> compactionBaselines =
+                prepareConflictChecks(committable.fileCommittables());
         ManifestEntryChanges changes = 
collectChanges(committable.fileCommittables());
         if (!changes.appendChangelog.isEmpty() || 
!changes.compactChangelog.isEmpty()) {
             StringBuilder warnMessage =
@@ -604,6 +609,7 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
                                                 changes.compactIndexFiles),
                                         CommitKind.COMPACT,
                                         Collections.emptySet()),
+                                compactionBaselines,
                                 committable.identifier(),
                                 committable.watermark(),
                                 committable.properties(),
@@ -774,6 +780,7 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
         String statsFileName = statsFileHandler.writeStats(stats);
         tryCommit(
                 CommitChangesProvider.provider(emptyList(), emptyList(), 
emptyList()),
+                emptyMap(),
                 commitIdentifier,
                 null,
                 Collections.emptyMap(),
@@ -800,6 +807,14 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
         return changes;
     }
 
+    private Map<Pair<BinaryRow, Integer>, Long> prepareConflictChecks(
+            List<CommitMessage> commitMessages) {
+        if (options.dataEvolutionEnabled()) {
+            configureRowIdCheckFromMessages(commitMessages);
+        }
+        return 
snapshotConflictChecker.prepareCompactionBaselines(commitMessages);
+    }
+
     private void configureRowIdCheckFromMessages(List<CommitMessage> 
commitMessages) {
         Long checkFromSnapshot = null;
         for (CommitMessage message : commitMessages) {
@@ -973,6 +988,7 @@ public class FileStoreCommitImpl implements FileStoreCommit 
{
 
     private int tryCommit(
             CommitChangesProvider changesProvider,
+            Map<Pair<BinaryRow, Integer>, Long> compactionBaselines,
             long identifier,
             @Nullable Long watermark,
             Map<String, String> properties,
@@ -990,6 +1006,7 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
                         tryCommitOnce(
                                 retryResult,
                                 changesProvider,
+                                compactionBaselines,
                                 identifier,
                                 watermark,
                                 properties,
@@ -1094,6 +1111,7 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
         return tryCommit(
                 scanner.overwriteChangesProvider(
                         options.bucket(), changes, indexFiles, 
partitionFilter),
+                emptyMap(),
                 identifier,
                 watermark,
                 properties,
@@ -1132,6 +1150,7 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
                 tryCommitOnce(
                         retryResult,
                         CommitChangesProvider.provider(deltaFiles, 
changelogFiles, indexFiles),
+                        emptyMap(),
                         identifier,
                         watermark,
                         properties,
@@ -1147,6 +1166,7 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
     private CommitResult tryCommitOnce(
             @Nullable RetryCommitResult retryResult,
             CommitChangesProvider changesProvider,
+            Map<Pair<BinaryRow, Integer>, Long> compactionBaselines,
             long identifier,
             @Nullable Long watermark,
             Map<String, String> properties,
@@ -1162,6 +1182,7 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
                             tryCommitOnceWithoutLock(
                                     retryResult,
                                     changesProvider,
+                                    compactionBaselines,
                                     identifier,
                                     watermark,
                                     properties,
@@ -1180,6 +1201,7 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
     private CommitResult tryCommitOnceWithoutLock(
             @Nullable RetryCommitResult retryResult,
             CommitChangesProvider changesProvider,
+            Map<Pair<BinaryRow, Integer>, Long> compactionBaselines,
             long identifier,
             @Nullable Long watermark,
             Map<String, String> properties,
@@ -1235,13 +1257,14 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
             conflictDetection.checkSameBucketWithinDelta(deltaFiles);
         }
 
-        List<BinaryRow> changedPartitions = null;
-        if (strictModeChecker != null) {
-            changedPartitions = changedPartitions(deltaFiles, indexFiles);
-            strictModeChecker.check(
-                    newSnapshotId, commitKind, changedPartitions, 
rebasedReassignments);
-            strictModeChecker.update(newSnapshotId - 1);
-        }
+        // Check snapshot history even when the file-level conflict scan can 
be skipped.
+        List<BinaryRow> changedPartitions =
+                snapshotConflictChecker.check(
+                        newSnapshotId,
+                        commitKind,
+                        changes,
+                        rebasedReassignments,
+                        compactionBaselines);
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("Ready to commit table files to snapshot {}", 
newSnapshotId);
@@ -1556,9 +1579,7 @@ public class FileStoreCommitImpl implements 
FileStoreCommit {
                 commitUser,
                 identifier,
                 commitKind.name());
-        if (strictModeChecker != null) {
-            strictModeChecker.update(newSnapshotId);
-        }
+        snapshotConflictChecker.onCommitSuccess(newSnapshotId);
         lastCommittedSnapshotId = newSnapshotId;
         CommitCallback.Context context =
                 new CommitCallback.Context(
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
index b685a152c7..4b9b3c6f6a 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
@@ -252,6 +252,11 @@ public class KeyValueFileStoreWrite extends 
MemoryFileStoreWrite<KeyValue> {
                 UserDefinedSeqComparator.create(valueType, options));
     }
 
+    @Override
+    protected boolean requiresCompactionBaseline() {
+        return options.deletionVectorsEnabled() && !options.writeOnly();
+    }
+
     @Override
     protected Function<WriterContainer<KeyValue>, Boolean> 
createWriterCleanChecker() {
         return createConflictAwareWriterCleanChecker(commitUser, restore);
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/commit/CommitScanner.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/commit/CommitScanner.java
index 8c1c57100a..74dd782e29 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/operation/commit/CommitScanner.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/operation/commit/CommitScanner.java
@@ -28,6 +28,7 @@ import org.apache.paimon.manifest.SimpleFileEntry;
 import org.apache.paimon.operation.FileStoreScan;
 import org.apache.paimon.partition.PartitionPredicate;
 import org.apache.paimon.table.source.ScanMode;
+import org.apache.paimon.utils.Pair;
 import org.apache.paimon.utils.Range;
 import org.apache.paimon.utils.SnapshotManager;
 
@@ -40,8 +41,11 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
+import java.util.function.Predicate;
 import java.util.function.Supplier;
+import java.util.stream.Collectors;
 
 /** Manifest entries scanner for commit. */
 public class CommitScanner {
@@ -91,6 +95,107 @@ public class CommitScanner {
                 .files();
     }
 
+    boolean hasDataChanges(Snapshot snapshot, Set<BinaryRow> partitions, 
boolean onlyRealBuckets) {
+        return hasDataChanges(
+                snapshot,
+                partitions,
+                onlyRealBuckets,
+                entry -> partitions.contains(entry.partition()));
+    }
+
+    boolean hasDataChangesInBuckets(Snapshot snapshot, Set<Pair<BinaryRow, 
Integer>> buckets) {
+        Set<BinaryRow> partitions = 
buckets.stream().map(Pair::getLeft).collect(Collectors.toSet());
+        return hasDataChanges(
+                snapshot,
+                partitions,
+                false,
+                entry -> buckets.contains(Pair.of(entry.partition(), 
entry.bucket())));
+    }
+
+    private boolean hasDataChanges(
+            Snapshot snapshot,
+            Set<BinaryRow> partitions,
+            boolean onlyRealBuckets,
+            Predicate<ManifestEntry> matches) {
+        if (partitions.isEmpty()) {
+            return false;
+        }
+        FileStoreScan deltaScan =
+                scanSupplier
+                        .get()
+                        .withSnapshot(snapshot)
+                        .withKind(ScanMode.DELTA)
+                        .withPartitionFilter(new ArrayList<>(partitions))
+                        .dropStats();
+        if (onlyRealBuckets) {
+            deltaScan.onlyReadRealBuckets();
+        }
+        Iterator<ManifestEntry> entries = deltaScan.readFileIterator();
+        while (entries.hasNext()) {
+            if (matches.test(entries.next())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    boolean hasIndexChanges(
+            Snapshot snapshot, Set<BinaryRow> partitions, boolean 
requirePreviousSnapshot) {
+        if (partitions.isEmpty()) {
+            return false;
+        }
+        return hasIndexChanges(
+                snapshot, entry -> partitions.contains(entry.partition()), 
requirePreviousSnapshot);
+    }
+
+    boolean hasIndexChangesInBuckets(Snapshot snapshot, Set<Pair<BinaryRow, 
Integer>> buckets) {
+        if (buckets.isEmpty()) {
+            return false;
+        }
+        return hasIndexChanges(
+                snapshot,
+                entry -> buckets.contains(Pair.of(entry.partition(), 
entry.bucket())),
+                true);
+    }
+
+    private boolean hasIndexChanges(
+            Snapshot snapshot,
+            Predicate<IndexManifestEntry> matches,
+            boolean requirePreviousSnapshot) {
+        String indexManifest = snapshot.indexManifest();
+        String previousIndexManifest = null;
+        long previousId = snapshot.id() - 1;
+        if (previousId >= Snapshot.FIRST_SNAPSHOT_ID
+                && (requirePreviousSnapshot || 
snapshotManager.snapshotExists(previousId))) {
+            previousIndexManifest = 
snapshotManager.snapshot(previousId).indexManifest();
+        }
+        if (Objects.equals(indexManifest, previousIndexManifest)) {
+            return false;
+        }
+        // Compare both sides. An OVERWRITE such as rollbackToAsLatest can 
drop a DV entry
+        // without any data-file delta.
+        Set<IndexManifestEntry> previousEntries = 
readIndexEntries(previousIndexManifest, matches);
+        for (IndexManifestEntry entry : readIndexEntries(indexManifest, 
matches)) {
+            if (!previousEntries.remove(entry)) {
+                return true;
+            }
+        }
+        return !previousEntries.isEmpty();
+    }
+
+    private Set<IndexManifestEntry> readIndexEntries(
+            @Nullable String indexManifest, Predicate<IndexManifestEntry> 
matches) {
+        Set<IndexManifestEntry> entries = new HashSet<>();
+        if (indexManifest != null) {
+            for (IndexManifestEntry entry : 
indexManifestFile.read(indexManifest)) {
+                if (matches.test(entry)) {
+                    entries.add(entry);
+                }
+            }
+        }
+        return entries;
+    }
+
     public List<SimpleFileEntry> readAllEntriesFromChangedPartitions(
             Snapshot snapshot, List<BinaryRow> changedPartitions) {
         try {
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/commit/DataEvolutionChangesProvider.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/commit/DataEvolutionChangesProvider.java
index 620326f69e..45f8fcc757 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/operation/commit/DataEvolutionChangesProvider.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/operation/commit/DataEvolutionChangesProvider.java
@@ -73,7 +73,7 @@ public final class DataEvolutionChangesProvider implements 
CommitChangesProvider
                 latest != null && latest.id() >= checkedSnapshot,
                 "Compaction planning snapshot %s is ahead of the current 
table.",
                 checkedSnapshot);
-        // Like StrictModeChecker, only history after the boundary is needed. 
The boundary
+        // Like strict mode, only history after the boundary is needed. The 
boundary
         // snapshot itself may already have expired.
         for (long id = checkedSnapshot + 1; id <= latest.id(); id++) {
             checkState(
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/commit/SnapshotConflictChecker.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/commit/SnapshotConflictChecker.java
new file mode 100644
index 0000000000..b698e81981
--- /dev/null
+++ 
b/paimon-core/src/main/java/org/apache/paimon/operation/commit/SnapshotConflictChecker.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.operation.commit;
+
+import org.apache.paimon.CoreOptions;
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.Snapshot.CommitKind;
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.io.CompactIncrement;
+import org.apache.paimon.io.DataFileMeta;
+import org.apache.paimon.io.DataFilePathFactory;
+import org.apache.paimon.table.sink.CommitMessage;
+import org.apache.paimon.table.sink.CommitMessageImpl;
+import org.apache.paimon.utils.Pair;
+import org.apache.paimon.utils.Range;
+import org.apache.paimon.utils.SnapshotManager;
+
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static 
org.apache.paimon.operation.commit.ManifestEntryChanges.changedPartitions;
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+
+/** Checks concurrent changes in snapshot history before committing. */
+public class SnapshotConflictChecker {
+
+    private final SnapshotManager snapshotManager;
+    private final String commitUser;
+    private final CommitScanner scanner;
+    private final boolean dataEvolutionEnabled;
+    private final boolean bucketCompactionCheckEnabled;
+
+    @Nullable private Long lastSafeSnapshot;
+    // Successfully checked intervals (from, to], independently of the 
writers' immutable bases.
+    private final Map<Pair<BinaryRow, Integer>, Range> 
checkedCompactionSnapshots = new HashMap<>();
+
+    public SnapshotConflictChecker(
+            SnapshotManager snapshotManager,
+            String commitUser,
+            CommitScanner scanner,
+            boolean dataEvolutionEnabled,
+            @Nullable Long lastSafeSnapshot,
+            boolean bucketCompactionCheckEnabled) {
+        this.snapshotManager = snapshotManager;
+        this.commitUser = commitUser;
+        this.scanner = scanner;
+        this.dataEvolutionEnabled = dataEvolutionEnabled;
+        this.lastSafeSnapshot = lastSafeSnapshot;
+        this.bucketCompactionCheckEnabled = bucketCompactionCheckEnabled;
+    }
+
+    /** Collects the writer baselines before publishing any part of the 
commit. */
+    public Map<Pair<BinaryRow, Integer>, Long> prepareCompactionBaselines(
+            List<CommitMessage> messages) {
+        if (!bucketCompactionCheckEnabled) {
+            return Collections.emptyMap();
+        }
+        Map<Pair<BinaryRow, Integer>, Long> baseSnapshots = new HashMap<>();
+        for (CommitMessage message : messages) {
+            if (!changesDataOrDeletionVectors(((CommitMessageImpl) 
message).compactIncrement())) {
+                continue;
+            }
+            Long snapshotId = message.checkFromSnapshot();
+            checkArgument(
+                    snapshotId != null && snapshotId >= 0,
+                    "A primary-key deletion-vector compaction message is 
missing its "
+                            + "restored snapshot. Reload the bucket and 
recompute compaction.");
+            baseSnapshots.merge(
+                    Pair.of(message.partition(), message.bucket()), 
snapshotId, Math::min);
+        }
+        return baseSnapshots;
+    }
+
+    /** Checks snapshot history and returns the changed partitions if 
collected for strict mode. */
+    @Nullable
+    public List<BinaryRow> check(
+            long newSnapshotId,
+            CommitKind newCommitKind,
+            CommitChanges changes,
+            Set<Long> rebasedReassignments,
+            Map<Pair<BinaryRow, Integer>, Long> compactionBaselines) {
+        if (newCommitKind == CommitKind.COMPACT && 
!compactionBaselines.isEmpty()) {
+            checkBucketCompaction(newSnapshotId, compactionBaselines);
+        }
+        if (lastSafeSnapshot == null) {
+            return null;
+        }
+        List<BinaryRow> partitions = changedPartitions(changes.tableFiles, 
changes.indexFiles);
+        checkStrictMode(newSnapshotId, newCommitKind, partitions, 
rebasedReassignments);
+        lastSafeSnapshot = newSnapshotId - 1;
+        return partitions;
+    }
+
+    public void onCommitSuccess(long snapshotId) {
+        if (lastSafeSnapshot != null) {
+            lastSafeSnapshot = snapshotId;
+        }
+    }
+
+    private void checkStrictMode(
+            long newSnapshotId,
+            CommitKind newCommitKind,
+            List<BinaryRow> newChangedPartitions,
+            Set<Long> rebasedReassignments) {
+        Set<BinaryRow> newPartitions = new HashSet<>(newChangedPartitions);
+        for (long id = lastSafeSnapshot + 1; id < newSnapshotId; id++) {
+            if ((newCommitKind == CommitKind.COMPACT || newCommitKind == 
CommitKind.APPEND)
+                    && rebasedReassignments.contains(id)) {
+                continue;
+            }
+            Snapshot snapshot = snapshotManager.snapshot(id);
+            if (snapshot.commitUser().equals(commitUser)) {
+                continue;
+            }
+            if (snapshot.commitKind() == CommitKind.COMPACT
+                    || snapshot.commitKind() == CommitKind.OVERWRITE) {
+                boolean hasOverlap = scanner.hasDataChanges(snapshot, 
newPartitions, false);
+                // OVERWRITE may contain logical changes represented only by 
deletion vectors,
+                // while an index-only COMPACT on a data evolution table does 
not change data.
+                if (!hasOverlap
+                        && (snapshot.commitKind() == CommitKind.OVERWRITE
+                                || !dataEvolutionEnabled)) {
+                    hasOverlap = scanner.hasIndexChanges(snapshot, 
newPartitions, false);
+                }
+                if (hasOverlap) {
+                    throw new RuntimeException(
+                            String.format(
+                                    "When trying to commit snapshot %d, "
+                                            + "commit user %s has found a %s 
snapshot (id: %d) by another user %s "
+                                            + "which modified the same 
partition. Giving up committing as %s is true.",
+                                    newSnapshotId,
+                                    commitUser,
+                                    snapshot.commitKind().name(),
+                                    id,
+                                    snapshot.commitUser(),
+                                    
CoreOptions.COMMIT_STRICT_MODE_ENABLED.key()));
+                }
+            }
+            if (snapshot.commitKind() == CommitKind.APPEND
+                    && newCommitKind == CommitKind.OVERWRITE
+                    && scanner.hasDataChanges(snapshot, newPartitions, true)) {
+                throw new RuntimeException(
+                        String.format(
+                                "When trying to commit snapshot %d, "
+                                        + "commit user %s has found a APPEND 
snapshot (id: %d) by another user %s "
+                                        + "which committed files to fixed 
bucket on the same partition. "
+                                        + "Giving up committing as %s is 
true.",
+                                newSnapshotId,
+                                commitUser,
+                                id,
+                                snapshot.commitUser(),
+                                CoreOptions.COMMIT_STRICT_MODE_ENABLED.key()));
+            }
+        }
+    }
+
+    private void checkBucketCompaction(
+            long newSnapshotId, Map<Pair<BinaryRow, Integer>, Long> 
baseSnapshots) {
+        Map<Pair<BinaryRow, Integer>, Range> ranges = new HashMap<>();
+        for (Map.Entry<Pair<BinaryRow, Integer>, Long> entry : 
baseSnapshots.entrySet()) {
+            long base = entry.getValue();
+            Range checked = checkedCompactionSnapshots.get(entry.getKey());
+            // A newer writer may have skipped an earlier conflicting COMPACT. 
Its checked
+            // interval cannot be reused for a subsequently received older 
writer state.
+            ranges.put(
+                    entry.getKey(),
+                    checked != null && checked.from <= base && base <= 
checked.to
+                            ? checked
+                            : new Range(base, base));
+        }
+        long firstSnapshot =
+                ranges.values().stream().mapToLong(range -> 
range.to).min().getAsLong() + 1;
+        for (long id = firstSnapshot; id < newSnapshotId; id++) {
+            Snapshot snapshot = snapshotManager.snapshot(id);
+            if (snapshot.commitUser().equals(commitUser)
+                    || (snapshot.commitKind() != CommitKind.COMPACT
+                            && snapshot.commitKind() != CommitKind.OVERWRITE)) 
{
+                continue;
+            }
+            Set<Pair<BinaryRow, Integer>> buckets = new HashSet<>();
+            for (Map.Entry<Pair<BinaryRow, Integer>, Range> entry : 
ranges.entrySet()) {
+                if (entry.getValue().to < id) {
+                    buckets.add(entry.getKey());
+                }
+            }
+            if (scanner.hasDataChangesInBuckets(snapshot, buckets)
+                    || scanner.hasIndexChangesInBuckets(snapshot, buckets)) {
+                throw new RuntimeException(
+                        String.format(
+                                "Concurrent compaction conflict when 
committing snapshot %d: "
+                                        + "%s snapshot %d by user %s modified 
the same partition and bucket "
+                                        + "after this writer restored its 
state. Reload the bucket "
+                                        + "and recompute compaction.",
+                                newSnapshotId, snapshot.commitKind(), id, 
snapshot.commitUser()));
+            }
+        }
+        // Only cache a fully verified interval. Publishing may still fail 
afterwards, but a
+        // retry must inspect all snapshots committed after this verified 
endpoint.
+        ranges.forEach(
+                (bucket, range) ->
+                        checkedCompactionSnapshots.put(
+                                Pair.of(bucket.getLeft().copy(), 
bucket.getRight()),
+                                new Range(range.from, newSnapshotId - 1)));
+    }
+
+    private static boolean changesDataOrDeletionVectors(CompactIncrement 
compact) {
+        if (Stream.concat(compact.newIndexFiles().stream(), 
compact.deletedIndexFiles().stream())
+                .anyMatch(file -> 
DELETION_VECTORS_INDEX.equals(file.indexType()))) {
+            return true;
+        }
+        List<DataFileMeta> before = compact.compactBefore();
+        List<DataFileMeta> after = compact.compactAfter();
+        if (before.isEmpty() && after.isEmpty()) {
+            return false;
+        }
+        // File index rewrites replace only index metadata on a single file. 
Level upgrades
+        // keep the same file name too, but change the data layout and still 
need validation.
+        return before.size() != 1
+                || after.size() != 1
+                || !before.get(0).fileName().equals(after.get(0).fileName())
+                || 
!withoutFileIndex(before.get(0)).equals(withoutFileIndex(after.get(0)));
+    }
+
+    private static DataFileMeta withoutFileIndex(DataFileMeta file) {
+        List<String> otherExtraFiles =
+                file.extraFiles().stream()
+                        .filter(name -> 
!name.endsWith(DataFilePathFactory.INDEX_PATH_SUFFIX))
+                        .collect(Collectors.toList());
+        return file.copy(otherExtraFiles).copy((byte[]) null);
+    }
+}
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/commit/StrictModeChecker.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/commit/StrictModeChecker.java
deleted file mode 100644
index cfb700982b..0000000000
--- 
a/paimon-core/src/main/java/org/apache/paimon/operation/commit/StrictModeChecker.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.paimon.operation.commit;
-
-import org.apache.paimon.CoreOptions;
-import org.apache.paimon.Snapshot;
-import org.apache.paimon.Snapshot.CommitKind;
-import org.apache.paimon.data.BinaryRow;
-import org.apache.paimon.manifest.IndexManifestEntry;
-import org.apache.paimon.manifest.IndexManifestFile;
-import org.apache.paimon.manifest.ManifestEntry;
-import org.apache.paimon.operation.FileStoreScan;
-import org.apache.paimon.table.source.ScanMode;
-import org.apache.paimon.utils.SnapshotManager;
-
-import javax.annotation.Nullable;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
-import java.util.function.Supplier;
-
-/** A checker to check strict mode based on last safe snapshot. */
-public class StrictModeChecker {
-
-    private final SnapshotManager snapshotManager;
-    private final String commitUser;
-    private final Supplier<FileStoreScan> scanSupplier;
-    private final IndexManifestFile indexManifestFile;
-    private final boolean dataEvolutionEnabled;
-
-    private long lastSafeSnapshot;
-
-    public StrictModeChecker(
-            SnapshotManager snapshotManager,
-            String commitUser,
-            Supplier<FileStoreScan> scanSupplier,
-            IndexManifestFile indexManifestFile,
-            boolean dataEvolutionEnabled,
-            long lastSafeSnapshot) {
-        this.snapshotManager = snapshotManager;
-        this.commitUser = commitUser;
-        this.scanSupplier = scanSupplier;
-        this.indexManifestFile = indexManifestFile;
-        this.dataEvolutionEnabled = dataEvolutionEnabled;
-        this.lastSafeSnapshot = lastSafeSnapshot;
-    }
-
-    public void check(
-            long newSnapshotId,
-            CommitKind newCommitKind,
-            List<BinaryRow> newChangedPartitions,
-            Set<Long> rebasedReassignments) {
-        Set<BinaryRow> newPartitions = new HashSet<>(newChangedPartitions);
-        for (long id = lastSafeSnapshot + 1; id < newSnapshotId; id++) {
-            if ((newCommitKind == CommitKind.COMPACT || newCommitKind == 
CommitKind.APPEND)
-                    && rebasedReassignments.contains(id)) {
-                continue;
-            }
-            Snapshot snapshot = snapshotManager.snapshot(id);
-            if (snapshot.commitUser().equals(commitUser)) {
-                continue;
-            }
-            if (snapshot.commitKind() == CommitKind.COMPACT
-                    || snapshot.commitKind() == CommitKind.OVERWRITE) {
-                boolean hasOverlap = hasOverlappedDataPartition(snapshot, 
newPartitions);
-                // OVERWRITE may contain logical changes represented only by 
deletion vectors,
-                // while an index-only COMPACT on a data evolution table does 
not change data.
-                if (!hasOverlap
-                        && (snapshot.commitKind() == CommitKind.OVERWRITE
-                                || !dataEvolutionEnabled)) {
-                    hasOverlap = hasOverlappedIndexPartition(snapshot, 
newPartitions);
-                }
-                if (hasOverlap) {
-                    throw new RuntimeException(
-                            String.format(
-                                    "When trying to commit snapshot %d, "
-                                            + "commit user %s has found a %s 
snapshot (id: %d) by another user %s "
-                                            + "which modified the same 
partition. Giving up committing as %s is true.",
-                                    newSnapshotId,
-                                    commitUser,
-                                    snapshot.commitKind().name(),
-                                    id,
-                                    snapshot.commitUser(),
-                                    
CoreOptions.COMMIT_STRICT_MODE_ENABLED.key()));
-                }
-            }
-            if (snapshot.commitKind() == CommitKind.APPEND
-                    && newCommitKind == CommitKind.OVERWRITE) {
-                Iterator<ManifestEntry> entries =
-                        scanSupplier
-                                .get()
-                                .withSnapshot(snapshot)
-                                .withKind(ScanMode.DELTA)
-                                .onlyReadRealBuckets()
-                                .dropStats()
-                                .readFileIterator();
-                if (hasOverlappedPartition(entries, newPartitions)) {
-                    throw new RuntimeException(
-                            String.format(
-                                    "When trying to commit snapshot %d, "
-                                            + "commit user %s has found a 
APPEND snapshot (id: %d) by another user %s "
-                                            + "which committed files to fixed 
bucket on the same partition. "
-                                            + "Giving up committing as %s is 
true.",
-                                    newSnapshotId,
-                                    commitUser,
-                                    id,
-                                    snapshot.commitUser(),
-                                    
CoreOptions.COMMIT_STRICT_MODE_ENABLED.key()));
-                }
-            }
-        }
-    }
-
-    private boolean hasOverlappedDataPartition(Snapshot snapshot, 
Set<BinaryRow> newPartitions) {
-        if (newPartitions.isEmpty()) {
-            return false;
-        }
-        Iterator<ManifestEntry> entries =
-                scanSupplier
-                        .get()
-                        .withSnapshot(snapshot)
-                        .withKind(ScanMode.DELTA)
-                        .dropStats()
-                        .readFileIterator();
-        return hasOverlappedPartition(entries, newPartitions);
-    }
-
-    private boolean hasOverlappedIndexPartition(Snapshot snapshot, 
Set<BinaryRow> newPartitions) {
-        if (newPartitions.isEmpty()) {
-            return false;
-        }
-        String indexManifest = snapshot.indexManifest();
-        // Fast exit: if this snapshot's indexManifest file name equals the
-        // previous snapshot's, no index file was added/removed by this commit
-        // (writeIndexFiles reuses the previous file when newIndexFiles is 
empty).
-        String prevIndexManifest = null;
-        long prevId = snapshot.id() - 1;
-        if (snapshotManager.snapshotExists(prevId)) {
-            prevIndexManifest = 
snapshotManager.snapshot(prevId).indexManifest();
-        }
-        if (Objects.equals(indexManifest, prevIndexManifest)) {
-            return false;
-        }
-        // Count only the index entries this commit added, replaced or removed 
relative to
-        // the previous snapshot (every entry if that snapshot is gone). 
Removals matter
-        // because an OVERWRITE such as rollbackToAsLatest can drop a DV entry 
without any
-        // data-file delta.
-        Set<IndexManifestEntry> previousEntries =
-                readEntriesInPartitions(prevIndexManifest, newPartitions);
-        for (IndexManifestEntry entry : readEntriesInPartitions(indexManifest, 
newPartitions)) {
-            if (!previousEntries.remove(entry)) {
-                return true;
-            }
-        }
-        return !previousEntries.isEmpty();
-    }
-
-    private Set<IndexManifestEntry> readEntriesInPartitions(
-            @Nullable String indexManifest, Set<BinaryRow> partitions) {
-        Set<IndexManifestEntry> entries = new HashSet<>();
-        if (indexManifest != null) {
-            for (IndexManifestEntry entry : 
indexManifestFile.read(indexManifest)) {
-                if (partitions.contains(entry.partition())) {
-                    entries.add(entry);
-                }
-            }
-        }
-        return entries;
-    }
-
-    private boolean hasOverlappedPartition(
-            Iterator<ManifestEntry> entries, Set<BinaryRow> newPartitions) {
-        if (newPartitions.isEmpty()) {
-            return false;
-        }
-        while (entries.hasNext()) {
-            ManifestEntry entry = entries.next();
-            if (newPartitions.contains(entry.partition())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public void update(long newSafeSnapshot) {
-        lastSafeSnapshot = newSafeSnapshot;
-    }
-}
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/postpone/BucketFiles.java 
b/paimon-core/src/main/java/org/apache/paimon/postpone/BucketFiles.java
index d019de4421..095e079efc 100644
--- a/paimon-core/src/main/java/org/apache/paimon/postpone/BucketFiles.java
+++ b/paimon-core/src/main/java/org/apache/paimon/postpone/BucketFiles.java
@@ -45,6 +45,7 @@ public class BucketFiles {
     private final FileIO fileIO;
 
     private @Nullable Integer totalBuckets;
+    private @Nullable Long checkFromSnapshot;
     private final Map<String, DataFileMeta> newFiles;
     private final List<DataFileMeta> compactBefore;
     private final List<DataFileMeta> compactAfter;
@@ -66,6 +67,10 @@ public class BucketFiles {
 
     public void update(CommitMessageImpl message) {
         totalBuckets = message.totalBuckets();
+        Long snapshotId = message.checkFromSnapshot();
+        if (snapshotId != null && (checkFromSnapshot == null || snapshotId < 
checkFromSnapshot)) {
+            checkFromSnapshot = snapshotId;
+        }
 
         for (DataFileMeta file : message.newFilesIncrement().newFiles()) {
             newFiles.put(file.fileName(), file);
@@ -110,6 +115,7 @@ public class BucketFiles {
                         realCompactAfter,
                         changelogFiles,
                         newIndexFiles,
-                        deletedIndexFiles));
+                        deletedIndexFiles),
+                checkFromSnapshot);
     }
 }
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/table/sink/CommitMessage.java 
b/paimon-core/src/main/java/org/apache/paimon/table/sink/CommitMessage.java
index 3b71a9f9b6..133449fef8 100644
--- a/paimon-core/src/main/java/org/apache/paimon/table/sink/CommitMessage.java
+++ b/paimon-core/src/main/java/org/apache/paimon/table/sink/CommitMessage.java
@@ -44,7 +44,8 @@ public interface CommitMessage extends Serializable {
     Integer totalBuckets();
 
     /**
-     * Snapshot used to read rows before producing this message, if row-id 
conflicts need checking.
+     * Writer's base snapshot, or the operation's read snapshot for a Data 
Evolution row-id conflict
+     * check.
      */
     @Nullable
     default Long checkFromSnapshot() {
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/index/pksorted/PrimaryKeySortedIndexMaintenanceTest.java
 
b/paimon-core/src/test/java/org/apache/paimon/index/pksorted/PrimaryKeySortedIndexMaintenanceTest.java
index 788f310e94..12a80864f1 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/index/pksorted/PrimaryKeySortedIndexMaintenanceTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/index/pksorted/PrimaryKeySortedIndexMaintenanceTest.java
@@ -37,8 +37,6 @@ import org.apache.paimon.index.pk.PrimaryKeyIndexSourceMeta;
 import org.apache.paimon.index.pk.PrimaryKeyIndexSourcePolicy;
 import org.apache.paimon.io.DataFileMeta;
 import org.apache.paimon.manifest.ManifestCommittable;
-import org.apache.paimon.memory.HeapMemorySegmentPool;
-import org.apache.paimon.memory.MemoryOwner;
 import org.apache.paimon.mergetree.compact.DeduplicateMergeFunction;
 import org.apache.paimon.mergetree.compact.LookupMergeFunction;
 import org.apache.paimon.operation.AbstractFileStoreWrite;
@@ -48,13 +46,10 @@ import org.apache.paimon.schema.Schema;
 import org.apache.paimon.schema.SchemaManager;
 import org.apache.paimon.schema.TableSchema;
 import org.apache.paimon.table.sink.CommitMessage;
-import org.apache.paimon.table.sink.CommitMessageImpl;
 import org.apache.paimon.types.DataField;
 import org.apache.paimon.types.DataTypes;
 import org.apache.paimon.types.RowType;
-import org.apache.paimon.utils.CommitIncrement;
 import org.apache.paimon.utils.InternalRowUtils;
-import org.apache.paimon.utils.RecordWriter;
 
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
@@ -188,59 +183,28 @@ class PrimaryKeySortedIndexMaintenanceTest {
             long identifier)
             throws Exception {
         AbstractFileStoreWrite<KeyValue> write = store.newWrite();
-        write.withIOManager(ioManager);
-        AbstractFileStoreWrite.WriterContainer<KeyValue> container =
-                write.createWriterContainer(partition, bucket);
-        RecordWriter<KeyValue> writer = container.writer;
-        ((MemoryOwner) writer)
-                .setMemoryPool(
-                        new HeapMemorySegmentPool(
-                                TestFileStore.WRITE_BUFFER_SIZE.getBytes(),
-                                (int) TestFileStore.PAGE_SIZE.getBytes()));
-        for (KeyValue record : records) {
-            writer.write(record);
+        try {
+            write.withIOManager(ioManager);
+            for (KeyValue record : records) {
+                write.write(partition, bucket, record);
+            }
+            commit(store, write.prepareCommit(true, identifier), identifier);
+        } finally {
+            write.close();
         }
-        commit(
-                store,
-                Collections.singletonList(prepareCommit(container, partition, 
bucket)),
-                identifier);
-        container.writer.close();
-        container.primaryKeyIndexMaintainer.close();
-        write.close();
     }
 
     private void compactAndCommit(
             TestFileStore store, BinaryRow partition, int bucket, long 
identifier)
             throws Exception {
         AbstractFileStoreWrite<KeyValue> write = store.newWrite();
-        write.withIOManager(ioManager);
-        AbstractFileStoreWrite.WriterContainer<KeyValue> container =
-                write.createWriterContainer(partition, bucket);
-        ((MemoryOwner) container.writer)
-                .setMemoryPool(
-                        new HeapMemorySegmentPool(
-                                TestFileStore.WRITE_BUFFER_SIZE.getBytes(),
-                                (int) TestFileStore.PAGE_SIZE.getBytes()));
-        container.writer.compact(true);
-        commit(
-                store,
-                Collections.singletonList(prepareCommit(container, partition, 
bucket)),
-                identifier);
-        container.writer.close();
-        container.primaryKeyIndexMaintainer.close();
-        write.close();
-    }
-
-    private CommitMessage prepareCommit(
-            AbstractFileStoreWrite.WriterContainer<KeyValue> container,
-            BinaryRow partition,
-            int bucket)
-            throws Exception {
-        CommitIncrement increment = container.writer.prepareCommit(true);
-        container.primaryKeyIndexMaintainer.prepareCommit(
-                increment.newFilesIncrement(), increment.compactIncrement(), 
true);
-        return new CommitMessageImpl(
-                partition, bucket, 1, increment.newFilesIncrement(), 
increment.compactIncrement());
+        try {
+            write.withIOManager(ioManager);
+            write.compact(partition, bucket, true);
+            commit(store, write.prepareCommit(true, identifier), identifier);
+        } finally {
+            write.close();
+        }
     }
 
     private void commit(TestFileStore store, List<CommitMessage> messages, 
long identifier) {
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/operation/PrimaryKeyDvConcurrentCompactionTest.java
 
b/paimon-core/src/test/java/org/apache/paimon/operation/PrimaryKeyDvConcurrentCompactionTest.java
new file mode 100644
index 0000000000..c4a4765a87
--- /dev/null
+++ 
b/paimon-core/src/test/java/org/apache/paimon/operation/PrimaryKeyDvConcurrentCompactionTest.java
@@ -0,0 +1,928 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.operation;
+
+import org.apache.paimon.KeyValue;
+import org.apache.paimon.KeyValueFileStore;
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.catalog.RenamingSnapshotCommit;
+import org.apache.paimon.catalog.SnapshotCommit;
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.deletionvectors.BitmapDeletionVector;
+import org.apache.paimon.disk.IOManager;
+import org.apache.paimon.disk.IOManagerImpl;
+import org.apache.paimon.fs.Path;
+import org.apache.paimon.fs.local.LocalFileIO;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.io.CompactIncrement;
+import org.apache.paimon.io.DataFileMeta;
+import org.apache.paimon.io.DataIncrement;
+import org.apache.paimon.manifest.ManifestCommittable;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.operation.commit.ConflictDetection;
+import org.apache.paimon.partition.PartitionStatistics;
+import org.apache.paimon.reader.RecordReaderIterator;
+import org.apache.paimon.schema.FileSystemSchemaManager;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.table.FileStoreTableFactory;
+import org.apache.paimon.table.PrimaryKeyFileStoreTable;
+import org.apache.paimon.table.sink.BatchTableCommit;
+import org.apache.paimon.table.sink.BatchTableWrite;
+import org.apache.paimon.table.sink.BatchWriteBuilder;
+import org.apache.paimon.table.sink.CommitMessage;
+import org.apache.paimon.table.sink.CommitMessageImpl;
+import org.apache.paimon.table.sink.CommitMessageSerializer;
+import org.apache.paimon.table.source.Split;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.RowKind;
+import org.apache.paimon.types.RowType;
+import org.apache.paimon.utils.IOUtils;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+import static org.apache.paimon.CoreOptions.COMMIT_LAST_SAFE_SNAPSHOT;
+import static 
org.apache.paimon.deletionvectors.DeletionVectorsIndexFile.DELETION_VECTORS_INDEX;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** Bucket isolation for automatic compaction of primary-key tables with 
deletion vectors. */
+class PrimaryKeyDvConcurrentCompactionTest {
+
+    @TempDir java.nio.file.Path tempDir;
+
+    private final List<AutoCloseable> resources = new ArrayList<>();
+    private PrimaryKeyFileStoreTable table;
+    private KeyValueFileStore store;
+    private IOManager ioManager;
+
+    @BeforeEach
+    void before() throws Exception {
+        Map<String, String> options = new HashMap<>();
+        options.put("bucket", "2");
+        options.put("file.format", "avro");
+        options.put("deletion-vectors.enabled", "true");
+        options.put("num-levels", "4");
+        options.put("num-sorted-run.compaction-trigger", "100");
+        options.put("target-file-size", "10 mb");
+        options.put("write-buffer-size", "1 mb");
+        options.put("page-size", "4 kb");
+        options.put("commit.min-retry-wait", "0 ms");
+        Path path = new Path(tempDir.toUri());
+        RowType type =
+                RowType.of(
+                        new DataType[] {DataTypes.INT(), DataTypes.INT(), 
DataTypes.STRING()},
+                        new String[] {"p", "id", "v"});
+        new FileSystemSchemaManager(LocalFileIO.create(), path)
+                .createTable(
+                        new Schema(
+                                type.getFields(),
+                                Collections.singletonList("p"),
+                                Arrays.asList("p", "id"),
+                                options,
+                                null));
+        table = (PrimaryKeyFileStoreTable) 
FileStoreTableFactory.create(LocalFileIO.create(), path);
+        store = table.store();
+        assertThat(store.options().writeOnly()).isFalse();
+        ioManager = new IOManagerImpl(tempDir.resolve("spill").toString());
+        resources.add(ioManager);
+    }
+
+    @AfterEach
+    void after() throws Exception {
+        IOUtils.closeAll(resources);
+    }
+
+    @Test
+    void testSameBucketCompactionConflicts() throws Exception {
+        seed(1, 0);
+        CommitMessageImpl first = prepare(newWrite("first"), 1, 0, 1);
+        CommitMessageImpl second = prepare(newWrite("second"), 1, 0, 2);
+
+        commit("first", first);
+        assertConflict(newCommit("second"), second);
+        assertThat(values(1, 1)).containsExactly("new");
+        assertThat(values(1, 2)).containsExactly("old");
+    }
+
+    @Test
+    void testSamePartitionDifferentBucketsCompactIndependently() throws 
Exception {
+        seed(1, 0);
+        seed(1, 1);
+        AbstractFileStoreWrite<KeyValue> firstWrite = newWrite("first");
+        AbstractFileStoreWrite<KeyValue> secondWrite = newWrite("second");
+        CommitMessageImpl first = prepare(firstWrite, 1, 0, 1);
+        CommitMessageImpl second = prepare(secondWrite, 1, 1, 1001);
+        
assertThat(first.checkFromSnapshot()).isEqualTo(second.checkFromSnapshot());
+
+        FileStoreCommitImpl firstCommit = newCommit("first");
+        FileStoreCommitImpl secondCommit = newCommit("second");
+        commit(firstCommit, 0, first);
+        BinaryRow partition = BinaryRow.singleColumn(1);
+        List<IndexFileMeta> firstIndexes =
+                store.newIndexFileHandler()
+                        .scan(
+                                store.snapshotManager().latestSnapshot(),
+                                DELETION_VECTORS_INDEX,
+                                partition,
+                                0);
+        assertThat(firstIndexes).isNotEmpty();
+
+        commit(secondCommit, 0, second);
+        Snapshot latest = store.snapshotManager().latestSnapshot();
+        assertThat(store.newIndexFileHandler().scan(latest, 
DELETION_VECTORS_INDEX, partition, 0))
+                .containsExactlyElementsOf(firstIndexes);
+        assertThat(store.newIndexFileHandler().scan(latest, 
DELETION_VECTORS_INDEX, partition, 1))
+                .isNotEmpty()
+                
.containsExactlyElementsOf(second.compactIncrement().newIndexFiles());
+        assertThat(values(1, 1)).containsExactly("new");
+        assertThat(values(1, 1001)).containsExactly("new");
+
+        commit(firstCommit, 1, prepare(firstWrite, 1, 0, 2));
+        assertThat(values(1, 1)).containsExactly("new");
+        assertThat(values(1, 2)).containsExactly("new");
+        assertThat(values(1, 1001)).containsExactly("new");
+    }
+
+    @Test
+    void testStrictModeStillChecksOtherBucketsInThePartition() throws 
Exception {
+        seed(1, 0);
+        seed(1, 1);
+        CommitMessageImpl pending = prepare(newWrite("second"), 1, 0, 2);
+        commit("first", prepare(newWrite("first"), 1, 1, 1001));
+        KeyValueFileStore strictStore =
+                ((PrimaryKeyFileStoreTable)
+                                table.copy(
+                                        Collections.singletonMap(
+                                                
COMMIT_LAST_SAFE_SNAPSHOT.key(),
+                                                
String.valueOf(pending.checkFromSnapshot()))))
+                        .store();
+
+        try (FileStoreCommitImpl second = strictStore.newCommit("second", 
null)) {
+            assertThatThrownBy(() -> commit(second, 0, pending))
+                    .hasMessageContaining("commit.strict-mode.enabled");
+        }
+        assertThat(values(1, 2)).containsExactly("old");
+        assertThat(values(1, 1001)).containsExactly("new");
+    }
+
+    @Test
+    void testDifferentPartitionsCompactIndependently() throws Exception {
+        seed(1, 0);
+        seed(2, 0);
+        AbstractFileStoreWrite<KeyValue> secondWrite = newWrite("second");
+        CommitMessageImpl first = prepare(newWrite("first"), 1, 0, 1);
+        CommitMessageImpl second = prepare(secondWrite, 2, 0, 1);
+
+        commit("first", first);
+        FileStoreCommitImpl secondCommit = newCommit("second");
+        commit(secondCommit, 0, second);
+        assertThat(values(1, 1)).containsExactly("new");
+        assertThat(values(2, 1)).containsExactly("new");
+
+        // A retained writer can keep compacting its own partition after its 
previous commit.
+        CommitMessageImpl next = prepare(secondWrite, 2, 0, 2);
+        commit(secondCommit, 1, next);
+        assertThat(values(2, 2)).containsExactly("new");
+    }
+
+    @ParameterizedTest
+    @ValueSource(ints = {0, 1})
+    void testCompactionWithoutDvChangesUsesBucketIsolation(int otherBucket) 
throws Exception {
+        seed(1, 0);
+        if (otherBucket != 0) {
+            seed(1, otherBucket);
+        }
+        CommitMessageImpl second = prepare(newWrite("second"), 1, 0, 2);
+        KeyValueFileStore fullCompactStore =
+                ((PrimaryKeyFileStoreTable)
+                                table.copy(
+                                        Collections.singletonMap(
+                                                
"compaction.total-size-threshold", "100 mb")))
+                        .store();
+        int firstKey = 2001 + 1000 * otherBucket;
+        CommitMessageImpl first =
+                prepare(newWrite("first", fullCompactStore), 1, otherBucket, 
firstKey);
+        assertThat(first.compactIncrement().newIndexFiles()).isEmpty();
+        assertThat(first.compactIncrement().compactBefore()).anyMatch(file -> 
file.level() == 3);
+
+        commit("first", first);
+        if (otherBucket == 0) {
+            assertConflict(newCommit("second"), second);
+            assertThat(values(1, 2)).containsExactly("old");
+        } else {
+            commit("second", second);
+            assertThat(values(1, 2)).containsExactly("new");
+        }
+        assertThat(values(1, firstKey)).containsExactly("new");
+    }
+
+    @Test
+    void testPartitionsUseTheirOwnRestoredSnapshots() throws Exception {
+        seed(1, 0);
+        seed(2, 0);
+        AbstractFileStoreWrite<KeyValue> second = newWrite("second");
+        second.write(BinaryRow.singleColumn(1), 0, kv(1, 2, "new"));
+        commit("first", prepare(newWrite("first"), 2, 0, 1));
+
+        second.write(BinaryRow.singleColumn(2), 0, kv(2, 2, "new"));
+        List<CommitMessage> messages = second.prepareCommit(true, 0);
+        assertThat(messages).hasSize(2);
+        
assertThat(messages.stream().map(CommitMessage::checkFromSnapshot).distinct()).hasSize(2);
+        commit(newCommit("second"), 0, messages);
+        assertThat(values(1, 2)).containsExactly("new");
+        assertThat(values(2, 1)).containsExactly("new");
+        assertThat(values(2, 2)).containsExactly("new");
+    }
+
+    @Test
+    void testBucketsUseTheirOwnRestoredSnapshots() throws Exception {
+        seed(1, 0);
+        seed(1, 1);
+        AbstractFileStoreWrite<KeyValue> second = newWrite("second");
+        second.write(BinaryRow.singleColumn(1), 0, kv(1, 2, "new"));
+        commit("first", prepare(newWrite("first"), 1, 1, 1001));
+
+        second.write(BinaryRow.singleColumn(1), 1, kv(1, 1002, "new"));
+        List<CommitMessage> messages = second.prepareCommit(true, 0);
+        assertThat(messages).hasSize(2);
+        
assertThat(messages.stream().map(CommitMessage::checkFromSnapshot).distinct()).hasSize(2);
+        commit(newCommit("second"), 0, messages);
+        assertThat(values(1, 2)).containsExactly("new");
+        assertThat(values(1, 1001)).containsExactly("new");
+        assertThat(values(1, 1002)).containsExactly("new");
+    }
+
+    @Test
+    void testCompactionWithoutRestoredSnapshotIsRejected() throws Exception {
+        seed(1, 0);
+        CommitMessageImpl message = prepare(newWrite("second"), 1, 0, 2);
+        CommitMessageImpl unchecked =
+                new CommitMessageImpl(
+                        message.partition(),
+                        message.bucket(),
+                        message.totalBuckets(),
+                        message.newFilesIncrement(),
+                        message.compactIncrement());
+        long before = store.snapshotManager().latestSnapshotId();
+        assertThatThrownBy(() -> commit("second", unchecked))
+                .hasMessageContaining("missing its restored snapshot");
+        
assertThat(store.snapshotManager().latestSnapshotId()).isEqualTo(before);
+    }
+
+    @Test
+    void testFileIndexRewriteDoesNotRequireCompactionBaseline() throws 
Exception {
+        seed(1, 0);
+        BinaryRow partition = BinaryRow.singleColumn(1);
+        DataFileMeta file =
+                store.newScan().withPartitionBucket(partition, 
0).plan().files().get(0).file();
+        DataFileMeta indexedFile = file.copy(new byte[] {1});
+        commit(
+                "rewrite-index",
+                new CommitMessageImpl(
+                        partition,
+                        0,
+                        2,
+                        DataIncrement.emptyIncrement(),
+                        new CompactIncrement(
+                                Collections.singletonList(file),
+                                Collections.singletonList(indexedFile),
+                                Collections.emptyList())));
+
+        assertThat(store.newScan().withPartitionBucket(partition, 
0).plan().files())
+                .extracting(ManifestEntry::file)
+                .containsExactly(indexedFile);
+    }
+
+    @Test
+    void testSameFileLevelUpgradeRequiresBaseline() throws Exception {
+        seed(1, 0, 2);
+        BinaryRow partition = BinaryRow.singleColumn(1);
+        DataFileMeta file =
+                store.newScan().withPartitionBucket(partition, 
0).plan().files().get(0).file();
+        CommitMessageImpl message =
+                new CommitMessageImpl(
+                        partition,
+                        0,
+                        2,
+                        DataIncrement.emptyIncrement(),
+                        new CompactIncrement(
+                                Collections.singletonList(file),
+                                Collections.singletonList(file.upgrade(3)),
+                                Collections.emptyList()));
+
+        assertThatThrownBy(() -> commit("second", message))
+                .hasMessageContaining("missing its restored snapshot");
+        assertThat(store.newScan().withPartitionBucket(partition, 
0).plan().files())
+                .extracting(ManifestEntry::file)
+                .containsExactly(file);
+    }
+
+    @Test
+    void testChangelogOnlyCompactionDoesNotRequireBaseline() throws Exception {
+        seed(1, 0);
+        KeyValueFileStore lookupStore =
+                ((PrimaryKeyFileStoreTable)
+                                table.copy(
+                                        
Collections.singletonMap("changelog-producer", "lookup")))
+                        .store();
+        CommitMessageImpl prepared = prepare(newWrite("second", lookupStore), 
1, 0, 1);
+        List<DataFileMeta> changelogFiles = 
prepared.compactIncrement().changelogFiles();
+        assertThat(changelogFiles).isNotEmpty();
+
+        commit(
+                "second",
+                new CommitMessageImpl(
+                        prepared.partition(),
+                        prepared.bucket(),
+                        prepared.totalBuckets(),
+                        DataIncrement.emptyIncrement(),
+                        new CompactIncrement(
+                                Collections.emptyList(), 
Collections.emptyList(), changelogFiles)));
+
+        Snapshot snapshot = store.snapshotManager().latestSnapshot();
+        
assertThat(snapshot.commitKind()).isEqualTo(Snapshot.CommitKind.COMPACT);
+        assertThat(snapshot.changelogManifestList()).isNotNull();
+        assertThat(values(1, 1)).containsExactly("old");
+    }
+
+    @Test
+    void testDeletionVectorOnlyCompactionRequiresBaseline() throws Exception {
+        seed(1, 0);
+        BinaryRow partition = BinaryRow.singleColumn(1);
+        DataFileMeta file =
+                store.newScan().withPartitionBucket(partition, 
0).plan().files().get(0).file();
+        BitmapDeletionVector dv = new BitmapDeletionVector();
+        dv.delete(0);
+        IndexFileMeta index =
+                store.newIndexFileHandler()
+                        .dvIndex(partition, 0)
+                        
.writeSingleFile(Collections.singletonMap(file.fileName(), dv));
+        CommitMessageImpl message =
+                new CommitMessageImpl(
+                        partition,
+                        0,
+                        2,
+                        DataIncrement.emptyIncrement(),
+                        new CompactIncrement(
+                                Collections.emptyList(),
+                                Collections.emptyList(),
+                                Collections.emptyList(),
+                                Collections.singletonList(index),
+                                Collections.emptyList()));
+
+        assertThatThrownBy(() -> commit("second", message))
+                .hasMessageContaining("missing its restored snapshot");
+        assertThat(values(1, 1)).containsExactly("old");
+    }
+
+    @Test
+    void testPartitionOverwriteInvalidatesCompaction() throws Exception {
+        seed(1, 0);
+        CommitMessageImpl pending = prepare(newWrite("second"), 1, 0, 2);
+        newCommit("first")
+                
.dropPartitions(Collections.singletonList(Collections.singletonMap("p", "1")), 
0);
+        assertThat(store.snapshotManager().latestSnapshot().commitKind())
+                .isEqualTo(Snapshot.CommitKind.OVERWRITE);
+
+        assertConflict(newCommit("second"), pending);
+        assertThat(values(1, 2)).isEmpty();
+    }
+
+    @Test
+    void testEmptyRestoreCannotSkipPublishedCompaction() throws Exception {
+        seed(1, 0);
+        int key = 2001;
+        commit("first", prepare(newWrite("first"), 1, 0, key));
+
+        AbstractFileStoreWrite<KeyValue> write = newWrite("second");
+        write.withWriteRestore(
+                new WriteRestore() {
+                    @Override
+                    public long latestCommittedIdentifier(String user) {
+                        return Long.MIN_VALUE;
+                    }
+
+                    @Override
+                    public RestoreFiles restoreFiles(
+                            BinaryRow partition,
+                            int bucket,
+                            boolean scanDynamicBucketIndex,
+                            boolean scanDeleteVectorsIndex,
+                            boolean scanSourceIndexPayloads) {
+                        return RestoreFiles.empty();
+                    }
+                });
+        CommitMessageImpl pending = prepare(write, 1, 0, key);
+        assertThat(pending.checkFromSnapshot()).isZero();
+        assertConflict(newCommit("second"), pending);
+        assertThat(values(1, key)).containsExactly("new");
+    }
+
+    @ParameterizedTest
+    @ValueSource(booleans = {false, true})
+    void testOverwriteCompactionUsesWriterCreationSnapshot(boolean concurrent) 
throws Exception {
+        seed(1, 0);
+        commit("first", prepare(newWrite("first"), 1, 0, 1));
+        long baseline = store.snapshotManager().latestSnapshotId();
+        BatchWriteBuilder overwrite =
+                
table.newBatchWriteBuilder().withOverwrite(Collections.singletonMap("p", "1"));
+        try (BatchTableWrite write = 
overwrite.newWrite().withIOManager(ioManager);
+                BatchTableCommit commit = overwrite.newCommit()) {
+            write.write(GenericRow.of(1, 2, 
BinaryString.fromString("replacement")));
+            if (concurrent) {
+                commit("concurrent", prepare(newWrite("concurrent"), 1, 0, 3));
+            }
+            List<CommitMessage> messages = write.prepareCommit();
+            assertThat(messages)
+                    .filteredOn(
+                            message -> !((CommitMessageImpl) 
message).compactIncrement().isEmpty())
+                    .extracting(CommitMessage::checkFromSnapshot)
+                    .containsExactly(baseline);
+            if (concurrent) {
+                assertThatThrownBy(() -> commit.commit(messages))
+                        .hasMessageContaining("Concurrent compaction 
conflict");
+                return;
+            }
+            commit.commit(messages);
+        }
+        assertThat(values(1, 1)).isEmpty();
+        assertThat(values(1, 2)).containsExactly("replacement");
+    }
+
+    @ParameterizedTest
+    @ValueSource(ints = {0, 1})
+    void testDeletionVectorRemovalUsesBucketIsolation(int changedBucket) 
throws Exception {
+        seed(1, 0);
+        if (changedBucket != 0) {
+            seed(1, changedBucket);
+        }
+        Snapshot beforeDelete = store.snapshotManager().latestSnapshot();
+        BinaryRow partition = BinaryRow.singleColumn(1);
+        DataFileMeta file =
+                store.newScan()
+                        .withPartitionBucket(partition, changedBucket)
+                        .plan()
+                        .files()
+                        .get(0)
+                        .file();
+        BitmapDeletionVector dv = new BitmapDeletionVector();
+        dv.delete(0);
+        IndexFileMeta index =
+                store.newIndexFileHandler()
+                        .dvIndex(partition, changedBucket)
+                        
.writeSingleFile(Collections.singletonMap(file.fileName(), dv));
+        commit(
+                "delete",
+                new CommitMessageImpl(
+                        partition,
+                        changedBucket,
+                        2,
+                        
DataIncrement.indexIncrement(Collections.singletonList(index)),
+                        CompactIncrement.emptyIncrement()));
+        int deletedKey = 1000 * changedBucket + 1;
+        assertThat(values(1, deletedKey)).isEmpty();
+        CommitMessageImpl pending = prepare(newWrite("second"), 1, 0, 1);
+        
assertThat(newCommit("rollback").rollbackToAsLatest(beforeDelete)).isTrue();
+        assertThat(values(1, deletedKey)).containsExactly("old");
+
+        if (changedBucket == 0) {
+            assertConflict(newCommit("second"), pending);
+            assertThat(values(1, 1)).containsExactly("old");
+        } else {
+            commit("second", pending);
+            assertThat(values(1, 1)).containsExactly("new");
+            assertThat(values(1, deletedKey)).containsExactly("old");
+        }
+    }
+
+    @ParameterizedTest
+    @CsvSource({"1, 0", "2, 0", "2, 1"})
+    void testIndexOnlyOverwriteUsesBucketIsolation(int changedPartition, int 
changedBucket)
+            throws Exception {
+        seed(1, 0);
+        seed(2, 0);
+        seed(2, 1);
+        CommitMessageImpl pending = prepare(newWrite("second"), 2, 0, 2);
+        BinaryRow partition = BinaryRow.singleColumn(changedPartition);
+        DataFileMeta file =
+                store.newScan()
+                        .withPartitionBucket(partition, changedBucket)
+                        .plan()
+                        .files()
+                        .get(0)
+                        .file();
+        BitmapDeletionVector dv = new BitmapDeletionVector();
+        dv.delete(0);
+        IndexFileMeta index =
+                store.newIndexFileHandler()
+                        .dvIndex(partition, changedBucket)
+                        
.writeSingleFile(Collections.singletonMap(file.fileName(), dv));
+        commit(
+                "first",
+                new CommitMessageImpl(
+                        partition,
+                        changedBucket,
+                        2,
+                        
DataIncrement.indexIncrement(Collections.singletonList(index)),
+                        CompactIncrement.emptyIncrement()));
+        assertThat(store.snapshotManager().latestSnapshot().commitKind())
+                .isEqualTo(Snapshot.CommitKind.OVERWRITE);
+
+        if (changedPartition == 2 && changedBucket == 0) {
+            assertConflict(newCommit("second"), pending);
+            assertThat(values(2, 2)).containsExactly("old");
+        } else {
+            commit("second", pending);
+            assertThat(values(2, 2)).containsExactly("new");
+        }
+        assertThat(values(changedPartition, 1000 * changedBucket + 
1)).isEmpty();
+    }
+
+    @Test
+    void testNewerWriterCheckDoesNotHideOlderBaselineConflict() throws 
Exception {
+        seed(1, 0);
+        CommitMessageImpl old = prepare(newWrite("second"), 1, 0, 2);
+        commit("first", prepare(newWrite("first"), 1, 0, 1));
+
+        FileStoreCommitImpl second = newCommit("second");
+        commit(second, 0, prepare(newWrite("second"), 1, 0, 3));
+        // A newer writer's verified interval does not cover the older 
writer's baseline.
+        assertConflict(second, old);
+        assertThat(values(1, 1)).containsExactly("new");
+        assertThat(values(1, 2)).containsExactly("old");
+        assertThat(values(1, 3)).containsExactly("new");
+    }
+
+    @Test
+    void testOtherBucketCommitDoesNotAdvancePendingBaseline() throws Exception 
{
+        seed(1, 0);
+        seed(1, 1);
+        AbstractFileStoreWrite<KeyValue> secondWrite = newWrite("second");
+        CommitMessageImpl pending = prepare(secondWrite, 1, 0, 2);
+        CommitMessageImpl otherBucket = prepare(secondWrite, 1, 1, 1001);
+        
assertThat(pending.checkFromSnapshot()).isEqualTo(otherBucket.checkFromSnapshot());
+        commit("first", prepare(newWrite("first"), 1, 0, 1));
+
+        FileStoreCommitImpl secondCommit = newCommit("second");
+        commit(secondCommit, 0, otherBucket);
+        assertThat(values(1, 1001)).containsExactly("new");
+        assertConflict(secondCommit, pending);
+        assertThat(values(1, 1)).containsExactly("new");
+        assertThat(values(1, 2)).containsExactly("old");
+    }
+
+    @Test
+    void testAppendDoesNotAdvanceCompactionBaseline() throws Exception {
+        seed(1, 0);
+        CommitMessageImpl first = prepare(newWrite("first"), 1, 0, 1);
+        CommitMessageImpl second = prepare(newWrite("second"), 1, 0, 2);
+        commit("first", first);
+
+        FileStoreCommitImpl secondCommit = newCommit("second");
+        CommitMessageImpl append =
+                new CommitMessageImpl(
+                        second.partition(),
+                        second.bucket(),
+                        second.totalBuckets(),
+                        second.newFilesIncrement(),
+                        CompactIncrement.emptyIncrement(),
+                        second.checkFromSnapshot());
+        commit(secondCommit, 0, append);
+        assertThat(store.snapshotManager().latestSnapshot().commitKind())
+                .isEqualTo(Snapshot.CommitKind.APPEND);
+
+        assertConflict(secondCommit, compactOnly(second));
+        assertThat(values(1, 1)).containsExactly("new");
+        assertThat(values(1, 2)).containsExactly("old");
+    }
+
+    @ParameterizedTest
+    @ValueSource(booleans = {false, true})
+    void testOtherPartitionCommitDoesNotAdvancePendingBaseline(boolean 
strictMode)
+            throws Exception {
+        seed(1, 0);
+        seed(2, 0);
+        AbstractFileStoreWrite<KeyValue> secondWrite = newWrite("second");
+        CommitMessageImpl pending = prepare(secondWrite, 1, 0, 2);
+        commit("first", prepare(newWrite("first"), 1, 0, 1));
+
+        Map<String, String> commitOptions =
+                strictMode
+                        ? Collections.singletonMap(
+                                COMMIT_LAST_SAFE_SNAPSHOT.key(),
+                                String.valueOf(pending.checkFromSnapshot()))
+                        : Collections.emptyMap();
+        KeyValueFileStore secondStore =
+                ((PrimaryKeyFileStoreTable) table.copy(commitOptions)).store();
+        try (FileStoreCommitImpl secondCommit = 
secondStore.newCommit("second", null)) {
+            CommitMessageImpl otherPartition = prepare(secondWrite, 2, 0, 1);
+            commit(secondCommit, 0, otherPartition);
+            assertThat(values(2, 1)).containsExactly("new");
+            assertConflict(secondCommit, pending);
+        }
+    }
+
+    @ParameterizedTest
+    @CsvSource({"false, 0", "true, 0", "true, 1"})
+    void testSnapshotRetryPreservesCompactionBaseline(boolean 
compactDuringRetry, int otherBucket)
+            throws Exception {
+        seed(1, 0);
+        if (otherBucket != 0) {
+            seed(1, otherBucket);
+        }
+        int firstKey = 1000 * otherBucket + 1;
+        CommitMessageImpl first = prepare(newWrite("first"), 1, otherBucket, 
firstKey);
+        CommitMessageImpl second = prepare(newWrite("second"), 1, 0, 2);
+        SnapshotCommit delegate = new 
RenamingSnapshotCommit(store.snapshotManager(), Lock.empty());
+        AtomicInteger attempts = new AtomicInteger();
+        SnapshotCommit publisher =
+                new SnapshotCommit(Lock.empty()) {
+                    @Override
+                    protected boolean commitImpl(
+                            @Nullable String baseSnapshotUuid,
+                            Snapshot snapshot,
+                            String branch,
+                            List<PartitionStatistics> statistics)
+                            throws Exception {
+                        if (snapshot.commitKind() == 
Snapshot.CommitKind.COMPACT
+                                && attempts.getAndIncrement() == 0) {
+                            CommitMessageImpl concurrent =
+                                    compactDuringRetry
+                                            ? first
+                                            : new CommitMessageImpl(
+                                                    first.partition(),
+                                                    first.bucket(),
+                                                    first.totalBuckets(),
+                                                    first.newFilesIncrement(),
+                                                    
CompactIncrement.emptyIncrement());
+                            
PrimaryKeyDvConcurrentCompactionTest.this.commit("first", concurrent);
+                            return false;
+                        }
+                        return delegate.commit(baseSnapshotUuid, snapshot, 
branch, statistics);
+                    }
+
+                    @Override
+                    protected void closeImpl() throws Exception {
+                        delegate.close();
+                    }
+                };
+        FileStoreCommitImpl secondCommit = newCommit("second", publisher);
+        if (compactDuringRetry && otherBucket == 0) {
+            assertConflict(secondCommit, second);
+            assertThat(attempts).hasValue(1);
+            // Reusing the committer must not forget the conflict encountered 
on retry.
+            assertConflict(secondCommit, compactOnly(second));
+            assertThat(values(1, 2)).containsExactly("old");
+        } else {
+            commit(secondCommit, 0, second);
+            assertThat(attempts).hasValue(2);
+            assertThat(values(1, 2)).containsExactly("new");
+        }
+        assertThat(values(1, firstKey)).containsExactly(compactDuringRetry ? 
"new" : "old");
+    }
+
+    @Test
+    void testCheckpointAndSerializationPreserveWriterBaseline() throws 
Exception {
+        seed(1, 0);
+        AbstractFileStoreWrite<KeyValue> secondWrite = newWrite("second");
+        CommitMessageImpl initial = prepare(secondWrite, 1, 0, 2);
+        long baseline = store.snapshotManager().latestSnapshotId();
+        commit("second", initial);
+        List<FileStoreWrite.State<KeyValue>> state = secondWrite.checkpoint();
+        commit("first", prepare(newWrite("first"), 1, 0, 1));
+
+        AbstractFileStoreWrite<KeyValue> restored = newWrite("second");
+        restored.restore(state);
+        CommitMessageImpl message = prepare(restored, 1, 0, 3);
+        CommitMessageSerializer serializer = new CommitMessageSerializer();
+        CommitMessageImpl roundTrip =
+                (CommitMessageImpl)
+                        serializer.deserialize(
+                                serializer.getVersion(), 
serializer.serialize(message));
+        assertThat(roundTrip.checkFromSnapshot()).isEqualTo(baseline);
+        assertConflict(newCommit("second"), roundTrip);
+    }
+
+    @Test
+    void testWriteOnlyWriterOmitsCompactionBaseline() throws Exception {
+        seed(1, 0);
+        KeyValueFileStore writeOnlyStore = writeOnlyStore();
+        String user = "write-only";
+        AbstractFileStoreWrite<KeyValue> write = newWrite(user, 
writeOnlyStore);
+        write.write(BinaryRow.singleColumn(1), 0, kv(1, 1, "new"));
+
+        List<CommitMessage> messages = write.prepareCommit(true, 0);
+        
assertThat(messages).singleElement().extracting(CommitMessage::checkFromSnapshot).isNull();
+        try (FileStoreCommitImpl commit = writeOnlyStore.newCommit(user, 
null)) {
+            commit(commit, 0, messages);
+        }
+        Snapshot snapshot = store.snapshotManager().latestSnapshot();
+        
assertThat(snapshot.commitKind()).isEqualTo(Snapshot.CommitKind.APPEND);
+        assertThat(snapshot.deltaRecordCount()).isEqualTo(1L);
+    }
+
+    private void seed(int partition, int bucket) throws Exception {
+        seed(partition, bucket, 3);
+    }
+
+    private void seed(int partition, int bucket, int level) throws Exception {
+        String user = "seed-" + partition + "-" + bucket;
+        AbstractFileStoreWrite<KeyValue> write = 
writeOnlyStore().newWrite(user);
+        write.withIOManager(ioManager);
+        resources.add(0, write::close);
+        for (int i = 1; i <= 1000; i++) {
+            write.write(
+                    BinaryRow.singleColumn(partition),
+                    bucket,
+                    kv(partition, 1000 * bucket + i, "old"));
+        }
+        CommitMessageImpl raw = (CommitMessageImpl) write.prepareCommit(true, 
0).get(0);
+        List<DataFileMeta> files =
+                raw.newFilesIncrement().newFiles().stream()
+                        .map(file -> file.upgrade(level))
+                        .collect(Collectors.toList());
+        assertThat(files).hasSize(1);
+        commit(
+                user,
+                new CommitMessageImpl(
+                        BinaryRow.singleColumn(partition),
+                        bucket,
+                        2,
+                        new DataIncrement(files, Collections.emptyList(), 
Collections.emptyList()),
+                        CompactIncrement.emptyIncrement()));
+    }
+
+    private KeyValueFileStore writeOnlyStore() {
+        return ((PrimaryKeyFileStoreTable)
+                        table.copy(Collections.singletonMap("write-only", 
"true")))
+                .store();
+    }
+
+    private AbstractFileStoreWrite<KeyValue> newWrite(String user) {
+        return newWrite(user, store);
+    }
+
+    private AbstractFileStoreWrite<KeyValue> newWrite(String user, 
KeyValueFileStore targetStore) {
+        AbstractFileStoreWrite<KeyValue> write = targetStore.newWrite(user);
+        write.withIOManager(ioManager);
+        resources.add(0, write::close);
+        return write;
+    }
+
+    private CommitMessageImpl prepare(
+            AbstractFileStoreWrite<KeyValue> write, int partition, int bucket, 
int key)
+            throws Exception {
+        write.write(BinaryRow.singleColumn(partition), bucket, kv(partition, 
key, "new"));
+        List<CommitMessage> messages =
+                write.prepareCommit(true, 0).stream()
+                        .filter(message -> !((CommitMessageImpl) 
message).isEmpty())
+                        .collect(Collectors.toList());
+        assertThat(messages).hasSize(1);
+        CommitMessageImpl message = (CommitMessageImpl) messages.get(0);
+        assertThat(message.compactIncrement().compactAfter()).isNotEmpty();
+        return message;
+    }
+
+    private static KeyValue kv(int partition, int key, String value) {
+        return new KeyValue()
+                .replace(
+                        GenericRow.of(key),
+                        0L,
+                        RowKind.INSERT,
+                        GenericRow.of(partition, key, 
BinaryString.fromString(value)));
+    }
+
+    private FileStoreCommitImpl newCommit(String user) {
+        FileStoreCommitImpl commit = store.newCommit(user, null);
+        resources.add(0, commit);
+        return commit;
+    }
+
+    private FileStoreCommitImpl newCommit(String user, SnapshotCommit 
publisher) {
+        String tableName = store.options().path().getName();
+        FileStoreCommitImpl commit =
+                new FileStoreCommitImpl(
+                        publisher,
+                        LocalFileIO.create(),
+                        new FileSystemSchemaManager(LocalFileIO.create(), 
store.options().path()),
+                        tableName,
+                        user,
+                        store.partitionType(),
+                        store.options(),
+                        store.pathFactory(),
+                        store.snapshotManager(),
+                        store.manifestFileFactory(),
+                        store.manifestListFactory(),
+                        store.indexManifestFileFactory(),
+                        store::newScan,
+                        store.newStatsFileHandler(),
+                        store.bucketMode(),
+                        Collections.emptyList(),
+                        Collections.emptyList(),
+                        scanner ->
+                                ConflictDetection.create(
+                                        tableName,
+                                        user,
+                                        store.partitionType(),
+                                        store.pathFactory(),
+                                        store.newKeyComparator(),
+                                        store.bucketMode(),
+                                        true,
+                                        false,
+                                        false,
+                                        false,
+                                        store.newIndexFileHandler(),
+                                        store.snapshotManager(),
+                                        scanner),
+                        null);
+        resources.add(0, commit);
+        return commit;
+    }
+
+    private void commit(String user, CommitMessageImpl message) {
+        commit(newCommit(user), 0, message);
+    }
+
+    private static void commit(
+            FileStoreCommitImpl commit, long identifier, CommitMessageImpl 
message) {
+        commit(commit, identifier, Collections.singletonList(message));
+    }
+
+    private static void commit(
+            FileStoreCommitImpl commit, long identifier, List<CommitMessage> 
messages) {
+        ManifestCommittable committable = new ManifestCommittable(identifier);
+        messages.forEach(committable::addFileCommittable);
+        commit.commit(committable, false);
+    }
+
+    private static CommitMessageImpl compactOnly(CommitMessageImpl message) {
+        return new CommitMessageImpl(
+                message.partition(),
+                message.bucket(),
+                message.totalBuckets(),
+                DataIncrement.emptyIncrement(),
+                message.compactIncrement(),
+                message.checkFromSnapshot());
+    }
+
+    private static void assertConflict(FileStoreCommitImpl commit, 
CommitMessageImpl message) {
+        assertThatThrownBy(() -> commit(commit, 0, message))
+                .isInstanceOf(RuntimeException.class)
+                .hasMessageContaining("Concurrent compaction")
+                .hasMessageContaining("partition")
+                .hasMessageContaining("bucket");
+    }
+
+    private List<String> values(int partition, int key) throws Exception {
+        List<String> values = new ArrayList<>();
+        for (Split split : table.newScan().plan().splits()) {
+            try (RecordReaderIterator<InternalRow> rows =
+                    new 
RecordReaderIterator<>(table.newRead().createReader(split))) {
+                while (rows.hasNext()) {
+                    InternalRow row = rows.next();
+                    if (row.getInt(0) == partition && row.getInt(1) == key) {
+                        values.add(row.getString(2).toString());
+                    }
+                }
+            }
+        }
+        return values;
+    }
+}
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/postpone/BucketFilesTest.java 
b/paimon-core/src/test/java/org/apache/paimon/postpone/BucketFilesTest.java
index 6c60075850..127fe3183b 100644
--- a/paimon-core/src/test/java/org/apache/paimon/postpone/BucketFilesTest.java
+++ b/paimon-core/src/test/java/org/apache/paimon/postpone/BucketFilesTest.java
@@ -66,6 +66,24 @@ class BucketFilesTest {
         assertThat(result.deletedIndexFiles()).containsExactly(dataDelete, 
compactDelete);
     }
 
+    @Test
+    void testKeepsEarliestSnapshotWhenMergingMessages() {
+        BucketFiles bucketFiles =
+                new BucketFiles(mock(DataFilePathFactory.class), 
mock(FileIO.class));
+        for (long snapshotId : new long[] {9, 5, 8}) {
+            bucketFiles.update(
+                    new CommitMessageImpl(
+                            EMPTY_ROW,
+                            0,
+                            1,
+                            DataIncrement.indexIncrement(
+                                    Collections.singletonList(index("index-" + 
snapshotId))),
+                            CompactIncrement.emptyIncrement(),
+                            snapshotId));
+        }
+        assertThat(bucketFiles.makeMessage(EMPTY_ROW, 
0).checkFromSnapshot()).isEqualTo(5L);
+    }
+
     private static IndexFileMeta index(String name) {
         return new IndexFileMeta(name, "ann", 1, 1, null, null, null);
     }
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/table/sink/TableCommitTest.java 
b/paimon-core/src/test/java/org/apache/paimon/table/sink/TableCommitTest.java
index d9652ccf68..e5ea3d3c5a 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/table/sink/TableCommitTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/table/sink/TableCommitTest.java
@@ -1097,7 +1097,7 @@ public class TableCommitTest {
 
     @Test
     public void testStrictModeScanStateNotLeakedAcrossSnapshots() throws 
Exception {
-        // Regression test: the FileStoreScan used by StrictModeChecker is 
mutable.
+        // Regression test: the FileStoreScan used by snapshot conflict checks 
is mutable.
         // When the APPEND branch (for an earlier APPEND snapshot) calls
         // onlyReadRealBuckets(), the flag is latched on the shared scan 
instance and
         // must not leak into the later COMPACT/OVERWRITE branch, otherwise 
entries
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperator.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperator.java
index d5294742c4..bc901cf63e 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperator.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperator.java
@@ -141,7 +141,8 @@ public class ChangelogCompactCoordinateOperator
                                 message.compactIncrement().compactAfter(),
                                 skippedCompactChangelogs,
                                 message.compactIncrement().newIndexFiles(),
-                                
message.compactIncrement().deletedIndexFiles()));
+                                
message.compactIncrement().deletedIndexFiles()),
+                        message.checkFromSnapshot());
         Committable newCommittable = new 
Committable(committable.checkpointId(), newMessage);
         output.collect(new StreamRecord<>(Either.Left(newCommittable)));
     }
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperator.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperator.java
index 7317a26b16..36e54a1c68 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperator.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperator.java
@@ -97,7 +97,8 @@ public class ChangelogCompactSortOperator extends 
AbstractStreamOperator<Committ
                                 message.compactIncrement().compactAfter(),
                                 Collections.emptyList(),
                                 message.compactIncrement().newIndexFiles(),
-                                
message.compactIncrement().deletedIndexFiles()));
+                                
message.compactIncrement().deletedIndexFiles()),
+                        message.checkFromSnapshot());
         if (!newMessage.isEmpty()) {
             Committable newCommittable = new 
Committable(committable.checkpointId(), newMessage);
             output.collect(new StreamRecord<>(newCommittable));
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/PostponeBucketCompactSplitSource.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/PostponeBucketCompactSplitSource.java
index 5331fd0e9b..41eabdf21f 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/PostponeBucketCompactSplitSource.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/PostponeBucketCompactSplitSource.java
@@ -194,7 +194,10 @@ public class PostponeBucketCompactSplitSource extends 
AbstractNonCoordinatedSour
                         .transform(
                                 "Remove new files",
                                 new CommittableTypeInfo(),
-                                new RemovePostponeBucketFilesOperator())
+                                new RemovePostponeBucketFilesOperator(
+                                        
table.coreOptions().deletionVectorsEnabled()
+                                                ? snapshotId
+                                                : null))
                         .forceNonParallel());
     }
 
diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/RemovePostponeBucketFilesOperator.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/RemovePostponeBucketFilesOperator.java
index 668a98879f..a65bbe37c5 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/RemovePostponeBucketFilesOperator.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/postpone/RemovePostponeBucketFilesOperator.java
@@ -28,6 +28,8 @@ import org.apache.paimon.table.source.Split;
 
 import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
 
+import javax.annotation.Nullable;
+
 import java.util.Collections;
 
 /**
@@ -38,6 +40,12 @@ public class RemovePostponeBucketFilesOperator extends 
BoundedOneInputOperator<S
 
     private static final long serialVersionUID = 1L;
 
+    @Nullable private final Long snapshotId;
+
+    public RemovePostponeBucketFilesOperator(@Nullable Long snapshotId) {
+        this.snapshotId = snapshotId;
+    }
+
     @Override
     public void processElement(StreamRecord<Split> element) throws Exception {
         DataSplit dataSplit = (DataSplit) element.getValue();
@@ -50,7 +58,8 @@ public class RemovePostponeBucketFilesOperator extends 
BoundedOneInputOperator<S
                         new CompactIncrement(
                                 dataSplit.dataFiles(),
                                 Collections.emptyList(),
-                                Collections.emptyList()));
+                                Collections.emptyList()),
+                        snapshotId);
         output.collect(new StreamRecord<>(new Committable(Long.MAX_VALUE, 
message)));
     }
 
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperatorTest.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperatorTest.java
index bbcc5394f9..9a5213dfda 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperatorTest.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactCoordinateOperatorTest.java
@@ -256,6 +256,42 @@ public class ChangelogCompactCoordinateOperatorTest {
         testHarness.close();
     }
 
+    @Test
+    public void testPreservesCompactionBaseline() throws Exception {
+        ChangelogCompactCoordinateOperator operator =
+                new ChangelogCompactCoordinateOperator(new CoreOptions(new 
Options()));
+        try (OneInputStreamOperatorTestHarness<
+                        Committable, Either<Committable, ChangelogCompactTask>>
+                testHarness = createTestHarness(operator)) {
+            testHarness.open();
+            List<DataFileMeta> before = 
Collections.singletonList(createDataFileMetaOfSize(1));
+            List<DataFileMeta> after = 
Collections.singletonList(createDataFileMetaOfSize(2));
+            List<DataFileMeta> changelog = 
Collections.singletonList(createDataFileMetaOfSize(1));
+            CommitMessageImpl message =
+                    new CommitMessageImpl(
+                            BinaryRow.EMPTY_ROW,
+                            0,
+                            2,
+                            DataIncrement.emptyIncrement(),
+                            new CompactIncrement(before, after, changelog),
+                            37L);
+            testHarness.processElement(new StreamRecord<>(new Committable(1, 
message)));
+
+            List<Either<Committable, ChangelogCompactTask>> output =
+                    testHarness.extractOutputValues();
+            assertThat(output).hasSize(1);
+            assertThat(output.get(0).left().commitMessage())
+                    .isEqualTo(
+                            new CommitMessageImpl(
+                                    BinaryRow.EMPTY_ROW,
+                                    0,
+                                    2,
+                                    DataIncrement.emptyIncrement(),
+                                    new CompactIncrement(before, after, 
Collections.emptyList()),
+                                    37L));
+        }
+    }
+
     @SuppressWarnings("unchecked")
     private void assertCommittable(
             Object o,
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperatorTest.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperatorTest.java
index bd706147a5..61e73ad8f7 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperatorTest.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/compact/changelog/ChangelogCompactSortOperatorTest.java
@@ -107,6 +107,11 @@ public class ChangelogCompactSortOperatorTest {
                         CompactIncrement.emptyIncrement());
         testHarness.processElement(new StreamRecord<>(new Committable(1, 
onlyChangelogBucket1)));
 
+        CompactIncrement dataCompaction =
+                new CompactIncrement(
+                        Collections.singletonList(createDataFileMeta(1, 0)),
+                        Collections.singletonList(createDataFileMeta(2, 0)),
+                        Collections.emptyList());
         CommitMessageImpl mixed =
                 new CommitMessageImpl(
                         binaryRow.apply(0),
@@ -116,7 +121,8 @@ public class ChangelogCompactSortOperatorTest {
                                 Arrays.asList(files.get(10), files.get(9)),
                                 Collections.emptyList(),
                                 Arrays.asList(files.get(6), files.get(5))),
-                        CompactIncrement.emptyIncrement());
+                        dataCompaction,
+                        37L);
         testHarness.processElement(new StreamRecord<>(new Committable(1, 
mixed)));
 
         testHarness.prepareSnapshotPreBarrier(1);
@@ -141,7 +147,8 @@ public class ChangelogCompactSortOperatorTest {
                                         Arrays.asList(files.get(10), 
files.get(9)),
                                         Collections.emptyList(),
                                         Collections.emptyList()),
-                                CompactIncrement.emptyIncrement()));
+                                dataCompaction,
+                                37L));
         assertThat(actual.get(2))
                 .isEqualTo(
                         new CommitMessageImpl(
diff --git 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkPostponeCompactProcedure.scala
 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkPostponeCompactProcedure.scala
index a39636e9c1..40c93e6b64 100644
--- 
a/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkPostponeCompactProcedure.scala
+++ 
b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkPostponeCompactProcedure.scala
@@ -247,7 +247,8 @@ case class SparkPostponeCompactProcedure(
             split.dataFiles(),
             Collections.emptyList[DataFileMeta],
             Collections.emptyList[DataFileMeta]
-          )
+          ),
+          if (realTable.coreOptions().deletionVectorsEnabled()) 
Long.box(snapshotId) else null
         )
     }
 

Reply via email to