From 755c7a13c82d77cb1a254429436757101a2ac6df Mon Sep 17 00:00:00 2001 From: Konrad Dziedzic Date: Mon, 2 May 2022 13:12:09 +0200 Subject: [PATCH] Don't delete files when commit to hive metastore fails According to https://github.com/apache/iceberg/issues/2317 it is better not to delete files after commit to metastore failed. --- .../catalog/hms/HiveMetastoreTableOperations.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java index fbe9f9945d05..3950a4c54277 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/hms/HiveMetastoreTableOperations.java @@ -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);