This is an automated email from the ASF dual-hosted git repository.
vinishjail97 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-xtable.git
The following commit(s) were added to refs/heads/main by this push:
new 51180afd [MINOR] Check for the .hoodie folder before loading a Hudi
meta client (#1031)
51180afd is described below
commit 51180afde495dd203ece826d4b9acdb05c8cbb67
Author: Tim Brown <[email protected]>
AuthorDate: Fri Dec 4 17:49:00 2026 -0500
[MINOR] Check for the .hoodie folder before loading a Hudi meta client
(#1031)
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).
---
.../org/apache/xtable/hudi/HudiTableManager.java | 21 +++++++++++++++++++++
.../hudi/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 fbf232a9..661d9e20 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 @@ package org.apache.xtable.hudi;
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 lombok.extern.log4j.Log4j2;
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.HoodieTableMetaClient;
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<HoodieTableMetaClient> 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 class HudiTableManager {
}
}
+ /**
+ * 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 2ebc5dc2..6dfbf1f2 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 com.google.common.base.Preconditions;
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 @@ public final class HudiBackedSecondaryIndexUtils {
}
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();
}