yihua commented on code in PR #11889:
URL: https://github.com/apache/hudi/pull/11889#discussion_r1757669702
##########
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:
Just deleting the partitions does not require timeline load. @codope to
confirm.
##########
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())
Review Comment:
`fromPartitionPath` might be less efficient because it goes through all keys
for each partition path look up.
##########
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) {
Review Comment:
you can return `Option.empty` or `Option.of(obj)` in the map function and
use `.filter` to filter out empty ones corresponding to the deleted partitions.
##########
hudi-client/hudi-client-common/src/test/java/org/apache/hudi/table/upgrade/TestEightToSevenDowngradeHandler.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.table.upgrade;
+
+import org.apache.hudi.common.config.ConfigProperty;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
+import org.apache.hudi.metadata.HoodieTableMetadataUtil;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.storage.hadoop.HoodieHadoopStorage;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static
org.apache.hudi.common.table.HoodieTableConfig.TABLE_METADATA_PARTITIONS;
+import static org.apache.hudi.metadata.MetadataPartitionType.FUNCTIONAL_INDEX;
+import static org.apache.hudi.metadata.MetadataPartitionType.PARTITION_STATS;
+import static org.apache.hudi.metadata.MetadataPartitionType.SECONDARY_INDEX;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class TestEightToSevenDowngradeHandler {
+ private static final List<String> SAMPLE_METADATA_PATHS = Arrays.asList(
+ FUNCTIONAL_INDEX.getPartitionPath(),
+ SECONDARY_INDEX.getPartitionPath(),
Review Comment:
Realistically the exact `FUNCTIONAL_INDEX.getPartitionPath()` and
`SECONDARY_INDEX.getPartitionPath()` do not appear as the partition path, your
current logic misses deleting index partitions with different names.
--
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]