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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
