You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "HuaHuaY (via GitHub)" <gi...@apache.org> on 2026/06/05 06:32:00 UTC
[PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
HuaHuaY opened a new pull request, #16686:
URL: https://github.com/apache/iceberg/pull/16686
`deleteFiles` and `duplicateDeleteCount` are not thread-safe and they are modified concurrently in `filterManifests`. In addition, `duplicateDeleteCount` will be counted repeatedly during the retry process after a commit failure.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3508300589
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -256,16 +264,15 @@ SnapshotSummary.Builder buildSummary(Iterable<ManifestFile> manifests) {
for (ManifestFile manifest : manifests) {
PartitionSpec manifestSpec = specsById.get(manifest.partitionSpecId());
- Iterable<F> manifestDeletes = filteredManifestToDeletedFiles.get(manifest);
- if (manifestDeletes != null) {
- for (F file : manifestDeletes) {
+ FilterResult<F> result = filteredManifestResults.get(manifest);
+ if (result != null) {
+ for (F file : result.deletedFiles()) {
summaryBuilder.deletedFile(manifestSpec, file);
}
+ summaryBuilder.incrementDuplicateDeletes(result.duplicateDeleteCount());
Review Comment:
This goes a lot farther than I think is necessary to make the duplicate delete count more reliable. The main problem is knowing that duplicate deletes have occurred, then you should go and find out which file was duplicated and how the duplication happened. The need is to produce anything non-zero. Still this isn't wrong.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3437606443
##########
core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java:
##########
@@ -212,6 +220,86 @@ public void deleteWithDuplicates() {
.containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
}
+ @TestTemplate
+ public void deleteDuplicateFilesWithinMultipleManifests() throws Exception {
Review Comment:
this one is passing for me even without the fix
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3518148757
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -300,16 +300,14 @@ private void validateRequiredDeletes(ManifestFile... manifests) {
}
}
- private Set<F> deletedFiles(ManifestFile[] manifests) {
+ private Set<F> collectDeletedFiles(ManifestFile[] manifests) {
Review Comment:
nit: are we renaming this on purpose?
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3518182579
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -300,16 +300,14 @@ private void validateRequiredDeletes(ManifestFile... manifests) {
}
}
- private Set<F> deletedFiles(ManifestFile[] manifests) {
+ private Set<F> collectDeletedFiles(ManifestFile[] manifests) {
Review Comment:
This change is a leftover from the continuous code refactoring that took place during implementation; it arose because we added a new call site for this function. I feel the new name is clearer, but if we want to avoid making too many Git diff changes, I am also open to reverting the rename.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3497954230
##########
core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java:
##########
@@ -212,6 +220,86 @@ public void deleteWithDuplicates() {
.containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
}
+ @TestTemplate
+ public void deleteDuplicateFilesWithinMultipleManifests() throws Exception {
Review Comment:
I followed suggestions behind and chose a merge-after approach without `ConcurrentLinkedQueue`.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#issuecomment-4629000477
@nastra @Fokko Could you help review this? @HuaHuaY found this issue when developing similar features in the iceberg-cpp.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3446852410
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -279,14 +281,16 @@ SnapshotSummary.Builder buildSummary(Iterable<ManifestFile> manifests) {
private void validateRequiredDeletes(ManifestFile... manifests) {
if (failMissingDeletePaths) {
Set<F> deletedFiles = deletedFiles(manifests);
- ValidationException.check(
- deletedFiles.containsAll(deleteFiles),
- "Missing required files to delete: %s",
- COMMA.join(
- deleteFiles.stream()
- .filter(f -> !deletedFiles.contains(f))
- .map(ContentFile::location)
- .collect(Collectors.toList())));
+ synchronized (deleteFiles) {
Review Comment:
Huge +1 to getting rid of this synchronized.
I pasted a diff above as well, but I think we can consolidate the duplicate and deletedFiles tracking, and and essentially not even populate deleteFiles in a multi-threaded manner and avoid this issue entirely. The usage of parallelism on that path is largely for I/O anyways.
I also think we don't even need the concurrent linked queue state for tracking the files deleted by expresssion. I think once we figure out the manifests that need to be rewritten, we already have all of the deleted files, we can add those back to the global deleteFiles after the parallel read.
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -95,6 +95,8 @@ public String partition() {
// tracking where files were deleted to validate retries quickly
private final Map<ManifestFile, Iterable<F>> filteredManifestToDeletedFiles =
Maps.newConcurrentMap();
+ private final Map<ManifestFile, Integer> filteredManifestToDuplicateDeleteCounts =
+ Maps.newConcurrentMap();
Review Comment:
```
--- a/core/src/main/java/org/apache/iceberg/ManifestFilterManager.java
+++ b/core/src/main/java/org/apache/iceberg/ManifestFilterManager.java
@@ -82,7 +82,6 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
private long minSequenceNumber = 0;
private boolean failAnyDelete = false;
private boolean failMissingDeletePaths = false;
- private int duplicateDeleteCount = 0;
private boolean caseSensitive = true;
private boolean allDeletesReferenceManifests = true;
// this is only being used for the DeleteManifestFilterManager to detect orphaned DVs for removed
@@ -93,8 +92,7 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
private final Map<ManifestFile, ManifestFile> filteredManifests = Maps.newConcurrentMap();
// tracking where files were deleted to validate retries quickly
- private final Map<ManifestFile, Iterable<F>> filteredManifestToDeletedFiles =
- Maps.newConcurrentMap();
+ private final Map<ManifestFile, FilterResult<F>> filteredManifestResults = Maps.newConcurrentMap();
private final Supplier<ExecutorService> workerPoolSupplier;
@@ -229,6 +227,15 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
filtered[index] = manifest;
});
+ // merge per-manifest deletes into deleteFiles after the parallel phase, avoiding concurrent
+ // mutation of deleteFiles during filtering
+ for (ManifestFile manifest : filtered) {
+ FilterResult<F> result = filteredManifestResults.get(manifest);
+ if (result != null) {
+ result.deletedFiles().forEach(deleteFiles::add);
+ }
+ }
+
validateRequiredDeletes(filtered);
return Arrays.asList(filtered);
@@ -256,16 +263,15 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
for (ManifestFile manifest : manifests) {
PartitionSpec manifestSpec = specsById.get(manifest.partitionSpecId());
- Iterable<F> manifestDeletes = filteredManifestToDeletedFiles.get(manifest);
- if (manifestDeletes != null) {
- for (F file : manifestDeletes) {
+ FilterResult<F> result = filteredManifestResults.get(manifest);
+ if (result != null) {
+ for (F file : result.deletedFiles()) {
summaryBuilder.deletedFile(manifestSpec, file);
}
+ summaryBuilder.incrementDuplicateDeletes(result.duplicateDeleteCount());
}
}
- summaryBuilder.incrementDuplicateDeletes(duplicateDeleteCount);
-
return summaryBuilder;
}
@@ -305,9 +311,9 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
if (manifests != null) {
for (ManifestFile manifest : manifests) {
- Iterable<F> manifestDeletes = filteredManifestToDeletedFiles.get(manifest);
- if (manifestDeletes != null) {
- for (F file : manifestDeletes) {
+ FilterResult<F> result = filteredManifestResults.get(manifest);
+ if (result != null) {
+ for (F file : result.deletedFiles()) {
deletedFiles.add(file);
}
}
@@ -353,6 +359,7 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
// remove the entry from the cache
filteredManifests.remove(manifest);
+ filteredManifestResults.remove(filtered);
}
}
}
@@ -501,6 +508,7 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
// when this point is reached, there is at least one file that will be deleted in the
// manifest. produce a copy of the manifest with all deleted files removed.
Set<F> deletedFiles = newFileSet();
+ AtomicInteger duplicateDeleteCount = new AtomicInteger(0);
try {
ManifestWriter<F> writer = newManifestWriter(reader.spec());
@@ -533,16 +541,13 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
if (allRowsMatch) {
writer.delete(entry);
F fileCopy = file.copyWithoutStats();
- // add the file here in case it was deleted using an expression. The
- // DeleteManifestFilterManager will then remove its matching DV
- deleteFiles.add(fileCopy);
if (deletedFiles.contains(file)) {
LOG.warn(
"Deleting a duplicate path from manifest {}: {}",
manifest.path(),
file.location());
- duplicateDeleteCount += 1;
+ duplicateDeleteCount.incrementAndGet();
} else {
// only add the file to deletes if it is a new delete
// this keeps the snapshot summary accurate for non-duplicate data
@@ -565,7 +570,8 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
// update caches
filteredManifests.put(manifest, filtered);
- filteredManifestToDeletedFiles.put(filtered, deletedFiles);
+ filteredManifestResults.put(
+ filtered, new FilterResult<>(deletedFiles, duplicateDeleteCount.get()));
return filtered;
@@ -574,6 +580,8 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
}
}
+ private record FilterResult<T>(Iterable<T> deletedFiles, int duplicateDeleteCount) {}
+
// an evaluator that checks whether rows in a file may/must match a given expression
// this class first partially evaluates the provided expression using the partition tuple
// and then checks the remaining part of the expression using metrics evaluators
```
here's the diff I came up with that I think addresses this issue as well
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -95,6 +95,8 @@ public String partition() {
// tracking where files were deleted to validate retries quickly
private final Map<ManifestFile, Iterable<F>> filteredManifestToDeletedFiles =
Maps.newConcurrentMap();
+ private final Map<ManifestFile, Integer> filteredManifestToDuplicateDeleteCounts =
+ Maps.newConcurrentMap();
Review Comment:
Instead of 2 separate maps I think we can have a bit more simplified of a state by having a single map and the value is a pair or record type with the Iterable and duplicateDelete counts.
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -95,6 +95,8 @@ public String partition() {
// tracking where files were deleted to validate retries quickly
private final Map<ManifestFile, Iterable<F>> filteredManifestToDeletedFiles =
Maps.newConcurrentMap();
+ private final Map<ManifestFile, Integer> filteredManifestToDuplicateDeleteCounts =
+ Maps.newConcurrentMap();
Review Comment:
Maybe use a class instead of the record type, this seems like something we'd want to backport and older versions would need to be JDK 11 compliant etc.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#issuecomment-4877183633
Thank you @HuaHuaY @liucao-dd , and @nastra @rdblue for reviewing! I will go ahead and merge
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3497419711
##########
core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java:
##########
@@ -212,6 +220,86 @@ public void deleteWithDuplicates() {
.containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
}
+ @TestTemplate
+ public void deleteDuplicateFilesWithinMultipleManifests() throws Exception {
Review Comment:
> this one is passing for me even without the fix
Because this PR merely resolves concurrency conflicts. Concurrency conflicts themselves cause problems unpredictably; issues may or may not arise.
> I've added a cherry-pickable commit
@liucao-dd Thanks for your test cases. I will cherry pick this commit.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#issuecomment-4842262196
Hi @nastra and @amogh-jahagirdar, I have updated this PR and followed @amogh-jahagirdar's suggestion. Please take a look again.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3510118293
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -533,16 +542,13 @@ private ManifestFile filterManifestWithDeletedFiles(
if (allRowsMatch) {
writer.delete(entry);
F fileCopy = file.copyWithoutStats();
- // add the file here in case it was deleted using an expression. The
- // DeleteManifestFilterManager will then remove its matching DV
- deleteFiles.add(fileCopy);
if (deletedFiles.contains(file)) {
LOG.warn(
"Deleting a duplicate path from manifest {}: {}",
manifest.path(),
file.location());
- duplicateDeleteCount += 1;
+ duplicateDeleteCount.incrementAndGet();
Review Comment:
I think we still need it. The reason we need `duplicateDeleteCount` here is that it's modified in the lambda expression.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#issuecomment-4732147624
I'll take a look at it this week, thanks @HuaHuaY for finding this.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3507110598
##########
core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java:
##########
@@ -212,6 +220,86 @@ public void deleteWithDuplicates() {
.containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
}
+ @TestTemplate
+ public void deleteDuplicateFilesWithinMultipleManifests() throws Exception {
Review Comment:
Thanks @HuaHuaY see my comment https://github.com/apache/iceberg/pull/16686#r3507100091 on my thoughts on the concurrency tests. the TLDR is I think i'd just remove the 2 concurrency focused tests now that we've structurally made the internal state for this path for collecting the files to delete after the parallel manifest read to be single threaded. The tests are more complexity than they're really worth imo.
##########
core/src/test/java/org/apache/iceberg/TestOverwrite.java:
##########
@@ -335,4 +336,55 @@ public void testValidatedOverwriteWithAppendSuccess() {
assertThat(latestSnapshot(base, branch).snapshotId()).isEqualTo(baseId);
}
+
+ @TestTemplate
+ public void testFullOverwriteAcrossManyManifests() {
Review Comment:
While this and the below concurrency test are well intentioned I think the issue with these kinds of tests is that we end up doing a lot of complex stuff just to try and repro the internal state of that class that used to be concurrent. We could use barriers but even that's super complex.
If we take a step back, in terms of the internal implementation we've now structurally changed the code to collect the deleted files in a single-threaded manner; so it's a bit questionable to write a test which does all this work to simulate the conditions to hit this internal state that no longer exists.
In combination with the deterministic test for making sure retries don't double count the duplicates, I think we're fairly well covered.
In that case, I would simply just recommend removing this and the test below.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3507100091
##########
core/src/test/java/org/apache/iceberg/TestOverwrite.java:
##########
@@ -335,4 +336,55 @@ public void testValidatedOverwriteWithAppendSuccess() {
assertThat(latestSnapshot(base, branch).snapshotId()).isEqualTo(baseId);
}
+
+ @TestTemplate
+ public void testFullOverwriteAcrossManyManifests() {
Review Comment:
While this and the below concurrency test are well intentioned I think the issue with these kinds of tests is that we end up doing a lot of complex stuff just to try and repro the internal state of that class that used to be concurrent but no longer is. We could use barriers but even that's super complex.
If we take a step back, in terms of the internal implementation we've now structurally changed the code to collect the deleted files in a single-threaded manner after the parallel manifest read; so it's a bit questionable to write a test which does all this work to simulate the conditions to hit this internal state that no longer exists.
In combination with the deterministic test for making sure retries don't double count the duplicates, I think we're fairly well covered.
In that case, I would simply just recommend removing this and the test below.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3518182579
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -300,16 +300,14 @@ private void validateRequiredDeletes(ManifestFile... manifests) {
}
}
- private Set<F> deletedFiles(ManifestFile[] manifests) {
+ private Set<F> collectDeletedFiles(ManifestFile[] manifests) {
Review Comment:
This change is a leftover from the continuous code refactoring that took place during implementation; it arose because we added a new call site for this function. I feel the new name is clearer, but if we want to avoid making too many changes, I am also open to reverting the rename.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3506909810
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -533,16 +542,13 @@ private ManifestFile filterManifestWithDeletedFiles(
if (allRowsMatch) {
writer.delete(entry);
F fileCopy = file.copyWithoutStats();
- // add the file here in case it was deleted using an expression. The
- // DeleteManifestFilterManager will then remove its matching DV
- deleteFiles.add(fileCopy);
if (deletedFiles.contains(file)) {
LOG.warn(
"Deleting a duplicate path from manifest {}: {}",
manifest.path(),
file.location());
- duplicateDeleteCount += 1;
+ duplicateDeleteCount.incrementAndGet();
Review Comment:
After the most recent change, does this still need to be atomic int? It's only being updated in a single threaded manner as far as I can tell.
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -229,6 +228,15 @@ List<ManifestFile> filterManifests(Schema tableSchema, List<ManifestFile> manife
filtered[index] = manifest;
});
+ for (ManifestFile manifest : filtered) {
Review Comment:
Minor: maybe an inline comment "collect all deleted files" or just a helper method which abstracts this `collectDeletedFiles(ManifestFile[] filter)`
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3508285914
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -574,6 +581,24 @@ private ManifestFile filterManifestWithDeletedFiles(
}
}
+ private static class FilterResult<T> {
Review Comment:
For simple cases like this, use `Pair` instead of of introducing new classes.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "liucao-dd (via GitHub)" <gi...@apache.org>.
liucao-dd commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3493327002
##########
core/src/test/java/org/apache/iceberg/TestSnapshotSummary.java:
##########
@@ -212,6 +220,86 @@ public void deleteWithDuplicates() {
.containsEntry(SnapshotSummary.REPLACED_MANIFESTS_COUNT, "1");
}
+ @TestTemplate
+ public void deleteDuplicateFilesWithinMultipleManifests() throws Exception {
Review Comment:
Seems like this issue is pretty popular and affecting many. I also ran into the issue multiple times in production and filed https://github.com/apache/iceberg/issues/16978 while unaware of this PR. After the issue was opened there are another 3 PRs working on this same issue haha (see the linked PRs on the issue)
I've added a cherry-pickable commit for the integration test that failed most of the times without the fix here, in case it is helpful. The remaining fix on my PR is mostly a duplicate of this.
https://github.com/apache/iceberg/pull/16984/commits/24ceb0feb47644f99e6539959ba4159c3a1d1144
One of the other PR author went with a merge-after approach while adopting this test as well - would need some guidance to land the most desirable fix.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3440832727
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -279,14 +281,16 @@ SnapshotSummary.Builder buildSummary(Iterable<ManifestFile> manifests) {
private void validateRequiredDeletes(ManifestFile... manifests) {
if (failMissingDeletePaths) {
Set<F> deletedFiles = deletedFiles(manifests);
- ValidationException.check(
- deletedFiles.containsAll(deleteFiles),
- "Missing required files to delete: %s",
- COMMA.join(
- deleteFiles.stream()
- .filter(f -> !deletedFiles.contains(f))
- .map(ContentFile::location)
- .collect(Collectors.toList())));
+ synchronized (deleteFiles) {
Review Comment:
it would be good to avoid the synchronized block. An alternative approach that avoids this would be
```
diff --git a/core/src/main/java/org/apache/iceberg/ManifestFilterManager.java b/core/src/main/java/org/apache/iceberg/ManifestFilterManager.java
index 7d146d9246..66ef96a658 100644
--- a/core/src/main/java/org/apache/iceberg/ManifestFilterManager.java
+++ b/core/src/main/java/org/apache/iceberg/ManifestFilterManager.java
@@ -22,7 +22,9 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Queue;
import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
@@ -82,18 +84,22 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
private long minSequenceNumber = 0;
private boolean failAnyDelete = false;
private boolean failMissingDeletePaths = false;
- private int duplicateDeleteCount = 0;
private boolean caseSensitive = true;
private boolean allDeletesReferenceManifests = true;
// this is only being used for the DeleteManifestFilterManager to detect orphaned DVs for removed
// data file paths
private Set<String> removedDataFilePaths = Sets.newHashSet();
+ // thread-safe queue for files discovered via expression matching during parallel filtering,
+ // drained into deleteFiles after the parallel phase completes
+ private final Queue<F> pendingDeletes = new ConcurrentLinkedQueue<>();
+
// cache filtered manifests to avoid extra work when commits fail.
private final Map<ManifestFile, ManifestFile> filteredManifests = Maps.newConcurrentMap();
- // tracking where files were deleted to validate retries quickly
- private final Map<ManifestFile, Iterable<F>> filteredManifestToDeletedFiles =
+ // cached per-manifest filter results (deleted files and duplicate count) for summary building
+ // and retry correctness
+ private final Map<ManifestFile, FilterResult<F>> filteredManifestToDeletedFiles =
Maps.newConcurrentMap();
private final Supplier<ExecutorService> workerPoolSupplier;
@@ -229,6 +235,11 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
filtered[index] = manifest;
});
+ // merge expression-matched files discovered during parallel filtering into deleteFiles
+ for (F file = pendingDeletes.poll(); file != null; file = pendingDeletes.poll()) {
+ deleteFiles.add(file);
+ }
+
validateRequiredDeletes(filtered);
return Arrays.asList(filtered);
@@ -256,16 +267,16 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
for (ManifestFile manifest : manifests) {
PartitionSpec manifestSpec = specsById.get(manifest.partitionSpecId());
- Iterable<F> manifestDeletes = filteredManifestToDeletedFiles.get(manifest);
- if (manifestDeletes != null) {
- for (F file : manifestDeletes) {
+ FilterResult<F> result = filteredManifestToDeletedFiles.get(manifest);
+ if (result != null) {
+ for (F file : result.deletedFiles()) {
summaryBuilder.deletedFile(manifestSpec, file);
}
+
+ summaryBuilder.incrementDuplicateDeletes(result.duplicateDeleteCount());
}
}
- summaryBuilder.incrementDuplicateDeletes(duplicateDeleteCount);
-
return summaryBuilder;
}
@@ -305,9 +316,9 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
if (manifests != null) {
for (ManifestFile manifest : manifests) {
- Iterable<F> manifestDeletes = filteredManifestToDeletedFiles.get(manifest);
- if (manifestDeletes != null) {
- for (F file : manifestDeletes) {
+ FilterResult<F> result = filteredManifestToDeletedFiles.get(manifest);
+ if (result != null) {
+ for (F file : result.deletedFiles()) {
deletedFiles.add(file);
}
}
@@ -351,8 +362,9 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
replacedManifestsCount.decrementAndGet();
}
- // remove the entry from the cache
+ // remove the entries from the caches
filteredManifests.remove(manifest);
+ filteredManifestToDeletedFiles.remove(filtered);
}
}
}
@@ -501,6 +513,7 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
// when this point is reached, there is at least one file that will be deleted in the
// manifest. produce a copy of the manifest with all deleted files removed.
Set<F> deletedFiles = newFileSet();
+ AtomicInteger duplicateDeleteCount = new AtomicInteger(0);
try {
ManifestWriter<F> writer = newManifestWriter(reader.spec());
@@ -533,16 +546,17 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
if (allRowsMatch) {
writer.delete(entry);
F fileCopy = file.copyWithoutStats();
- // add the file here in case it was deleted using an expression. The
- // DeleteManifestFilterManager will then remove its matching DV
- deleteFiles.add(fileCopy);
+ // add the file to the pending queue so it can be merged into deleteFiles
+ // after the parallel phase. The DeleteManifestFilterManager will then
+ // remove its matching DV
+ pendingDeletes.add(fileCopy);
if (deletedFiles.contains(file)) {
LOG.warn(
"Deleting a duplicate path from manifest {}: {}",
manifest.path(),
file.location());
- duplicateDeleteCount += 1;
+ duplicateDeleteCount.incrementAndGet();
} else {
// only add the file to deletes if it is a new delete
// this keeps the snapshot summary accurate for non-duplicate data
@@ -565,7 +579,8 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
// update caches
filteredManifests.put(manifest, filtered);
- filteredManifestToDeletedFiles.put(filtered, deletedFiles);
+ filteredManifestToDeletedFiles.put(
+ filtered, new FilterResult<>(deletedFiles, duplicateDeleteCount.get()));
return filtered;
@@ -574,6 +589,8 @@ abstract class ManifestFilterManager<F extends ContentFile<F>> {
}
}
+ private record FilterResult<F>(Iterable<F> deletedFiles, int duplicateDeleteCount) {}
+
// an evaluator that checks whether rows in a file may/must match a given expression
// this class first partially evaluates the provided expression using the partition tuple
// and then checks the remaining part of the expression using metrics evaluators
```
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar merged PR #16686:
URL: https://github.com/apache/iceberg/pull/16686
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3518317430
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -300,16 +300,14 @@ private void validateRequiredDeletes(ManifestFile... manifests) {
}
}
- private Set<F> deletedFiles(ManifestFile[] manifests) {
+ private Set<F> collectDeletedFiles(ManifestFile[] manifests) {
Review Comment:
yeah let's just rename it back to avoid unnecessary changes
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3507100091
##########
core/src/test/java/org/apache/iceberg/TestOverwrite.java:
##########
@@ -335,4 +336,55 @@ public void testValidatedOverwriteWithAppendSuccess() {
assertThat(latestSnapshot(base, branch).snapshotId()).isEqualTo(baseId);
}
+
+ @TestTemplate
+ public void testFullOverwriteAcrossManyManifests() {
Review Comment:
While this and the below concurrency test are well intentioned I think the issue with these kinds of tests is that we end up doing a lot of complex stuff just to try and repro the internal state of that class that used to be concurrent but no longer is. We could use barriers but even that's super complex.
If we take a step back, in terms of the internal implementation we've now structurally changed the code to collect the deleted files in a single-threaded manner; so it's a bit questionable to write a test which does all this work to simulate the conditions to hit this internal state that no longer exists.
In combination with the deterministic test for making sure retries don't double count the duplicates, I think we're fairly well covered.
In that case, I would simply just recommend removing this and the test below.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Fix thread conflict when deleting duplicate files in manifest [iceberg]
Posted by "HuaHuaY (via GitHub)" <gi...@apache.org>.
HuaHuaY commented on code in PR #16686:
URL: https://github.com/apache/iceberg/pull/16686#discussion_r3510252870
##########
core/src/main/java/org/apache/iceberg/ManifestFilterManager.java:
##########
@@ -229,6 +228,15 @@ List<ManifestFile> filterManifests(Schema tableSchema, List<ManifestFile> manife
filtered[index] = manifest;
});
+ for (ManifestFile manifest : filtered) {
Review Comment:
I found that there are some duplicate code between `deletedFiles` and `collectDeletedFiles` methods. So I changed `deletedFiles(ManifestFile[] manifests)` to `collectDeletedFiles(Set<F> deletedFiles, ManifestFile[] manifests)`.
--
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@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org