danny0405 commented on code in PR #12327:
URL: https://github.com/apache/hudi/pull/12327#discussion_r1855716813


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -99,53 +102,19 @@ public Map<ConfigProperty, String> 
downgrade(HoodieWriteConfig config, HoodieEng
       CommitMetadataSerDeV1 commitMetadataSerDeV1 = new 
CommitMetadataSerDeV1();
       ActiveTimelineV1 activeTimelineV1 = new ActiveTimelineV1(metaClient);
       context.map(instants, instant -> {
-        String fileName = instantFileNameGenerator.getFileName(instant);
-        // Rename the metadata file name from the 
${instant_time}_${completion_time}.action[.state] format in version 1.x to the 
${instant_time}.action[.state] format in version 0.x.
-        StoragePath fromPath = new 
StoragePath(TIMELINE_LAYOUT_V2.getTimelinePathProvider().getTimelinePath(
-            metaClient.getTableConfig(), metaClient.getBasePath()), fileName);
-        long modificationTime = instant.isCompleted() ? 
convertCompletionTimeToEpoch(instant) : -1;
-        StoragePath toPath = new 
StoragePath(TIMELINE_LAYOUT_V1.getTimelinePathProvider().getTimelinePath(
-            metaClient.getTableConfig(), metaClient.getBasePath()), 
fileName.replaceAll(UNDERSCORE + "\\d+", ""));
-        boolean success = true;
-        if (fileName.contains(UNDERSCORE)) {
-          try {
-            if (instant.getAction().equals(HoodieTimeline.COMMIT_ACTION) || 
instant.getAction().equals(HoodieTimeline.DELTA_COMMIT_ACTION)) {
-              HoodieCommitMetadata commitMetadata =
-                  commitMetadataSerDeV2.deserialize(instant, 
metaClient.getActiveTimeline().getInstantDetails(instant).get(), 
HoodieCommitMetadata.class);
-              Option<byte[]> data = 
commitMetadataSerDeV1.serialize(commitMetadata);
-              String toPathStr = toPath.toUri().toString();
-              activeTimelineV1.createFileInMetaPath(toPathStr, data, true);
-              /**
-               * When we downgrade the table from 1.0 to 0.x, it is important 
to set the modification
-               * timestamp of the 0.x completed instant to match the 
completion time of the
-               * corresponding 1.x instant. Otherwise,  log files in previous 
file slices could
-               * be wrongly attributed to latest file slice for 1.0 readers.
-               * (see HoodieFileGroup.getBaseInstantTime)
-               */
-              if (modificationTime > 0) {
-                metaClient.getStorage().setModificationTime(toPath, 
modificationTime);
-              }
-              metaClient.getStorage().deleteFile(fromPath);
-            } else {
-              success = metaClient.getStorage().rename(fromPath, toPath);
-            }
-            // TODO: We need to rename the action-related part of the metadata 
file name here when we bring separate action name for clustering/compaction in 
1.x as well.
-            if (!success) {
-              throw new HoodieIOException("an error that occurred while 
renaming " + fromPath + " to: " + toPath);
-            }
-            return true;
-          } catch (IOException e) {
-            LOG.error("Can not to complete the downgrade from version eight to 
version seven. The reason for failure is {}", e.getMessage());
-            throw new HoodieException(e);
-          }
-        } else {
-          success = metaClient.getStorage().rename(fromPath, toPath);
-        }
-        return false;
+        String originalFileName = 
instantFileNameGenerator.getFileName(instant);
+        return downgradeActiveTimelineInstant(instant, originalFileName, 
metaClient, commitMetadataSerDeV2, commitMetadataSerDeV1, activeTimelineV1);

Review Comment:
   yeah, the downgrade is limited to the 8->6 scope, maybe just keep the method 
locally here.



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