Skip to content

Commit

Permalink
Sync from server repo (2528d624d26)
Browse files Browse the repository at this point in the history
  • Loading branch information
releng committed Nov 9, 2024
1 parent af0bb42 commit e1c388a
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion vclusterops/stop_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func (vcc VClusterCommands) VStopNode(options *VStopNodeOptions) error {
return err
}

// stop_node should fail if the nodes to stop belong to different sandboxes
targetSandbox, err := checkTargetNodesSandboxes(&vdb, options)
if err != nil {
return err
}

options.completeVDBSetting(&vdb)

// stop_node is aborted if requirements are not met.
Expand All @@ -122,12 +128,44 @@ func (vcc VClusterCommands) VStopNode(options *VStopNodeOptions) error {
}

clusterOpEngine := makeClusterOpEngine(instructions, options)
if runError := clusterOpEngine.run(vcc.Log); runError != nil {
if runError := clusterOpEngine.runInSandbox(vcc.Log, &vdb, targetSandbox); runError != nil {
return fmt.Errorf("fail to complete stop node operation, %w", runError)
}
return nil
}

// checkStopNodeRequirements checks whether the nodes to stop belong to the same sandbox (or main cluster)
func checkTargetNodesSandboxes(vdb *VCoordinationDatabase,
options *VStopNodeOptions) (targetSandbox string, err error) {
sandboxHostMap := make(map[string][]string)
for _, host := range options.StopHosts {
vnode, exists := vdb.HostNodeMap[host]
if !exists {
return "", fmt.Errorf("cannot find host %s in vdb", host)
}

var sandboxDisplayName string
if vnode.Sandbox == util.MainClusterSandbox {
sandboxDisplayName = "main-cluster"
} else {
sandboxDisplayName = vnode.Sandbox
}

if _, exists := sandboxHostMap[sandboxDisplayName]; !exists {
sandboxHostMap[sandboxDisplayName] = []string{host}
} else {
sandboxHostMap[sandboxDisplayName] = append(sandboxHostMap[sandboxDisplayName], host)
}

targetSandbox = vnode.Sandbox
}
if len(sandboxHostMap) > 1 {
return "", fmt.Errorf("the hosts to stop cannot belong to different sandboxes %+v", sandboxHostMap)
}

return targetSandbox, nil
}

// checkStopNodeRequirements returns an error if at least one of the nodes
// to stop does not exist in db.
func checkStopNodeRequirements(vdb *VCoordinationDatabase, hostsToStop []string) error {
Expand Down

0 comments on commit e1c388a

Please sign in to comment.