Skip to content

Commit

Permalink
Sync from server repo (cd029db13dd)
Browse files Browse the repository at this point in the history
  • Loading branch information
releng committed Nov 6, 2024
1 parent 6a227d7 commit 95d733b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
24 changes: 24 additions & 0 deletions vclusterops/cluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ type clusterOp interface {
applyTLSOptions(tlsOptions opTLSOptions) error
isSkipExecute() bool
filterUnreachableHosts(execContext *opEngineExecContext)
filterHostsBySandbox(execContext *opEngineExecContext)
}

/* Cluster ops basic fields and functions
Expand Down Expand Up @@ -475,6 +476,29 @@ func (op *opBase) filterUnreachableHosts(execContext *opEngineExecContext) {
op.hosts = util.SliceDiff(op.hosts, execContext.unreachableHosts)
}

// filterHostsBySandbox selects hosts only in the target sandbox or main cluster
func (op *opBase) filterHostsBySandbox(execContext *opEngineExecContext) {
if execContext.sandbox == util.MainClusterSandbox {
return
}

// If vdb is given as nil or the vdb is obtained,
// we will not filter hosts by sandbox.
// Instead, we will send requests to all hosts.
if execContext.vdbForSandboxInfo == nil {
return
}

// filter out hosts that are not in the target sandbox or main cluster
var hostsNotInSandbox []string
for h, vnode := range execContext.vdbForSandboxInfo.HostNodeMap {
if vnode.Sandbox != execContext.sandbox {
hostsNotInSandbox = append(hostsNotInSandbox, h)
}
}
op.hosts = util.SliceDiff(op.hosts, hostsNotInSandbox)
}

/* Sensitive fields in request body
*/
type sensitiveFields struct {
Expand Down
11 changes: 11 additions & 0 deletions vclusterops/cluster_op_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vclusterops
import (
"fmt"

"github.com/vertica/vcluster/vclusterops/util"
"github.com/vertica/vcluster/vclusterops/vlog"
)

Expand All @@ -35,7 +36,16 @@ func makeClusterOpEngine(instructions []clusterOp, tlsOptions opTLSOptions) VClu
}

func (opEngine *VClusterOpEngine) run(logger vlog.Printer) error {
// when vdb is nil or sandbox is not specified,
// the op engine will not filter any hosts to send requests
return opEngine.runInSandbox(logger, nil /*vdb*/, util.MainClusterSandbox)
}

func (opEngine *VClusterOpEngine) runInSandbox(logger vlog.Printer,
vdb *VCoordinationDatabase, sandbox string) error {
execContext := makeOpEngineExecContext(logger)
execContext.vdbForSandboxInfo = vdb
execContext.sandbox = sandbox
opEngine.execContext = &execContext

return opEngine.runWithExecContext(logger, &execContext)
Expand Down Expand Up @@ -67,6 +77,7 @@ func (opEngine *VClusterOpEngine) runInstruction(
defer op.cleanupSpinner()

op.filterUnreachableHosts(execContext)
op.filterHostsBySandbox(execContext)

op.logPrepare()
err := op.prepare(execContext)
Expand Down
7 changes: 6 additions & 1 deletion vclusterops/cluster_op_engine_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type opEngineExecContext struct {
nodesInfo []NodeInfo
scNodesInfo []NodeInfo // a node list contains all nodes in a subcluster

// This field is specifically used for sandboxing
// this field is specifically used for sandboxing
// as sandboxing requires all nodes in the subcluster to be sandboxed to be UP.
upScInfo map[string]string // map with UP hosts as keys and their subcluster names as values.
upHostsToSandboxes map[string]string // map with UP hosts as keys and their corresponding sandbox names as values.
Expand All @@ -44,6 +44,11 @@ type opEngineExecContext struct {

// hosts that have the VCluster server PID file
HostsWithVclusterServerPid []string

// sandbox on which the op engine will run instruction
sandbox string
// this vdb will only be used to get sandbox info of the nodes
vdbForSandboxInfo *VCoordinationDatabase
}

func makeOpEngineExecContext(logger vlog.Printer) opEngineExecContext {
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/start_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (vcc VClusterCommands) VStartNodes(options *VStartNodesOptions) error {
clusterOpEngine := makeClusterOpEngine(instructions, options)

// Give the instructions to the VClusterOpEngine to run
err = clusterOpEngine.run(vcc.Log)
err = clusterOpEngine.runInSandbox(vcc.Log, &vdb, startNodeInfo.Sandbox)
if err != nil {
return fmt.Errorf("fail to start node, %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/stop_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (vcc VClusterCommands) VStopDatabase(options *VStopDatabaseOptions) error {
clusterOpEngine := makeClusterOpEngine(instructions, options)

// Give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
runError := clusterOpEngine.runInSandbox(vcc.GetLog(), &vdb, options.SandboxName)
if runError != nil {
return fmt.Errorf("fail to stop database: %w", runError)
}
Expand Down

0 comments on commit 95d733b

Please sign in to comment.