Skip to content

Commit

Permalink
Sync from server repo (4a793107f3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Oct 16, 2023
1 parent 491554f commit 0487bd6
Show file tree
Hide file tree
Showing 52 changed files with 335 additions and 292 deletions.
53 changes: 25 additions & 28 deletions vclusterops/add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strings"

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

// VAddNodeOptions are the option arguments for the VAddNode API
Expand Down Expand Up @@ -142,7 +141,7 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa
return vdb, err
}

err = getVDBFromRunningDB(&vdb, &options.DatabaseOptions)
err = vcc.getVDBFromRunningDB(&vdb, &options.DatabaseOptions)
if err != nil {
return vdb, err
}
Expand All @@ -167,7 +166,7 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa

// trim stale node information from catalog
// if NodeNames is provided
err = trimNodesInCatalog(&vdb, options)
err = vcc.trimNodesInCatalog(&vdb, options)
if err != nil {
return vdb, err
}
Expand All @@ -186,15 +185,13 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa

instructions, err := vcc.produceAddNodeInstructions(&vdb, options)
if err != nil {
vlog.LogPrintError("fail to produce add node instructions, %s", err)
return vdb, err
return vdb, fmt.Errorf("fail to produce add node instructions, %w", err)
}

certs := HTTPSCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := MakeClusterOpEngine(instructions, &certs)
if runError := clusterOpEngine.Run(); runError != nil {
vlog.LogPrintError("fail to complete add node operation, %s", runError)
return vdb, runError
return vdb, fmt.Errorf("fail to complete add node operation, %w", runError)
}
return vdb, nil
}
Expand Down Expand Up @@ -234,10 +231,10 @@ func (o *VAddNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) error {

// trimNodesInCatalog removes failed node info from catalog
// which can be used to remove partially added nodes
func trimNodesInCatalog(vdb *VCoordinationDatabase,
func (vcc *VClusterCommands) trimNodesInCatalog(vdb *VCoordinationDatabase,
options *VAddNodeOptions) error {
if len(options.ExpectedNodeNames) == 0 {
vlog.LogInfoln("ExpectedNodeNames is not set, skip trimming nodes")
vcc.Log.Info("ExpectedNodeNames is not set, skip trimming nodes", "ExpectedNodeNames", options.ExpectedNodeNames)
return nil
}

Expand Down Expand Up @@ -272,7 +269,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase,
invalidNodeNames, vdb.Name)
}

vlog.LogPrintInfo("Trim nodes %+v from catalog", nodesToTrim)
vcc.Log.PrintInfo("Trim nodes %+v from catalog", nodesToTrim)

// pick any up host as intiator
initiator := aliveHosts[:1]
Expand All @@ -281,7 +278,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase,

// mark k-safety
if len(aliveHosts) < ksafetyThreshold {
httpsMarkDesignKSafeOp, err := makeHTTPSMarkDesignKSafeOp(initiator,
httpsMarkDesignKSafeOp, err := makeHTTPSMarkDesignKSafeOp(vcc.Log, initiator,
options.usePassword, *options.UserName, options.Password,
ksafeValueZero)
if err != nil {
Expand All @@ -292,7 +289,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase,

// remove down nodes from catalog
for _, nodeName := range nodesToTrim {
httpsDropNodeOp, err := makeHTTPSDropNodeOp(nodeName, initiator,
httpsDropNodeOp, err := makeHTTPSDropNodeOp(vcc.Log, nodeName, initiator,
options.usePassword, *options.UserName, options.Password, vdb.IsEon)
if err != nil {
return err
Expand All @@ -304,7 +301,7 @@ func trimNodesInCatalog(vdb *VCoordinationDatabase,
clusterOpEngine := MakeClusterOpEngine(instructions, &certs)
err := clusterOpEngine.Run()
if err != nil {
vlog.LogPrintError("fail to trim nodes from catalog, %v", err)
vcc.Log.Error(err, "fail to trim nodes from catalog, %v")
return err
}

Expand Down Expand Up @@ -344,7 +341,7 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba
usePassword := options.usePassword
password := options.Password

nmaHealthOp := makeNMAHealthOp(vdb.HostList)
nmaHealthOp := makeNMAHealthOp(vcc.Log, vdb.HostList)
// require to have the same vertica version
nmaVerticaVersionOp := makeNMAVerticaVersionOp(vcc.Log, vdb.HostList, true)
instructions = append(instructions,
Expand All @@ -353,7 +350,7 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba

if vdb.IsEon {
httpsFindSubclusterOp, e := makeHTTPSFindSubclusterOp(
allHosts, usePassword, username, password, *options.SCName,
vcc.Log, allHosts, usePassword, username, password, *options.SCName,
true /*ignore not found*/)
if e != nil {
return instructions, e
Expand All @@ -364,22 +361,22 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba
// this is a copy of the original HostNodeMap that only
// contains the hosts to add.
newHostNodeMap := vdb.copyHostNodeMap(options.NewHosts)
nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(newHostNodeMap,
nmaPrepareDirectoriesOp, err := makeNMAPrepareDirectoriesOp(vcc.Log, newHostNodeMap,
*options.ForceRemoval /*force cleanup*/, false /*for db revive*/)
if err != nil {
return instructions, err
}
nmaNetworkProfileOp := makeNMANetworkProfileOp(vdb.HostList)
httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(newHosts, initiatorHost,
nmaNetworkProfileOp := makeNMANetworkProfileOp(vcc.Log, vdb.HostList)
httpsCreateNodeOp, err := makeHTTPSCreateNodeOp(vcc.Log, newHosts, initiatorHost,
usePassword, username, password, vdb, *options.SCName)
if err != nil {
return instructions, err
}
httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(initiatorHost, usePassword, username, password)
httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(vcc.Log, initiatorHost, usePassword, username, password)
if err != nil {
return instructions, err
}
httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandOp(usePassword, username, password, vdb)
httpsRestartUpCommandOp, err := makeHTTPSStartUpCommandOp(vcc.Log, usePassword, username, password, vdb)
if err != nil {
return instructions, err
}
Expand All @@ -392,13 +389,13 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba
)

// we will remove the nil parameters in VER-88401 by adding them in execContext
produceTransferConfigOps(&instructions,
produceTransferConfigOps(vcc.Log, &instructions,
nil,
vdb.HostList,
vdb /*db configurations retrieved from a running db*/)

nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(newHosts, vdb)
httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(newHosts, usePassword, username, password)
nmaStartNewNodesOp := makeNMAStartNodeOpWithVDB(vcc.Log, newHosts, vdb)
httpsPollNodeStateOp, err := makeHTTPSPollNodeStateOp(vcc.Log, newHosts, usePassword, username, password)
if err != nil {
return instructions, err
}
Expand All @@ -407,17 +404,17 @@ func (vcc *VClusterCommands) produceAddNodeInstructions(vdb *VCoordinationDataba
&httpsPollNodeStateOp,
)

return prepareAdditionalEonInstructions(vdb, options, instructions,
return vcc.prepareAdditionalEonInstructions(vdb, options, instructions,
username, usePassword, initiatorHost, newHosts)
}

func prepareAdditionalEonInstructions(vdb *VCoordinationDatabase,
func (vcc *VClusterCommands) prepareAdditionalEonInstructions(vdb *VCoordinationDatabase,
options *VAddNodeOptions,
instructions []ClusterOp,
username string, usePassword bool,
initiatorHost, newHosts []string) ([]ClusterOp, error) {
if vdb.UseDepot {
httpsCreateNodesDepotOp, err := makeHTTPSCreateNodesDepotOp(vdb,
httpsCreateNodesDepotOp, err := makeHTTPSCreateNodesDepotOp(vcc.Log, vdb,
newHosts, usePassword, username, options.Password)
if err != nil {
return instructions, err
Expand All @@ -426,14 +423,14 @@ func prepareAdditionalEonInstructions(vdb *VCoordinationDatabase,
}

if vdb.IsEon {
httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(initiatorHost, true, username, options.Password)
httpsSyncCatalogOp, err := makeHTTPSSyncCatalogOp(vcc.Log, initiatorHost, true, username, options.Password)
if err != nil {
return instructions, err
}
instructions = append(instructions, &httpsSyncCatalogOp)
if !*options.SkipRebalanceShards {
httpsRBSCShardsOp, err := makeHTTPSRebalanceSubclusterShardsOp(
initiatorHost, usePassword, username, options.Password, *options.SCName)
vcc.Log, initiatorHost, usePassword, username, options.Password, *options.SCName)
if err != nil {
return instructions, err
}
Expand Down
19 changes: 9 additions & 10 deletions vclusterops/add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro
return err
}

instructions, err := produceAddSubclusterInstructions(&addSubclusterInfo, options)
instructions, err := vcc.produceAddSubclusterInstructions(&addSubclusterInfo, options)
if err != nil {
vlog.LogPrintError("fail to produce instructions, %s", err)
return err
return fmt.Errorf("fail to produce instructions, %w", err)
}

// Create a VClusterOpEngine, and add certs to the engine
Expand All @@ -217,8 +216,7 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro
// Give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.Run()
if runError != nil {
vlog.LogPrintError("fail to add subcluster %s, %s", addSubclusterInfo.SCName, runError)
return runError
return fmt.Errorf("fail to add subcluster %s, %w", addSubclusterInfo.SCName, runError)
}

return nil
Expand All @@ -235,33 +233,34 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro
// if the subcluster name already exists or the db is an enterprise db
// - Check if the new subcluster is created in database through HTTPS call
// - TODO: add new nodes to the subcluster
func produceAddSubclusterInstructions(addSubclusterInfo *VAddSubclusterInfo, options *VAddSubclusterOptions) ([]ClusterOp, error) {
func (vcc *VClusterCommands) produceAddSubclusterInstructions(addSubclusterInfo *VAddSubclusterInfo,
options *VAddSubclusterOptions) ([]ClusterOp, error) {
var instructions []ClusterOp

// when password is specified, we will use username/password to call https endpoints
usePassword := false
if addSubclusterInfo.Password != nil {
usePassword = true
err := options.ValidateUserName()
err := options.ValidateUserName(vcc)
if err != nil {
return instructions, err
}
}

username := *options.UserName
httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(addSubclusterInfo.DBName, addSubclusterInfo.Hosts,
httpsGetUpNodesOp, err := makeHTTPSGetUpNodesOp(vcc.Log, addSubclusterInfo.DBName, addSubclusterInfo.Hosts,
usePassword, username, addSubclusterInfo.Password)
if err != nil {
return instructions, err
}

httpsAddSubclusterOp, err := makeHTTPSAddSubclusterOp(usePassword, username, addSubclusterInfo.Password,
httpsAddSubclusterOp, err := makeHTTPSAddSubclusterOp(vcc.Log, usePassword, username, addSubclusterInfo.Password,
addSubclusterInfo.SCName, addSubclusterInfo.IsPrimary, addSubclusterInfo.ControlSetSize)
if err != nil {
return instructions, err
}

httpsCheckSubclusterOp, err := makeHTTPSCheckSubclusterOp(usePassword, username, addSubclusterInfo.Password,
httpsCheckSubclusterOp, err := makeHTTPSCheckSubclusterOp(vcc.Log, usePassword, username, addSubclusterInfo.Password,
addSubclusterInfo.SCName, addSubclusterInfo.IsPrimary, addSubclusterInfo.ControlSetSize)
if err != nil {
return instructions, err
Expand Down
17 changes: 8 additions & 9 deletions vclusterops/cluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,10 @@ func (op *OpBase) getName() string {
func (op *OpBase) parseAndCheckResponse(host, responseContent string, responseObj any) error {
err := util.GetJSONLogErrors(responseContent, &responseObj, op.name)
if err != nil {
vlog.LogError("[%s] fail to parse response on host %s, detail: %s", op.name, host, err)
op.log.Error(err, "fail to parse response on host %s", host)
return err
}
vlog.LogInfo("[%s] JSON response from %s is %+v\n", op.name, host, responseObj)

op.log.Info("JSON response", "host", host, "responseObj", responseObj)
return nil
}

Expand All @@ -226,26 +225,26 @@ func (op *OpBase) setVersionToSemVar() {
// TODO: implement another parse function for list response

func (op *OpBase) logResponse(host string, result HostHTTPResult) {
vlog.LogPrintInfo("[%s] result from host %s summary %s, details: %+v",
op.log.PrintInfo("[%s] result from host %s summary %s, details: %+v",
op.name, host, result.status.getStatusString(), result)
}

func (op *OpBase) logPrepare() {
vlog.LogInfo("[%s] Prepare() called\n", op.name)
op.log.Info("Prepare() called", "name", op.name)
}

func (op *OpBase) logExecute() {
vlog.LogInfo("[%s] Execute() called\n", op.name)
op.log.Info("Execute() called", "name", op.name)
}

func (op *OpBase) logFinalize() {
vlog.LogInfo("[%s] Finalize() called\n", op.name)
op.log.Info("Finalize() called", "name", op.name)
}

func (op *OpBase) runExecute(execContext *OpEngineExecContext) error {
err := execContext.dispatcher.sendRequest(&op.clusterHTTPRequest)
if err != nil {
vlog.LogError("Fail to dispatch request %v", op.clusterHTTPRequest)
op.log.Error(err, "Fail to dispatch request %v", op.clusterHTTPRequest)
return err
}
return nil
Expand Down Expand Up @@ -287,7 +286,7 @@ func (op *OpBase) isSkipExecute() bool {
func (op *OpBase) hasQuorum(hostCount, primaryNodeCount uint) bool {
quorumCount := (primaryNodeCount + 1) / 2
if hostCount < quorumCount {
vlog.LogPrintError("[%s] Quorum check failed: "+
op.log.PrintError("[%s] Quorum check failed: "+
"number of hosts with latest catalog (%d) is not "+
"greater than or equal to 1/2 of number of the primary nodes (%d)\n",
op.name, hostCount, primaryNodeCount)
Expand Down
Loading

0 comments on commit 0487bd6

Please sign in to comment.