diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/HiveTableOperations.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/HiveTableOperations.java index e5d8bc46d9526..4ea437d5feea9 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/HiveTableOperations.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/HiveTableOperations.java @@ -51,6 +51,7 @@ import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; +import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Map; import java.util.Objects; @@ -400,6 +401,7 @@ private void refreshFromMetadataLocation(String newLocation) try { Tasks.foreach(newLocation) .retry(config.getTableRefreshRetries()) + .shouldRetryTest(this::shouldRetry) .exponentialBackoff( config.getTableRefreshBackoffMinSleepTime().toMillis(), config.getTableRefreshBackoffMaxSleepTime().toMillis(), @@ -428,6 +430,11 @@ private void refreshFromMetadataLocation(String newLocation) shouldRefresh = false; } + private boolean shouldRetry(Exception exception) + { + return !(exception.getCause() instanceof FileNotFoundException); + } + private static String newTableMetadataFilePath(TableMetadata meta, int newVersion) { String codec = meta.property(METADATA_COMPRESSION, METADATA_COMPRESSION_DEFAULT); diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergMetadataListing.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergMetadataListing.java index 580396a2c9cd9..4cb866e1072bd 100644 --- a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergMetadataListing.java +++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/TestIcebergMetadataListing.java @@ -39,6 +39,7 @@ public class TestIcebergMetadataListing extends AbstractTestQueryFramework { + private static final int TEST_TIMEOUT = 10_000; @Override protected QueryRunner createQueryRunner() throws Exception @@ -61,7 +62,7 @@ protected QueryRunner createQueryRunner() Map icebergProperties = ImmutableMap.builder() .put("hive.metastore", "file") .put("hive.metastore.catalog.dir", catalogDirectory.toFile().toURI().toString()) - .put("iceberg.hive.table-refresh.max-retry-time", "500ms") // improves test time for testTableDropWithMissingMetadata + .put("iceberg.hive.table-refresh.max-retry-time", "20s") // improves test time for testTableDropWithMissingMetadata .build(); queryRunner.createCatalog(ICEBERG_CATALOG, "iceberg", icebergProperties); @@ -120,7 +121,12 @@ public void testTableDescribing() assertQuery("DESCRIBE iceberg.test_schema.iceberg_table1", "VALUES ('_string', 'varchar', '', ''), ('_integer', 'integer', '', '')"); } - @Test + /* + * The property iceberg.hive.table-refresh.max-retry-time is important for controlling the maximum retry duration + * when refreshing Iceberg table metadata. If this test fails, check the refreshFromMetadataLocation method + * in HiveTableOperations. + */ + @Test (timeOut = TEST_TIMEOUT) public void testTableDropWithMissingMetadata() { assertQuerySucceeds("CREATE SCHEMA hive.test_metadata_schema");