diff --git a/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java b/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java index d6ad112c682b..62f67fb295df 100644 --- a/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java +++ b/core/src/main/java/org/apache/iceberg/hadoop/HadoopTableOperations.java @@ -92,16 +92,20 @@ public TableMetadata refresh() { nextMetadataFile = getMetadataFile(ver + 1); } - this.version = ver; + // only load if the current version is out of date + if (version == null || version != ver) { + this.version = ver; + + TableMetadata newMetadata = TableMetadataParser.read(io(), io().newInputFile(metadataFile.toString())); + String newUUID = newMetadata.uuid(); + if (currentMetadata != null) { + Preconditions.checkState(newUUID == null || newUUID.equals(currentMetadata.uuid()), + "Table UUID does not match: current=%s != refreshed=%s", currentMetadata.uuid(), newUUID); + } - TableMetadata newMetadata = TableMetadataParser.read(io(), io().newInputFile(metadataFile.toString())); - String newUUID = newMetadata.uuid(); - if (currentMetadata != null) { - Preconditions.checkState(newUUID == null || newUUID.equals(currentMetadata.uuid()), - "Table UUID does not match: current=%s != refreshed=%s", currentMetadata.uuid(), newUUID); + this.currentMetadata = newMetadata; } - this.currentMetadata = newMetadata; this.shouldRefresh = false; return currentMetadata; } catch (IOException e) { diff --git a/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCommits.java b/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCommits.java index 2012122ed7fe..c1c8e2e5e820 100644 --- a/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCommits.java +++ b/core/src/test/java/org/apache/iceberg/hadoop/TestHadoopCommits.java @@ -357,7 +357,7 @@ private void testRenameWithFileSystem(FileSystem mockFs) throws Exception { // inject the mockFS into the TableOperations doReturn(mockFs).when(spyOps).getFileSystem(any(), any()); try { - spyOps.commit(spyOps.current(), meta1); + spyOps.commit(tops.current(), meta1); fail("Commit should fail due to mock file system"); } catch (CommitFailedException expected) { }