From 4aa985ef1218b20100b7c6ddf1777f618fd32207 Mon Sep 17 00:00:00 2001 From: Tim Brown Date: Mon, 23 Nov 2026 08:54:37 -0500 Subject: [PATCH] [MINOR] Check for the .hoodie folder before loading a Hudi meta client Hudi only reports a missing table after retrying the read of hoodie.properties five times with one-second sleeps, so every first sync to a new Hudi target waited ~5s. Check for the .hoodie folder first, as Hudi's own writers do (FSUtils.isTableExists). --- .../apache/xtable/hudi/HudiTableManager.java | 21 +++++++++++++++++++ .../index/HudiBackedSecondaryIndexUtils.java | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/xtable-core/src/main/java/org/apache/xtable/hudi/HudiTableManager.java b/xtable-core/src/main/java/org/apache/xtable/hudi/HudiTableManager.java index fbf232a9b..661d9e20c 100644 --- a/xtable-core/src/main/java/org/apache/xtable/hudi/HudiTableManager.java +++ b/xtable-core/src/main/java/org/apache/xtable/hudi/HudiTableManager.java @@ -21,6 +21,7 @@ import static org.apache.hudi.hadoop.fs.HadoopFSUtils.getStorageConf; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -30,6 +31,7 @@ import org.apache.hadoop.conf.Configuration; +import org.apache.hudi.common.fs.FSUtils; import org.apache.hudi.common.model.HoodieAvroPayload; import org.apache.hudi.common.model.HoodieTableType; import org.apache.hudi.common.model.HoodieTimelineTimeZone; @@ -37,6 +39,7 @@ import org.apache.hudi.common.table.HoodieTableVersion; import org.apache.hudi.common.util.VisibleForTesting; import org.apache.hudi.exception.TableNotFoundException; +import org.apache.hudi.storage.hadoop.HoodieHadoopStorage; import org.apache.xtable.exception.PartitionSpecException; import org.apache.xtable.exception.UpdateException; @@ -72,6 +75,10 @@ public class HudiTableManager { * @return {@link HoodieTableMetaClient} if table exists, otherwise null */ public Optional loadTableMetaClientIfExists(String tableDataPath) { + if (!metaFolderExists(tableDataPath, configuration)) { + log.info("Hudi table does not exist, will be created on first sync"); + return Optional.empty(); + } try { return Optional.of( HoodieTableMetaClient.builder() @@ -85,6 +92,20 @@ public Optional loadTableMetaClientIfExists(String tableD } } + /** + * Returns whether a Hudi table exists at the path, the same check Hudi's own writers make before + * loading a meta client. The meta client alone only reports a missing table after retrying the + * read of its properties file with one-second sleeps. + */ + public static boolean metaFolderExists(String tableDataPath, Configuration configuration) { + try { + return FSUtils.isTableExists( + tableDataPath, new HoodieHadoopStorage(tableDataPath, configuration)); + } catch (IOException e) { + throw new UncheckedIOException("Failed to check for Hudi table at " + tableDataPath, e); + } + } + /** * Initializes a Hudi table with properties matching the provided {@link InternalTable} * diff --git a/xtable-core/src/main/java/org/apache/xtable/hudi/index/HudiBackedSecondaryIndexUtils.java b/xtable-core/src/main/java/org/apache/xtable/hudi/index/HudiBackedSecondaryIndexUtils.java index 2ebc5dc25..6dfbf1f2a 100644 --- a/xtable-core/src/main/java/org/apache/xtable/hudi/index/HudiBackedSecondaryIndexUtils.java +++ b/xtable-core/src/main/java/org/apache/xtable/hudi/index/HudiBackedSecondaryIndexUtils.java @@ -46,6 +46,7 @@ import org.apache.xtable.conversion.ConversionSourceProvider; import org.apache.xtable.conversion.SourceTable; +import org.apache.xtable.hudi.HudiTableManager; import org.apache.xtable.model.metadata.TableSyncMetadata; import org.apache.xtable.model.schema.InternalField; import org.apache.xtable.model.schema.InternalSchema; @@ -113,6 +114,9 @@ static void checkIndexedTable(String tableLocation, SourceTable table) { } static HoodieTableMetaClient getMetaClient(String dataPath, Configuration configuration) { + if (!HudiTableManager.metaFolderExists(dataPath, configuration)) { + throw new TableNotFoundException(dataPath); + } HoodieStorage storage = new HoodieHadoopStorage(dataPath, configuration); return HoodieTableMetaClient.builder().setStorage(storage).setBasePath(dataPath).build(); }