[HUDI-2537] Fix metadata table for flink (#3774)
This commit is contained in:
@@ -22,6 +22,7 @@ import org.apache.hudi.avro.model.HoodieCleanMetadata;
|
||||
import org.apache.hudi.avro.model.HoodieMetadataRecord;
|
||||
import org.apache.hudi.avro.model.HoodieRestoreMetadata;
|
||||
import org.apache.hudi.avro.model.HoodieRollbackMetadata;
|
||||
import org.apache.hudi.client.AbstractHoodieWriteClient;
|
||||
import org.apache.hudi.common.config.HoodieMetadataConfig;
|
||||
import org.apache.hudi.common.config.SerializableConfiguration;
|
||||
import org.apache.hudi.common.engine.HoodieEngineContext;
|
||||
@@ -219,7 +220,7 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
*/
|
||||
protected abstract void initialize(HoodieEngineContext engineContext);
|
||||
|
||||
protected void initTableMetadata() {
|
||||
public void initTableMetadata() {
|
||||
try {
|
||||
if (this.metadata != null) {
|
||||
this.metadata.close();
|
||||
@@ -533,4 +534,42 @@ public abstract class HoodieBackedTableMetadataWriter implements HoodieTableMeta
|
||||
* @param instantTime The timestamp to use for the deltacommit.
|
||||
*/
|
||||
protected abstract void commit(List<HoodieRecord> records, String partitionName, String instantTime);
|
||||
|
||||
/**
|
||||
* Perform a compaction on the Metadata Table.
|
||||
*
|
||||
* Cases to be handled:
|
||||
* 1. We cannot perform compaction if there are previous inflight operations on the dataset. This is because
|
||||
* a compacted metadata base file at time Tx should represent all the actions on the dataset till time Tx.
|
||||
*
|
||||
* 2. In multi-writer scenario, a parallel operation with a greater instantTime may have completed creating a
|
||||
* deltacommit.
|
||||
*/
|
||||
protected void compactIfNecessary(AbstractHoodieWriteClient writeClient, String instantTime) {
|
||||
String latestDeltacommitTime = metadataMetaClient.getActiveTimeline().getDeltaCommitTimeline().filterCompletedInstants().lastInstant()
|
||||
.get().getTimestamp();
|
||||
List<HoodieInstant> pendingInstants = dataMetaClient.reloadActiveTimeline().filterInflightsAndRequested()
|
||||
.findInstantsBefore(latestDeltacommitTime).getInstants().collect(Collectors.toList());
|
||||
|
||||
if (!pendingInstants.isEmpty()) {
|
||||
LOG.info(String.format("Cannot compact metadata table as there are %d inflight instants before latest deltacommit %s: %s",
|
||||
pendingInstants.size(), latestDeltacommitTime, Arrays.toString(pendingInstants.toArray())));
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger compaction with suffixes based on the same instant time. This ensures that any future
|
||||
// delta commits synced over will not have an instant time lesser than the last completed instant on the
|
||||
// metadata table.
|
||||
final String compactionInstantTime = latestDeltacommitTime + "001";
|
||||
if (writeClient.scheduleCompactionAtInstant(compactionInstantTime, Option.empty())) {
|
||||
writeClient.compact(compactionInstantTime);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doClean(AbstractHoodieWriteClient writeClient, String instantTime) {
|
||||
// Trigger cleaning with suffixes based on the same instant time. This ensures that any future
|
||||
// delta commits synced over will not have an instant time lesser than the last completed instant on the
|
||||
// metadata table.
|
||||
writeClient.clean(instantTime + "002");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user