Stephen0421 commented on code in PR #9207:
URL: https://github.com/apache/paimon/pull/9207#discussion_r3892277088


##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkManagedBlobOrphanFilesClean.scala:
##########
@@ -0,0 +1,341 @@
+/*
+ * 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.spark.procedure
+
+import org.apache.paimon.catalog.{Catalog, Identifier}
+import org.apache.paimon.fs.Path
+import org.apache.paimon.manifest.{ManifestFile, ManifestFileMeta, 
ManifestList}
+import org.apache.paimon.operation.{CleanOrphanFilesResult, 
ManagedBlobOrphanFilesClean}
+import org.apache.paimon.operation.ManagedBlobOrphanFilesClean.SidecarWorkItem
+import org.apache.paimon.operation.OrphanFilesClean.retryReadingFiles
+import org.apache.paimon.table.FileStoreTable
+import org.apache.paimon.utils.DataFilePathFactories
+import org.apache.paimon.utils.FileStorePathFactory.BUCKET_PATH_PREFIX
+import org.apache.paimon.utils.Preconditions
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.{functions, Dataset, PaimonSparkSession, 
SparkSession}
+import org.apache.spark.sql.catalyst.SQLConfHelper
+
+import java.util
+import java.util.function.Consumer
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+case class SparkManagedBlobOrphanFilesClean(
+    specifiedTable: FileStoreTable,
+    specifiedOlderThanMillis: Long,
+    parallelism: Int,
+    dryRunPara: Boolean,
+    @transient spark: SparkSession)
+  extends SparkManagedBlobOrphanFilesCleanBase(specifiedTable, 
specifiedOlderThanMillis, dryRunPara)
+  with SQLConfHelper
+  with Logging {
+
+  def doClean(): (Dataset[(Long, Long)], Seq[Dataset[_]]) = {
+    import spark.implicits._
+
+    SparkManagedBlobOrphanFilesClean.checkParallelism(parallelism)
+    val cached = new mutable.ArrayBuffer[Dataset[_]]()
+    try {
+      val topologyBefore = snapshotTopology()
+      val usedPacks = collectUsedPacksDf().cache()
+      cached += usedPacks
+      val skipGc = usedPacks
+        .filter($"used_name" === 
ManagedBlobOrphanFilesClean.SKIP_MANAGED_BLOB_GC)
+        .limit(1)
+        .collect()
+        .nonEmpty
+
+      val fileDirs = listPaimonFileDirs.asScala.map(_.toString).toSeq
+      val maxFileDirsParallelism = Math.min(Math.max(fileDirs.size, 1), 
parallelism)
+      val candidates = spark.sparkContext
+        .parallelize(fileDirs, maxFileDirsParallelism)
+        .flatMap {
+          dir =>
+            tryBestListingDirs(new Path(dir)).asScala
+              .filter(file => !file.isDir)
+              .filter(oldEnough)
+              .filter(
+                file => 
ManagedBlobOrphanFilesClean.isManagedBlobPackName(file.getPath.getName))
+              .map {
+                file =>
+                  val path = file.getPath
+                  val parent = path.getParent
+                  (
+                    packIdentityForCandidate(path),
+                    path.toString,
+                    file.getLen,
+                    if (parent == null) "" else parent.toString)
+              }
+        }
+        .toDF("name", "path", "len", "dataDir")
+        .repartition(parallelism)
+        .cache()
+      cached += candidates
+      val candidateSkipGc = candidates
+        .filter($"name" === ManagedBlobOrphanFilesClean.SKIP_MANAGED_BLOB_GC)
+        .limit(1)
+        .collect()
+        .nonEmpty
+      val canonicalCandidates = candidates
+        .filter($"name" =!= ManagedBlobOrphanFilesClean.SKIP_MANAGED_BLOB_GC)
+
+      betweenUsedCollections()
+      val usedPacks2 = collectUsedPacksDf().cache()

Review Comment:
   Thanks. Skip flags, topology changes, and used-set differences are no longer 
used only as driver booleans that gate `limit(0)`. Observed aborts are frozen 
into the deletion DAG (`spark.range` + `left_anti` on abort keys), and 
cache-miss recomputes that newly emit `SKIP_MANAGED_BLOB_GC` still abort in the 
same job. Added regressions that unpersist the marks (including clearing 
shuffle outputs) and fail the next sidecar read, and that verify a used-set 
change is logged and deletes nothing.



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

Reply via email to