codope commented on code in PR #5837:
URL: https://github.com/apache/hudi/pull/5837#discussion_r928146386


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/client/HoodieTimelineArchiver.java:
##########
@@ -491,14 +503,33 @@ private Stream<HoodieInstant> getInstantsToArchive() {
     // active timeline. This is required by metadata table,
     // see HoodieTableMetadataUtil#processRollbackMetadata for details.
     if (HoodieTableMetadata.isMetadataTable(config.getBasePath())) {
-      HoodieTableMetaClient dataMetaClient = HoodieTableMetaClient.builder()
-          
.setBasePath(HoodieTableMetadata.getDatasetBasePath(config.getBasePath()))
+      HoodieTableMetaClient metadataTableMetaClient = 
HoodieTableMetaClient.builder()
+          .setBasePath(getDatasetBasePath(config.getBasePath()))
           .setConf(metaClient.getHadoopConf())
           .build();
-      Option<String> earliestActiveDatasetCommit = 
dataMetaClient.getActiveTimeline().firstInstant().map(HoodieInstant::getTimestamp);
-      if (earliestActiveDatasetCommit.isPresent()) {
+      Option<HoodieInstant> earliestActiveDatasetCommit = 
metadataTableMetaClient.getActiveTimeline().firstInstant();
+
+      // There are chances that there could be holes in the timeline due to 
archival and savepoint interplay.
+      // So, the first non-savepoint commit in the data timeline is considered 
as beginning of the active timeline.
+      HoodieTableMetaClient dataTableMetaClient = 
HoodieTableMetaClient.builder()
+          
.setBasePath(getDataTableBasePathFromMetadataTable(config.getBasePath()))
+          .setConf(metaClient.getHadoopConf())
+          .build();
+      Set<String> savepointTimestamps = 
dataTableMetaClient.getActiveTimeline().getInstants()
+          .filter(entry -> 
entry.getAction().equals(HoodieTimeline.SAVEPOINT_ACTION))
+          .map(HoodieInstant::getTimestamp)
+          .collect(Collectors.toSet());
+      Option<HoodieInstant> firstNonSavepointCommit = 
earliestActiveDatasetCommit;
+      if (!savepointTimestamps.isEmpty()) {
+        firstNonSavepointCommit = 
Option.fromJavaOptional(dataTableMetaClient.getActiveTimeline().getInstants()
+            .filter(entry -> 
!savepointTimestamps.contains(entry.getTimestamp()))
+            .findFirst());
+      }

Review Comment:
   Yew, that's a good point. It should be guarded



-- 
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]

Reply via email to