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

[PR] [core] Publish required compaction work atomically and reconcile recovery [paimon]

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

   ### Purpose
   
   Primary-key full-compaction commits currently publish APPEND and COMPACT snapshots with the same commit identifier. Recovering after APPEND is durable can filter the identifier as already committed and discard required final changelog/index work. Batch readers then see the new value while incremental readers miss its final change. This is tracked by [StreamFusion #318](https://github.com/datafusion-contrib/StreamFusion/issues/318); this PR proposes the upstream recovery fix against current Apache master.
   
   For ordinary full-compaction/lookup commits with required compact changelog or index work, publish data and that work atomically in one APPEND snapshot, marked with an explicit protocol version. Retain recovery of legacy unmarked incomplete APPEND/COMPACT pairs.
   
   Competing full compactions need more than preserving the old compact messages: refresh against a pinned current committed snapshot plus the pending raw input, recompute the compaction, publish the resulting data/changelog together, and signal the caller to refresh its stale writer. The durable identifier still deduplicates retry. Full-compaction writer checkpoint recovery also rebuilds from completed atomic state while preserving pending uncommitted raw input, including when prepared derived outputs have been removed or later ordinary APPENDs exist. Data-evolution and other producer paths retain their existing protocol.
   
   Injected filesystem failures also exposed reader cleanup gaps: unchecked schema-lookup failures could leak readers opened earlier, and batch-release failure could prevent closing other loser-tree leaves. The separate first commit closes all owned readers and preserves primary/suppressed failures.
   
   ### Tests
   
   - Normal Maven reactor verification (without `fast-build`, with style/checkstyle/enforcer/licensing checks): **352 passed, one opt-in performance test skipped**. Includes the unchanged 101-case commit suite, 39 recovery cases, 201 loser-tree cases, three construction-ownership cases, six writer tests and two write-restore tests.
   - Three additional unchanged multi-writer conflict runs: **18 cases passed**. No original assertions or deadlines changed.
   - Recovery tests cover publication crash points, legacy incomplete pairs, direct/filter retries, multiple pending identifiers, index-only work, expired history, competing full compaction/file upgrades, writer restore with pending input and later ordinary APPENDs, and batch/incremental final results.
   - Opt-in commit-API-only comparison against pristine Apache master `937b5e1d51a5d346634df56794c562150aa1a2b5`: 16 commits per trial, two warmups and three trials. Mean publication time at 64 keys: stock 0.11626s / candidate 0.09651s (1.20x); at 4096 keys: stock 0.11456s / candidate 0.09299s (1.23x). Variance is retained; writing/compaction/prepare and verification reads are outside timing. These are publication measurements, not whole-job acceleration claims.
   
   The local selection is not a claim that the complete upstream integration matrix has passed; upstream CI and review remain required. StreamFusion continues to use canonical released dependencies. Upstream review and a verified canonical release are still required before adopting this recovery change there.
   


-- 
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] Resume unfinished full-compaction commits while preserving snapshot semantics [paimon]

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


##########
paimon-core/src/main/java/org/apache/paimon/operation/FullCompactionRefresh.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.CoreOptions;
+import org.apache.paimon.Snapshot;
+import org.apache.paimon.data.BinaryRow;
+import org.apache.paimon.disk.IOManager;
+import org.apache.paimon.index.IndexFileHandler;
+import org.apache.paimon.io.CompactIncrement;
+import org.apache.paimon.io.DataFileMeta;
+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.SnapshotManager;
+
+import javax.annotation.Nullable;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+
+/** Reprepares stale compaction against a pinned committed snapshot. */
+public final class FullCompactionRefresh {
+    private final CoreOptions options;
+    private final SnapshotManager snapshots;
+    private final Supplier<FileStoreScan> scans;
+    private final Supplier<IndexFileHandler> indexes;
+    private final Supplier<FileStoreWrite<?>> writers;
+
+    public FullCompactionRefresh(
+            CoreOptions options,
+            SnapshotManager snapshots,
+            Supplier<FileStoreScan> scans,
+            Supplier<IndexFileHandler> indexes,
+            Supplier<FileStoreWrite<?>> writers) {
+        this.options = options;
+        this.snapshots = snapshots;
+        this.scans = scans;
+        this.indexes = indexes;
+        this.writers = writers;
+    }
+
+    public List<CommitMessage> refresh(
+            Snapshot snapshot,
+            List<CommitMessage> messages,
+            long identifier,
+            @Nullable IOManager borrowedIO) {
+        Map<Pair<BinaryRow, Integer>, List<CommitMessageImpl>> groups = new LinkedHashMap<>();
+        for (CommitMessage message : messages) {
+            CommitMessageImpl original = (CommitMessageImpl) message;
+            groups.computeIfAbsent(
+                            Pair.of(original.partition(), original.bucket()),
+                            ignored -> new ArrayList<>())
+                    .add(original);
+        }
+        WriteRestore committed =
+                new FileSystemWriteRestore(
+                        options, snapshots, scans.get(), indexes.get(), snapshot.id());
+        WriteRestore pending =
+                new WriteRestore() {
+                    @Override
+                    public long latestCommittedIdentifier(String user) {
+                        return committed.latestCommittedIdentifier(user);
+                    }
+
+                    @Override
+                    public RestoreFiles restoreFiles(
+                            BinaryRow partition,
+                            int bucket,
+                            boolean dynamicIndex,
+                            boolean deleteVectors,
+                            boolean sourceIndexes) {
+                        RestoreFiles base =
+                                committed.restoreFiles(
+                                        partition,
+                                        bucket,
+                                        dynamicIndex,
+                                        deleteVectors,
+                                        sourceIndexes);
+                        Map<String, DataFileMeta> files = new LinkedHashMap<>();
+                        if (base.dataFiles() != null) {
+                            for (DataFileMeta file : base.dataFiles()) {
+                                files.put(file.fileName(), file);
+                            }
+                        }
+                        List<CommitMessageImpl> originals = groups.get(Pair.of(partition, bucket));
+                        for (CommitMessageImpl original : originals) {
+                            for (DataFileMeta file : original.newFilesIncrement().deletedFiles()) {
+                                files.remove(file.fileName());
+                            }
+                            for (DataFileMeta file : original.newFilesIncrement().newFiles()) {
+                                files.put(file.fileName(), file);
+                            }
+                        }
+                        return new RestoreFiles(
+                                snapshot,
+                                originals.get(0).totalBuckets(),
+                                new ArrayList<>(files.values()),
+                                base.dynamicBucketIndex(),
+                                base.deleteVectorsIndex(),
+                                base.sourceIndexPayloads());
+                    }
+                };
+        try (IOManager ownedIO =
+                borrowedIO == null
+                        ? IOManager.create(System.getProperties().getProperty("java.io.tmpdir"))
+                        : null) {
+            Map<Pair<BinaryRow, Integer>, CompactIncrement> refreshed = new LinkedHashMap<>();
+            // Prepare each bucket before starting the next one, so a failing prepare cannot
+            // abandon readers belonging to other asynchronous compactions.
+            for (Map.Entry<Pair<BinaryRow, Integer>, List<CommitMessageImpl>> group :
+                    groups.entrySet()) {
+                if (group.getValue().stream().noneMatch(m -> !m.compactIncrement().isEmpty())) {
+                    continue;
+                }
+                boolean full =
+                        group.getValue().stream()
+                                .anyMatch(m -> !m.compactIncrement().changelogFiles().isEmpty());
+                FileStoreWrite<?> write = writers.get();

Review Comment:
   [P1] Preserve the current schema when rebuilding a stale compaction
   
   The writer supplier captured by `AbstractFileStore.newCommit()` still uses the original store schema, while `pending` restores all files from the newer pinned snapshot. If another writer adds a column and compacts before this recovery, the refresh reads its data through the old projection and publishes replacement files that have lost that column. I reproduced: create `(k,v)`, prepare old writer's update `(1,20)`, add `extra INT`, then have a new-schema writer commit `(2,30,99)` and fully compact. Before the old commit retries, the row is `(2,30,99)`; after this refresh publishes COMPACT it is `(2,30,NULL)`, even though the exception merely asks the caller to refresh its writer. The exact merge-base committer rejects the stale compaction and preserves `99`. Please reject refresh when its writer schema is stale, or rebuild against the current schema and preserve every current field. Add a schema-evolution regression covering both stored data and changelog before publishing this rec
 overed rewrite.



-- 
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