Skip to content

Commit

Permalink
Don't delete files when commit to hive metastore fails
Browse files Browse the repository at this point in the history
According to apache/iceberg#2317
it is better not to delete files after commit to metastore failed.
  • Loading branch information
homar authored and findepi committed May 6, 2022
1 parent 7ca52ff commit 068787a
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,15 @@ protected void commitToExistingTable(TableMetadata base, TableMetadata metadata)
.setParameter(METADATA_LOCATION_PROP, newMetadataLocation)
.setParameter(PREVIOUS_METADATA_LOCATION_PROP, currentMetadataLocation)
.build();

// todo privileges should not be replaced for an alter
PrincipalPrivileges privileges = table.getOwner().map(MetastoreUtil::buildInitialPrivilegeSet).orElse(NO_PRIVILEGES);
metastore.replaceTable(database, tableName, table, privileges);
}
catch (RuntimeException e) {
try {
io().deleteFile(newMetadataLocation);
}
catch (RuntimeException ex) {
e.addSuppressed(ex);
}
// CommitFailedException is handled as a special case in the Iceberg library. This commit will automatically retry
throw new CommitFailedException(e, "Failed to commit to table %s.%s", database, tableName);
}

// todo privileges should not be replaced for an alter
PrincipalPrivileges privileges = table.getOwner().map(MetastoreUtil::buildInitialPrivilegeSet).orElse(NO_PRIVILEGES);
metastore.replaceTable(database, tableName, table, privileges);
}
finally {
thriftMetastore.releaseTableLock(identity, lockId);
Expand Down

0 comments on commit 068787a

Please sign in to comment.