You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "leaves12138 (via GitHub)" <gi...@apache.org> on 2026/10/08 06:47:13 UTC

[PR] [core] Reuse compaction results across row ID reassignment [paimon]

leaves12138 opened a new pull request, #10432:
URL: https://github.com/apache/paimon/pull/10432

   ### Purpose
   
   When a data-evolution compaction finishes and a concurrent commit reassigns row IDs before its commit, otherwise reusable physical outputs can be rejected by conflict checks. Reuse those completed normal/BLOB and global-index compaction outputs by translating their metadata through verified, persisted reassignment plans.
   
   For eligible `COMPACT` commits with `commit.last-safe-snapshot`, apply subsequent reassignment plans to both ADD and DELETE entries, accepting only complete, contiguous, length-preserving range mappings. Preserve physical file names and contents, carry the translated changes across commit retries, and resolve uncertain successful commits before checking inputs that the completed commit already removed.
   
   Strict-mode checks skip only reassignment snapshots whose plans have been validated and applied. Ordinary overwrite/input-replacement conflicts still fail. Physical `_ROW_ID` and materialized-deletion paths retain their existing behavior; missing history or missing/corrupt plans reject reuse. Compaction tasks, task serializers, and persisted data/index formats are unchanged.
   
   Replaces #10150 using the `leaves12138:reassign_compact` branch.
   
   ### Tests
   
   - `CompactReassignReuseTest` covers normal/BLOB and BTree metadata translation, repeated reassignments, commit retries, lost successful commit responses, ordinary conflicts, missing/corrupt plans, legacy-option fallback, expired boundary snapshots, and unsafe mappings.
   - Before the master update, #10150 reported 295 passing targeted tests and passing Checkstyle/Spotless validation.
   - On the current head, `git diff --check` passed. `git range-diff` confirms the feature and test changes are preserved; the only patch-context adjustment retains the imports required by the updated master.
   - Runtime tests have not been rerun after updating the master base.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [core] Reuse compaction results across row ID reassignment [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #10432:
URL: https://github.com/apache/paimon/pull/10432#discussion_r4226302662


##########
paimon-core/src/main/java/org/apache/paimon/operation/commit/ReassignCompactChangesProvider.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.Snapshot;
+import org.apache.paimon.append.dataevolution.SerializationAssignment;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.index.GlobalIndexMeta;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.io.DataFileMeta;
+import org.apache.paimon.manifest.IndexManifestEntry;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.table.SpecialFields;
+import org.apache.paimon.utils.FileStorePathFactory;
+import org.apache.paimon.utils.Range;
+import org.apache.paimon.utils.SnapshotManager;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+import static org.apache.paimon.utils.Preconditions.checkState;
+
+/** Reuses immutable compact outputs after verified, metadata-only row-id reassignments. */
+public final class ReassignCompactChangesProvider implements CommitChangesProvider {
+
+    private final FileIO fileIO;
+    private final FileStorePathFactory paths;
+    private final SnapshotManager snapshots;
+    private final Set<Long> reassignments = new HashSet<>();
+    private long checkedSnapshot;
+    private CommitChanges changes;
+
+    public ReassignCompactChangesProvider(
+            FileIO fileIO,
+            FileStorePathFactory paths,
+            SnapshotManager snapshots,
+            long scanSnapshotId,
+            CommitChanges changes) {
+        this.fileIO = fileIO;
+        this.paths = paths;
+        this.snapshots = snapshots;
+        this.checkedSnapshot = scanSnapshotId;
+        this.changes = changes;
+    }
+
+    @Override
+    public CommitChanges provide(@Nullable Snapshot latest) {
+        checkState(
+                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
+        // snapshot itself may already have expired.
+        for (long id = checkedSnapshot + 1; id <= latest.id(); id++) {
+            checkState(
+                    snapshots.snapshotExists(id),
+                    "Cannot reuse compaction with missing snapshot %s.",
+                    id);
+            Snapshot snapshot = snapshots.snapshot(id);
+            String plan =
+                    snapshot.commitKind() == Snapshot.CommitKind.OVERWRITE
+                            ? SerializationAssignment.planFile(snapshot)
+                            : null;
+            if (plan != null) {
+                SerializationAssignment assignment;
+                try {
+                    assignment = SerializationAssignment.readPlan(fileIO, paths, plan);
+                } catch (IOException e) {
+                    throw new UncheckedIOException(
+                            "Cannot read compaction reassignment plan " + plan, e);
+                }
+                checkState(
+                        assignment.snapshotId() == id
+                                && Objects.equals(snapshot.nextRowId(), assignment.nextRowId()),
+                        "Reassignment plan does not match snapshot %s.",
+                        id);
+                changes = mapChanges(assignment);

Review Comment:
   [P2] Resolve the previous commit attempt before rebasing its changes
   
   `tryCommit()` calls this provider before `tryCommitOnce()` checks whether the previous attempt already committed. This can turn a successful index COMPACT into a reported failure: the COMPACT replaces an index covering `[0, 1]`, its response is lost, a concurrent DELETE removes the data files for row 0, and a subsequent reassignment maps only the surviving part of that range. Reassignment legitimately drops the partially covered index, but this retry still tries to map the obsolete `[0, 1]` changes and throws `IllegalStateException` before reaching the successful-commit check.
   
   I reproduced this with real data/index files and a persisted reassignment plan; the same scenario passes with the baseline commit/retry implementation. Please check whether the previous attempt has already committed before calling `provide()`/rebasing, and add a regression test covering a lost successful response followed by deletion and reassignment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [core] Reuse compaction results across row ID reassignment [paimon]

Posted by "leaves12138 (via GitHub)" <gi...@apache.org>.
leaves12138 commented on code in PR #10432:
URL: https://github.com/apache/paimon/pull/10432#discussion_r4227038294


##########
paimon-core/src/main/java/org/apache/paimon/operation/commit/ReassignCompactChangesProvider.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.Snapshot;
+import org.apache.paimon.append.dataevolution.SerializationAssignment;
+import org.apache.paimon.fs.FileIO;
+import org.apache.paimon.index.GlobalIndexMeta;
+import org.apache.paimon.index.IndexFileMeta;
+import org.apache.paimon.io.DataFileMeta;
+import org.apache.paimon.manifest.IndexManifestEntry;
+import org.apache.paimon.manifest.ManifestEntry;
+import org.apache.paimon.table.SpecialFields;
+import org.apache.paimon.utils.FileStorePathFactory;
+import org.apache.paimon.utils.Range;
+import org.apache.paimon.utils.SnapshotManager;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+import static org.apache.paimon.utils.Preconditions.checkState;
+
+/** Reuses immutable compact outputs after verified, metadata-only row-id reassignments. */
+public final class ReassignCompactChangesProvider implements CommitChangesProvider {
+
+    private final FileIO fileIO;
+    private final FileStorePathFactory paths;
+    private final SnapshotManager snapshots;
+    private final Set<Long> reassignments = new HashSet<>();
+    private long checkedSnapshot;
+    private CommitChanges changes;
+
+    public ReassignCompactChangesProvider(
+            FileIO fileIO,
+            FileStorePathFactory paths,
+            SnapshotManager snapshots,
+            long scanSnapshotId,
+            CommitChanges changes) {
+        this.fileIO = fileIO;
+        this.paths = paths;
+        this.snapshots = snapshots;
+        this.checkedSnapshot = scanSnapshotId;
+        this.changes = changes;
+    }
+
+    @Override
+    public CommitChanges provide(@Nullable Snapshot latest) {
+        checkState(
+                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
+        // snapshot itself may already have expired.
+        for (long id = checkedSnapshot + 1; id <= latest.id(); id++) {
+            checkState(
+                    snapshots.snapshotExists(id),
+                    "Cannot reuse compaction with missing snapshot %s.",
+                    id);
+            Snapshot snapshot = snapshots.snapshot(id);
+            String plan =
+                    snapshot.commitKind() == Snapshot.CommitKind.OVERWRITE
+                            ? SerializationAssignment.planFile(snapshot)
+                            : null;
+            if (plan != null) {
+                SerializationAssignment assignment;
+                try {
+                    assignment = SerializationAssignment.readPlan(fileIO, paths, plan);
+                } catch (IOException e) {
+                    throw new UncheckedIOException(
+                            "Cannot read compaction reassignment plan " + plan, e);
+                }
+                checkState(
+                        assignment.snapshotId() == id
+                                && Objects.equals(snapshot.nextRowId(), assignment.nextRowId()),
+                        "Reassignment plan does not match snapshot %s.",
+                        id);
+                changes = mapChanges(assignment);

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [core] Reuse compaction results across row ID reassignment [paimon]

Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #10432:
URL: https://github.com/apache/paimon/pull/10432


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org