Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import org.apache.hudi.exception.HoodieSavepointException;
import org.apache.hudi.hadoop.fs.HadoopFSUtils;
import org.apache.hudi.index.HoodieIndex;
import org.apache.hudi.keygen.KeyGenUtils;
import org.apache.hudi.keygen.constant.ComplexKeyGenEncoding;
import org.apache.hudi.internal.schema.InternalSchema;
import org.apache.hudi.internal.schema.Type;
import org.apache.hudi.internal.schema.action.InternalSchemaChangeApplier;
Expand Down Expand Up @@ -113,8 +115,6 @@
import static org.apache.hudi.avro.AvroSchemaUtils.getAvroRecordQualifiedName;
import static org.apache.hudi.common.model.HoodieCommitMetadata.SCHEMA_KEY;
import static org.apache.hudi.common.util.StringUtils.getUTF8Bytes;
import static org.apache.hudi.keygen.KeyGenUtils.getComplexKeygenErrorMessage;
import static org.apache.hudi.keygen.KeyGenUtils.isComplexKeyGeneratorWithSingleRecordKeyField;
import static org.apache.hudi.metadata.HoodieTableMetadata.getMetadataTableBasePath;

/**
Expand Down Expand Up @@ -1315,6 +1315,9 @@ public final HoodieTable initTable(WriteOperationType operationType, Option<Stri
}

doInitTable(operationType, metaClient, instantTime);
if (WriteOperationType.isInsert(operationType) || WriteOperationType.isChangingRecords(operationType)) {
ensureComplexKeyGenEncodingRecorded(metaClient);
}
HoodieTable table = createTable(config, hadoopConf, metaClient);

// Validate table properties
Expand Down Expand Up @@ -1342,6 +1345,40 @@ public final HoodieTable initTable(WriteOperationType operationType, Option<Stri
return table;
}

/**
* A write that keys records needs {@link HoodieTableConfig#COMPLEX_KEYGEN_ENCODING} recorded, and must key them
* the way it says. Engines that key records outside the client (Spark, the streamer) record it when ingestion is
* set up, before this client exists; a client whose callers key records with the client's config records it here
* ({@link #recordsComplexKeyGenEncodingFromData}). A table without any commit records the encoding this
* client's config keys with, since no stored key can contradict it.
*/
protected void ensureComplexKeyGenEncodingRecorded(HoodieTableMetaClient metaClient) {
if (!KeyGenUtils.requireComplexKeyGenEncodingTracked(metaClient.getTableConfig())) {
return;
}
if (!metaClient.getTableConfig().getComplexKeyGenEncoding().isPresent()) {
// an upgrade run by this initialization writes hoodie.properties without refreshing this meta client
metaClient.reloadTableConfig();
}
if (!metaClient.getTableConfig().getComplexKeyGenEncoding().isPresent()
&& (recordsComplexKeyGenEncodingFromData() || !KeyGenUtils.hasCompletedCommits(metaClient))) {
KeyGenUtils.recordComplexKeygenEncodingIfMissing(metaClient, config);
}
ComplexKeyGenEncoding recorded = metaClient.getTableConfig().getComplexKeyGenEncoding()
.orElseThrow(() -> new HoodieException(KeyGenUtils.getComplexKeygenEncodingMissingMessage()));
if (KeyGenUtils.encodeSingleKeyFieldNameForComplexKeyGen(config.getProps()) != recorded.encodesFieldName()) {
throw new HoodieException(KeyGenUtils.getComplexKeygenEncodingMismatchMessage(recorded));
}
}

/**
* Whether this client records a missing complex key generator encoding from the table's data itself, for callers
* that key records with this client's config and have no ingestion setup that records it first.
*/
protected boolean recordsComplexKeyGenEncodingFromData() {
return false;
}

/**
* Sets write schema from last instant since deletes may not have schema set in the config.
*/
Expand Down Expand Up @@ -1410,10 +1447,6 @@ public void validateTableProperties(HoodieTableConfig tableConfig, Properties pr
throw new HoodieException("Only simple, non-partitioned or complex key generator are supported when meta-fields are disabled. Used: " + keyGenClass);
}
}
if (config.enableComplexKeygenValidation()
&& isComplexKeyGeneratorWithSingleRecordKeyField(tableConfig)) {
throw new HoodieException(getComplexKeygenErrorMessage("ingestion"));
}

//Check to make sure it's not a COW table with consistent hashing bucket index
if (tableConfig.getTableType() == HoodieTableType.COPY_ON_WRITE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ public class HoodieWriteConfig extends HoodieConfig {
.markAdvanced()
.sinceVersion("0.14.2")
.supportedVersions("0.14.2", "0.15.1", "1.0.3", "1.1.0")
.withDocumentation("This config only takes effect for writing table version 8 and below. "
.withDocumentation("Only takes effect when the table property `hoodie.table.complex.keygenerator.encoding` is absent. "
+ "That property is recorded by the next Spark, Spark SQL, Hudi Streamer, Flink or Java client write, or upgrade, "
+ "of a table that lacks it, from the encoding found in its data (for a table without data, from this config); "
+ "once present it is authoritative and a writer configured otherwise is refused, so this config is "
+ "ignored. When the encoding cannot be determined from the data and `hoodie.write.complex.keygen.validation.enable` "
+ "is false, this config supplies the value that gets recorded. "
+ "If set to false, the record key field name is encoded and prepended "
+ "in the case where a single record key field is used in the complex key generator, "
+ "i.e., record keys stored in _hoodie_record_key meta field is in the format of "
Expand All @@ -210,8 +215,9 @@ public class HoodieWriteConfig extends HoodieConfig {
.markAdvanced()
.sinceVersion("0.14.2")
.supportedVersions("0.14.2", "0.15.1", "1.0.3", "1.1.0")
.withDocumentation("This config only takes effect for writing table version 8 and below, "
+ "upgrade or downgrade. If set to true, the writer enables the validation on whether the "
.withDocumentation("Only takes effect when the table property `hoodie.table.complex.keygenerator.encoding` is absent "
+ "and the record key encoding cannot be determined from the table's data during a write, upgrade or "
+ "downgrade. If set to true, the writer enables the validation on whether the "
+ "table uses the complex key generator with a single record key field, which can be affected "
+ "by a breaking change in 0.14.1, 0.15.0, 1.0.0, 1.0.1, 1.0.2 releases, causing key "
+ "encoding change and potential duplicates in the table. The validation fails the "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

public class HoodieUpgradeDowngradeException extends HoodieException {

public HoodieUpgradeDowngradeException(String msg) {
super(msg);
}

public HoodieUpgradeDowngradeException(String msg, Throwable t) {
super(msg, t);
}
Expand Down
Loading
Loading