Skip to content

Commit

Permalink
Core: Reword exception message in RewriteManifests validation (apache…
Browse files Browse the repository at this point in the history
  • Loading branch information
ajantha-bhat authored Jun 7, 2024
1 parent e0dc57e commit c7de6cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public List<ManifestFile> apply(TableMetadata base, Snapshot snapshot) {
List<ManifestFile> currentManifests = base.currentSnapshot().allManifests(ops.io());
Set<ManifestFile> currentManifestSet = ImmutableSet.copyOf(currentManifests);

validateDeletedManifests(currentManifestSet);
validateDeletedManifests(currentManifestSet, base.currentSnapshot().snapshotId());

if (requiresRewrite(currentManifestSet)) {
performRewrite(currentManifests);
Expand Down Expand Up @@ -275,14 +275,17 @@ private boolean matchesPredicate(ManifestFile manifest) {
return predicate == null || predicate.test(manifest);
}

private void validateDeletedManifests(Set<ManifestFile> currentManifests) {
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("Manifest is missing: %s", manifest.path());
throw new ValidationException(
"Deleted manifest %s could not be found in the latest snapshot %d",
manifest.path(), currentSnapshotID);
});
}

Expand Down
10 changes: 8 additions & 2 deletions core/src/test/java/org/apache/iceberg/TestRewriteManifests.java
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,10 @@ public void testManifestReplacementConcurrentConflictingDelete() throws IOExcept

assertThatThrownBy(rewriteManifests::commit)
.isInstanceOf(ValidationException.class)
.hasMessageStartingWith("Manifest is missing");
.hasMessageStartingWith(
String.format(
"Deleted manifest %s could not be found in the latest snapshot %d",
firstSnapshotManifest.path(), table.currentSnapshot().snapshotId()));
}

@TestTemplate
Expand Down Expand Up @@ -1604,7 +1607,10 @@ public void testDeleteManifestReplacementConflictingDeleteFileRemoval() throws I
// the rewrite must fail as the original delete manifest was replaced concurrently
assertThatThrownBy(rewriteManifests::commit)
.isInstanceOf(ValidationException.class)
.hasMessageStartingWith("Manifest is missing");
.hasMessageStartingWith(
String.format(
"Deleted manifest %s could not be found in the latest snapshot %d",
originalDeleteManifest.path(), table.currentSnapshot().snapshotId()));
}

@TestTemplate
Expand Down

0 comments on commit c7de6cb

Please sign in to comment.