prashantwason commented on code in PR #8837: URL: https://github.com/apache/hudi/pull/8837#discussion_r1218524723
########## hudi-client/hudi-client-common/src/main/java/org/apache/hudi/metadata/HoodieBackedTableMetadataWriter.java: ########## @@ -837,10 +840,75 @@ public void update(HoodieCleanMetadata cleanMetadata, String instantTime) { */ @Override public void update(HoodieRestoreMetadata restoreMetadata, String instantTime) { - processAndCommit(instantTime, () -> HoodieTableMetadataUtil.convertMetadataToRecords(engineContext, - metadataMetaClient.getActiveTimeline(), restoreMetadata, getRecordsGenerationParams(), instantTime, - metadata.getSyncedInstantTime()), false); - closeInternal(); + dataMetaClient.reloadActiveTimeline(); + + // Since the restore has completed on the dataset, the latest write timeline instant is the one to which the + // restore was performed. This should be always present. + final String restoreToInstantTime = dataMetaClient.getActiveTimeline().getWriteTimeline() + .getReverseOrderedInstants().findFirst().get().getTimestamp(); + + // We cannot restore to before the oldest compaction on MDT as we don't have the basefiles before that time. + Option<HoodieInstant> lastCompaction = metadataMetaClient.getCommitTimeline().filterCompletedInstants().lastInstant(); + if (lastCompaction.isPresent()) { + if (HoodieTimeline.LESSER_THAN_OR_EQUALS.test(restoreToInstantTime, lastCompaction.get().getTimestamp())) { + String msg = String.format("Cannot restore MDT to %s because it is older than latest compaction at %s", restoreToInstantTime, + lastCompaction.get().getTimestamp()) + ". Please delete MDT and restore again"; + LOG.error(msg); + throw new HoodieMetadataException(msg); + } + } + + // Restore requires the existing pipelines to be shutdown. So we can safely scan the dataset to find the current + // list of files in the filesystem. + List<DirectoryInfo> dirInfoList = listAllPartitions(dataMetaClient); + Map<String, DirectoryInfo> dirInfoMap = dirInfoList.stream().collect(Collectors.toMap(DirectoryInfo::getRelativePath, Function.identity())); + dirInfoList.clear(); + + LOG.info("Restoring MDT to " + restoreToInstantTime + " at " + instantTime); + getWriteClient().restoreToInstant(restoreToInstantTime, false); + + // At this point we have also reverted the cleans which have occurred after the restoreToInstantTime. Hence, a sync Review Comment: TestHoodieBackedMetadata#testTableOperationsWithRestore -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org