[HUDI-2595] Fixing metadata table updates such that only regular writes from data table can trigger table services in metadata table (#3900)
This commit is contained in:
committed by
GitHub
parent
7aaf47e716
commit
6d109c6de5
@@ -184,11 +184,12 @@ public abstract class AbstractHoodieWriteClient<T extends HoodieRecordPayload, I
|
||||
HoodieTable table = createTable(config, hadoopConf);
|
||||
HoodieCommitMetadata metadata = CommitUtils.buildMetadata(stats, partitionToReplaceFileIds,
|
||||
extraMetadata, operationType, config.getWriteSchema(), commitActionType);
|
||||
HoodieInstant inflightInstant = new HoodieInstant(State.INFLIGHT, table.getMetaClient().getCommitActionType(), instantTime);
|
||||
HeartbeatUtils.abortIfHeartbeatExpired(instantTime, table, heartbeatClient, config);
|
||||
this.txnManager.beginTransaction(Option.of(new HoodieInstant(State.INFLIGHT, table.getMetaClient().getCommitActionType(), instantTime)),
|
||||
this.txnManager.beginTransaction(Option.of(inflightInstant),
|
||||
lastCompletedTxnAndMetadata.isPresent() ? Option.of(lastCompletedTxnAndMetadata.get().getLeft()) : Option.empty());
|
||||
try {
|
||||
preCommit(instantTime, metadata);
|
||||
preCommit(inflightInstant, metadata);
|
||||
commit(table, commitActionType, instantTime, metadata, stats);
|
||||
postCommit(table, metadata, instantTime, extraMetadata);
|
||||
LOG.info("Committed " + instantTime);
|
||||
@@ -244,14 +245,15 @@ public abstract class AbstractHoodieWriteClient<T extends HoodieRecordPayload, I
|
||||
|
||||
/**
|
||||
* Any pre-commit actions like conflict resolution or updating metadata table goes here.
|
||||
* @param instantTime commit instant time.
|
||||
* @param inflightInstant instant of inflight operation.
|
||||
* @param metadata commit metadata for which pre commit is being invoked.
|
||||
*/
|
||||
protected void preCommit(String instantTime, HoodieCommitMetadata metadata) {
|
||||
protected void preCommit(HoodieInstant inflightInstant, HoodieCommitMetadata metadata) {
|
||||
// Create a Hoodie table after starting the transaction which encapsulated the commits and files visible.
|
||||
// Important to create this after the lock to ensure latest commits show up in the timeline without need for reload
|
||||
HoodieTable table = createTable(config, hadoopConf);
|
||||
table.getMetadataWriter().ifPresent(w -> ((HoodieTableMetadataWriter)w).update(metadata, instantTime));
|
||||
table.getMetadataWriter().ifPresent(w -> ((HoodieTableMetadataWriter)w).update(metadata, inflightInstant.getTimestamp(),
|
||||
table.isTableServiceAction(inflightInstant.getAction())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -409,7 +409,7 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
});
|
||||
|
||||
LOG.info("Committing " + partitionToFileStatus.size() + " partitions and " + stats[0] + " files to metadata");
|
||||
update(commitMetadata, createInstantTime);
|
||||
update(commitMetadata, createInstantTime, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -523,23 +523,24 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
* @param instantTime instant time of interest.
|
||||
* @param convertMetadataFunction converter function to convert the respective metadata to List of HoodieRecords to be written to metadata table.
|
||||
* @param <T> type of commit metadata.
|
||||
* @param canTriggerTableService true if table services can be triggered. false otherwise.
|
||||
*/
|
||||
private <T> void processAndCommit(String instantTime, ConvertMetadataFunction convertMetadataFunction) {
|
||||
private <T> void processAndCommit(String instantTime, ConvertMetadataFunction convertMetadataFunction, boolean canTriggerTableService) {
|
||||
if (enabled && metadata != null) {
|
||||
List<HoodieRecord> records = convertMetadataFunction.convertMetadata();
|
||||
commit(records, MetadataPartitionType.FILES.partitionPath(), instantTime);
|
||||
commit(records, MetadataPartitionType.FILES.partitionPath(), instantTime, canTriggerTableService);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update from {@code HoodieCommitMetadata}.
|
||||
*
|
||||
* @param commitMetadata {@code HoodieCommitMetadata}
|
||||
* @param instantTime Timestamp at which the commit was performed
|
||||
* @param isTableServiceAction {@code true} if commit metadata is pertaining to a table service. {@code false} otherwise.
|
||||
*/
|
||||
@Override
|
||||
public void update(HoodieCommitMetadata commitMetadata, String instantTime) {
|
||||
processAndCommit(instantTime, () -> HoodieTableMetadataUtil.convertMetadataToRecords(commitMetadata, instantTime));
|
||||
public void update(HoodieCommitMetadata commitMetadata, String instantTime, boolean isTableServiceAction) {
|
||||
processAndCommit(instantTime, () -> HoodieTableMetadataUtil.convertMetadataToRecords(commitMetadata, instantTime), !isTableServiceAction);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -550,7 +551,8 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
*/
|
||||
@Override
|
||||
public void update(HoodieCleanMetadata cleanMetadata, String instantTime) {
|
||||
processAndCommit(instantTime, () -> HoodieTableMetadataUtil.convertMetadataToRecords(cleanMetadata, instantTime));
|
||||
processAndCommit(instantTime, () -> HoodieTableMetadataUtil.convertMetadataToRecords(cleanMetadata, instantTime),
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,7 +564,7 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
@Override
|
||||
public void update(HoodieRestoreMetadata restoreMetadata, String instantTime) {
|
||||
processAndCommit(instantTime, () -> HoodieTableMetadataUtil.convertMetadataToRecords(metadataMetaClient.getActiveTimeline(),
|
||||
restoreMetadata, instantTime, metadata.getSyncedInstantTime()));
|
||||
restoreMetadata, instantTime, metadata.getSyncedInstantTime()), false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -588,7 +590,7 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
|
||||
List<HoodieRecord> records = HoodieTableMetadataUtil.convertMetadataToRecords(metadataMetaClient.getActiveTimeline(), rollbackMetadata, instantTime,
|
||||
metadata.getSyncedInstantTime(), wasSynced);
|
||||
commit(records, MetadataPartitionType.FILES.partitionPath(), instantTime);
|
||||
commit(records, MetadataPartitionType.FILES.partitionPath(), instantTime, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -601,12 +603,12 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
|
||||
/**
|
||||
* Commit the {@code HoodieRecord}s to Metadata Table as a new delta-commit.
|
||||
*
|
||||
* @param records The list of records to be written.
|
||||
* @param records The list of records to be written.
|
||||
* @param partitionName The partition to which the records are to be written.
|
||||
* @param instantTime The timestamp to use for the deltacommit.
|
||||
* @param canTriggerTableService true if table services can be scheduled and executed. false otherwise.
|
||||
*/
|
||||
protected abstract void commit(List<HoodieRecord> records, String partitionName, String instantTime);
|
||||
protected abstract void commit(List<HoodieRecord> records, String partitionName, String instantTime, boolean canTriggerTableService);
|
||||
|
||||
/**
|
||||
* Perform a compaction on the Metadata Table.
|
||||
|
||||
@@ -34,8 +34,10 @@ public interface HoodieTableMetadataWriter extends Serializable, AutoCloseable {
|
||||
* Update the metadata table due to a COMMIT operation.
|
||||
* @param commitMetadata commit metadata of the operation of interest.
|
||||
* @param instantTime instant time of the commit.
|
||||
* @param isTableServiceAction true if caller is a table service. false otherwise. Only regular write operations can trigger metadata table services and this argument
|
||||
* will assist in this.
|
||||
*/
|
||||
void update(HoodieCommitMetadata commitMetadata, String instantTime);
|
||||
void update(HoodieCommitMetadata commitMetadata, String instantTime, boolean isTableServiceAction);
|
||||
|
||||
/**
|
||||
* Update the metadata table due to a CLEAN operation.
|
||||
|
||||
@@ -738,6 +738,13 @@ public abstract class HoodieTable<T extends HoodieRecordPayload, I, K, O> implem
|
||||
return getMetadataWriter(Option.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if action type is a table service.
|
||||
* @param actionType action type of interest.
|
||||
* @return true if action represents a table service. false otherwise.
|
||||
*/
|
||||
public abstract boolean isTableServiceAction(String actionType);
|
||||
|
||||
/**
|
||||
* Get Table metadata writer.
|
||||
*
|
||||
|
||||
@@ -56,8 +56,8 @@ public abstract class BaseActionExecutor<T extends HoodieRecordPayload, I, K, O,
|
||||
* Writes commits metadata to table metadata.
|
||||
* @param metadata commit metadata of interest.
|
||||
*/
|
||||
protected final void writeTableMetadata(HoodieCommitMetadata metadata) {
|
||||
table.getMetadataWriter().ifPresent(w -> w.update(metadata, instantTime));
|
||||
protected final void writeTableMetadata(HoodieCommitMetadata metadata, String actionType) {
|
||||
table.getMetadataWriter().ifPresent(w -> w.update(metadata, instantTime, table.isTableServiceAction(actionType)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user