You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "heye1005 (via GitHub)" <gi...@apache.org> on 2026/04/27 16:01:17 UTC
[PR] [core] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
heye1005 opened a new pull request, #7715:
URL: https://github.com/apache/paimon/pull/7715
### Purpose
Fix #7710.
`LocalOrphanFilesClean.clean()` collects used files by reading all snapshots via `safelyGetAllSnapshots()`. However, this method silently catches `FileNotFoundException` — if concurrent snapshot expiration deletes all snapshots between listing and reading, `usedFiles` ends up empty, and all candidate data files get deleted as orphans.
This patch skips orphan file deletion when `usedFiles` is empty to prevent accidental data loss.
### Tests
Added `LocalOrphanFilesCleanTest#testSkipCleaningWhenAllSnapshotsDeleted`.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5041095062
Thanks for the review, @lijingsong!
I fixed it to only early-abort when a manifest / manifest-list is missing for a live snapshot on the main branch — missing manifests on tags and other branches are ignored as before.
I also updated an existing test whose assumption conflicted with this new abort behavior.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5058774871
The current `early-abort` behavior, which lacks a manifest, only protects `main`: `LocalOrphanFilesClean` constructs `liveSnapshots` only for `DEFAULT_MAIN_BRANCH`, and Flink/Spark also use the same `liveOnMainBranch` gating.
- However, the orphan cleaner’s `validBranches()` scans all active branches; since branches have independent snapshot directories, writes and snapshot expiration can also be performed via the branch table. When new snapshots are generated concurrently on branches and old snapshots are deleted due to expiration, stale-list/missing-manifest race conditions may also occur.
- Because a branch’s `missingManifest` is `null`, a read failure is treated as an empty result, which may still cause data files referenced by active branches to be marked as orphans. Recommendation: **All active branch snapshots should adopt the same `missing-manifest` abort behavior as the main branch; tags can remain on a best-effort basis**, and additional regression tests for concurrent branch commits and expirations should be implemented.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #7715:
URL: https://github.com/apache/paimon/pull/7715#discussion_r3932261979
##########
paimon-core/src/main/java/org/apache/paimon/operation/OrphanFilesClean.java:
##########
@@ -243,22 +243,26 @@ protected boolean isManagedBlobPack(Path path) {
return path.getName().endsWith(ManagedBlobReferenceFile.MANAGED_BLOB_SUFFIX);
}
- protected Set<Snapshot> safelyGetAllSnapshots(String branch) throws IOException {
+ protected Set<Snapshot> safelyGetLiveSnapshots(String branch) throws IOException {
FileStoreTable branchTable = table.switchToBranch(branch);
- SnapshotManager snapshotManager = branchTable.snapshotManager();
- ChangelogManager changelogManager = branchTable.changelogManager();
- TagManager tagManager = branchTable.tagManager();
- Set<Snapshot> readSnapshots = new HashSet<>(snapshotManager.safelyGetAllSnapshots());
- readSnapshots.addAll(tagManager.taggedSnapshots());
- readSnapshots.addAll(changelogManager.safelyGetAllChangelogs());
- return readSnapshots;
+ return new HashSet<>(branchTable.snapshotManager().safelyGetAllSnapshots());
Review Comment:
[P1] Detect an incomplete live-snapshot enumeration before deleting files
This helper still delegates to `safelyGetAllSnapshots()`, which first freezes the snapshot-path list and then silently skips any path that disappears while it is read. For example, it can list only S1, then a concurrent commit creates S2 and retention-1 expiration deletes S1; the method returns an empty set, never scans S2, and never sets `missingManifest` because no `Snapshot` reaches the new guarded manifest readers. Local/Flink/Spark can then proceed with no live files from this branch and delete old manifests/data files still inherited by S2. This is the original data-loss interleaving one level earlier than the new sentinel. Please make live enumeration itself complete (for example, anchor/revalidate a latest snapshot and abort on a changed/incomplete view) and add a deterministic test where commit+expiration occurs between path listing and snapshot reading.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #7715:
URL: https://github.com/apache/paimon/pull/7715#discussion_r3443113772
##########
paimon-core/src/main/java/org/apache/paimon/operation/LocalOrphanFilesClean.java:
##########
@@ -114,6 +114,15 @@ public CleanOrphanFilesResult clean()
.flatMap(branch -> getUsedFiles(branch).stream())
.collect(Collectors.toSet());
+ if (usedFiles.isEmpty()) {
Review Comment:
This guard still does not protect the race described in the PR. `collectWithoutDataFileWithManifestFlag` adds the snapshot manifest-list names to `usedFiles` before reading the manifest-list contents, and `retryReadingFiles(..., emptyList())` returns an empty list when those manifest-lists are concurrently removed. In that case `usedFiles` is not empty, so this check is bypassed, but none of the data files referenced by the expired manifests are protected and `candidateDeletes.removeAll(usedFiles)` can still delete them. Can we guard the data-file collection result instead, or treat a missing manifest-list as an abort for the branch/table rather than only checking whether the overall used-file set is empty?
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #7715:
URL: https://github.com/apache/paimon/pull/7715#discussion_r3888769060
##########
paimon-core/src/main/java/org/apache/paimon/operation/LocalOrphanFilesClean.java:
##########
@@ -157,35 +173,59 @@ private void cleanEmptyDataDirectory(List<Path> deleteFiles) {
}
private void collectWithoutDataFile(
- String branch, Consumer<String> usedFileConsumer, Consumer<String> manifestConsumer)
+ String branch,
+ Consumer<String> usedFileConsumer,
+ Consumer<String> manifestConsumer,
+ Consumer<String> liveManifestConsumer,
+ AtomicBoolean missingManifest)
throws IOException {
+ Set<Snapshot> liveSnapshots =
Review Comment:
[P1] Reuse one active-snapshot view instead of rescanning it
This captures `liveSnapshots` here, but line 207 independently calls `safelyGetAllSnapshots(branch)` again. That helper fixes the path list first and silently skips a snapshot whose file is deleted before it is read. A concurrent S1 -> S2 commit plus retention-1 expiration can therefore make the second scan drop S1 without seeing S2 or setting `missingManifest`. If another branch contributes any used files, the global `usedFiles.isEmpty()` guard is bypassed and old files still referenced by S2 can be deleted. Please process the captured live snapshot objects (adding tags/changelogs separately), or propagate a per-branch incomplete-enumeration signal and abort globally. A deterministic two-branch race test would cover this gap.
##########
paimon-core/src/main/java/org/apache/paimon/operation/LocalOrphanFilesClean.java:
##########
@@ -108,12 +110,26 @@ public CleanOrphanFilesResult clean()
}
candidateDeletes = new HashSet<>(candidates.keySet());
+ AtomicBoolean missingManifest = new AtomicBoolean(false);
+
// find used files
Set<String> usedFiles =
branches.stream()
- .flatMap(branch -> getUsedFiles(branch).stream())
+ .flatMap(branch -> getUsedFiles(branch, missingManifest).stream())
.collect(Collectors.toSet());
+ if (usedFiles.isEmpty()) {
Review Comment:
[P2] Preserve cleanup for a valid zero-snapshot table
An empty `usedFiles` set is also the successful result for a never-committed table. If an aborted first write leaves old bucket or manifest files, local cleanup now returns here forever, while Flink and Spark still clean against zero references. Please base the abort on an explicit per-branch incomplete or missing signal instead of the empty set itself, so legitimate zero-reference cleanup still works.
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkOrphanFilesClean.scala:
##########
@@ -102,18 +136,41 @@ case class SparkOrphanFilesClean(
(key: String) =>
specifiedTable.switchToBranch(key).store.manifestFileFactory.create)
- retryReadingFiles(
+ val manifestMissing =
+ if (branchAndManifestFile.isLiveSnapshot) new AtomicBoolean(false) else null
+ val entries = retryReadingFiles(
() => manifestFile.readWithIOException(branchAndManifestFile.manifestName),
- Collections.emptyList[ManifestEntry]
- ).asScala.flatMap {
- manifestEntry =>
- manifestEntry.fileName() +: manifestEntry.file().extraFiles().asScala
+ Collections.emptyList[ManifestEntry],
+ manifestMissing
+ ).asScala
+ if (manifestMissing != null && manifestMissing.get()) {
+ Iterator.single(("", true))
+ } else {
+ entries
+ .flatMap {
+ manifestEntry =>
+ manifestEntry.fileName() +: manifestEntry.file().extraFiles().asScala
+ }
+ .map(name => (name, false))
+ .iterator
}
}
}
+ .cache()
Review Comment:
[P2] Release this cached dataset
`dataFilesWithFlag` is materialized by the `isEmpty` check and later reused by deletion planning, but `doOrphanClean` returns only `usedManifestFiles`; `executeDatabaseOrphanFiles` therefore unpersists only that dataset in its `finally` block. Normal runs and the early return at line 163 leave this cache registered in the Spark session, so repeated or database-wide cleanup can retain large executor memory/local-disk blocks. Please return and release all cached datasets, including every early-return path.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5033774177
@JingsongLi Thanks for the careful review, I fix it through if manifist or manifist list file not found, ignore this clean, and applied to Local/Flink/Spark, and added a test that drops a live manifest-list and checks no data files get deleted.The missing file is detected via a missingManifest flag in retryReadingFiles, and we abort before the delete/anti-join step.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub) via issues" <is...@paimon.apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-7011281446
Thanks @JingsongLi, I missed this case. I've added the check before the filter and updated the test to cover recomputing only the data branch.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-4529122130
Thanks for thorough review, @JingsongLi.
Fix by your feedback. only retain add an explicit empty-set guard, and tests adjusted. PTAL.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub) via issues" <is...@paimon.apache.org>.
JingsongLi commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-7092652553
Thanks for updating the Spark regression test. I reviewed `49b107a3`. Checking the missing marker before filtering covers the previously reported data-side recomputation case. I would hold the merge for the following issues.
- **[P1] Keep the same snapshot input across Spark retries.** The snapshot RDD enumerates files inside `mapPartitions` and repartitions the results by iterator position. After a concurrent commit and expiration, recomputing that upstream shuffle can put the latest snapshot in a different partition. If Spark recomputes the partition that previously held it and reuses the old downstream map output for the new partition, the data references from the live snapshot can be omitted. The reads that do execute can all succeed, leaving no missing marker and allowing the anti-join to classify live files as orphans. I traced this in the Paimon lineage and Spark 3.5.9 scheduler. Please pin the snapshot input for the run and add a regression for upstream snapshot shuffle recomputation. This scenario still needs end-to-end verification. [Paimon snapshot enumeration](https://github.com/apache/paimon/blob/49b107a3afa35de24a048a263860b6e20a0489b5/paimon-spark/paimon-spark-common/src/main/scala/org/
apache/paimon/spark/procedure/SparkOrphanFilesClean.scala#L82-L90) · [Spark scheduler](https://github.com/apache/spark/blob/v3.5.9/core/src/main/scala/org/apache/spark/scheduler/DAGScheduler.scala#L2064-L2077)
- **[P2] Close the LOCAL executor when snapshot enumeration aborts.** A normal commit during enumeration can now throw an `IOException`. The LOCAL procedure propagates the `Future.get()` failure before reaching `shutdownNow()`. Repeated cleanup in a long-lived Spark or Flink process can leave fixed-pool workers behind. Please close the pool in `finally`. [Enumeration check](https://github.com/apache/paimon/blob/49b107a3afa35de24a048a263860b6e20a0489b5/paimon-core/src/main/java/org/apache/paimon/utils/SnapshotManager.java#L584-L598) · [LOCAL executor](https://github.com/apache/paimon/blob/49b107a3afa35de24a048a263860b6e20a0489b5/paimon-core/src/main/java/org/apache/paimon/operation/LocalOrphanFilesClean.java#L354-L375)
- **[P2] Preserve the managed BLOB cleaner's per-table skip.** On `master`, `remove_orphan_blobs` calls the shared `safelyGetAllSnapshots()` helper. Routing it through strict enumeration can throw on a concurrent commit before the existing topology check can skip that table. This can fail a wildcard cleanup across otherwise unrelated tables. Please keep strict enumeration scoped to `remove_orphan_files` and preserve the existing helper behavior for managed BLOB cleanup. [Shared helper](https://github.com/apache/paimon/blob/49b107a3afa35de24a048a263860b6e20a0489b5/paimon-core/src/main/java/org/apache/paimon/operation/OrphanFilesClean.java#L261-L264) · [Managed BLOB topology check](https://github.com/apache/paimon/blob/ff1a004379c22c671c5d98acbec1f8e912e210dc/paimon-core/src/main/java/org/apache/paimon/operation/ManagedBlobOrphanFilesClean.java#L134-L148)
All 92 focused Core, Flink 1.20, and Spark 3.5.9 tests passed on the merge tree with `master` at `d7b90ecf`. That includes the Flink global abort and Spark data-side recomputation regressions. The licensing job failed while extracting Temurin 8, before it reached the licensing check. [Licensing job](https://github.com/apache/paimon/actions/runs/44875417241/job/136759008344)
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5301743133
@JingsongLi Thanks for this. I broadcast the missing-manifest flag to all subtasks before candidate files are processed. I also added a parallelism-5 regression test to cover this case. Could you please take another look again? thanks a lot
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5997238836
**[P1] Preserve the abort condition when Spark recomputes cached references**
There is still a data-loss path in the Spark implementation at head `c2cb7f0535cafa04ec6bc4d1b1822abecee8813b`.
The two `isEmpty` checks validate the references during the initial reads, but the cached datasets do not provide a durable snapshot. If an executor loses cached partitions, Spark can recompute them from the original lineage and surviving shuffle output ([Spark persistence documentation](https://spark.apache.org/docs/3.5.8/rdd-programming-guide.html#rdd-persistence)).
A concurrent commit can merge the old manifests while retaining their data files, and snapshot expiration can then remove those old manifests. On recomputation, the reader correctly emits a missing-manifest marker, but [line 177](https://github.com/apache/paimon/blob/c2cb7f0535cafa04ec6bc4d1b1822abecee8813b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkOrphanFilesClean.scala#L177) filters that marker out instead of aborting. [Line 181](https://github.com/apache/paimon/blob/c2cb7f0535cafa04ec6bc4d1b1822abecee8813b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkOrphanFilesClean.scala#L181) has the equivalent issue for manifest-list markers. The final `left_anti` join can therefore delete old data files that the current snapshot still references.
I reproduced this with Spark 3.5.8, real Paimon commits and expiration, and simulated cache loss:
1. Create an append table with `bucket=1`, `bucket-key=id`, `manifest.merge-min-count=1`, and both snapshot retention limits set to `1`.
2. Insert two batches, set their data-file modification times to two days ago, and use the default one-day cleanup cutoff.
3. Call `doOrphanClean()`; both missing-manifest prechecks pass. Obtain the returned deletion dataset and initialize its execution plan.
4. Insert a third batch. Expiration removes obsolete merged manifests, while the latest snapshot still contains all three rows.
5. Simulate loss of the cached RDD contents while keeping the SQL cache registrations:
```scala
spark.sparkContext.getPersistentRDDs.values.foreach(_.unpersist(blocking = true))
```
6. Execute `deleted.collect()`. It reports `(2, 932)`, and both old data files still referenced by the latest snapshot are deleted.
This is a remaining gap in the intended concurrent-expiration fix; the baseline also has a similar risk.
Please make a missing live manifest/manifest-list fail the execution even during recomputation, or preserve a global abort barrier in the final deletion query. A reliable checkpoint of the validated references is another option. A regression test covering commit + expiration + cache loss would protect this path.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-4344621113
Hi @heye1005 It is better to fix it reading full ref files for latest snapshot.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5100509512
> The current `early-abort` behavior, which lacks a manifest, only protects `main`: `LocalOrphanFilesClean` constructs `liveSnapshots` only for `DEFAULT_MAIN_BRANCH`, and Flink/Spark also use the same `liveOnMainBranch` gating.
>
> * However, the orphan cleaner’s `validBranches()` scans all active branches; since branches have independent snapshot directories, writes and snapshot expiration can also be performed via the branch table. When new snapshots are generated concurrently on branches and old snapshots are deleted due to expiration, stale-list/missing-manifest race conditions may also occur.
> * Because a branch’s `missingManifest` is `null`, a read failure is treated as an empty result, which may still cause data files referenced by active branches to be marked as orphans. Recommendation: **All active branch snapshots should adopt the same `missing-manifest` abort behavior as the main branch; tags can remain on a best-effort basis**, and additional regression tests for concurrent branch commits and expirations should be implemented.
Thanks for the review — fixed by building liveSnapshots for every active branch across local/Flink/Spark so all branch snapshots share the same missing-manifest abort behavior, kept tags best-effort also, all tests and spot passed
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #7715:
URL: https://github.com/apache/paimon/pull/7715#discussion_r4284442266
##########
paimon-core/src/main/java/org/apache/paimon/operation/OrphanFilesClean.java:
##########
@@ -243,22 +243,26 @@ protected boolean isManagedBlobPack(Path path) {
return path.getName().endsWith(ManagedBlobReferenceFile.MANAGED_BLOB_SUFFIX);
}
- protected Set<Snapshot> safelyGetAllSnapshots(String branch) throws IOException {
+ protected Set<Snapshot> safelyGetLiveSnapshots(String branch) throws IOException {
FileStoreTable branchTable = table.switchToBranch(branch);
- SnapshotManager snapshotManager = branchTable.snapshotManager();
- ChangelogManager changelogManager = branchTable.changelogManager();
- TagManager tagManager = branchTable.tagManager();
- Set<Snapshot> readSnapshots = new HashSet<>(snapshotManager.safelyGetAllSnapshots());
- readSnapshots.addAll(tagManager.taggedSnapshots());
- readSnapshots.addAll(changelogManager.safelyGetAllChangelogs());
- return readSnapshots;
+ return new HashSet<>(branchTable.snapshotManager().safelyGetAllSnapshots());
Review Comment:
Verified fixed on 09a86e0217. I independently ran the normal core/Flink/Spark cleanup suites (54 tests), then used real main/branch commits and snapshot expiration to trigger both list/read and captured-live/manifest-read races. Enumeration rejects the changed latest; missing live manifests abort deletion, and live data plus orphan candidates remain. Stable-history and zero-snapshot cleanup controls also pass. Spark cache-loss/recomputation additionally passed with parallelism 5 under sort-merge (AQE off/on) and broadcast joins: all old candidates survive and all 30 live rows remain readable. No remaining finding in these reviewed paths; resolving this thread.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #7715:
URL: https://github.com/apache/paimon/pull/7715#discussion_r4291189295
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkOrphanFilesClean.scala:
##########
@@ -69,29 +82,57 @@ case class SparkOrphanFilesClean(
val usedManifestFiles = spark.sparkContext
.parallelize(branches.asScala.toSeq, maxBranchParallelism)
.mapPartitions(_.flatMap {
- branch => safelyGetAllSnapshots(branch).asScala.map(snapshot => (branch, snapshot.toJson))
+ branch =>
+ val liveSnapshots = safelyGetLiveSnapshots(branch)
+ snapshotsIncludingTagsAndChangelogs(branch, liveSnapshots).asScala.map(
+ snapshot => (branch, snapshot.toJson, liveSnapshots.contains(snapshot)))
})
.repartition(parallelism)
.flatMap {
- case (branch, snapshotJson) =>
+ case (branch, snapshotJson, isLive) =>
val usedFileBuffer = new ArrayBuffer[BranchAndManifestFile]()
val usedFileConsumer =
new Consumer[org.apache.paimon.utils.Pair[String, java.lang.Boolean]] {
override def accept(pair: utils.Pair[String, java.lang.Boolean]): Unit = {
- usedFileBuffer.append(BranchAndManifestFile(branch, pair.getLeft, pair.getRight))
+ usedFileBuffer.append(
+ BranchAndManifestFile(
+ branch,
+ pair.getLeft,
+ pair.getRight,
+ isMissing = false,
+ isLiveSnapshot = isLive))
}
}
+ val missingManifest = if (isLive) new AtomicBoolean(false) else null
val snapshot = Snapshot.fromJson(snapshotJson)
- collectWithoutDataFileWithManifestFlag(branch, snapshot, usedFileConsumer)
+ collectWithoutDataFileWithManifestFlag(
+ branch,
+ snapshot,
+ usedFileConsumer,
+ missingManifest)
+ if (missingManifest != null && missingManifest.get()) {
+ usedFileBuffer.append(
+ BranchAndManifestFile(branch, "", isManifestFile = false, isMissing = true))
+ }
usedFileBuffer
}
.toDS()
.cache()
+ cachedDatasets += usedManifestFiles
+
+ if (!usedManifestFiles.filter(_.isMissing).isEmpty) {
+ logWarning("Detected missing manifest during used-files collection, aborting clean.")
+ return (
+ spark.createDataset(
+ Seq((deletedFilesCountInLocal.get(), deletedFilesLenInBytesInLocal.get()))),
+ cachedDatasets.toSeq)
+ }
- // find all data files
- val dataFiles = usedManifestFiles
- .filter(_.isManifestFile)
- .distinct()
+ val dataFilesWithFlag = usedManifestFiles
+ .filter(f => f.isManifestFile && !f.isMissing)
Review Comment:
[P1] Check missing metadata before filtering the data-reference branch
This filter still discards the missing-manifest marker when only the data-reference branch is recomputed. The two branches of `usedFiles.union(dataFiles)` can reuse different shuffle outputs: if the metadata branch has already produced its output, loss of the reference caches and the manifest-grouping shuffle can rerun only the data branch from the surviving captured-snapshot shuffle. After concurrent commit/expiration removes the old manifest list, its `isMissing` record is filtered out here. The metadata branch reuses its completed output, so its later missing-marker check does not run again. The anti-join can then delete data files still referenced by the current snapshot.
I reproduced this on `09a86e021779569d7ea79bd50f58729a26fec170` with Spark 3.5.8, real commits/expiration, and selective cache/shuffle-loss injection. After preserving the completed metadata-branch output and invalidating only the manifest-grouping shuffle map output plus the two reference caches, Spark retried the grouping stage following `MetadataFetchFailedException`. `usedManifestFiles` contained missing markers, but `dataFilesWithFlag` was empty; cleanup returned `(2, 594)`, deleted both old live data files, and a subsequent table read failed with `FileNotFoundException`. A control that throws on `isMissing` before this filter aborted cleanup and preserved all three rows.
Please check `isMissing` and fail before filtering out non-manifest records, or propagate the abort signal through this branch. Add a regression test that retains the completed metadata-branch shuffle output while recomputing the data-reference branch; the current test evicts all caches before execution and therefore reruns the other branch's guard.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on code in PR #7715:
URL: https://github.com/apache/paimon/pull/7715#discussion_r4182525772
##########
paimon-core/src/main/java/org/apache/paimon/operation/OrphanFilesClean.java:
##########
@@ -243,22 +243,26 @@ protected boolean isManagedBlobPack(Path path) {
return path.getName().endsWith(ManagedBlobReferenceFile.MANAGED_BLOB_SUFFIX);
}
- protected Set<Snapshot> safelyGetAllSnapshots(String branch) throws IOException {
+ protected Set<Snapshot> safelyGetLiveSnapshots(String branch) throws IOException {
FileStoreTable branchTable = table.switchToBranch(branch);
- SnapshotManager snapshotManager = branchTable.snapshotManager();
- ChangelogManager changelogManager = branchTable.changelogManager();
- TagManager tagManager = branchTable.tagManager();
- Set<Snapshot> readSnapshots = new HashSet<>(snapshotManager.safelyGetAllSnapshots());
- readSnapshots.addAll(tagManager.taggedSnapshots());
- readSnapshots.addAll(changelogManager.safelyGetAllChangelogs());
- return readSnapshots;
+ return new HashSet<>(branchTable.snapshotManager().safelyGetAllSnapshots());
Review Comment:
@JingsongLi Thanks for catching this. Fixed by recording the latest snapshot id before and after enumeration and aborting if it changes. This may be conservative for frequently committed tables, and I prefer to optimize this by checking that the enumerated snapshots include the latest snapshot id observed before enumeration.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on code in PR #7715:
URL: https://github.com/apache/paimon/pull/7715#discussion_r3443119539
##########
paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkOrphanFilesClean.scala:
##########
@@ -88,6 +88,18 @@ case class SparkOrphanFilesClean(
.toDS()
.cache()
+ if (usedManifestFiles.isEmpty) {
Review Comment:
Same issue here: this only checks whether any snapshot/manifest-list names were collected, not whether the referenced data files were protected. `collectWithoutDataFileWithManifestFlag` emits the manifest-list names before reading their contents; if concurrent expiration removes those manifest-lists, `retryReadingFiles(..., emptyList())` yields no manifest entries, but `usedManifestFiles` is still non-empty. The job then builds an empty `dataFiles` dataset and anti-joins candidates only against the manifest-list names, so old data files can still be deleted. Please make the abort condition cover the data-file collection failure/missing manifest-list case as well.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5104967325
In Flink's distributed orphan file cleanup, the `missing-manifest` sentinel generated by the `keyBy` operation is sent to only one join sub-task. Unless that sub-task has `abortDeletion` enabled, other parallel sub-tasks may still delete the file, making it impossible to prevent accidental deletions globally.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5999393027
> **[P1] Preserve the abort condition when Spark recomputes cached references**
>
> There is still a data-loss path in the Spark implementation at head `c2cb7f0535cafa04ec6bc4d1b1822abecee8813b`.
>
> The two `isEmpty` checks validate the references during the initial reads, but the cached datasets do not provide a durable snapshot. If an executor loses cached partitions, Spark can recompute them from the original lineage and surviving shuffle output ([Spark persistence documentation](https://spark.apache.org/docs/3.5.8/rdd-programming-guide.html#rdd-persistence)).
>
> A concurrent commit can merge the old manifests while retaining their data files, and snapshot expiration can then remove those old manifests. On recomputation, the reader correctly emits a missing-manifest marker, but [line 177](https://github.com/apache/paimon/blob/c2cb7f0535cafa04ec6bc4d1b1822abecee8813b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkOrphanFilesClean.scala#L177) filters that marker out instead of aborting. [Line 181](https://github.com/apache/paimon/blob/c2cb7f0535cafa04ec6bc4d1b1822abecee8813b/paimon-spark/paimon-spark-common/src/main/scala/org/apache/paimon/spark/procedure/SparkOrphanFilesClean.scala#L181) has the equivalent issue for manifest-list markers. The final `left_anti` join can therefore delete old data files that the current snapshot still references.
>
> I reproduced this with Spark 3.5.8, real Paimon commits and expiration, and simulated cache loss:
>
> 1. Create an append table with `bucket=1`, `bucket-key=id`, `manifest.merge-min-count=1`, and both snapshot retention limits set to `1`.
> 2. Insert two batches, set their data-file modification times to two days ago, and use the default one-day cleanup cutoff.
> 3. Call `doOrphanClean()`; both missing-manifest prechecks pass. Obtain the returned deletion dataset and initialize its execution plan.
> 4. Insert a third batch. Expiration removes obsolete merged manifests, while the latest snapshot still contains all three rows.
> 5. Simulate loss of the cached RDD contents while keeping the SQL cache registrations:
> ```scala
> spark.sparkContext.getPersistentRDDs.values.foreach(_.unpersist(blocking = true))
> ```
> 6. Execute `deleted.collect()`. It reports `(2, 932)`, and both old data files still referenced by the latest snapshot are deleted.
>
> This is a remaining gap in the intended concurrent-expiration fix; the baseline also has a similar risk.
>
> Please make a missing live manifest/manifest-list fail the execution even during recomputation, or preserve a global abort barrier in the final deletion query. A reliable checkpoint of the validated references is another option. A regression test covering commit + expiration + cache loss would protect this path.
Thanks for suggests. I removed the spark filters that dropped missing markers and moved the check into the final execution path, so cache loss and recomputation won’t bypass it. I also added a regression test for this case.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-4358890786
> Hi @heye1005 It is better to fix it reading full ref files for latest snapshot.
Thanks for the review! Updated the PR based on your suggestion.
The root cause here is that `safelyGetAllSnapshots()` lists the snapshot directory first, then reads each file. If expiration deletes the snapshot file (along with its manifest-list) between these two steps, the read silently fails and returns an empty list — all old data files then get treated as orphans.
This PR has two changes:
1. Replaced the list-then-read in `safelyGetAllSnapshots()` with `latestSnapshot()` + ID range traversal. Expiration never deletes the latest snapshot, so the snapshot file read is safe. But the manifest-list of that snapshot can still be deleted before we read it.
2. Added `collectLatestSnapshotFiles()` — re-reads the latest snapshot right before deletion and removes its referenced files from candidates. By then expiration is usually done, so the current latest snapshot's manifest-list is intact. This is applied to Local, Flink, and Spark subclasses.
This doesn't 100% eliminate the race — if expiration happens to delete the latest snapshot's manifest-list during the pre-deletion check, it would still fail. But that window is just milliseconds, so practically very unlikely.
To fully solve this, I think we'd need either some form of locking between orphan clean and expiration, or delay manifest-list deletion (similar to how orphan clean already requires data files to be older than `olderThanMillis`). Happy to discuss further.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-4358417940
Thanks for the review! Moved the fix into parent class `safelyGetAllSnapshots()` so Flink/Spark also benefit. Basically replaced the list-then-read with latestSnapshot() + ID range traversal. Also added a regression test.
--
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] Fix orphan files clean deleting data files during concurrent snapshot expiration [paimon]
Posted by "heye1005 (via GitHub)" <gi...@apache.org>.
heye1005 commented on PR #7715:
URL: https://github.com/apache/paimon/pull/7715#issuecomment-5469227502
> Inline findings from the review.
@JingsongLi thanks,fixed three issues:
1.split two functions (get active snapshots per branch,get tags and changelog snapshot), and reuse liveSnapshots function;
2. all spark cached datasets are free on exit path
3. local cleanup now supports valid zero-snapshot tables by aborting only on an explicit missing-manifest signal.
--
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