linliu-code commented on code in PR #11889:
URL: https://github.com/apache/hudi/pull/11889#discussion_r1757622025


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -92,4 +115,52 @@ private static void 
downgradePartitionFields(HoodieWriteConfig config, HoodieEng
       tablePropsToAdd.put(HoodieTableConfig.PARTITION_FIELDS, 
tableConfig.getPartitionFieldProp());
     }
   }
+
+  static void downgradeMetadataPartitions(HoodieEngineContext context,
+                                          HoodieStorage hoodieStorage,
+                                          HoodieTableMetaClient mdtMetaClient,
+                                          Map<ConfigProperty, String> 
tablePropsToAdd) {
+    // Fetch metadata partition paths.
+    List<String> metadataPartitions = FSUtils.getAllPartitionPaths(
+        context,
+        hoodieStorage,
+        mdtMetaClient.getBasePath(),
+        true);
+
+    // Delete partitions.
+    List<String> validPartitionPaths = deleteMetadataPartition(context, 
mdtMetaClient, metadataPartitions);
+
+    // Clean the configuration.
+    tablePropsToAdd.put(TABLE_METADATA_PARTITIONS, String.join(",", 
validPartitionPaths));
+  }
+
+  static List<String> deleteMetadataPartition(HoodieEngineContext context,
+                                              HoodieTableMetaClient 
mdtMetaClient,
+                                              List<String> metadataPartitions) 
{
+    List<String> validPartitionPaths = new ArrayList<>();
+
+    for (String partitionPath : metadataPartitions) {
+      if (partitionPath.equals(FUNCTIONAL_INDEX.getPartitionPath())
+          || partitionPath.equals(SECONDARY_INDEX.getPartitionPath())
+          || partitionPath.equals(PARTITION_STATS.getPartitionPath())) {
+        HoodieTableMetadataUtil.deleteMetadataTablePartition(
+            mdtMetaClient, context, partitionPath, true);
+      } else {
+        validPartitionPaths.add(partitionPath);
+      }
+    }
+    return validPartitionPaths;
+  }
+
+  private static HoodieTableMetaClient 
createMetadataTableMetaClient(HoodieEngineContext context,
+                                                                     
StoragePath basePath) {
+    return HoodieTableMetaClient.builder()
+        .setConf(HadoopFSUtils.getStorageConfWithCopy(
+            (Configuration) context.getStorageConf().unwrap()))
+        .setBasePath(
+            new Path(basePath.toString(),
+                HoodieTableMetaClient.METADATA_TABLE_FOLDER_PATH).toString())
+        .setLoadActiveTimelineOnLoad(true)

Review Comment:
   I don' know. I can remove it if it works.



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

Reply via email to