Skip to content

Commit

Permalink
[PLAT-10705] Enhance universe lock to have two phases - lock only and…
Browse files Browse the repository at this point in the history
… freeze

Summary:
Add a lock flavor to first lock without tying the universe to the task and make an explicit call to freeze. The freezing can be done via a subtask if some validations are run in subtasks.
The correct task UUID and type (parent or user task) must be set even if it is called from a subtask.

No API change except a task type addition.

Test Plan:
Create universe followed by software upgrade where the change is present.

  "updatingTask": "SoftwareUpgrade",
  "updatingTaskUUID": "bbfe9ed3-7779-4eef-b736-6126085d5ea9",

Itest should catch the rest.

Reviewers: yshchetinin, cwang, hzare, sanketh

Reviewed By: cwang

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D29111
  • Loading branch information
nkhogen committed Oct 12, 2023
1 parent 0467a72 commit 66b1a52
Show file tree
Hide file tree
Showing 20 changed files with 423 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.Builder;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -81,17 +82,38 @@ protected UpgradeTaskParams taskParams() {
// State set on node while it is being upgraded
public abstract NodeState getNodeState();

// Wrapper that takes care of common pre and post upgrade tasks and user has
// flexibility to manipulate subTaskGroupQueue through the lambda passed in parameter
/** Similar to {@link #runUpgrade(Consumer, Consumer, Runnable)} without the other params. */
public void runUpgrade(Runnable upgradeLambda) {
runUpgrade(null, null, upgradeLambda);
}

/**
* Wrapper that takes care of common pre and post upgrade tasks and user has the flexibility to
* manipulate subTaskGroupQueue through the lambdas passed as parameters.
*
* @param validationLambda the callback for validations which can be run as subtasks.
* @param freezeCallback the callback to be executed in transaction when the universe is frozen.
* Any DB change can be added here.
* @param upgradeLambda the actual upgrade callback.
*/
public void runUpgrade(
@Nullable Consumer<Universe> validationLambda,
@Nullable Consumer<Universe> freezeLambda,
Runnable upgradeLambda) {
try {
checkUniverseVersion();
// Update the universe DB with the update to be performed and set the
// 'updateInProgress' flag to prevent other updates from happening.
lockUniverseForUpdate(taskParams().expectedUniverseVersion);
Universe universe = lockUniverseForFreezeAndUpdate(taskParams().expectedUniverseVersion);

if (validationLambda != null) {
validationLambda.accept(universe);
}
Set<NodeDetails> nodeList = fetchAllNodes(taskParams().upgradeOption);

createFreezeUniverseTask(freezeLambda)
.setSubTaskGroupType(SubTaskGroupType.ValidateConfigurations);

// Run the pre-upgrade hooks
createHookTriggerTasks(nodeList, true, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,10 @@ public enum SubTaskGroupType {
InstallingThirdPartySoftware,

// Promote Auto Flags
PromoteAutoFlags
PromoteAutoFlags,

// Validate configurations.
ValidateConfigurations
}

public List<SubTaskDetails> taskDetails;
Expand Down Expand Up @@ -545,6 +548,10 @@ public static SubTaskDetails createSubTask(SubTaskGroupType subTaskGroupType) {
title = "Promote Auto flags";
description = "Promote Auto flags for a universe";
break;
case ValidateConfigurations:
title = "Validating configurations";
description = "Validating configurations before proceeding";
break;
default:
LOG.warn("UserTaskDetails: Missing SubTaskDetails for : {}", subTaskGroupType);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public void run() {
// to prevent other updates from happening.
Universe universe;
if (params().isForceDelete) {
universe = forceLockUniverseForUpdate(-1, true);
universe = forceLockUniverseForUpdate(-1);
} else {
universe = lockUniverseForUpdate(-1, true);
universe = lockUniverseForUpdate(-1);
}

// Delete xCluster configs involving this universe and put the locked universes to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void run() {
try {
// Update the universe DB with the update to be performed and set the 'updateInProgress' flag
// to prevent other updates from happening.
Universe universe = lockUniverseForUpdate(-1 /* expectedUniverseVersion */, true);
Universe universe = lockUniverseForUpdate(-1 /* expectedUniverseVersion */);
UniverseDefinitionTaskParams universeDetails = universe.getUniverseDetails();
Collection<NodeDetails> nodes = universe.getNodes();

Expand Down
Loading

0 comments on commit 66b1a52

Please sign in to comment.