raunaqmorarka commented on code in PR #17754:
URL: https://github.com/apache/iceberg/pull/17754#discussion_r4711726033
##########
api/src/main/java/org/apache/iceberg/RowDelta.java:
##########
@@ -41,6 +41,10 @@ public interface RowDelta extends SnapshotUpdate<RowDelta> {
/**
* Add a {@link DeleteFile} to the table.
*
+ * <p>A deletion vector added concurrently for the same data file may be
merged into this
+ * operation's deletion vector instead of failing the commit; see {@link
+ * #validateNoConflictingDeleteFiles()} for the conditions.
Review Comment:
Dropped all three. The existing javadoc on
`validateNoConflictingDeleteFiles()` already allows DELETE operations to delete
a record that is also deleted concurrently.
##########
core/src/main/java/org/apache/iceberg/BaseRowDelta.java:
##########
@@ -168,9 +168,16 @@ protected void validate(TableMetadata base, Snapshot
parent) {
}
validateNoConflictingFileAndPositionDeletes();
-
- validateAddedDVs(base, startingSnapshotId, conflictDetectionFilter,
parent);
}
+
+ // concurrent DVs can be merged only when this operation does not add or
remove data files and
+ // does not require concurrent delete files to fail validation
+ boolean canMergeConcurrentDVs =
+ !validateNewDeleteFiles && !addsDataFiles() && !deletesDataFiles();
Review Comment:
This already happens without merging. With v2 position deletes, or with DVs
on different data files, both deletes commit and no copy is left.
Engines that need this to fail can call
`validateNoConflictingDeleteFiles()`, which also turns the merge off.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -902,15 +923,43 @@ protected void validateAddedDVs(
filterManifestsByPartition(base, conflictDetectionFilter,
newDeleteManifests),
ManifestFile::hasAddedFiles);
+ List<DeleteFile> concurrentDVs =
Collections.synchronizedList(Lists.newArrayList());
+
+ // only DVs added by delete operations can be merged; a DV added by an
operation that also
+ // adds data files marks rows that were rewritten into those files, so
merging it would let
+ // rows deleted by this operation survive in the rewritten files
+ Set<Long> mergeableSnapshotIds;
+ if (canMergeConcurrentDVs) {
+ mergeableSnapshotIds =
+ newSnapshotIds.stream()
+ .filter(id ->
DataOperations.DELETE.equals(base.snapshot(id).operation()))
Review Comment:
Fixed. The merge is now refused when data files matching the conflict filter
were added since the starting snapshot.
That includes snapshots from the same transaction, so no transaction API
change is needed.
Covered by `concurrentDVNotMergedWhenDataFilesAdded`.
##########
core/src/main/java/org/apache/iceberg/BaseRowDelta.java:
##########
@@ -168,9 +168,16 @@ protected void validate(TableMetadata base, Snapshot
parent) {
}
validateNoConflictingFileAndPositionDeletes();
-
- validateAddedDVs(base, startingSnapshotId, conflictDetectionFilter,
parent);
}
+
+ // concurrent DVs can be merged only when this operation does not add or
remove data files and
+ // does not require concurrent delete files to fail validation
+ boolean canMergeConcurrentDVs =
Review Comment:
I'd keep it on by default. In v2, two concurrent delete-only commits on the
same data file both succeed. The one-DV-per-file rule turned that into a
failure in v3, and this restores the v2 behavior.
It also matches the existing javadoc on `validateNoConflictingDeleteFiles()`.
> Calling this method isn't required for DELETE operations as it is OK to
delete a record that is also deleted concurrently.
The merged commit has the same shape as running the second delete after the
first. It replaces the earlier DV with one that holds both sets of positions.
The opt-out already exists. Calling `validateNoConflictingDeleteFiles()`
turns the merge off.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -871,8 +874,26 @@ protected void validateAddedDVs(
Long startingSnapshotId,
Expression conflictDetectionFilter,
Snapshot parent) {
- // skip if there is no current table state or this operation doesn't add
new DVs
- if (parent == null || dvsByReferencedFile.isEmpty()) {
+ validateAddedDVs(base, startingSnapshotId, conflictDetectionFilter,
parent, false);
+ }
+
+ // validates there are no concurrently added DVs for referenced data files;
when
Review Comment:
Trimmed the ones here to one line each, and dropped the two in
`BaseRowDelta`.
##########
core/src/main/java/org/apache/iceberg/MergingSnapshotProducer.java:
##########
@@ -919,19 +968,109 @@ private void validateAddedDVs(
for (ManifestEntry<DeleteFile> entry : entries) {
DeleteFile file = entry.file();
- if (newSnapshotIds.contains(entry.snapshotId()) &&
ContentFileUtil.isDV(file)) {
+ if (newSnapshotIds.contains(entry.snapshotId())
+ && ContentFileUtil.isDV(file)
+ && dvsByReferencedFile.containsKey(file.referencedDataFile())) {
ValidationException.check(
- !dvsByReferencedFile.containsKey(file.referencedDataFile()),
+ mergeableSnapshotIds.contains(entry.snapshotId()),
"Found concurrently added DV for %s: %s",
file.referencedDataFile(),
ContentFileUtil.dvDesc(file));
+ concurrentDVs.add(file.copy());
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
+ /**
+ * Merges concurrently added DVs into this operation's DVs.
Review Comment:
Dropped all four.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]