rahil-c commented on code in PR #13642:
URL: https://github.com/apache/hudi/pull/13642#discussion_r2257550496
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/upgrade/UpgradeDowngrade.java:
##########
@@ -275,4 +302,54 @@ protected Pair<Map<ConfigProperty, String>,
List<ConfigProperty>> downgrade(Hood
throw new HoodieUpgradeDowngradeException(fromVersion.versionCode(),
toVersion.versionCode(), false);
}
}
+
+ /**
+ * Checks if any handlers in the upgrade/downgrade path require running
rollback and compaction before starting process.
+ *
+ * @param fromVersion the current table version
+ * @param toVersion the target table version
+ */
+ private void performRollbackAndCompactionIfRequired(HoodieTableVersion
fromVersion, HoodieTableVersion toVersion, boolean isUpgrade) {
+ boolean requireRollbackAndCompaction = false;
+ if (isUpgrade) {
+ // Check upgrade handlers
+ HoodieTableVersion checkVersion = fromVersion;
+ while (checkVersion.versionCode() < toVersion.versionCode()) {
+ HoodieTableVersion nextVersion =
HoodieTableVersion.fromVersionCode(checkVersion.versionCode() + 1);
+ if
(UPGRADE_HANDLERS_REQUIRING_ROLLBACK_AND_COMPACT.contains(Pair.of(checkVersion.versionCode(),
nextVersion.versionCode()))) {
+ requireRollbackAndCompaction = true;
+ break;
+ }
+ checkVersion = nextVersion;
+ }
+ } else {
+ // Check downgrade handlers
+ HoodieTableVersion checkVersion = fromVersion;
+ while (checkVersion.versionCode() > toVersion.versionCode()) {
+ HoodieTableVersion prevVersion =
HoodieTableVersion.fromVersionCode(checkVersion.versionCode() - 1);
+ if
(DOWNGRADE_HANDLERS_REQUIRING_ROLLBACK_ANDCOMPACT.contains(Pair.of(checkVersion.versionCode(),
prevVersion.versionCode()))) {
+ requireRollbackAndCompaction = true;
+ break;
+ }
+ checkVersion = prevVersion;
+ }
+ }
+ if (requireRollbackAndCompaction) {
+ LOG.info("Rolling back failed writes and compacting table before
upgrade/downgrade");
+ // For version SEVEN to EIGHT upgrade, use SIX as tableVersion to avoid
hitting issue with WRITE_TABLE_VERSION,
+ // as table version SEVEN is not considered as a valid value due to
being a bridge release.
+ // otherwise use current table version
+ HoodieTableVersion tableVersion = fromVersion == HoodieTableVersion.SEVEN
Review Comment:
This was done to handle this one specific case
https://github.com/apache/hudi/pull/13642/files#diff-730d011a46e0dd54b97c339243409c79e8fe857fdfc8359b92a951a6e9a9ebacL105
--
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]