@@ -339,21 +339,11 @@ private <T extends SpecificRecordBase> boolean isBootstrapNeeded(Option<HoodieIn
339339 return false ;
340340 }
341341
342- boolean isRollbackAction = false ;
343- List <String > rollbackedTimestamps = Collections .emptyList ();
344- if (actionMetadata .isPresent () && actionMetadata .get () instanceof HoodieRollbackMetadata ) {
345- isRollbackAction = true ;
346- List <HoodieInstantInfo > rollbackedInstants =
347- ((HoodieRollbackMetadata ) actionMetadata .get ()).getInstantsRollback ();
348- rollbackedTimestamps = rollbackedInstants .stream ().map (instant -> {
349- return instant .getCommitTime ().toString ();
350- }).collect (Collectors .toList ());
351- }
352-
342+ // Detect the commit gaps if any from the data and the metadata active timeline
353343 if (dataMetaClient .getActiveTimeline ().getAllCommitsTimeline ().isBeforeTimelineStarts (
354344 latestMetadataInstant .get ().getTimestamp ())
355- && (! isRollbackAction || ! rollbackedTimestamps . contains ( latestMetadataInstantTimestamp ) )) {
356- LOG .warn ("Metadata Table will need to be re-bootstrapped as un-synced instants have been archived."
345+ && ! isCommitRevertedByInFlightAction ( actionMetadata , latestMetadataInstantTimestamp )) {
346+ LOG .error ("Metadata Table will need to be re-bootstrapped as un-synced instants have been archived."
357347 + " latestMetadataInstant=" + latestMetadataInstant .get ().getTimestamp ()
358348 + ", latestDataInstant=" + dataMetaClient .getActiveTimeline ().firstInstant ().get ().getTimestamp ());
359349 return true ;
@@ -362,10 +352,62 @@ private <T extends SpecificRecordBase> boolean isBootstrapNeeded(Option<HoodieIn
362352 return false ;
363353 }
364354
355+ /**
356+ * Is the latest commit instant reverted by the in-flight instant action?
357+ *
358+ * @param actionMetadata - In-flight instant action metadata
359+ * @param latestMetadataInstantTimestamp - Metadata table latest instant timestamp
360+ * @param <T> - ActionMetadata type
361+ * @return True if the latest instant action is reverted by the action
362+ */
363+ private <T extends SpecificRecordBase > boolean isCommitRevertedByInFlightAction (Option <T > actionMetadata ,
364+ final String latestMetadataInstantTimestamp ) {
365+
366+ if (!actionMetadata .isPresent ()) {
367+ return false ;
368+ }
369+
370+ final String INSTANT_ACTION = (actionMetadata .get () instanceof HoodieRollbackMetadata
371+ ? HoodieTimeline .ROLLBACK_ACTION
372+ : (actionMetadata .get () instanceof HoodieRestoreMetadata ? HoodieTimeline .RESTORE_ACTION : "" ));
373+
374+ List <String > affectedInstantTimestamps ;
375+ switch (INSTANT_ACTION ) {
376+ case HoodieTimeline .ROLLBACK_ACTION :
377+ List <HoodieInstantInfo > rollbackedInstants =
378+ ((HoodieRollbackMetadata ) actionMetadata .get ()).getInstantsRollback ();
379+ affectedInstantTimestamps = rollbackedInstants .stream ().map (instant -> {
380+ return instant .getCommitTime ().toString ();
381+ }).collect (Collectors .toList ());
382+
383+ if (affectedInstantTimestamps .contains (latestMetadataInstantTimestamp )) {
384+ return true ;
385+ }
386+ break ;
387+
388+ case HoodieTimeline .RESTORE_ACTION :
389+ List <HoodieInstantInfo > restoredInstants =
390+ ((HoodieRestoreMetadata ) actionMetadata .get ()).getRestoreInstantInfo ();
391+ affectedInstantTimestamps = restoredInstants .stream ().map (instant -> {
392+ return instant .getCommitTime ().toString ();
393+ }).collect (Collectors .toList ());
394+
395+ if (affectedInstantTimestamps .contains (latestMetadataInstantTimestamp )) {
396+ return true ;
397+ }
398+ break ;
399+
400+ default :
401+ return false ;
402+ }
403+
404+ return false ;
405+ }
406+
365407 /**
366408 * Initialize the Metadata Table by listing files and partitions from the file system.
367409 *
368- * @param dataMetaClient {@code HoodieTableMetaClient} for the dataset.
410+ * @param dataMetaClient {@code HoodieTableMetaClient} for the dataset.
369411 * @param inflightInstantTimestamp
370412 */
371413 private boolean bootstrapFromFilesystem (HoodieEngineContext engineContext , HoodieTableMetaClient dataMetaClient ,
0 commit comments