-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[HUDI-2285] Metadata Table synchronous design #3426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
985ae86
e85c712
d683122
690ea20
47c3000
b658779
12d6eb5
f417390
fdc267c
59cd841
21e8d70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ | |
| import org.apache.hudi.exception.HoodieRollbackException; | ||
| import org.apache.hudi.exception.HoodieSavepointException; | ||
| import org.apache.hudi.index.HoodieIndex; | ||
| import org.apache.hudi.metadata.HoodieTableMetadataWriter; | ||
| import org.apache.hudi.metrics.HoodieMetrics; | ||
| import org.apache.hudi.table.BulkInsertPartitioner; | ||
| import org.apache.hudi.table.HoodieTable; | ||
|
|
@@ -187,6 +188,8 @@ public boolean commitStats(String instantTime, List<HoodieWriteStat> stats, Opti | |
| lastCompletedTxnAndMetadata.isPresent() ? Option.of(lastCompletedTxnAndMetadata.get().getLeft()) : Option.empty()); | ||
| try { | ||
| preCommit(instantTime, metadata); | ||
| // TODO: Should this be under its own transaction | ||
| table.getMetadataWriter().ifPresent(w -> ((HoodieTableMetadataWriter)w).update(metadata, instantTime)); | ||
| commit(table, commitActionType, instantTime, metadata, stats); | ||
| postCommit(table, metadata, instantTime, extraMetadata); | ||
| LOG.info("Committed " + instantTime); | ||
|
|
@@ -241,10 +244,6 @@ protected void preCommit(String instantTime, HoodieCommitMetadata metadata) { | |
| // TODO : Conflict resolution is not supported for Flink & Java engines | ||
| } | ||
|
|
||
| protected void syncTableMetadata() { | ||
| // no-op | ||
| } | ||
|
|
||
| /** | ||
| * Filter out HoodieRecords that already exists in the output folder. This is useful in deduplication. | ||
| * | ||
|
|
@@ -399,14 +398,6 @@ protected void preWrite(String instantTime, WriteOperationType writeOperationTyp | |
| HoodieTableMetaClient metaClient) { | ||
| setOperationType(writeOperationType); | ||
| this.lastCompletedTxnAndMetadata = TransactionUtils.getLastCompletedTxnInstantAndMetadata(metaClient); | ||
| this.txnManager.beginTransaction(Option.of(new HoodieInstant(State.INFLIGHT, metaClient.getCommitActionType(), instantTime)), lastCompletedTxnAndMetadata | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nts: this lock was only being taken for purposes of syncing. So removing this is fine. |
||
| .isPresent() | ||
| ? Option.of(lastCompletedTxnAndMetadata.get().getLeft()) : Option.empty()); | ||
| try { | ||
| syncTableMetadata(); | ||
| } finally { | ||
| this.txnManager.endTransaction(); | ||
| } | ||
| this.asyncCleanerService = AsyncCleanerService.startAsyncCleaningIfEnabled(this); | ||
| } | ||
|
|
||
|
|
@@ -435,7 +426,6 @@ protected void postCommit(HoodieTable<T, I, K, O> table, HoodieCommitMetadata me | |
| HoodieTimelineArchiveLog archiveLog = new HoodieTimelineArchiveLog(config, table); | ||
| archiveLog.archiveIfRequired(context); | ||
| autoCleanOnCommit(); | ||
| syncTableMetadata(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove the metadata table sync?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no more additional sync process, with this re-design. |
||
| } catch (IOException ioe) { | ||
| throw new HoodieIOException(ioe.getMessage(), ioe); | ||
| } finally { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,6 +197,11 @@ public List<HoodieRollbackStat> doRollbackAndGetStats() { | |
|
|
||
| protected void finishRollback(HoodieRollbackMetadata rollbackMetadata) throws HoodieIOException { | ||
| try { | ||
| // TODO: Potential error here - rollbacks have already completed here so if the syncTableMetadata fails, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here how can we handle the case, re-bootstrap?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, @leesf can you please clarify your question. |
||
| // metadata table will be left in an inconsistent state. This is because we do not use the inflight | ||
| // state for rollback. | ||
| syncTableMetadata(rollbackMetadata); | ||
|
|
||
| table.getActiveTimeline().createNewInstant( | ||
| new HoodieInstant(HoodieInstant.State.INFLIGHT, HoodieTimeline.ROLLBACK_ACTION, instantTime)); | ||
| table.getActiveTimeline().saveAsComplete( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,13 +141,14 @@ protected void commit(Option<Map<String, String>> extraMetadata, HoodieWriteMeta | |
| result.setWriteStats(writeStats); | ||
| // Finalize write | ||
| finalizeWrite(instantTime, writeStats, result); | ||
| syncTableMetadata(); | ||
| try { | ||
| LOG.info("Committing " + instantTime + ", action Type " + getCommitActionType()); | ||
| HoodieActiveTimeline activeTimeline = table.getActiveTimeline(); | ||
| HoodieCommitMetadata metadata = CommitUtils.buildMetadata(writeStats, result.getPartitionToReplaceFileIds(), | ||
| extraMetadata, operationType, getSchemaToStoreInCommit(), getCommitActionType()); | ||
|
|
||
| syncTableMetadata(metadata); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here means we take syncing to metadata table into a commit. more reasonable than making sync table metadata in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Flink, this code is still executed at the driver, right? |
||
|
|
||
| activeTimeline.saveAsComplete(new HoodieInstant(true, getCommitActionType(), instantTime), | ||
| Option.of(metadata.toJsonString().getBytes(StandardCharsets.UTF_8))); | ||
| LOG.info("Committed " + instantTime); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
|
|
||
| package org.apache.hudi.table; | ||
|
|
||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hudi.client.WriteStatus; | ||
| import org.apache.hudi.client.common.HoodieSparkEngineContext; | ||
| import org.apache.hudi.common.engine.HoodieEngineContext; | ||
|
|
@@ -29,9 +30,12 @@ | |
| import org.apache.hudi.common.util.Option; | ||
| import org.apache.hudi.config.HoodieWriteConfig; | ||
| import org.apache.hudi.exception.HoodieException; | ||
| import org.apache.hudi.exception.HoodieMetadataException; | ||
| import org.apache.hudi.index.HoodieIndex; | ||
| import org.apache.hudi.index.SparkHoodieIndex; | ||
|
|
||
| import org.apache.hudi.metadata.HoodieTableMetadata; | ||
| import org.apache.hudi.metadata.HoodieTableMetadataWriter; | ||
| import org.apache.hudi.metadata.SparkHoodieBackedTableMetadataWriter; | ||
| import org.apache.spark.api.java.JavaRDD; | ||
|
|
||
| public abstract class HoodieSparkTable<T extends HoodieRecordPayload> | ||
|
|
@@ -66,4 +70,21 @@ public static <T extends HoodieRecordPayload> HoodieSparkTable<T> create(HoodieW | |
| protected HoodieIndex<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, JavaRDD<WriteStatus>> getIndex(HoodieWriteConfig config, HoodieEngineContext context) { | ||
| return SparkHoodieIndex.createIndex(config); | ||
| } | ||
|
|
||
| @Override | ||
| public Option<HoodieTableMetadataWriter> getMetadataWriter() { | ||
| if (!config.useFileListingMetadata()) { | ||
| return Option.empty(); | ||
| } | ||
|
|
||
| try { | ||
| if (!metaClient.getFs().exists(new Path(HoodieTableMetadata.getMetadataTableBasePath(metaClient.getBasePath())))) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we avoid this
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SparkRDDWriteClient instantiation actually triggers bootstrap for the first time when metadata is enabled. so, not really sure on what scenario, we will hit this case where metadata is enabled, but table does not exist. @prashantwason @nbalajee : do you know the reason why we have this check here. |
||
| return Option.empty(); | ||
| } | ||
| } catch (Exception e) { | ||
| throw new HoodieMetadataException("Could not create metadata table writer", e); | ||
| } | ||
|
|
||
| return Option.of(SparkHoodieBackedTableMetadataWriter.create(context.getHadoopConf().get(), config, context)); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nts: first committing to metadata table