Skip to content

Commit

Permalink
[HUDI-8666] Revisit error message when timeline layout version cannot…
Browse files Browse the repository at this point in the history
… be read
  • Loading branch information
Vova Kolmakov committed Feb 21, 2025
1 parent 3b205d1 commit 16daa7a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public class HoodieTableConfig extends HoodieConfig {
public static final ConfigProperty<String> TIMELINE_LAYOUT_VERSION = ConfigProperty
.key("hoodie.timeline.layout.version")
.noDefaultValue()
.withDocumentation("Version of timeline used, by the table.");
.withDocumentation("Version of timeline used by the table.");

public static final ConfigProperty<RecordMergeMode> RECORD_MERGE_MODE = ConfigProperty
.key("hoodie.record.merge.mode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import org.apache.hudi.common.util.collection.Triple;
import org.apache.hudi.exception.HoodieException;
import org.apache.hudi.exception.HoodieIOException;
import org.apache.hudi.exception.TableNotFoundException;
import org.apache.hudi.exception.InvalidTableException;
import org.apache.hudi.keygen.constant.KeyGeneratorType;
import org.apache.hudi.metadata.HoodieTableMetadata;
import org.apache.hudi.storage.HoodieStorage;
Expand Down Expand Up @@ -181,7 +181,7 @@ protected HoodieTableMetaClient(HoodieStorage storage, String basePath, boolean
"Layout Version defined in hoodie properties has higher version (" + tableConfigVersion.get()
+ ") than the one passed in config (" + layoutVersion.get() + ")");
} else if (layoutVersion.isEmpty() && tableConfigVersion.isEmpty()) {
throw new TableNotFoundException("Table does not exist");
throw new InvalidTableException(basePath, "timeline layout version is not set");
}
this.timelineLayoutVersion = layoutVersion.orElseGet(tableConfigVersion::get);
this.timelineLayout = TimelineLayout.fromVersion(timelineLayoutVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,9 @@ private Option<Schema> getTableParquetSchemaFromDataFile() {
return Option.empty();
}
default:
LOG.error("Unknown table type {}", metaClient.getTableType());
throw new InvalidTableException(metaClient.getBasePath().toString());
String errMsg = String.format("Unknown table type %s", metaClient.getTableType());
LOG.error(errMsg);
throw new InvalidTableException(metaClient.getBasePath().toString(), errMsg);
}
} catch (IOException e) {
throw new HoodieException("Failed to read data schema", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

package org.apache.hudi.exception;

import org.apache.hudi.common.util.StringUtils;

/**
* Exception thrown to indicate that a hoodie table is invalid.
*/
public class InvalidTableException extends HoodieException {

public InvalidTableException(String basePath) {
super(getErrorMessage(basePath));
public InvalidTableException(String basePath, String error) {
super(buildErrorMessage(basePath, error));
}

private static String getErrorMessage(String basePath) {
return "Invalid Hoodie Table. " + basePath;
private static String buildErrorMessage(String basePath, String error) {
return StringUtils.isNullOrEmpty(error)
? "Invalid Hoodie Table: " + basePath
: "Invalid Hoodie Table (" + error + "): " + basePath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.hudi.common.util.ValidationUtils;
import org.apache.hudi.config.HoodieCompactionConfig;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.TableNotFoundException;
import org.apache.hudi.exception.InvalidTableException;
import org.apache.hudi.hive.HiveSyncConfig;
import org.apache.hudi.hive.MultiPartKeysValueExtractor;
import org.apache.hudi.hive.SlashEncodedDayPartitionValueExtractor;
Expand Down Expand Up @@ -266,7 +266,7 @@ private void waitTillNCommits(FileSystem fs, int numCommits, int timeoutSecs, in
}
HoodieTableMetaClient metaClient = createMetaClient(new HadoopStorageConfiguration(fs.getConf()), tablePath);
System.out.println("Instants :" + metaClient.getActiveTimeline().getInstants());
} catch (TableNotFoundException te) {
} catch (InvalidTableException te) {
LOG.info("Got table not found exception. Retrying");
} finally {
Thread.sleep(sleepSecsAfterEachRun * 1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import org.apache.hudi.common.testutils.{HoodieTestDataGenerator, HoodieTestTabl
import org.apache.hudi.common.testutils.RawTripTestPayload.recordsToStrings
import org.apache.hudi.common.util.{CollectionUtils, CommitUtils}
import org.apache.hudi.config.{HoodieClusteringConfig, HoodieCompactionConfig, HoodieLockConfig, HoodieWriteConfig}
import org.apache.hudi.exception.TableNotFoundException
import org.apache.hudi.exception.InvalidTableException
import org.apache.hudi.storage.{HoodieStorage, StoragePath}
import org.apache.hudi.testutils.{DataSourceTestUtils, HoodieSparkClientTestBase, HoodieSparkDeleteRecordMerger}

import org.apache.spark.sql._
import org.apache.spark.sql.streaming.{OutputMode, StreamingQuery, Trigger}
import org.apache.spark.sql.types.StructType
Expand Down Expand Up @@ -228,8 +227,8 @@ class TestStructuredStreaming extends HoodieSparkClientTestBase {
success = true
}
} catch {
case _: TableNotFoundException =>
log.info("Got table not found exception. Retrying")
case _: InvalidTableException =>
log.info("Got invalid table exception. Retrying")
} finally {
if (!success) {
Thread.sleep(sleepSecsAfterEachRun * 1000)
Expand Down Expand Up @@ -455,8 +454,8 @@ class TestStructuredStreaming extends HoodieSparkClientTestBase {
success = true
}
} catch {
case _: TableNotFoundException =>
log.info("Got table not found exception. Retrying")
case _: InvalidTableException =>
log.info("Got invalid table exception. Retrying")
} finally {
Thread.sleep(sleepSecsAfterEachRun * 1000)
currTime = System.currentTimeMillis
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ private void initTableNameVars(HiveSyncConfig config) {
: Option.of(tableName + SUFFIX_READ_OPTIMIZED_TABLE);
break;
default:
LOG.error("Unknown table type " + syncClient.getTableType());
throw new InvalidTableException(syncClient.getBasePath());
throwInvalidTableTypeException();
}
}
}

private void throwInvalidTableTypeException() {
String errMsg = String.format("Unknown table type %s", syncClient.getTableType());
LOG.error(errMsg);
throw new InvalidTableException(syncClient.getBasePath(), errMsg);
}

@Override
public void syncHoodieTable() {
try {
Expand Down Expand Up @@ -210,8 +215,7 @@ protected void doSync() {
}
break;
default:
LOG.error("Unknown table type " + syncClient.getTableType());
throw new InvalidTableException(syncClient.getBasePath());
throwInvalidTableTypeException();
}
}

Expand Down

0 comments on commit 16daa7a

Please sign in to comment.