diff --git a/core/src/main/java/org/apache/iceberg/BaseMetastoreTableOperations.java b/core/src/main/java/org/apache/iceberg/BaseMetastoreTableOperations.java index 78bc1d423a73..45b6047cdf52 100644 --- a/core/src/main/java/org/apache/iceberg/BaseMetastoreTableOperations.java +++ b/core/src/main/java/org/apache/iceberg/BaseMetastoreTableOperations.java @@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import org.apache.iceberg.encryption.EncryptionManager; +import org.apache.iceberg.exceptions.CommitFailedException; import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.iceberg.io.FileIO; import org.apache.iceberg.io.LocationProvider; @@ -88,6 +89,16 @@ protected void doRefresh() { @Override public void commit(TableMetadata base, TableMetadata metadata) { + // if the metadata is already out of date, reject it + if (base != current()) { + throw new CommitFailedException("Cannot commit: stale table metadata"); + } + // if the metadata is not changed, return early + if (base == metadata) { + LOG.info("Nothing to commit."); + return; + } + doCommit(base, metadata); requestRefresh(); } diff --git a/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java b/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java index 1cb4edc26f99..0b77450854ba 100644 --- a/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java +++ b/hive/src/main/java/org/apache/iceberg/hive/HiveTableOperations.java @@ -123,17 +123,6 @@ protected void doRefresh() { @Override protected void doCommit(TableMetadata base, TableMetadata metadata) { - // if the metadata is already out of date, reject it - if (base != current()) { - throw new CommitFailedException("Cannot commit: stale table metadata for %s.%s", database, tableName); - } - - // if the metadata is not changed, return early - if (base == metadata) { - LOG.info("Nothing to commit."); - return; - } - String newMetadataLocation = writeNewMetadata(metadata, currentVersion() + 1); boolean threw = true;