Skip to content

Commit

Permalink
Sync from server repo (490afcac43e)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Sep 7, 2023
1 parent b466b39 commit a7b1e1f
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 60 deletions.
7 changes: 3 additions & 4 deletions vclusterops/add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,10 @@ func (o *VAddNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) error {
vdb.DataPrefix = *o.DataPrefix
vdb.DepotPrefix = *o.DepotPrefix

hostNodeMap := make(map[string]VCoordinationNode)
hostNodeMap := makeVHostNodeMap()
// we set depot/data paths manually because there is not yet an https endpoint for
// that(VER-88122). This is useful for NMAPrepareDirectoriesOp.
for h := range vdb.HostNodeMap {
vnode := vdb.HostNodeMap[h]
for h, vnode := range vdb.HostNodeMap {
dataPath := vdb.genDataPath(vnode.Name)
vnode.StorageLocations = append(vnode.StorageLocations, dataPath)
if vdb.DepotPrefix != "" {
Expand Down Expand Up @@ -280,7 +279,7 @@ func produceAddNodeInstructions(vdb *VCoordinationDatabase,
if err != nil {
return instructions, err
}
httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOp(initiatorHost, usePassword, username, password)
httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(initiatorHost, usePassword, username, password)
if err != nil {
return instructions, err
}
Expand Down
36 changes: 21 additions & 15 deletions vclusterops/coordinator_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type VCoordinationDatabase struct {
// processed path prefixes
CatalogPrefix string
DataPrefix string
HostNodeMap map[string]VCoordinationNode
HostNodeMap vHostNodeMap
// for convenience
HostList []string // expected to be resolved IP addresses

Expand All @@ -60,6 +60,12 @@ type VCoordinationDatabase struct {
PrimaryUpNodes []string
}

type vHostNodeMap map[string]*VCoordinationNode

func makeVHostNodeMap() vHostNodeMap {
return make(vHostNodeMap)
}

func MakeVCoordinationDatabase() VCoordinationDatabase {
return VCoordinationDatabase{}
}
Expand All @@ -78,7 +84,7 @@ func (vdb *VCoordinationDatabase) SetFromCreateDBOptions(options *VCreateDatabas
vdb.DataPrefix = *options.DataPrefix
vdb.HostList = make([]string, len(options.Hosts))
vdb.HostList = options.Hosts
vdb.HostNodeMap = make(map[string]VCoordinationNode)
vdb.HostNodeMap = makeVHostNodeMap()
vdb.LicensePathOnNode = *options.LicensePathOnNode
vdb.Ipv6 = options.Ipv6.ToBool()

Expand Down Expand Up @@ -109,7 +115,7 @@ func (vdb *VCoordinationDatabase) SetFromCreateDBOptions(options *VCreateDatabas
if err != nil {
return err
}
vdb.HostNodeMap[host] = vNode
vdb.HostNodeMap[host] = &vNode
}

return nil
Expand All @@ -133,7 +139,7 @@ func (vdb *VCoordinationDatabase) addHosts(hosts []string) error {
}
vNode.SetFromNodeConfig(nodeConfig, vdb)
vdb.HostList = append(vdb.HostList, host)
vdb.HostNodeMap[host] = vNode
vdb.HostNodeMap[host] = &vNode
}

return nil
Expand All @@ -153,11 +159,11 @@ func (vdb *VCoordinationDatabase) SetFromClusterConfig(clusterConfig *ClusterCon
vdb.UseDepot = true
}

vdb.HostNodeMap = make(map[string]VCoordinationNode)
vdb.HostNodeMap = makeVHostNodeMap()
for _, nodeConfig := range clusterConfig.Nodes {
vnode := VCoordinationNode{}
vnode.SetFromNodeConfig(nodeConfig, vdb)
vdb.HostNodeMap[vnode.Address] = vnode
vdb.HostNodeMap[vnode.Address] = &vnode
}
}

Expand Down Expand Up @@ -196,7 +202,7 @@ func (vdb *VCoordinationDatabase) Copy(targetHosts []string) VCoordinationDataba

// copyHostNodeMap copies the receiver's HostNodeMap. You can choose to copy
// only a subset of the receiver's hosts by passing a slice of hosts to keep.
func (vdb *VCoordinationDatabase) copyHostNodeMap(targetHosts []string) map[string]VCoordinationNode {
func (vdb *VCoordinationDatabase) copyHostNodeMap(targetHosts []string) vHostNodeMap {
if len(targetHosts) == 0 {
return util.CopyMap(vdb.HostNodeMap)
}
Expand All @@ -208,8 +214,8 @@ func (vdb *VCoordinationDatabase) copyHostNodeMap(targetHosts []string) map[stri
// host ip as value, from HostNodeMap.
func (vdb *VCoordinationDatabase) genNodeNameToHostMap() map[string]string {
vnodes := make(map[string]string)
for h := range vdb.HostNodeMap {
vnodes[vdb.HostNodeMap[h].Name] = h
for h, vnode := range vdb.HostNodeMap {
vnodes[vnode.Name] = h
}
return vnodes
}
Expand All @@ -234,8 +240,8 @@ func (vdb *VCoordinationDatabase) SetDBInfoFromClusterConfig(clusterConfig *Clus
func (vdb *VCoordinationDatabase) getSCNames() []string {
allKeys := make(map[string]bool)
scNames := []string{}
for h := range vdb.HostNodeMap {
sc := vdb.HostNodeMap[h].Subcluster
for _, vnode := range vdb.HostNodeMap {
sc := vnode.Subcluster
if _, value := allKeys[sc]; !value {
allKeys[sc] = true
scNames = append(scNames, sc)
Expand All @@ -251,8 +257,8 @@ func (vdb *VCoordinationDatabase) containNodes(nodes []string) []string {
hostSet[n] = struct{}{}
}
dupHosts := []string{}
for h := range vdb.HostNodeMap {
address := vdb.HostNodeMap[h].Address
for _, vnode := range vdb.HostNodeMap {
address := vnode.Address
if _, exist := hostSet[address]; exist {
dupHosts = append(dupHosts, address)
}
Expand All @@ -264,8 +270,8 @@ func (vdb *VCoordinationDatabase) containNodes(nodes []string) []string {
// hasAtLeastOneDownNode returns true if the current VCoordinationDatabase instance
// has at least one down node.
func (vdb *VCoordinationDatabase) hasAtLeastOneDownNode() bool {
for host := range vdb.HostNodeMap {
if vdb.HostNodeMap[host].State == util.NodeDownState {
for _, vnode := range vdb.HostNodeMap {
if vnode.State == util.NodeDownState {
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func produceBasicCreateDBInstructions(vdb *VCoordinationDatabase, options *VCrea
instructions = append(instructions, &httpsCreateNodeOp)
}

httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOp(bootstrapHost, true, *options.UserName, options.Password)
httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(bootstrapHost, true, *options.UserName, options.Password)
if err != nil {
return instructions, err
}
Expand Down
4 changes: 2 additions & 2 deletions vclusterops/create_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func TestWriteClusterConfig(t *testing.T) {
vdb.DataPrefix = defaultPath
vdb.DepotPrefix = defaultPath
vdb.HostList = []string{"ip_1", "ip_2", "ip_3"}
vdb.HostNodeMap = make(map[string]VCoordinationNode)
vdb.HostNodeMap = makeVHostNodeMap()
for i, h := range vdb.HostList {
n := VCoordinationNode{}
n.Name = fmt.Sprintf("node_name_%d", i+1)
vdb.HostNodeMap[h] = n
vdb.HostNodeMap[h] = &n
}
vdb.IsEon = true

Expand Down
4 changes: 2 additions & 2 deletions vclusterops/https_create_cluster_depot_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func makeHTTPSCreateClusterDepotOp(vdb *VCoordinationDatabase, hosts []string,

// store nodeName-depotPath values for later http response verification
httpsCreateDepotOp.NodeDepotPaths = make(map[string]string)
for host := range vdb.HostNodeMap {
httpsCreateDepotOp.NodeDepotPaths[vdb.HostNodeMap[host].Name] = vdb.HostNodeMap[host].DepotPath
for _, vnode := range vdb.HostNodeMap {
httpsCreateDepotOp.NodeDepotPaths[vnode.Name] = vnode.DepotPath
}

// set the query params, "path" is required, "size" is optional
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/https_create_nodes_depot_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type HTTPSCreateNodesDepotOp struct {
OpBase
OpHTTPSBase
HostNodeMap map[string]VCoordinationNode
HostNodeMap vHostNodeMap
DepotSize string
}

Expand Down
4 changes: 2 additions & 2 deletions vclusterops/https_get_nodes_info_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (op *httpsGetNodesInfoOp) processResult(_ *OpEngineExecContext) error {
break
}
// save nodes info to vdb
op.vdb.HostNodeMap = make(map[string]VCoordinationNode)
op.vdb.HostNodeMap = makeVHostNodeMap()
for _, node := range nodesStateInfo.NodeList {
if node.Database != op.dbName {
err = fmt.Errorf(`[%s] database %s is running on host %s, rather than database %s`, op.name, node.Database, host, op.dbName)
Expand All @@ -117,7 +117,7 @@ func (op *httpsGetNodesInfoOp) processResult(_ *OpEngineExecContext) error {
if node.IsPrimary && node.State == util.NodeUpState {
op.vdb.PrimaryUpNodes = append(op.vdb.PrimaryUpNodes, node.Address)
}
op.vdb.HostNodeMap[node.Address] = vNode
op.vdb.HostNodeMap[node.Address] = &vNode
// extract catalog prefix from node's catalog path
// catalog prefix is preceding db name
dbPath := "/" + node.Database
Expand Down
10 changes: 8 additions & 2 deletions vclusterops/https_reload_spread_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ type HTTPSReloadSpreadOp struct {
OpHTTPSBase
}

func makeHTTPSReloadSpreadOp(hosts []string, useHTTPPassword bool,
func makeHTTPSReloadSpreadOpWithInitiator(initHosts []string,
useHTTPPassword bool,
userName string, httpsPassword *string) (HTTPSReloadSpreadOp, error) {
httpsReloadSpreadOp := HTTPSReloadSpreadOp{}
httpsReloadSpreadOp.name = "HTTPSReloadSpreadOp"
httpsReloadSpreadOp.hosts = hosts
httpsReloadSpreadOp.hosts = initHosts
httpsReloadSpreadOp.useHTTPPassword = useHTTPPassword

err := util.ValidateUsernameAndPassword(httpsReloadSpreadOp.name, useHTTPPassword, userName)
Expand All @@ -43,6 +44,11 @@ func makeHTTPSReloadSpreadOp(hosts []string, useHTTPPassword bool,
return httpsReloadSpreadOp, nil
}

func makeHTTPSReloadSpreadOp(useHTTPPassword bool,
userName string, httpsPassword *string) (HTTPSReloadSpreadOp, error) {
return makeHTTPSReloadSpreadOpWithInitiator(nil, useHTTPPassword, userName, httpsPassword)
}

func (op *HTTPSReloadSpreadOp) setupClusterHTTPRequest(hosts []string) error {
op.clusterHTTPRequest = ClusterHTTPRequest{}
op.clusterHTTPRequest.RequestCollection = make(map[string]HostHTTPRequest)
Expand Down
2 changes: 1 addition & 1 deletion vclusterops/https_spread_remove_node_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type HTTPSSpreadRemoveNodeOp struct {
}

func makeHTTPSSpreadRemoveNodeOp(hostsToRemove []string, initiatorHost []string, useHTTPPassword bool,
userName string, httpsPassword *string, hostNodeMap map[string]VCoordinationNode) (HTTPSSpreadRemoveNodeOp, error) {
userName string, httpsPassword *string, hostNodeMap vHostNodeMap) (HTTPSSpreadRemoveNodeOp, error) {
op := HTTPSSpreadRemoveNodeOp{}
op.name = "HTTPSSpreadRemoveNodeOp"
op.hosts = initiatorHost
Expand Down
8 changes: 4 additions & 4 deletions vclusterops/nma_delete_dir_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func (op *NMADeleteDirectoriesOp) buildRequestBody(
forceDelete bool,
) error {
op.hostRequestBodyMap = make(map[string]string)
for h := range vdb.HostNodeMap {
for h, vnode := range vdb.HostNodeMap {
p := deleteDirParams{}
// directories
p.Directories = append(p.Directories, vdb.HostNodeMap[h].CatalogPath)
p.Directories = append(p.Directories, vdb.HostNodeMap[h].StorageLocations...)
p.Directories = append(p.Directories, vnode.CatalogPath)
p.Directories = append(p.Directories, vnode.StorageLocations...)

if vdb.UseDepot {
dbDepotPath := filepath.Join(vdb.DepotPrefix, vdb.Name)
p.Directories = append(p.Directories, vdb.HostNodeMap[h].DepotPath, dbDepotPath)
p.Directories = append(p.Directories, vnode.DepotPath, dbDepotPath)
}

dbCatalogPath := filepath.Join(vdb.CatalogPrefix, vdb.Name)
Expand Down
4 changes: 2 additions & 2 deletions vclusterops/nma_download_file_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (op *NMADownloadFileOp) processResult(execContext *OpEngineExecContext) err
}

// save descFileContent in vdb
op.vdb.HostNodeMap = make(map[string]VCoordinationNode)
op.vdb.HostNodeMap = makeVHostNodeMap()
for _, node := range descFileContent.NodeList {
op.vdb.HostList = append(op.vdb.HostList, node.Address)
vNode := MakeVCoordinationNode()
Expand Down Expand Up @@ -224,7 +224,7 @@ func (op *NMADownloadFileOp) processResult(execContext *OpEngineExecContext) err
}
}

op.vdb.HostNodeMap[node.Address] = vNode
op.vdb.HostNodeMap[node.Address] = &vNode
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions vclusterops/nma_get_nodes_info_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func makeNMAGetNodesInfoOp(hosts []string,
op.dbName = dbName
op.catalogPrefix = catalogPrefix
op.vdb = vdb
op.vdb.HostNodeMap = make(map[string]VCoordinationNode)
op.vdb.HostNodeMap = makeVHostNodeMap()
return op
}

Expand Down Expand Up @@ -87,7 +87,7 @@ func (op *nmaGetNodesInfoOp) processResult(_ *OpEngineExecContext) error {
return errors.Join(allErrs, err)
}
vnode.Address = host
op.vdb.HostNodeMap[host] = vnode
op.vdb.HostNodeMap[host] = &vnode
} else {
allErrs = errors.Join(allErrs, result.err)
}
Expand Down
4 changes: 2 additions & 2 deletions vclusterops/nma_load_remote_catalog_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ func makeNMALoadRemoteCatalogOp(oldHosts []string, communalStorageParameters map
op.timeout = timeout

op.primaryNodeCount = 0
for host := range vdb.HostNodeMap {
if vdb.HostNodeMap[host].IsPrimary {
for _, vnode := range vdb.HostNodeMap {
if vnode.IsPrimary {
op.primaryNodeCount++
}
}
Expand Down
4 changes: 2 additions & 2 deletions vclusterops/nma_prepare_directories_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type prepareDirectoriesRequestData struct {
IgnoreParent bool `json:"ignore_parent"`
}

func makeNMAPrepareDirectoriesOp(hostNodeMap map[string]VCoordinationNode,
func makeNMAPrepareDirectoriesOp(hostNodeMap vHostNodeMap,
forceCleanup, forRevive bool) (NMAPrepareDirectoriesOp, error) {
nmaPrepareDirectoriesOp := NMAPrepareDirectoriesOp{}
nmaPrepareDirectoriesOp.name = "NMAPrepareDirectoriesOp"
Expand All @@ -58,7 +58,7 @@ func makeNMAPrepareDirectoriesOp(hostNodeMap map[string]VCoordinationNode,
return nmaPrepareDirectoriesOp, nil
}

func (op *NMAPrepareDirectoriesOp) setupRequestBody(hostNodeMap map[string]VCoordinationNode) error {
func (op *NMAPrepareDirectoriesOp) setupRequestBody(hostNodeMap vHostNodeMap) error {
op.hostRequestBodyMap = make(map[string]string)

for host := range hostNodeMap {
Expand Down
11 changes: 5 additions & 6 deletions vclusterops/remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,10 @@ func (o *VRemoveNodeOptions) completeVDBSetting(vdb *VCoordinationDatabase) erro
}
}
vdb.DepotPrefix = *o.DepotPrefix
hostNodeMap := make(map[string]VCoordinationNode)
hostNodeMap := makeVHostNodeMap()
// we set the depot path manually because there is not yet an https endpoint for
// that(VER-88122). This is useful for NMADeleteDirectoriesOp.
for h := range vdb.HostNodeMap {
vnode := vdb.HostNodeMap[h]
for h, vnode := range vdb.HostNodeMap {
vnode.DepotPath = vdb.genDepotPath(vnode.Name)
hostNodeMap[h] = vnode
}
Expand Down Expand Up @@ -304,7 +303,7 @@ func produceRemoveNodeInstructions(vdb *VCoordinationDatabase, options *VRemoveN
if err != nil {
return instructions, err
}
httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOp(initiatorHost, true, username, password)
httpsReloadSpreadOp, err := makeHTTPSReloadSpreadOpWithInitiator(initiatorHost, true, username, password)
if err != nil {
return instructions, err
}
Expand Down Expand Up @@ -343,7 +342,7 @@ func produceRebalanceSubclusterShardsOps(instructions *[]ClusterOp, initiatorHos
// produces an HTTPSMarkEphemeralNodeOp.
func produceMarkEphemeralNodeOps(instructions *[]ClusterOp, targetHosts, hosts []string,
useHTTPPassword bool, userName string, httpsPassword *string,
hostNodeMap map[string]VCoordinationNode) error {
hostNodeMap vHostNodeMap) error {
for _, host := range targetHosts {
httpsMarkEphemeralNodeOp, err := makeHTTPSMarkEphemeralNodeOp(hostNodeMap[host].Name, hosts,
useHTTPPassword, userName, httpsPassword)
Expand All @@ -359,7 +358,7 @@ func produceMarkEphemeralNodeOps(instructions *[]ClusterOp, targetHosts, hosts [
// This is because we must drop node one by one to avoid losing quorum.
func produceDropNodeOps(instructions *[]ClusterOp, targetHosts, hosts []string,
useHTTPPassword bool, userName string, httpsPassword *string,
hostNodeMap map[string]VCoordinationNode, isEon bool) error {
hostNodeMap vHostNodeMap, isEon bool) error {
for _, host := range targetHosts {
httpsDropNodeOp, err := makeHTTPSDropNodeOp(hostNodeMap[host].Name, hosts,
useHTTPPassword, userName, httpsPassword, isEon)
Expand Down
3 changes: 1 addition & 2 deletions vclusterops/remove_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ func removeScPreCheck(vdb *VCoordinationDatabase, options *VRemoveScOptions) ([]
}

// get nodes of the to-be-removed subcluster
for h := range vdb.HostNodeMap {
vnode := vdb.HostNodeMap[h]
for h, vnode := range vdb.HostNodeMap {
if vnode.Subcluster == *options.SubclusterToRemove {
hostsToRemove = append(hostsToRemove, h)
}
Expand Down
Loading

0 comments on commit a7b1e1f

Please sign in to comment.