codope commented on code in PR #11889:
URL: https://github.com/apache/hudi/pull/11889#discussion_r1745228153
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -79,17 +96,60 @@ public Map<ConfigProperty, String>
downgrade(HoodieWriteConfig config, HoodieEng
}
downgradePartitionFields(config, context, upgradeDowngradeHelper,
tablePropsToAdd);
+ downgradeMetadataPartitions(metaClient, context, tablePropsToAdd);
return tablePropsToAdd;
}
- private static void downgradePartitionFields(HoodieWriteConfig config,
HoodieEngineContext context, SupportsUpgradeDowngrade upgradeDowngradeHelper,
+ private static void downgradePartitionFields(HoodieWriteConfig config,
+ HoodieEngineContext context,
+ SupportsUpgradeDowngrade
upgradeDowngradeHelper,
Map<ConfigProperty, String>
tablePropsToAdd) {
HoodieTableConfig tableConfig = upgradeDowngradeHelper.getTable(config,
context).getMetaClient().getTableConfig();
String keyGenerator = tableConfig.getKeyGeneratorClassName();
String partitionPathField =
config.getString(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key());
- if (keyGenerator != null && partitionPathField != null
- && (keyGenerator.equals(KeyGeneratorType.CUSTOM.getClassName()) ||
keyGenerator.equals(KeyGeneratorType.CUSTOM_AVRO.getClassName()))) {
+ if (keyGenerator != null
+ && partitionPathField != null
+ && (keyGenerator.equals(KeyGeneratorType.CUSTOM.getClassName())
+ ||
keyGenerator.equals(KeyGeneratorType.CUSTOM_AVRO.getClassName()))) {
tablePropsToAdd.put(HoodieTableConfig.PARTITION_FIELDS,
tableConfig.getPartitionFieldProp());
}
}
+
+ static void downgradeMetadataPartitions(HoodieTableMetaClient metaClient,
+ HoodieEngineContext context,
+ Map<ConfigProperty, String>
tablePropsToAdd) {
+ metaClient.reloadActiveTimeline();
+ StoragePath basePath = metaClient.getBasePath();
+
+ HoodieTableMetaClient mdtMetaClient = HoodieTableMetaClient.builder()
+ .setConf(HadoopFSUtils.getStorageConfWithCopy(
+ (Configuration) context.getStorageConf().unwrap()))
+ .setBasePath(
+ new Path(basePath.toString(),
+ HoodieTableMetaClient.METADATA_TABLE_FOLDER_PATH).toString())
+ .setLoadActiveTimelineOnLoad(true)
+ .build();
+
+ // Delete partitions.
+ deleteMetadataPartition(context, metaClient.getStorage(), mdtMetaClient);
+
+ // No matter if partitions have been removed, block their creation.
+ tablePropsToAdd.put(TABLE_METADATA_PARTITIONS, "");
Review Comment:
this config could have other values (metadata partitions) that are supported
in previous versions e.g. files,record_index,column_stats etc. We should not be
setting it to empty. Shouldn't we only remove the newer partitions that are
supported since 1.0?
##########
hudi-client/hudi-client-common/pom.xml:
##########
@@ -179,7 +179,11 @@
</exclusion>
</exclusions>
</dependency>
-
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-inline</artifactId>
Review Comment:
Why is this new dependency needed? For mocking static methods? If so, can we
not make it just private and visible for testing, and mock metaclient if needed.
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -79,17 +96,60 @@ public Map<ConfigProperty, String>
downgrade(HoodieWriteConfig config, HoodieEng
}
downgradePartitionFields(config, context, upgradeDowngradeHelper,
tablePropsToAdd);
+ downgradeMetadataPartitions(metaClient, context, tablePropsToAdd);
return tablePropsToAdd;
}
- private static void downgradePartitionFields(HoodieWriteConfig config,
HoodieEngineContext context, SupportsUpgradeDowngrade upgradeDowngradeHelper,
+ private static void downgradePartitionFields(HoodieWriteConfig config,
+ HoodieEngineContext context,
+ SupportsUpgradeDowngrade
upgradeDowngradeHelper,
Map<ConfigProperty, String>
tablePropsToAdd) {
HoodieTableConfig tableConfig = upgradeDowngradeHelper.getTable(config,
context).getMetaClient().getTableConfig();
String keyGenerator = tableConfig.getKeyGeneratorClassName();
String partitionPathField =
config.getString(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key());
- if (keyGenerator != null && partitionPathField != null
- && (keyGenerator.equals(KeyGeneratorType.CUSTOM.getClassName()) ||
keyGenerator.equals(KeyGeneratorType.CUSTOM_AVRO.getClassName()))) {
+ if (keyGenerator != null
+ && partitionPathField != null
+ && (keyGenerator.equals(KeyGeneratorType.CUSTOM.getClassName())
+ ||
keyGenerator.equals(KeyGeneratorType.CUSTOM_AVRO.getClassName()))) {
tablePropsToAdd.put(HoodieTableConfig.PARTITION_FIELDS,
tableConfig.getPartitionFieldProp());
}
}
+
+ static void downgradeMetadataPartitions(HoodieTableMetaClient metaClient,
+ HoodieEngineContext context,
+ Map<ConfigProperty, String>
tablePropsToAdd) {
+ metaClient.reloadActiveTimeline();
+ StoragePath basePath = metaClient.getBasePath();
+
+ HoodieTableMetaClient mdtMetaClient = HoodieTableMetaClient.builder()
+ .setConf(HadoopFSUtils.getStorageConfWithCopy(
+ (Configuration) context.getStorageConf().unwrap()))
+ .setBasePath(
+ new Path(basePath.toString(),
+ HoodieTableMetaClient.METADATA_TABLE_FOLDER_PATH).toString())
+ .setLoadActiveTimelineOnLoad(true)
+ .build();
+
+ // Delete partitions.
+ deleteMetadataPartition(context, metaClient.getStorage(), mdtMetaClient);
+
+ // No matter if partitions have been removed, block their creation.
+ tablePropsToAdd.put(TABLE_METADATA_PARTITIONS, "");
+ }
+
+ static void deleteMetadataPartition(HoodieEngineContext context,
+ HoodieStorage hoodieStorage,
+ HoodieTableMetaClient mdtMetaClient) {
+ List<String> metadataPartitions = FSUtils.getAllPartitionPaths(
+ context, hoodieStorage, mdtMetaClient.getBasePath(), true);
+
+ 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);
+ }
Review Comment:
Since only certain metadata partitions are being deleted, so the table
config should remove such partitions only. Otherwise, we can be in a scenario
where table config is empty but there are still some metadata partitions like
files, record_index.
##########
hudi-client/hudi-client-common/src/test/java/org/apache/hudi/table/upgrade/TestEightToSevenDowngradeHandler.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.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.mockito.MockedStatic;
+
+import java.util.Arrays;
+import java.util.List;
+
+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.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class TestEightToSevenDowngradeHandler {
+ @Test
+ void testDeleteMetadataPartition() {
Review Comment:
can we assert table config update as well in this test?
--
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]