You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "xiaoxuandev (via GitHub)" <gi...@apache.org> on 2026/08/22 00:34:29 UTC
[PR] Core: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
xiaoxuandev opened a new pull request, #17764:
URL: https://github.com/apache/iceberg/pull/17764
## Problem
On format-v3 merge-on-read tables, compaction and other commit-time validations can fail with
ValidationException: Can't index multiple DVs for <data file>
on a table that is not corrupt, scans succeed, and the current snapshot has exactly one live DV per data file.
`MergingSnapshotProducer.addedDeleteFiles` builds a `DeleteFileIndex` over the delete manifests added across the whole validation history between the starting snapshot and the current parent. A data file can legitimately have more than one DV in that window:
* S0: append data file A (compactor starts here)
* S1: writer adds DV1 for A
* S2: writer removes DV1 and adds DV2 for A (valid MoR upsert)
Manifests are immutable: DV1 is still live in the manifest S1 wrote, DV2 in the one S2 wrote. The index reads live entries from every collected manifest, filtered only by sequence number, so it sees both. `Builder.build()` then throws from `putIfAbsent` on `dvByPath`, before validation reaches its conflict check.
The index covers the whole window and is not scoped to the data files being validated, so this rejects even a rewrite of an unrelated, delete-free file, stalling compaction on sustained-upsert workloads. The single-live-DV invariant is correct for scans, where a data file really does have at most one live DV. It does not hold across snapshots.
## Fix
Add a package-private, default-off `indexDVsAsPositionDeletes()` to `DeleteFileIndex.Builder`. When set, DVs are indexed in `posDeletesByPath`, which already allows many entries per data file, instead of the strict `dvByPath`.
The same delete files are indexed either way; only the container changes. Per data file the tolerant path returns a superset: where a DV exists, the strict path returns the equality deletes plus that one DV and short-circuits the
position-delete buckets, while the tolerant path returns those buckets and every DV for the file. `findDV` asserts `dataSequenceNumber >= seq` where `PositionDeletes.filter` silently drops below it, but that difference is unreachable here — `afterSequenceNumber` has already dropped every entry at or below `startingSequenceNumber`, the same value later passed to `forDataFile`. So validation sees more candidate deletes, never fewer, and cannot miss a conflict
it previously caught.
The index answers whether a data file has new deletes, not which deletes apply to it. That is sufficient because all three consumers only test emptiness or content type; anything needing the applicable set must use the strict default.
Only commit-time validation enables the flag: `buildDeleteFileIndex`, reached from `validateNoNewDeletesForDataFiles` and both `validateNoNewDeleteFiles` overloads. Scans keep the default and stay strict, so genuinely corrupt live metadata still surfaces there.
## Tests
New regression tests across all three validation entry points (all format v3+):
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3909837909
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
partitionSet,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
+ }
+
+ private static Iterable<String> referencedDeleteFileLocations(
+ List<DeleteFileIndex> deleteIndexes) {
+ return Iterables.transform(
+ Iterables.concat(
+ Iterables.transform(deleteIndexes, DeleteFileIndex::referencedDeleteFiles)),
+ ContentFile::location);
}
/**
- * Returns matching delete files have been added to the table since a starting snapshot.
+ * Returns one index of matching delete files per snapshot added to the table since a starting
+ * snapshot.
+ *
+ * <p>Callers must check every index. A single index cannot hold them all because it allows at
+ * most one deletion vector per data file. That holds within a snapshot but not across them: a
+ * data file can be referenced by a replacement deletion vector in each snapshot in the window.
*
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find delete files
* @param partitionSet a partition set used to find delete files
* @param parent parent snapshot of the branch
*/
- protected DeleteFileIndex addedDeleteFiles(
+ private List<DeleteFileIndex> addedDeleteFileIndexes(
Review Comment:
Renamed to `addedDeleteFilesIndexedPerSnapshot`, I kept the return type as a List though: none of the three callers reads the snapshot ID, so a Map hands them a key they'd each have to drop with .values(). Same reason for PerSnapshot over BySnapshot.
It also wouldn't save work, if that was the motivation: the map we build holds manifests, not indexes, so the loop after it isn't a map-to-list conversion, it's building one index per group. That loop only goes away if construction moves into the collector (groupingBy + collectingAndThen), which buries buildDeleteFileIndex and its manifest reads inside a nested collector.
Happy to switch if you'd still rather have the grouping stated in the type.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3930119475
##########
core/src/test/java/org/apache/iceberg/TestRewriteFiles.java:
##########
@@ -813,4 +813,221 @@ public void removingDataFileAlsoRemovesDV() {
files(fileADeletes(), fileBDeletes()),
statuses(ManifestEntry.Status.DELETED, ManifestEntry.Status.EXISTING));
}
+
+ @TestTemplate
+ public void testRewriteOfFileWithSuccessiveDVReplacementsRejectedAsConflict() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of()),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageContaining("Cannot commit, found new delete for replaced data file")
+ .hasMessageNotContaining("Can't index multiple DVs");
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWithSuccessiveDVReplacements() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWhenDVRemovedByReplaceSnapshot() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+
+ // VALIDATE_ADDED_DELETE_FILES_OPERATIONS excludes "replace", so the window never opens the
+ // manifest that records the removal of DV1 and DV1 keeps a live entry in it
+ DeleteFile dv1prime = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(),
+ ImmutableSet.of(dv1),
+ ImmutableSet.of(),
+ ImmutableSet.of(dv1prime)),
+ branch);
+ Snapshot s2 = latestSnapshot(table, branch);
+ assertThat(s2.operation()).isEqualTo(DataOperations.REPLACE);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1prime)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s2.snapshotId()),
+ branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
+ }
+
+ @TestTemplate
+ public void testRewriteWithOldSequenceNumberRejectsSuccessiveDVReplacements() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+ long oldSequenceNumber = s0.sequenceNumber();
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A), ImmutableSet.of(FILE_D), oldSequenceNumber),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageContaining("Cannot commit, found new position delete for replaced data file")
+ .hasMessageNotContaining("Can't index multiple DVs");
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWhenDVIsLiveInTwoManifests() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(
+ table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B).appendFile(FILE_C), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ // both DVs land in one delete manifest
+ commit(table, table.newRowDelta().addDeletes(newDV(FILE_A)).addDeletes(newDV(FILE_B)), branch);
+
+ // dropping FILE_B's DV as dangling rewrites that manifest, and the copy still carries the DV
+ // for FILE_A, leaving it live in both
+ commit(table, table.newDelete().deleteFile(FILE_B), branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_D),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
Review Comment:
Updated, thanks!
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3873394949
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
+ Builder indexDVsAsPositionDeletes() {
Review Comment:
I get why this works for the MergingSnapshotProducer validation case but I feel like it's at the wrong abstraction imo. DeleteFileIndex shouldn't really expose ways to allow callers to express a different way of indexing things, and this option only exists just for our validation case. It also feels a bit dangerous to expose this for DVs, granted it's not pbulic, still want to prevent misuse.
I think the right way to fix this is in MergingSnapshotProducer#validateNoNewDeletesForDataFiles to build a DeleteFileIndex _per_ concurrently added snapshot. For every data file we're validating we go through each delete index and do the validation. @xiaoxuandev , let me know if that makes sense or not.
The index is already bound to only added delete manifests for the concurrently added snapshots for this validation case (N snapshots added concurrnetly, N delete indices). Each index is bound to how many delete files there are.
I think in general we expect the number of concurrently added snapshots to be slim especially for batch cases; the worst case is a ton of streaming upsert snapshots concurrently, and even then it's no additional I/O cost compared to what we do today, it's rather CPU bound hashing etc where we're doing more lookups than before, but I think we can always optimize that later.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3930245438
##########
core/src/test/java/org/apache/iceberg/TestReplacePartitions.java:
##########
@@ -669,6 +669,42 @@ public void testDeleteReplaceConflict() {
+ "[data_bucket=0]: [/path/to/data-a-deletes.parquet]");
}
+ @TestTemplate
+ public void testConcurrentSuccessiveDVsReplaceConflict() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newFastAppend().appendFile(FILE_A), branch);
+
+ TableMetadata base = readMetadata();
+ long baseId = latestSnapshot(base, branch).snapshotId();
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1).validateFromSnapshot(baseId), branch);
+
+ long dvSnapshotId = latestSnapshot(readMetadata(), branch).snapshotId();
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table.newRowDelta().removeDeletes(dv1).addDeletes(dv2).validateFromSnapshot(dvSnapshotId),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newReplacePartitions()
+ .validateFromSnapshot(baseId)
+ .validateNoConflictingDeletes()
+ .addFile(FILE_A),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageStartingWith(
+ "Found new conflicting delete files that can apply to records matching [data_bucket=0]")
+ .hasMessageNotContaining("Can't index multiple DVs");
Review Comment:
Fixed, thanks!
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3920887818
##########
core/src/test/java/org/apache/iceberg/TestReplacePartitions.java:
##########
@@ -669,6 +669,42 @@ public void testDeleteReplaceConflict() {
+ "[data_bucket=0]: [/path/to/data-a-deletes.parquet]");
}
+ @TestTemplate
+ public void testConcurrentSuccessiveDVsReplaceConflict() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newFastAppend().appendFile(FILE_A), branch);
+
+ TableMetadata base = readMetadata();
+ long baseId = latestSnapshot(base, branch).snapshotId();
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1).validateFromSnapshot(baseId), branch);
+
+ long dvSnapshotId = latestSnapshot(readMetadata(), branch).snapshotId();
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table.newRowDelta().removeDeletes(dv1).addDeletes(dv2).validateFromSnapshot(dvSnapshotId),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newReplacePartitions()
+ .validateFromSnapshot(baseId)
+ .validateNoConflictingDeletes()
+ .addFile(FILE_A),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageStartingWith(
+ "Found new conflicting delete files that can apply to records matching [data_bucket=0]")
+ .hasMessageNotContaining("Can't index multiple DVs");
Review Comment:
I'd rather update the message test expectation to just be an exact match rather than "startingWith" and then notContaining., it makes it easier to read and verify the test is right.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3904638440
##########
core/src/test/java/org/apache/iceberg/TestRewriteFiles.java:
##########
@@ -813,4 +813,254 @@ public void removingDataFileAlsoRemovesDV() {
files(fileADeletes(), fileBDeletes()),
statuses(ManifestEntry.Status.DELETED, ManifestEntry.Status.EXISTING));
}
+
+ /**
+ * A rewrite of a data file that acquired a new deletion vector after the starting snapshot is a
+ * genuine conflict and must be reported as one, even when concurrent writers superseded that
+ * deletion vector several times within the validation window. This is the path compaction takes
+ * on merge-on-read tables where writers replace deletion vectors faster than a rewrite commits.
+ *
+ * <p>See: https://github.com/apache/iceberg/issues/17206
+ */
Review Comment:
Can we remove these top level comments from the tests in this and the other files? It's a bit noisy and not adding too much value, especially when the test method names are pretty clear.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
partitionSet,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
+ }
+
+ private static Iterable<String> referencedDeleteFileLocations(
+ List<DeleteFileIndex> deleteIndexes) {
+ return Iterables.transform(
+ Iterables.concat(
+ Iterables.transform(deleteIndexes, DeleteFileIndex::referencedDeleteFiles)),
+ ContentFile::location);
}
/**
- * Returns matching delete files have been added to the table since a starting snapshot.
+ * Returns one index of matching delete files per snapshot added to the table since a starting
+ * snapshot.
+ *
+ * <p>Callers must check every index. A single index cannot hold them all because it allows at
+ * most one deletion vector per data file. That holds within a snapshot but not across them: a
+ * data file can be referenced by a replacement deletion vector in each snapshot in the window.
*
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find delete files
* @param partitionSet a partition set used to find delete files
* @param parent parent snapshot of the branch
*/
- protected DeleteFileIndex addedDeleteFiles(
+ private List<DeleteFileIndex> addedDeleteFileIndexes(
Review Comment:
`deleteFileIndicesBySnapshot`? And I think it should return a Map<Long, DeleteFileIndex>, I think that would avoid the extra work we do in the method to take the map we already build and make a list out of it.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
Review Comment:
Maybe not required in this PR because I don't think it's a huge deal in practice, but honestly after staring at all this validation code, I feel like we don't even need a DeleteFileIndex for at least the validations we do currently.
e.g.
validateNoNewDeleteFiles needs to just look for any delete files matching the partition predicate or data filter since the starting snapshotID. etc
validateNoNewDeletesForDataFiles is a bit more complex with equality deletes matching that DeleteFileIndex does take care of for us but I think it's possible (maybe a bit duplicative).
But either way where my comment is largely coming from is that DeleteFileIndex allocates a few maps and has some state that largely is irrelevant for the kinds of checks we do currently in validation, so that's why it feels a bit heavy. But like I said, I don't think it matters too much. For the batch case it's basically nothing. For the streaming upsert case where there's a bunch of DV churn and many concurrent snapshots added, then there's probably GC churn as maps/state get created/torn down eetc. But for those cases the structure,lookups should be fast because the contents of what's being added is fairly small in those cases.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
Review Comment:
Think we should remove this, not adding too much value and can just be a comment that churns as the implementation changes.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
Review Comment:
Same as the other comments, don't think we need this.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
Review Comment:
I'd just keep track of Set<String> referencedDeleteFiles.
```
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
List<DeleteFileIndex> deleteIndices =
addedDeleteFilesIndexedBySnapshot(base, startingSnapshotId, dataFilter, null, parent);
Set<String> deleteFileLocations = Sets.newLinkedHashSet();
for (DeleteFileIndex deletes : deleteIndices) {
if (!deletes.isEmpty()) {
for (DeleteFile deleteFile : deletes.referencedDeleteFiles()) {
deleteFileLocations.add(deleteFile.location());
}
}
}
ValidationException.check(
deleteFileLocations.isEmpty(),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
deleteFileLocations);
}
```
This also avoids the minor issue in the exception message currently where we'll include duplicate paths in the error message because we aggregate across all indices. To include all the conflicting delete file paths in case of a conflict exception we can't really short-circuit as soon as a single DeleteFileIndex fails anyways,.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
partitionSet,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
+ }
+
+ private static Iterable<String> referencedDeleteFileLocations(
+ List<DeleteFileIndex> deleteIndexes) {
+ return Iterables.transform(
+ Iterables.concat(
+ Iterables.transform(deleteIndexes, DeleteFileIndex::referencedDeleteFiles)),
+ ContentFile::location);
}
/**
- * Returns matching delete files have been added to the table since a starting snapshot.
+ * Returns one index of matching delete files per snapshot added to the table since a starting
+ * snapshot.
+ *
+ * <p>Callers must check every index. A single index cannot hold them all because it allows at
+ * most one deletion vector per data file. That holds within a snapshot but not across them: a
+ * data file can be referenced by a replacement deletion vector in each snapshot in the window.
*
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find delete files
* @param partitionSet a partition set used to find delete files
* @param parent parent snapshot of the branch
*/
- protected DeleteFileIndex addedDeleteFiles(
+ private List<DeleteFileIndex> addedDeleteFileIndexes(
Review Comment:
Or addedDeleteFilesIndexedBySnapshot? Bit wordy but I feel like addedDeleteFileIndexes reads kind of weird (no indices were really added, it's an in memory construct we're leveraging)
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3876578629
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
+ Builder indexDVsAsPositionDeletes() {
Review Comment:
> I think the right way to fix this is in MergingSnapshotProducer#validateNoNewDeletesForDataFiles to build a DeleteFileIndex per concurrently added snapshot. For every data file we're validating we go through each delete index and do the validation
+1. I think in `validateNoDeletesForDataFiles` we can have:
```
for (DataFile dataFile : dataFiles) {
for (DeleteFileIndex deletes : deleteIndexes) {
DeleteFile[] deleteFiles =
deletes.forDataFile(startingSequenceNumber, dataFile);
```
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar merged PR #17764:
URL: https://github.com/apache/iceberg/pull/17764
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3909891561
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
Review Comment:
Good catch on the duplicates, updated, thanks!
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3909883719
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
Review Comment:
Mostly readability, and allocation on the default compaction path; the loop is now nested (D×N), and compaction defaults into the `ignoreEqualityDeletes` branch. Since `forDataFile` returns an empty array on no conflict, the inline Arrays.stream(...) allocated a pipeline every success-path iteration; the plain loop avoids that and reads clearer. Escape analysis might elide it, but isn't guaranteed to. Small either way.
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3873394949
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
+ Builder indexDVsAsPositionDeletes() {
Review Comment:
I get why this works for the MergingSnapshotProducer validation case but I feel like it's at the wrong abstraction imo. DeleteFileIndex shouldn't really expose ways to allow callers to express a different way of indexing things, and this option only exists just for our validation case. It also feels a bit dangerous to expose this for DVs, granted it's not pbulic, still want to prevent misuse.
I think the right way to fix this is in MergingSnapshotProducer#validateNoNewDeletesForDataFiles to build a DeleteFileIndex _per_ concurrently added snapshot. For every data file we're validating we go through each delete index and do the validation. Does this make sense @xiaoxuandev , let me know if that makes sense or not.
The index is already bound to only added delete manifests for the concurrently added snapshots for this validation case (N snapshots added concurrnetly, N delete indices). Each index is bound to how many delete files there are.
I think in general we expect the number of concurrently added snapshots to be slim especially for batch cases; the worst case is a ton of streaming upsert snapshots concurrently, and even then it's no additional I/O cost compared to what we do today, it's rather CPU bound hashing etc where we're doing more lookups than before, but I think we can always optimize that later.
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3873394949
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
+ Builder indexDVsAsPositionDeletes() {
Review Comment:
I get why this works for the MergingSnapshotProducer validation case but I feel like it's at the wrong abstraction imo. DeleteFileIndex shouldn't really expose ways to allow callers to express a different way of indexing things, and this option only exists just for our validation case.
I think the right way to fix this is in MergingSnapshotProducer#validateNoNewDeletesForDataFiles to build a DeleteFileIndex _per_ concurrently added snapshot. For every data file we're validating we go through each delete index and do the validation. Does this make sense @xiaoxuandev , let me know if that makes sense or not.
The index is already bound to only added delete manifests for the concurrently added snapshots for this validation case (N snapshots added concurrnetly, N delete indices). I think in general we expect the number of concurrently added snapshots to be slim especially for batch cases; the worst case is a ton of streaming upsert snapshots concurrently, and even then it's no additional I/O cost compared to what we do today, it's rather CPU bound hashing etc where we're doing more lookups than before, but I think we can always optimize that later.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3909886887
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
Review Comment:
Removed, thanks!
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3839622876
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
Review Comment:
In tolerant mode, validateNoNewDeleteFiles constructs its error message from posDeletesByPath, which now contains both dv1 (already compacted away) and dv2 (current). Users troubleshooting a real conflict will see a reference to a DV that no longer exists in the live snapshot; correctness is unaffected, but the message is misleading. The error path should filter to only active entries or document this in a javadoc caveat on the method.
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3848221821
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
Review Comment:
Thanks, good catch, you're right that both DVs show up in that list.
Two things worth noting: pre-fix this scenario had no message at all — `Can't index multiple DVs` was thrown before `isEmpty()`. The error path is untouched; only where DVs get indexed changed. And it isn't DV-specific: `posDeletesByPath` has always held multiple entries per data file across the window, including ones later removed, so v2 file-scoped position deletes report the same way today.
I'm hesitant to go with filtering for two reasons. The list answers "what was added since your starting snapshot", so trimming it to live files would hide that two writers touched the file, not one. And liveness isn't derivable from the window: a removal is recorded only in the manifest written by the removing snapshot, and the window skips `replace` snapshots — so a superseded DV still looks live there. Filtering would need fresh reads of the parent's delete manifests, a different source than the validation uses.
So I went with your javadoc suggestion for now, on both overloads and worded to hold for v2 deletes too.
Happy to revisit if you think the message still needs trimming, though it would probably want to cover v2 position deletes as well, which likely makes it its own change.
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3876514936
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
+ Builder indexDVsAsPositionDeletes() {
Review Comment:
Thanks @amogh-jahagirdar for the review, agreed, the per-snapshot `DeleteFileIndex` is the better abstraction. This version works but shouldn't put a validation-only knob on `DeleteFileIndex` that changes `forDataFile`'s semantics.
Streaming upserts is the case we're targeting here. An optimized version might end up looking like "single index tolerating multiple DVs," but doing it at the right layer keeps forDataFile intact and still catches within-snapshot corruption. Will update this PR and do the optimization in a separate PR later. Thanks!
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3909885105
##########
core/src/test/java/org/apache/iceberg/TestRewriteFiles.java:
##########
@@ -813,4 +813,254 @@ public void removingDataFileAlsoRemovesDV() {
files(fileADeletes(), fileBDeletes()),
statuses(ManifestEntry.Status.DELETED, ManifestEntry.Status.EXISTING));
}
+
+ /**
+ * A rewrite of a data file that acquired a new deletion vector after the starting snapshot is a
+ * genuine conflict and must be reported as one, even when concurrent writers superseded that
+ * deletion vector several times within the validation window. This is the path compaction takes
+ * on merge-on-read tables where writers replace deletion vectors faster than a rewrite commits.
+ *
+ * <p>See: https://github.com/apache/iceberg/issues/17206
+ */
Review Comment:
Removed, thanks!
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3905224413
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
Review Comment:
Don't know if @RussellSpitzer @CTTY have any opinions here. My take is largely we can clean this up in a follow on, but for now we can stick to using DeleteFileIndex even though I find it a bit heavy for the validation we're trying to do.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3899691298
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
Review Comment:
why do we need this?
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
Review Comment:
If there are new delete files associated with multiple snapshots, then this will fail early and not reporting all new delete files
How about moving validations to the outer for loop?
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3873394949
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
+ Builder indexDVsAsPositionDeletes() {
Review Comment:
I get why this works for the MergingSnapshotProducer validation case but I feel like it's at the wrong abstraction imo. DeleteFileIndex shouldn't really expose ways to allow callers to express a different way of indexing things, and this option only exists just for our validation case.
I think the right way to fix this is in MergingSnapshotProducer#validateNoNewDeletesForDataFiles to build a DeleteFileIndex for concurrently added snapshots. For every data file we're validating we go through each delete index and do the validation. Does this make sense @xiaoxuandev , let me know if that makes sense or not.
The index is already bound to only added delete manifests for the concurrently added snapshots for this validation case (N snapshots added concurrnetly, N delete indices). I think in general we expect the number of concurrently added snapshots to be slim especially for batch cases; the worst case is a ton of streaming upsert snapshots concurrently, and even then it's no additional I/O cost compared to what we do today, it's rather CPU bound hashing etc where we're doing more lookups than before, but I think we can always optimize that later.
--
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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3873394949
##########
core/src/main/java/org/apache/iceberg/DeleteFileIndex.java:
##########
@@ -485,6 +486,24 @@ Builder ignoreResiduals() {
return this;
}
+ /**
+ * Indexes deletion vectors as file-scoped position deletes, allowing a data file to have more
+ * than one DV.
+ *
+ * <p>A data file has at most one live DV in a single snapshot, so by default {@link #build()}
+ * rejects a second DV for the same data file. That invariant does not hold across snapshots,
+ * and commit validation indexes delete manifests from every snapshot in the validation window,
+ * so it requires an index that accepts them.
+ *
+ * <p>The resulting index only answers whether deletes exist for a data file, not which deletes
+ * apply to it: {@code forDataFile} no longer suppresses partition-scoped position deletes when
+ * a DV is present. Scans must use the default so that corrupt live metadata is still detected.
+ */
+ Builder indexDVsAsPositionDeletes() {
Review Comment:
I get why this works for the MergingSnapshotProducer validation case but I feel like it's at the wrong abstraction imo. DeleteFileIndex shouldn't really expose ways to allow callers to express a different way of indexing things, and this option only exists just for our validation case.
I think the right way to fix this is in MergingSnapshotProducer#validateNoNewDeletesForDataFiles to build a DeleteFileIndex _per_ concurrently added snapshot. For every data file we're validating we go through each delete index and do the validation. Does this make sense @xiaoxuandev , let me know if that makes sense or not.
The index is already bound to only added delete manifests for the concurrently added snapshots for this validation case (N snapshots added concurrnetly, N delete indices). Each index is bound to how many delete files there are.
I think in general we expect the number of concurrently added snapshots to be slim especially for batch cases; the worst case is a ton of streaming upsert snapshots concurrently, and even then it's no additional I/O cost compared to what we do today, it's rather CPU bound hashing etc where we're doing more lookups than before, but I think we can always optimize that later.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "CTTY (via GitHub)" <gi...@apache.org>.
CTTY commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3899753345
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
Review Comment:
If there are new delete files associated with multiple snapshots, then this will fail early and not reporting all new delete files
How about moving validations to the outer for loop?
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3909818095
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -528,87 +528,117 @@ private void validateNoNewDeletesForDataFiles(
return;
}
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
long startingSequenceNumber = startingSequenceNumber(base, startingSnapshotId);
for (DataFile dataFile : dataFiles) {
- // if any delete is found that applies to files written in or before the starting snapshot,
- // fail
- DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
- if (ignoreEqualityDeletes) {
- ValidationException.check(
- Arrays.stream(deleteFiles)
- .noneMatch(deleteFile -> deleteFile.content() == FileContent.POSITION_DELETES),
- "Cannot commit, found new position delete for replaced data file: %s",
- dataFile);
- } else {
- ValidationException.check(
- deleteFiles.length == 0,
- "Cannot commit, found new delete for replaced data file: %s",
- dataFile);
+ for (DeleteFileIndex deletes : deleteIndexes) {
+ // if any delete is found that applies to files written in or before the starting snapshot,
+ // fail
+ DeleteFile[] deleteFiles = deletes.forDataFile(startingSequenceNumber, dataFile);
+ if (ignoreEqualityDeletes) {
+ ValidationException.check(
+ !containsPositionDeletes(deleteFiles),
+ "Cannot commit, found new position delete for replaced data file: %s",
+ dataFile);
+ } else {
+ ValidationException.check(
+ deleteFiles.length == 0,
+ "Cannot commit, found new delete for replaced data file: %s",
+ dataFile);
+ }
+ }
+ }
+ }
+
+ private static boolean containsPositionDeletes(DeleteFile[] deleteFiles) {
+ for (DeleteFile deleteFile : deleteFiles) {
+ if (deleteFile.content() == FileContent.POSITION_DELETES) {
+ return true;
}
}
+
+ return false;
}
/**
* Validates that no delete files matching a filter have been added to the table since a starting
* snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param dataFilter an expression used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, Expression dataFilter, Snapshot parent) {
- DeleteFileIndex deletes = addedDeleteFiles(base, startingSnapshotId, dataFilter, null, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, dataFilter, null, parent);
ValidationException.check(
- deletes.isEmpty(),
+ deleteIndexes.stream().allMatch(DeleteFileIndex::isEmpty),
"Found new conflicting delete files that can apply to records matching %s: %s",
dataFilter,
- Iterables.transform(deletes.referencedDeleteFiles(), ContentFile::location));
+ referencedDeleteFileLocations(deleteIndexes));
}
/**
* Validates that no delete files matching a partition set have been added to the table since a
* starting snapshot.
*
+ * <p>On failure, the exception lists the matching delete files added since that snapshot rather
+ * than those currently live in the table, so it can name a file that was later removed.
+ *
* @param base table metadata to validate
* @param startingSnapshotId id of the snapshot current at the start of the operation
* @param partitionSet a partition set used to find new conflicting delete files
* @param parent ending snapshot on the branch being validated
*/
protected void validateNoNewDeleteFiles(
TableMetadata base, Long startingSnapshotId, PartitionSet partitionSet, Snapshot parent) {
- DeleteFileIndex deletes =
- addedDeleteFiles(base, startingSnapshotId, null, partitionSet, parent);
+ List<DeleteFileIndex> deleteIndexes =
+ addedDeleteFileIndexes(base, startingSnapshotId, null, partitionSet, parent);
Review Comment:
Yeah, agreed on the abstraction, an existence check doesn't care about the one-DV-per-data-file invariant, so dropping the index in both `validateNoNewDeleteFiles` overloads would also drop the per-snapshot grouping they inherit but never need. `validateAddedDVs` already scans delete manifests this way without an index.
But worth noting it probably won't move the GC churn case you're describing, though. N there is the validation window, which scales with how stale the committer's starting snapshot is, not with commit rate — so the large-N committer is RewriteFiles, which only goes through validateNoNewDeletesForDataFiles and would keep the index either way. RowDelta commits far more often but usually reads and commits within a window of a few snapshots.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3920887818
##########
core/src/test/java/org/apache/iceberg/TestReplacePartitions.java:
##########
@@ -669,6 +669,42 @@ public void testDeleteReplaceConflict() {
+ "[data_bucket=0]: [/path/to/data-a-deletes.parquet]");
}
+ @TestTemplate
+ public void testConcurrentSuccessiveDVsReplaceConflict() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newFastAppend().appendFile(FILE_A), branch);
+
+ TableMetadata base = readMetadata();
+ long baseId = latestSnapshot(base, branch).snapshotId();
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1).validateFromSnapshot(baseId), branch);
+
+ long dvSnapshotId = latestSnapshot(readMetadata(), branch).snapshotId();
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table.newRowDelta().removeDeletes(dv1).addDeletes(dv2).validateFromSnapshot(dvSnapshotId),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newReplacePartitions()
+ .validateFromSnapshot(baseId)
+ .validateNoConflictingDeletes()
+ .addFile(FILE_A),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageStartingWith(
+ "Found new conflicting delete files that can apply to records matching [data_bucket=0]")
+ .hasMessageNotContaining("Can't index multiple DVs");
Review Comment:
I'd rather update the message test expectation to just be an exact match (wherever possible, I know some of these may have exact paths whihc are annoying, but in those cases, I think the hasMessageStarting with is more than sufficient to give us confidence). rather than "startingWith" and then notContaining., it makes it easier to read and verify the test is right.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#discussion_r3920879468
##########
core/src/test/java/org/apache/iceberg/TestRewriteFiles.java:
##########
@@ -813,4 +813,221 @@ public void removingDataFileAlsoRemovesDV() {
files(fileADeletes(), fileBDeletes()),
statuses(ManifestEntry.Status.DELETED, ManifestEntry.Status.EXISTING));
}
+
+ @TestTemplate
+ public void testRewriteOfFileWithSuccessiveDVReplacementsRejectedAsConflict() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of()),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageContaining("Cannot commit, found new delete for replaced data file")
+ .hasMessageNotContaining("Can't index multiple DVs");
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWithSuccessiveDVReplacements() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWhenDVRemovedByReplaceSnapshot() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+
+ // VALIDATE_ADDED_DELETE_FILES_OPERATIONS excludes "replace", so the window never opens the
+ // manifest that records the removal of DV1 and DV1 keeps a live entry in it
+ DeleteFile dv1prime = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(),
+ ImmutableSet.of(dv1),
+ ImmutableSet.of(),
+ ImmutableSet.of(dv1prime)),
+ branch);
+ Snapshot s2 = latestSnapshot(table, branch);
+ assertThat(s2.operation()).isEqualTo(DataOperations.REPLACE);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1prime)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s2.snapshotId()),
+ branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
+ }
+
+ @TestTemplate
+ public void testRewriteWithOldSequenceNumberRejectsSuccessiveDVReplacements() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+ long oldSequenceNumber = s0.sequenceNumber();
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A), ImmutableSet.of(FILE_D), oldSequenceNumber),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageContaining("Cannot commit, found new position delete for replaced data file")
+ .hasMessageNotContaining("Can't index multiple DVs");
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWhenDVIsLiveInTwoManifests() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(
+ table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B).appendFile(FILE_C), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ // both DVs land in one delete manifest
+ commit(table, table.newRowDelta().addDeletes(newDV(FILE_A)).addDeletes(newDV(FILE_B)), branch);
+
+ // dropping FILE_B's DV as dangling rewrites that manifest, and the copy still carries the DV
+ // for FILE_A, leaving it live in both
+ commit(table, table.newDelete().deleteFile(FILE_B), branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_D),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWithSingleDV() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ commit(table, table.newRowDelta().addDeletes(newDV(FILE_A)), branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
Review Comment:
Same as above. We should also assert the entries (check out `validateManifestEntries` )
##########
core/src/test/java/org/apache/iceberg/TestRewriteFiles.java:
##########
@@ -813,4 +813,221 @@ public void removingDataFileAlsoRemovesDV() {
files(fileADeletes(), fileBDeletes()),
statuses(ManifestEntry.Status.DELETED, ManifestEntry.Status.EXISTING));
}
+
+ @TestTemplate
+ public void testRewriteOfFileWithSuccessiveDVReplacementsRejectedAsConflict() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of()),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageContaining("Cannot commit, found new delete for replaced data file")
+ .hasMessageNotContaining("Can't index multiple DVs");
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWithSuccessiveDVReplacements() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWhenDVRemovedByReplaceSnapshot() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+
+ // VALIDATE_ADDED_DELETE_FILES_OPERATIONS excludes "replace", so the window never opens the
+ // manifest that records the removal of DV1 and DV1 keeps a live entry in it
+ DeleteFile dv1prime = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRewrite()
+ .rewriteFiles(
+ ImmutableSet.of(),
+ ImmutableSet.of(dv1),
+ ImmutableSet.of(),
+ ImmutableSet.of(dv1prime)),
+ branch);
+ Snapshot s2 = latestSnapshot(table, branch);
+ assertThat(s2.operation()).isEqualTo(DataOperations.REPLACE);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1prime)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s2.snapshotId()),
+ branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_B),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
+ }
+
+ @TestTemplate
+ public void testRewriteWithOldSequenceNumberRejectsSuccessiveDVReplacements() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newAppend().appendFile(FILE_A), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+ long oldSequenceNumber = s0.sequenceNumber();
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1), branch);
+ Snapshot s1 = latestSnapshot(table, branch);
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table
+ .newRowDelta()
+ .removeDeletes(dv1)
+ .addDeletes(dv2)
+ .validateFromSnapshot(s1.snapshotId()),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_A), ImmutableSet.of(FILE_D), oldSequenceNumber),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageContaining("Cannot commit, found new position delete for replaced data file")
+ .hasMessageNotContaining("Can't index multiple DVs");
+ }
+
+ @TestTemplate
+ public void testRewriteOfUnrelatedFileSucceedsWhenDVIsLiveInTwoManifests() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(
+ table, table.newAppend().appendFile(FILE_A).appendFile(FILE_B).appendFile(FILE_C), branch);
+ Snapshot s0 = latestSnapshot(table, branch);
+
+ // both DVs land in one delete manifest
+ commit(table, table.newRowDelta().addDeletes(newDV(FILE_A)).addDeletes(newDV(FILE_B)), branch);
+
+ // dropping FILE_B's DV as dangling rewrites that manifest, and the copy still carries the DV
+ // for FILE_A, leaving it live in both
+ commit(table, table.newDelete().deleteFile(FILE_B), branch);
+
+ commit(
+ table,
+ table
+ .newRewrite()
+ .validateFromSnapshot(s0.snapshotId())
+ .rewriteFiles(
+ ImmutableSet.of(FILE_C),
+ ImmutableSet.of(),
+ ImmutableSet.of(FILE_D),
+ ImmutableSet.of()),
+ branch);
+
+ assertThat(latestSnapshot(table, branch).operation()).isEqualTo(DataOperations.REPLACE);
Review Comment:
I think we should also assert the final state of the entries.
##########
core/src/test/java/org/apache/iceberg/TestReplacePartitions.java:
##########
@@ -669,6 +669,42 @@ public void testDeleteReplaceConflict() {
+ "[data_bucket=0]: [/path/to/data-a-deletes.parquet]");
}
+ @TestTemplate
+ public void testConcurrentSuccessiveDVsReplaceConflict() {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(3);
+
+ commit(table, table.newFastAppend().appendFile(FILE_A), branch);
+
+ TableMetadata base = readMetadata();
+ long baseId = latestSnapshot(base, branch).snapshotId();
+
+ DeleteFile dv1 = newDV(FILE_A);
+ commit(table, table.newRowDelta().addDeletes(dv1).validateFromSnapshot(baseId), branch);
+
+ long dvSnapshotId = latestSnapshot(readMetadata(), branch).snapshotId();
+
+ DeleteFile dv2 = newDV(FILE_A);
+ commit(
+ table,
+ table.newRowDelta().removeDeletes(dv1).addDeletes(dv2).validateFromSnapshot(dvSnapshotId),
+ branch);
+
+ assertThatThrownBy(
+ () ->
+ commit(
+ table,
+ table
+ .newReplacePartitions()
+ .validateFromSnapshot(baseId)
+ .validateNoConflictingDeletes()
+ .addFile(FILE_A),
+ branch))
+ .isInstanceOf(ValidationException.class)
+ .hasMessageStartingWith(
+ "Found new conflicting delete files that can apply to records matching [data_bucket=0]")
+ .hasMessageNotContaining("Can't index multiple DVs");
Review Comment:
I'd rather update the message test expectation to just be an exact match rather than "startingWith" and then notContaining.
--
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 commit validation when a data file has multiple DVs across snapshots [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#issuecomment-5541961292
Thank you @xiaoxuandev for the fix! and thank you @CTTY @uros-b for reviewing the changes. 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: Tolerate multiple cross-snapshot DVs for the same data file in commit validation [iceberg]
Posted by "xiaoxuandev (via GitHub)" <gi...@apache.org>.
xiaoxuandev commented on PR #17764:
URL: https://github.com/apache/iceberg/pull/17764#issuecomment-5402869564
@amogh-jahagirdar @RussellSpitzer, tagging you both since you reviewed #16957, which added `validatePartitionMatch` to the `DeleteFileIndex` paths this PR touches. This PR relaxes the single-live-DV check for commit validation only, where the index spans several snapshots and one data file can legitimately have several DVs; scans keep the strict default. That partition check survives the change, since #16957 mirrored it into `findPathDeletes` and not just `findDV`.
--
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