the-other-tim-brown commented on code in PR #9379:
URL: https://github.com/apache/hudi/pull/9379#discussion_r1286198874
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadataWriter.java:
##########
@@ -1055,6 +1063,69 @@ public void close() throws Exception {
*/
protected abstract void commit(String instantTime,
Map<MetadataPartitionType, HoodieData<HoodieRecord>> partitionRecordsMap);
+ /**
+ * Converts the input records to the input format expected by the write
client.
+ * @param records records to be converted
+ * @return converted records
+ */
+ protected abstract I
convertRecordsToWriteClientInput(HoodieData<HoodieRecord> records);
+
+ protected void commitInternal(String instantTime, Map<MetadataPartitionType,
HoodieData<HoodieRecord>> partitionRecordsMap, boolean isInitializing,
+ Option<BulkInsertPartitioner>
bulkInsertPartitioner) {
+ ValidationUtils.checkState(metadataMetaClient != null, "Metadata table is
not fully initialized yet.");
+ HoodieData<HoodieRecord> preppedRecords = prepRecords(partitionRecordsMap);
+ I preppedRecordInputs = convertRecordsToWriteClientInput(preppedRecords);
+
+ try (BaseHoodieWriteClient<?, I, ?, O> writeClient = getWriteClient()) {
+ // rollback partially failed writes if any.
+ if (dataWriteConfig.getFailedWritesCleanPolicy().isEager() &&
writeClient.rollbackFailedWrites()) {
+ metadataMetaClient = HoodieTableMetaClient.reload(metadataMetaClient);
+ }
+
+ if
(!metadataMetaClient.getActiveTimeline().getCommitsTimeline().containsInstant(instantTime))
{
+ // if this is a new commit being applied to metadata for the first time
+ LOG.info("New commit at " + instantTime + " being applied to MDT.");
+ } else {
+ // this code path refers to a re-attempted commit that:
+ // 1. got committed to metadata table, but failed in datatable.
+ // 2. failed while committing to metadata table
+ // for e.g., let's say compaction c1 on 1st attempt succeeded in
metadata table and failed before committing to datatable.
+ // when retried again, data table will first rollback pending
compaction. these will be applied to metadata table, but all changes
+ // are upserts to metadata table and so only a new delta commit will
be created.
+ // once rollback is complete in datatable, compaction will be retried
again, which will eventually hit this code block where the respective commit is
+ // already part of completed commit. So, we have to manually rollback
the completed instant and proceed.
+ Option<HoodieInstant> alreadyCompletedInstant =
metadataMetaClient.getActiveTimeline().filterCompletedInstants().filter(entry
-> entry.getTimestamp().equals(instantTime))
+ .lastInstant();
+ LOG.info(String.format("%s completed commit at %s being applied to
MDT.",
+ alreadyCompletedInstant.isPresent() ? "Already" : "Partially",
instantTime));
+
+ // Rollback the previous commit
+ if (!writeClient.rollback(instantTime)) {
+ throw new HoodieMetadataException("Failed to rollback deltacommit at
" + instantTime + " from MDT");
+ }
+ metadataMetaClient.reloadActiveTimeline();
+ }
+
+ writeClient.startCommitWithTime(instantTime);
+ if (manuallyTransitionCommit) {
+
metadataMetaClient.getActiveTimeline().transitionRequestedToInflight(HoodieActiveTimeline.DELTA_COMMIT_ACTION,
instantTime);
+ }
+ O statuses;
Review Comment:
Removed, this was left over from when I was trying to make the flink writer
also go through this path (it needs to take action with the write statuses)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]