Skip to content

Commit

Permalink
[PLAT-13024] Restore YBC doesn't honour new DB version checks
Browse files Browse the repository at this point in the history
Summary:
Restore YBC flow currently has preflight checks for:
1. DB version comparison
2. Autoflags check

This diff modifies yugabyte#1 to check for version numbers greater (compare stable to stable, preview to preview, other combinations result in error).
Autoflags check remains the same.

Test Plan:
Manually test all existing flows work as usual.
Run UTs.
Run itests.

Reviewers: sanketh, vbansal

Reviewed By: vbansal

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D32944
  • Loading branch information
Sahith02 authored and asrinivasanyb committed Mar 18, 2024
1 parent 1b2e4ac commit e67e74e
Showing 1 changed file with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.yugabyte.yw.common.backuprestore.ybc.YbcBackupUtil;
import com.yugabyte.yw.common.backuprestore.ybc.YbcBackupUtil.YbcBackupResponse;
import com.yugabyte.yw.common.backuprestore.ybc.YbcManager;
import com.yugabyte.yw.common.config.GlobalConfKeys;
import com.yugabyte.yw.common.config.UniverseConfKeys;
import com.yugabyte.yw.common.services.YbcClientService;
import com.yugabyte.yw.common.utils.Pair;
Expand Down Expand Up @@ -268,32 +269,53 @@ private void validateBackupMetadata(Universe universe) {
if (backupConfig == null) {
return;
}
// Restore universe DB version should be greater or equal to the backup universe DB current
// version or
// version to which it can rollback.
if (backupConfig.ybdbVersion != null
&& Util.compareYbVersions(
restoreUniverseDBVersion, backupConfig.ybdbVersion, true /*suppressFormatError*/)
< 0) {
if (backupConfig.rollbackYbdbVersion == null) {
throw new PlatformServiceException(
BAD_REQUEST, "Unable to restore backup as it was taken on higher DB version.");
// Skip all DB version checks if the runtime flag "yb.skip_version_checks" is true. User must
// take care of downgrades and restores.
if (!confGetter.getGlobalConf(GlobalConfKeys.skipVersionChecks)) {
// Do the following DB version checks only if both the source universe version or target
// universe version are part of stable or preview. Restoring a backup can now only happen
// from stable to stable and preview to preview.
boolean isPreviousVersionStable = Util.isStableVersion(backupConfig.ybdbVersion, false);
boolean isCurrentVersionStable = Util.isStableVersion(restoreUniverseDBVersion, false);
// Skip version checks if runtime flag enabled. User must take care of downgrades
if (isPreviousVersionStable ^ isCurrentVersionStable) {
String msg =
String.format(
"Cannot restore backup from preview to stable version or stable to preview. If"
+ " required, set runtime flag 'yb.skip_version_checks' to true. Tried to"
+ " restore a backup from '%s' to '%s'.",
backupConfig.ybdbVersion, restoreUniverseDBVersion);
throw new PlatformServiceException(BAD_REQUEST, msg);
}
if (backupConfig.rollbackYbdbVersion != null
// Restore universe DB version should be greater or equal to the backup universe DB
// current
// version or version to which it can rollback.
if (backupConfig.ybdbVersion != null
&& Util.compareYbVersions(
restoreUniverseDBVersion,
backupConfig.rollbackYbdbVersion,
backupConfig.ybdbVersion,
true /*suppressFormatError*/)
< 0) {
throw new PlatformServiceException(
BAD_REQUEST,
String.format(
"Unable to restore as the current universe is at an older DB version %s but the"
+ " backup was taken on a universe with DB version %s that can rollback only"
+ " to %s",
restoreUniverseDBVersion,
backupConfig.ybdbVersion,
backupConfig.rollbackYbdbVersion));
if (backupConfig.rollbackYbdbVersion == null) {
throw new PlatformServiceException(
BAD_REQUEST, "Unable to restore backup as it was taken on higher DB version.");
}
if (backupConfig.rollbackYbdbVersion != null
&& Util.compareYbVersions(
restoreUniverseDBVersion,
backupConfig.rollbackYbdbVersion,
true /*suppressFormatError*/)
< 0) {
throw new PlatformServiceException(
BAD_REQUEST,
String.format(
"Unable to restore as the current universe is at an older DB version %s but"
+ " the backup was taken on a universe with DB version %s that can"
+ " rollback only to %s",
restoreUniverseDBVersion,
backupConfig.ybdbVersion,
backupConfig.rollbackYbdbVersion));
}
}
}
// Validate that all master and tserver auto flags present during backup
Expand Down

0 comments on commit e67e74e

Please sign in to comment.