Skip to content

Commit

Permalink
Core: Delete temp metadata file when version already exists (#11350)
Browse files Browse the repository at this point in the history
  • Loading branch information
leesf authored Nov 20, 2024
1 parent 3badfe0 commit f6d02de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,14 @@ private void renameToFinal(FileSystem fs, Path src, Path dst, int nextVersion) {
}

if (fs.exists(dst)) {
throw new CommitFailedException("Version %d already exists: %s", nextVersion, dst);
CommitFailedException cfe =
new CommitFailedException("Version %d already exists: %s", nextVersion, dst);
RuntimeException re = tryDelete(src);
if (re != null) {
cfe.addSuppressed(re);
}

throw cfe;
}

if (!fs.rename(src, dst)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ public void testFailedCommit() throws Exception {

List<File> manifests = listManifestFiles();
assertThat(manifests).as("Should contain 0 Avro manifest files").isEmpty();

// verifies that there is no temporary metadata.json files left on disk
List<String> actual =
listMetadataJsonFiles().stream().map(File::getName).sorted().collect(Collectors.toList());
assertThat(actual)
.as("only v1 and v2 metadata.json should exist.")
.containsExactly("v1.metadata.json", "v2.metadata.json");
}

@Test
Expand Down

0 comments on commit f6d02de

Please sign in to comment.