yihua commented on code in PR #11889:
URL: https://github.com/apache/hudi/pull/11889#discussion_r1757234045
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -79,10 +90,22 @@ public Map<ConfigProperty, String>
downgrade(HoodieWriteConfig config, HoodieEng
}
downgradePartitionFields(config, context, upgradeDowngradeHelper,
tablePropsToAdd);
+
+ // Prepare parameters.
+ if (metaClient.getTableConfig().isMetadataTableAvailable()) {
+ metaClient.reloadActiveTimeline();
Review Comment:
No need to reload active timeline.
##########
hudi-client/hudi-client-common/pom.xml:
##########
@@ -174,7 +174,16 @@
</exclusion>
</exclusions>
</dependency>
-
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-inline</artifactId>
+ <scope>test</scope>
+ </dependency>
Review Comment:
Could you add these dependencies to `hudi-tests-common` only?
##########
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);
Review Comment:
```suggestion
false);
```
##########
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:
Functional index and secondary index uses index definition as the partition
path. Instead of doing exact matches, it's better to check the supported
indexes (`FILES`, `COLUMN_STATS`, `BLOOM_FILTERS`, `RECORD_INDEX`) and delete
other partitions that do not match these.
##########
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:
possible to use `metadataPartitions.stream().map()` to do the deletion and
get `validPartitionPaths` in one shot?
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -20,25 +20,36 @@
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.HoodieTableConfig;
import org.apache.hudi.common.table.HoodieTableMetaClient;
import org.apache.hudi.common.table.timeline.HoodieInstant;
import org.apache.hudi.config.HoodieWriteConfig;
import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.hadoop.fs.HadoopFSUtils;
import org.apache.hudi.keygen.constant.KeyGeneratorOptions;
import org.apache.hudi.keygen.constant.KeyGeneratorType;
+import org.apache.hudi.metadata.HoodieTableMetadataUtil;
+import org.apache.hudi.storage.HoodieStorage;
import org.apache.hudi.storage.StoragePath;
import org.apache.hudi.table.HoodieTable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
Review Comment:
Avoid these
##########
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(
Review Comment:
Use `context.getStorageConf().newInstance()`
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/EightToSevenDowngradeHandler.java:
##########
@@ -79,10 +90,22 @@ public Map<ConfigProperty, String>
downgrade(HoodieWriteConfig config, HoodieEng
}
downgradePartitionFields(config, context, upgradeDowngradeHelper,
tablePropsToAdd);
+
+ // Prepare parameters.
+ if (metaClient.getTableConfig().isMetadataTableAvailable()) {
+ metaClient.reloadActiveTimeline();
+ StoragePath basePath = metaClient.getBasePath();
+ HoodieTableMetaClient mdtMetaClient =
createMetadataTableMetaClient(context, basePath);
+ // Delete unused metadata partitions.
Review Comment:
```suggestion
// Delete unsupported metadata partitions in table version 7.
```
##########
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())
Review Comment:
Avoid using Hadoop's `Path`
```suggestion
.setBasePath(HoodieTableMetadata.getMetadataTableBasePath(basePath).toString())
```
--
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]