Skip to content

Commit

Permalink
[PLAT-16832]: Set Flag ysql_yb_major_version_upgrade_compatibility on…
Browse files Browse the repository at this point in the history
…ly when upgrade/rollback is in-progress

Summary:
As per this thread: https://yugabyte.slack.com/archives/C07DG9B7C3T/p1740011485617489
Earlier, YBA used to set the flag with value right from the start of the upgrade until the upgrade is rolled back or finalized. The flag also needs to be set even during the monitoring phase on all existing and new nodes.
But now YBA is only supposed to set the flag when upgrade/rollback is in progress. So, YBA will set this flag at the start of upgrade/rollback and unset it at the end of upgrade/rollback. There is no need to configure this flag during the finalize upgrade process.

Test Plan:
Tested manually by performing an upgrade/rollback on both VM and K8s universes and verified from the logs and gflags server.conf file that flag was set while upgrade/rollback was in progress and unset after the task is completed.
Verified that the flag is unset when the univ is in the monitoring phase, and any new node added in this phase also has the flag unset, unlike earlier.

Reviewers: sanketh, anijhawan, sneelakantan

Reviewed By: sanketh

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D42164
  • Loading branch information
vipul-yb committed Mar 3, 2025
1 parent 0046ce7 commit edcaee5
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.yugabyte.yw.commissioner.tasks.subtasks.KubernetesCommandExecutor.CommandType;
import com.yugabyte.yw.common.KubernetesManagerFactory;
import com.yugabyte.yw.common.KubernetesUtil;
import com.yugabyte.yw.common.config.UniverseConfKeys;
import com.yugabyte.yw.common.gflags.GFlagsUtil;
import com.yugabyte.yw.common.operator.OperatorStatusUpdater;
import com.yugabyte.yw.common.operator.OperatorStatusUpdater.UniverseState;
Expand Down Expand Up @@ -676,39 +675,7 @@ protected void createSoftwareUpgradePrecheckTasks(
}
}

protected void createFinalizeUpgradeTasks(
boolean upgradeSystemCatalog,
boolean finalizeCatalogUpgrade,
boolean requireAdditionalSuperUserForCatalogUpgrade) {
Universe universe = getUniverse();

createUpdateUniverseSoftwareUpgradeStateTask(
UniverseDefinitionTaskParams.SoftwareUpgradeState.Finalizing,
false /* isSoftwareRollbackAllowed */,
true /* retainPrevYBSoftwareConfig */);

if (!confGetter.getConfForScope(universe, UniverseConfKeys.skipUpgradeFinalize)) {

createCommonFinalizeUpgradeTasks(
upgradeSystemCatalog,
finalizeCatalogUpgrade,
requireAdditionalSuperUserForCatalogUpgrade);
if (finalizeCatalogUpgrade) {
createGFlagsUpgradeAndRollbackMastersTaskForYSQLMajorUpgrade(
universe,
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion,
YsqlMajorVersionUpgradeState.FINALIZE_IN_PROGRESS);
}
} else {
log.info("Skipping upgrade finalization for universe : " + universe.getUniverseUUID());
}

createUpdateUniverseSoftwareUpgradeStateTask(
UniverseDefinitionTaskParams.SoftwareUpgradeState.Ready,
false /* isSoftwareRollbackAllowed */);
}

protected void createGFlagsUpgradeAndRollbackMastersTaskForYSQLMajorUpgrade(
protected void createGFlagsUpgradeAndUpdateMastersTaskForYSQLMajorUpgrade(
Universe universe,
String softwareVersion,
YsqlMajorVersionUpgradeState ysqlMajorVersionUpgradeState) {
Expand All @@ -717,11 +684,11 @@ protected void createGFlagsUpgradeAndRollbackMastersTaskForYSQLMajorUpgrade(
universe.getTServers(),
UpgradeDetails.getMajorUpgradeCompatibilityFlagValue(ysqlMajorVersionUpgradeState));

createServerConfUpdateTaskAndRollbackMasterForYsqlMajorUpgrade(
createServerConfUpdateTaskAndUpdateMasterForYsqlMajorUpgrade(
universe, universe.getTServers(), softwareVersion, ysqlMajorVersionUpgradeState);
}

private void createServerConfUpdateTaskAndRollbackMasterForYsqlMajorUpgrade(
private void createServerConfUpdateTaskAndUpdateMasterForYsqlMajorUpgrade(
Universe universe,
List<NodeDetails> nodes,
String softwareVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1859,8 +1859,6 @@ public KubernetesCommandExecutor createKubernetesExecutorTaskForServerType(
}
if (ysqlMajorVersionUpgradeState != null) {
params.ysqlMajorVersionUpgradeState = ysqlMajorVersionUpgradeState;
} else if (isYsqlMajorUpgradeStateInPreFinalizeState(universe, gFlagsValidation)) {
params.ysqlMajorVersionUpgradeState = YsqlMajorVersionUpgradeState.PRE_FINALIZE;
}
params.masterPartition = masterPartition;
params.tserverPartition = tserverPartition;
Expand Down Expand Up @@ -2203,8 +2201,6 @@ public KubernetesCommandExecutor getSingleKubernetesExecutorTaskForServerTypeTas
}
if (ysqlMajorVersionUpgradeState != null) {
params.ysqlMajorVersionUpgradeState = ysqlMajorVersionUpgradeState;
} else if (isYsqlMajorUpgradeStateInPreFinalizeState(universe, gFlagsValidation)) {
params.ysqlMajorVersionUpgradeState = YsqlMajorVersionUpgradeState.PRE_FINALIZE;
}
params.masterPartition = masterPartition;
params.tserverPartition = tserverPartition;
Expand Down Expand Up @@ -2291,8 +2287,6 @@ public KubernetesCommandExecutor getSingleNonRollingKubernetesExecutorTaskForSer
}
if (ysqlMajorVersionUpgradeState != null) {
params.ysqlMajorVersionUpgradeState = ysqlMajorVersionUpgradeState;
} else if (isYsqlMajorUpgradeStateInPreFinalizeState(universe, gFlagsValidation)) {
params.ysqlMajorVersionUpgradeState = YsqlMajorVersionUpgradeState.PRE_FINALIZE;
}
params.enableNodeToNodeEncrypt = primaryCluster.userIntent.enableNodeToNodeEncrypt;
params.enableClientToNodeEncrypt = primaryCluster.userIntent.enableClientToNodeEncrypt;
Expand Down Expand Up @@ -2366,8 +2360,6 @@ public KubernetesCommandExecutor getSingleNonRestartKubernetesExecutorTaskForSer
}
if (ysqlMajorVersionUpgradeState != null) {
params.ysqlMajorVersionUpgradeState = ysqlMajorVersionUpgradeState;
} else if (isYsqlMajorUpgradeStateInPreFinalizeState(universe, gFlagsValidation)) {
params.ysqlMajorVersionUpgradeState = YsqlMajorVersionUpgradeState.PRE_FINALIZE;
}
params.enableNodeToNodeEncrypt = primaryCluster.userIntent.enableNodeToNodeEncrypt;
params.enableClientToNodeEncrypt = primaryCluster.userIntent.enableClientToNodeEncrypt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2933,14 +2933,6 @@ public void createSoftwareInstallTasks(

public void createYbcSoftwareInstallTasks(
List<NodeDetails> nodes, String softwareVersion, SubTaskGroupType subTaskGroupType) {
createYbcSoftwareInstallTasks(nodes, softwareVersion, subTaskGroupType, null);
}

public void createYbcSoftwareInstallTasks(
List<NodeDetails> nodes,
String softwareVersion,
SubTaskGroupType subTaskGroupType,
YsqlMajorVersionUpgradeState ysqlMajorVersionUpgradeState) {

// If the node list is empty, we don't need to do anything.
if (nodes.isEmpty()) {
Expand All @@ -2962,8 +2954,7 @@ public void createYbcSoftwareInstallTasks(
ServerType.CONTROLLER,
UpgradeTaskSubType.YbcInstall,
softwareVersion,
stableYbcVersion,
ysqlMajorVersionUpgradeState));
stableYbcVersion));
}
subTaskGroup.setSubTaskGroupType(subTaskGroupType);
getRunnableTask().addSubTaskGroup(subTaskGroup);
Expand Down Expand Up @@ -3842,32 +3833,45 @@ public void createResumeUniverseTasks(Universe universe, UUID customerUUID) {
});
}

protected void createCommonFinalizeUpgradeTasks(
protected void createFinalizeUpgradeTasks(
boolean upgradeSystemCatalog,
boolean finalizeCatalogUpgrade,
boolean requireAdditionalSuperUserForCatalogUpgrade) {
Universe universe = getUniverse();
String version = universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion;

if (finalizeCatalogUpgrade) {
createFinalizeYsqlMajorCatalogUpgradeTask();
}
createUpdateUniverseSoftwareUpgradeStateTask(
UniverseDefinitionTaskParams.SoftwareUpgradeState.Finalizing,
false /* isSoftwareRollbackAllowed */,
true /* retainPrevYBSoftwareConfig */);

// Promote all auto flags upto class External.
createPromoteAutoFlagTask(
universe.getUniverseUUID(),
true /* ignoreErrors */,
AutoFlagUtil.EXTERNAL_AUTO_FLAG_CLASS_NAME /* maxClass */);
if (!confGetter.getConfForScope(universe, UniverseConfKeys.skipUpgradeFinalize)) {
if (finalizeCatalogUpgrade) {
createFinalizeYsqlMajorCatalogUpgradeTask();
}
// Promote all auto flags upto class External.
createPromoteAutoFlagTask(
universe.getUniverseUUID(),
true /* ignoreErrors */,
AutoFlagUtil.EXTERNAL_AUTO_FLAG_CLASS_NAME /* maxClass */);

if (upgradeSystemCatalog) {
// Run YSQL upgrade on the universe.
String version =
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion;
createRunYsqlUpgradeTask(version);
}

if (upgradeSystemCatalog) {
// Run YSQL upgrade on the universe.
createRunYsqlUpgradeTask(version);
if (requireAdditionalSuperUserForCatalogUpgrade) {
// Delete the superuser created for catalog upgrade.
createManageCatalogUpgradeSuperUserTask(Action.DELETE_USER);
}
} else {
log.info("Skipping upgrade finalization for universe : " + universe.getUniverseUUID());
}

if (requireAdditionalSuperUserForCatalogUpgrade) {
// Delete the superuser created for catalog upgrade.
createManageCatalogUpgradeSuperUserTask(Action.DELETE_USER);
}
createUpdateUniverseSoftwareUpgradeStateTask(
UniverseDefinitionTaskParams.SoftwareUpgradeState.Ready,
false /* isSoftwareRollbackAllowed */);
}

protected void createSetYBMajorVersionUpgradeCompatibility(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@
import com.yugabyte.yw.common.config.UniverseConfKeys;
import com.yugabyte.yw.common.gflags.AutoFlagUtil;
import com.yugabyte.yw.common.gflags.GFlagsUtil;
import com.yugabyte.yw.common.gflags.GFlagsValidation;
import com.yugabyte.yw.common.gflags.SpecificGFlags;
import com.yugabyte.yw.common.nodeui.DumpEntitiesResponse;
import com.yugabyte.yw.forms.BackupRequestParams;
Expand Down Expand Up @@ -244,7 +243,6 @@
import com.yugabyte.yw.models.helpers.PlacementInfo;
import com.yugabyte.yw.models.helpers.TableDetails;
import com.yugabyte.yw.models.helpers.TaskType;
import com.yugabyte.yw.models.helpers.UpgradeDetails.YsqlMajorVersionUpgradeState;
import io.ebean.Model;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -1361,10 +1359,6 @@ public AnsibleConfigureServers.Params getBaseAnsibleServerTaskParams(
// The software package to install for this cluster.
params.ybSoftwareVersion = userIntent.ybSoftwareVersion;

if (isYsqlMajorUpgradeStateInPreFinalizeState(universe, gFlagsValidation)) {
params.ysqlMajorVersionUpgradeState = YsqlMajorVersionUpgradeState.PRE_FINALIZE;
}

params.instanceType = node.cloudInfo.instance_type;
params.enableNodeToNodeEncrypt = userIntent.enableNodeToNodeEncrypt;
params.enableClientToNodeEncrypt = userIntent.enableClientToNodeEncrypt;
Expand All @@ -1388,18 +1382,6 @@ public AnsibleConfigureServers.Params getBaseAnsibleServerTaskParams(
return params;
}

public static boolean isYsqlMajorUpgradeStateInPreFinalizeState(
Universe universe, GFlagsValidation gFlagsValidation) {
if (universe.getUniverseDetails().softwareUpgradeState.equals(SoftwareUpgradeState.PreFinalize)
|| universe.getUniverseDetails().prevYBSoftwareConfig != null) {
String currentVersion =
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion;
String oldVersion = universe.getUniverseDetails().prevYBSoftwareConfig.getSoftwareVersion();
return gFlagsValidation.ysqlMajorVersionUpgrade(oldVersion, currentVersion);
}
return false;
}

/** Create a task to mark the change on a universe as success. */
public SubTaskGroup createMarkUniverseUpdateSuccessTasks() {
return createMarkUniverseUpdateSuccessTasks(taskParams().getUniverseUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ private String generateHelmOverride() {
GFlagsUtil.YSQL_PG_CONF_CSV,
GFlagsUtil.mergeCSVs(
tserverGFlags.getOrDefault(GFlagsUtil.YSQL_PG_CONF_CSV, ""),
GFlagsUtil.getYsqlPgConfCsv(auditLogConfig, null),
GFlagsUtil.getYsqlPgConfCsv(auditLogConfig),
true));
overrides.put(
"otelCollector",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ public void run() {
String userProvidedYsqlPgConfCsv = gflags.getOrDefault(GFlagsUtil.YSQL_PG_CONF_CSV, "");
String auditLogYsqlPgConfCsv =
GFlagsUtil.getYsqlPgConfCsv(
universe.getUniverseDetails().getPrimaryCluster().userIntent.getAuditLogConfig(),
null);
universe.getUniverseDetails().getPrimaryCluster().userIntent.getAuditLogConfig());
String finalYsqlPgConfCsv =
GFlagsUtil.mergeCSVs(userProvidedYsqlPgConfCsv, auditLogYsqlPgConfCsv, true);
if (StringUtils.isNotBlank(finalYsqlPgConfCsv)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ public void run() {
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion;
boolean ysqlMajorVersionUpgrade = false;
boolean requireAdditionalSuperUserForCatalogUpgrade = false;

String currentVersion =
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion;
if (prevYBSoftwareConfig != null) {
targetVersion = prevYBSoftwareConfig.getSoftwareVersion();
String currentVersion =
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion;
if (!StringUtils.isEmpty(prevYBSoftwareConfig.getTargetUpgradeSoftwareVersion())) {
currentVersion = prevYBSoftwareConfig.getTargetUpgradeSoftwareVersion();
}
Expand All @@ -101,6 +100,13 @@ public void run() {
createRollbackAutoFlagTask(taskParams().getUniverseUUID(), autoFlagConfigVersion);
}

if (ysqlMajorVersionUpgrade) {
// Set the flag ysql_yb_major_version_upgrade_compatibility as major version upgrade is
// rolled back.
createGFlagsUpgradeAndUpdateMastersTaskForYSQLMajorUpgrade(
universe, currentVersion, YsqlMajorVersionUpgradeState.ROLLBACK_IN_PROGRESS);
}

// Create Kubernetes Upgrade Task
createUpgradeTask(
getUniverse(),
Expand Down Expand Up @@ -138,10 +144,8 @@ public void run() {
// Un-set the flag ysql_yb_major_version_upgrade_compatibility as major version upgrade
// is
// rolled back.
createGFlagsUpgradeAndRollbackMastersTaskForYSQLMajorUpgrade(
universe,
getTargetSoftwareVersion(),
YsqlMajorVersionUpgradeState.ROLLBACK_COMPLETE);
createGFlagsUpgradeAndUpdateMastersTaskForYSQLMajorUpgrade(
universe, targetVersion, YsqlMajorVersionUpgradeState.ROLLBACK_COMPLETE);

createCleanUpPGUpgradeDataDirTask();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ public void run() {
// version.
createDownloadTasks(toOrderedSet(nodes.asPair()), oldVersion);

if (ysqlMajorVersionUpgrade) {
// Set ysql_yb_major_version_upgrade_compatibility to `11` for tservers during ysql
// upgrade rollback.
createGFlagsUpgradeTaskForYSQLMajorUpgrade(
universe, YsqlMajorVersionUpgradeState.ROLLBACK_IN_PROGRESS);
}

if (nodes.tserversList.size() > 0) {
createTServerUpgradeFlowTasks(
universe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void run() {
// want to revert masters to the previous version and proceed with the ysql major
// upgrade.
if (!catalogUpgradeCompleted) {
createGFlagsUpgradeAndRollbackMastersTaskForYSQLMajorUpgrade(
createGFlagsUpgradeAndUpdateMastersTaskForYSQLMajorUpgrade(
universe, currentVersion, YsqlMajorVersionUpgradeState.IN_PROGRESS);

if (requireAdditionalSuperUserForCatalogUpgrade) {
Expand Down Expand Up @@ -175,6 +175,13 @@ public void run() {
newVersion,
ysqlMajorVersionUpgrade ? YsqlMajorVersionUpgradeState.IN_PROGRESS : null));

if (ysqlMajorVersionUpgrade) {
createGFlagsUpgradeAndUpdateMastersTaskForYSQLMajorUpgrade(
universe,
taskParams().ybSoftwareVersion,
YsqlMajorVersionUpgradeState.UPGRADE_COMPLETE);
}

createPromoteAutoFlagTask(
taskParams().getUniverseUUID(),
true /* ignoreErrors*/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,6 @@ protected void createTServerUpgradeFlowTasks(

protected void createYbcInstallTask(
Universe universe, List<NodeDetails> nodes, String newVersion) {
createYbcInstallTask(universe, nodes, newVersion, null /* ysqlMajorVersionUpgradeState */);
}

protected void createYbcInstallTask(
Universe universe,
List<NodeDetails> nodes,
String newVersion,
YsqlMajorVersionUpgradeState ysqlMajorVersionUpgradeState) {
createYbcSoftwareInstallTasks(nodes, newVersion, getTaskSubGroupType());
// Start yb-controller process and wait for it to get responsive.
createStartYbcProcessTasks(
Expand Down Expand Up @@ -457,37 +449,6 @@ private boolean isDBVersionSameOnNode(
return false;
}

protected void createFinalizeUpgradeTasks(
boolean upgradeSystemCatalog,
boolean finalizeCatalogUpgrade,
boolean requireAdditionalSuperUserForCatalogUpgrade) {
Universe universe = getUniverse();

createUpdateUniverseSoftwareUpgradeStateTask(
UniverseDefinitionTaskParams.SoftwareUpgradeState.Finalizing,
false /* isSoftwareRollbackAllowed */,
true /* retainPrevYBSoftwareConfig */);

if (!confGetter.getConfForScope(universe, UniverseConfKeys.skipUpgradeFinalize)) {

createCommonFinalizeUpgradeTasks(
upgradeSystemCatalog,
finalizeCatalogUpgrade,
requireAdditionalSuperUserForCatalogUpgrade);

if (finalizeCatalogUpgrade) {
createGFlagsUpgradeTaskForYSQLMajorUpgrade(
universe, YsqlMajorVersionUpgradeState.FINALIZE_IN_PROGRESS);
}
} else {
log.info("Skipping upgrade finalization for universe : " + universe.getUniverseUUID());
}

createUpdateUniverseSoftwareUpgradeStateTask(
UniverseDefinitionTaskParams.SoftwareUpgradeState.Ready,
false /* isSoftwareRollbackAllowed */);
}

protected void createGFlagsUpgradeTaskForYSQLMajorUpgrade(
Universe universe, YsqlMajorVersionUpgradeState ysqlMajorVersionUpgradeState) {
// Set the flag in memory for all the nodes.
Expand Down
Loading

0 comments on commit edcaee5

Please sign in to comment.