Skip to content

Commit d707a04

Browse files
committed
add test for autoUpgrade disabled case
1 parent f1eb504 commit d707a04

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/UpgradeDowngrade.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ public void run(HoodieTableVersion toVersion, String instantTime) {
153153
// if we are attempting to upgrade and auto-upgrade is disabled
154154
// we set the write config table version to bounded by the current hudi table version
155155
// and then exit out the upgrade process
156-
config.setValue(HoodieWriteConfig.WRITE_TABLE_VERSION, String.valueOf(fromVersion));
157-
LOG.warn("AUTO_UPGRADE_VERSION was explicitly disabled. Setting WRITE_TABLE_VERSION to the current hudi table version {} "
158-
+ "and skipping upgrade process", fromVersion);
156+
LOG.warn("AUTO_UPGRADE_VERSION was explicitly disabled, skipping table version upgrade process");
159157
return;
160158
}
161159

hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/table/upgrade/TestUpgradeDowngrade.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,50 @@ public void testUpgradeFourToFiveWithMetadataTableFailure() throws Exception {
460460
"Main table version should remain unchanged when metadata table upgrade fails");
461461
}
462462

463+
@Test
464+
public void testAutoUpgradeDisabledDuringUpgrade() throws Exception {
465+
// Follow same setup of testUpgradeFourToFiveInternal
466+
String tableName = metaClient.getTableConfig().getTableName();
467+
cleanUp();
468+
initSparkContexts();
469+
initPath();
470+
initTestDataGenerator();
471+
472+
Map<String, String> params = new HashMap<>();
473+
addNewTableParamsToProps(params, tableName);
474+
Properties properties = new Properties();
475+
params.forEach((k, v) -> properties.setProperty(k, v));
476+
477+
initMetaClient(getTableType(), properties);
478+
// Create config with auto-upgrade disabled
479+
HoodieWriteConfig cfg = getConfigBuilder()
480+
.withRollbackUsingMarkers(false)
481+
.withWriteTableVersion(6)
482+
.withAutoUpgradeVersion(false) // Disable auto-upgrade
483+
.withProps(params)
484+
.build();
485+
486+
SparkRDDWriteClient client = getHoodieWriteClient(cfg);
487+
// Write inserts to establish table
488+
doInsert(client);
489+
490+
// Downgrade to version 4 first
491+
downgradeTableConfigsFromFiveToFour(cfg);
492+
493+
metaClient = HoodieTableMetaClient.reload(metaClient);
494+
HoodieTableVersion originalVersion = metaClient.getTableConfig().getTableVersion();
495+
assertEquals(HoodieTableVersion.FOUR, originalVersion, "Table should be at version 4 before test");
496+
497+
// Attempt upgrade from version 4 to 5 with auto-upgrade disabled
498+
new UpgradeDowngrade(metaClient, cfg, context, SparkUpgradeDowngradeHelper.getInstance())
499+
.run(HoodieTableVersion.FIVE, null);
500+
501+
// Verify that upgrade was skipped and table version remains unchanged
502+
metaClient = HoodieTableMetaClient.reload(metaClient);
503+
assertEquals(HoodieTableVersion.FOUR, metaClient.getTableConfig().getTableVersion(),
504+
"Table version should remain at 4 when auto-upgrade is disabled");
505+
}
506+
463507
private void testUpgradeFourToFiveInternal(boolean assertDefaultPartition, boolean skipDefaultPartitionValidation, boolean isHiveStyle) throws Exception {
464508
String tableName = metaClient.getTableConfig().getTableName();
465509
// clean up and re instantiate meta client w/ right table props

0 commit comments

Comments
 (0)