Stephen0421 commented on code in PR #9207: URL: https://github.com/apache/paimon/pull/9207#discussion_r3795104370
########## paimon-core/src/main/java/org/apache/paimon/operation/ManagedBlobOrphanFilesClean.java: ########## @@ -0,0 +1,266 @@ +/* + * 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.Snapshot; +import org.apache.paimon.blob.ManagedBlobReachabilityCollector; +import org.apache.paimon.blob.ManagedBlobReachabilityCollector.Result; +import org.apache.paimon.blob.ManagedBlobReferenceFile; +import org.apache.paimon.blob.ManagedBlobReferenceFile.Reference; +import org.apache.paimon.fs.Path; +import org.apache.paimon.io.DataFilePathFactory; +import org.apache.paimon.manifest.FileKind; +import org.apache.paimon.manifest.ManifestEntry; +import org.apache.paimon.manifest.ManifestFile; +import org.apache.paimon.manifest.ManifestFileMeta; +import org.apache.paimon.manifest.ManifestList; +import org.apache.paimon.table.FileStoreTable; +import org.apache.paimon.utils.DataFilePathFactories; + +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Consumer; + +/** + * Cleans unreferenced primary-key {@code .managed.blob} packs. + * + * <p>Unlike {@link OrphanFilesClean}, this cleaner only lists and deletes managed BLOB packs. Pack + * reachability is collected from live {@link FileKind#ADD} data-file {@code .blobref} sidecars. + * Missing manifest lists or unreadable sidecars on a still-existing data file abort pack deletion + * for the rest of the run. + * + * <p>Used packs are collected twice. If the snapshot topology or the used-pack set changes between + * those collections, this run deletes nothing. That shrinks the race with compaction reuse; it is + * not a commit lease. + */ +public abstract class ManagedBlobOrphanFilesClean extends OrphanFilesClean { + + /** + * Marker emitted into the used-pack set when a {@code .blobref} sidecar or a required manifest + * cannot be trusted. Callers must skip deleting every {@code .managed.blob} pack. + */ + public static final String SKIP_MANAGED_BLOB_GC = "__paimon_skip_managed_blob_gc__"; + + public ManagedBlobOrphanFilesClean(FileStoreTable table, long olderThanMillis, boolean dryRun) { + super(table, olderThanMillis, dryRun); + } + + /** + * Join key for a managed pack. Identity is {@code storageRootId + relativePath}, reconstructed + * by {@link Reference#toPath()}. The FileIO scheme is omitted so a wrapper such as test {@code + * traceable:} still matches listed {@code file:} paths at the same location. + */ + public static String packIdentity(Path packPath) { + URI uri = packPath.toUri(); + String authority = uri.getAuthority(); Review Comment: Fixed. Pack references and listed candidates now go through the same FileIO-aware canonicalization: - absolute qualified and unqualified paths use the same normalized URI path, so `hdfs:///warehouse/...` and `hdfs://nn:8020/warehouse/...` match; - relative LocalFileIO paths are converted to normalized absolute paths; - relative paths from non-local FileIO implementations are qualified through that FileIO; - if either side cannot be canonicalized reliably, the mark emits the global SKIP marker and the run deletes nothing. Local, Flink, and Spark candidate joins all use this canonical identity. I added deterministic FileIO regression tests covering qualified/unqualified identities and unresolved relative candidates. These exercise the same mismatch without introducing a MiniDFS dependency, and verify that a live pack cannot be classified as orphan. -- 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]
