timothyw553 commented on code in PR #19027:
URL: https://github.com/apache/iceberg/pull/19027#discussion_r4727500150
##########
core/src/main/java/org/apache/iceberg/BaseRewriteManifests.java:
##########
@@ -284,17 +295,39 @@ private boolean matchesPredicate(ManifestFile manifest) {
}
private void validateDeletedManifests(
- Set<ManifestFile> currentManifests, long currentSnapshotID) {
- // directly deleted manifests must be still present in the current snapshot
- deletedManifests.stream()
- .filter(manifest -> !currentManifests.contains(manifest))
- .findAny()
- .ifPresent(
- manifest -> {
- throw new ValidationException(
- "Deleted manifest %s could not be found in the latest
snapshot %d",
- manifest.path(), currentSnapshotID);
- });
+ Map<String, ManifestFile> currentManifestsByPath, long
currentSnapshotID) {
+ for (ManifestFile manifest : deletedManifests) {
+ // directly deleted manifests must be still present in the current
snapshot
+ ManifestFile current = currentManifestsByPath.get(manifest.path());
+ ValidationException.check(
+ current != null,
+ "Deleted manifest %s could not be found in the latest snapshot %d",
+ manifest.path(),
+ currentSnapshotID);
+
+ // a replacement written from the entries of a manifest that inherits
other metadata now would
+ // not have it
+ ValidationException.check(
+ inheritsSameMetadata(manifest, current),
Review Comment:
if an earlier operation in the transaction already hit
`SnapshotProducer.manifestsWithMetadata` or
`ManifestFilterManager.filteredManifests`, won't `manifest` and `current` both
carry the same stale metadata and bypass `inheritsSameMetadata`? in
`SnapshotProducer.java` we could skip the cache when `manifest.snapshotId() !=
null` (and similarly validate source metadata in `ManifestFilterManager`), or
explicitly track both cache bugs in a follow-up if out of scope here:
```diff
- .run(index -> manifestFiles[index] =
manifestsWithMetadata.get(manifests.get(index)));
+ .run(
+ index -> {
+ ManifestFile manifest = manifests.get(index);
+ manifestFiles[index] =
+ manifest.snapshotId() != null
+ ? manifest
+ : manifestsWithMetadata.get(manifest);
+ });
```
##########
core/src/main/java/org/apache/iceberg/BaseRewriteManifests.java:
##########
@@ -284,17 +295,39 @@ private boolean matchesPredicate(ManifestFile manifest) {
}
private void validateDeletedManifests(
- Set<ManifestFile> currentManifests, long currentSnapshotID) {
- // directly deleted manifests must be still present in the current snapshot
- deletedManifests.stream()
- .filter(manifest -> !currentManifests.contains(manifest))
- .findAny()
- .ifPresent(
- manifest -> {
- throw new ValidationException(
- "Deleted manifest %s could not be found in the latest
snapshot %d",
- manifest.path(), currentSnapshotID);
- });
+ Map<String, ManifestFile> currentManifestsByPath, long
currentSnapshotID) {
+ for (ManifestFile manifest : deletedManifests) {
+ // directly deleted manifests must be still present in the current
snapshot
+ ManifestFile current = currentManifestsByPath.get(manifest.path());
Review Comment:
validation now matches `deletedManifests` by path, while
`keepActiveManifests` and `performRewrite` still filter with
`deletedManifests.contains(manifest)`. if a caller passes a `ManifestFile` with
identity equality, could it pass validation and stay in the snapshot alongside
its replacement? should we normalize in `deleteManifest` and add a test for it?
```diff
- deletedManifests.add(manifest);
+ deletedManifests.add(GenericManifestFile.copyOf(manifest).build());
```
##########
core/src/main/java/org/apache/iceberg/BaseRewriteManifests.java:
##########
@@ -284,17 +295,39 @@ private boolean matchesPredicate(ManifestFile manifest) {
}
private void validateDeletedManifests(
- Set<ManifestFile> currentManifests, long currentSnapshotID) {
- // directly deleted manifests must be still present in the current snapshot
- deletedManifests.stream()
- .filter(manifest -> !currentManifests.contains(manifest))
- .findAny()
- .ifPresent(
- manifest -> {
- throw new ValidationException(
- "Deleted manifest %s could not be found in the latest
snapshot %d",
- manifest.path(), currentSnapshotID);
- });
+ Map<String, ManifestFile> currentManifestsByPath, long
currentSnapshotID) {
+ for (ManifestFile manifest : deletedManifests) {
+ // directly deleted manifests must be still present in the current
snapshot
+ ManifestFile current = currentManifestsByPath.get(manifest.path());
+ ValidationException.check(
+ current != null,
+ "Deleted manifest %s could not be found in the latest snapshot %d",
+ manifest.path(),
+ currentSnapshotID);
+
+ // a replacement written from the entries of a manifest that inherits
other metadata now would
+ // not have it
+ ValidationException.check(
+ inheritsSameMetadata(manifest, current),
+ "Deleted manifest %s changed in the latest snapshot %d: "
+ + "sequence number %s -> %s, min sequence number %s -> %s, first
row ID %s -> %s",
Review Comment:
if a caller retains the `ManifestFile` from
`ManifestWriter.toManifestFile()` (which keeps `sequenceNumber == -1` after
commit) and passes it to `deleteManifest`, this now fails with `sequence number
-1 -> 0` even without a retry. should we update the error message to mention
rebuilding from current snapshot metadata and document that `deleteManifest`
expects descriptors from `Snapshot.allManifests`?
##########
core/src/main/java/org/apache/iceberg/BaseRewriteManifests.java:
##########
@@ -214,8 +218,15 @@ private boolean requiresRewrite(Set<ManifestFile>
currentManifests) {
return true;
}
- // if any processed manifest is not in the current manifest list, perform
a full rewrite
- return rewrittenManifests.stream().anyMatch(manifest ->
!currentManifests.contains(manifest));
+ // if any processed manifest is not in the current manifest list, or
inherits other metadata
+ // there, such as a manifest staged earlier in a transaction that retries,
perform a full
+ // rewrite
+ return rewrittenManifests.stream()
+ .anyMatch(
+ manifest -> {
+ ManifestFile current =
currentManifestsByPath.get(manifest.path());
+ return current == null || !inheritsSameMetadata(manifest,
current);
Review Comment:
if another writer adds a new partition spec and appends under it before the
retry, won't `requiresRewrite` now re-read that new manifest and NPE in
`getWriter` since `this.specsById` was captured before the retry? could we read
from `ops().current().specsById()` there too and add a retry test with
partition evolution?
```diff
return writers.computeIfAbsent(
- Pair.of(key, partitionSpecId), k -> new
WriterWrapper(specsById.get(partitionSpecId)));
+ Pair.of(key, partitionSpecId),
+ k -> new
WriterWrapper(ops().current().specsById().get(partitionSpecId)));
```
--
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]