Skip to content

Commit

Permalink
Sync from server repo (56ae6518c53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Apr 11, 2024
1 parent cf2e31d commit 29d822a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 25 deletions.
1 change: 0 additions & 1 deletion commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ func configViper(cmd *cobra.Command, flagsInConfig []string) error {
// manage_config does not need viper to load config file info
if cmd.CalledAs() != createDBSubCmd &&
cmd.CalledAs() != reviveDBSubCmd &&
cmd.CalledAs() != manageConfigSubCmd && // VER-92992: remove this line once manage_config is not runnable
cmd.CalledAs() != configRecoverSubCmd &&
cmd.CalledAs() != configShowSubCmd {
err = loadConfigToViper()
Expand Down
4 changes: 2 additions & 2 deletions commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ Omitting the option will skip this node trimming process.
Examples:
# Add a single host to the existing database with config file
vcluster db_add_node --db-name test_db --add 10.20.30.43 \
vcluster db_add_node --db-name test_db --new-hosts 10.20.30.43 \
--config /opt/vertica/config/vertica_cluster.yaml
# Add multiple hosts to the existing database with user input
vcluster db_add_node --db-name test_db --add 10.20.30.43,10.20.30.44 \
vcluster db_add_node --db-name test_db --new-hosts 10.20.30.43,10.20.30.44 \
--data-path /data --hosts 10.20.30.40 \
--node-names v_test_db_node0001,v_test_db_node0002
`,
Expand Down
4 changes: 2 additions & 2 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ Examples:
# Add a subcluster and new nodes in the subcluster with config file
vcluster db_add_subcluster --subcluster sc1 \
--config /opt/vertica/config/vertica_cluster.yaml \
--is-primary --control-set-size 1 --add 10.20.30.43
--is-primary --control-set-size 1 --new-hosts 10.20.30.43
# Add a subcluster new nodes in the subcluster with user input
vcluster db_add_subcluster --subcluster sc1 --db-name test_db \
--hosts 10.20.30.40,10.20.30.41,10.20.30.42 \
--is-primary --control-set-size -1 --add 10.20.30.43
--is-primary --control-set-size -1 --new-hosts 10.20.30.43
`,
)

Expand Down
3 changes: 1 addition & 2 deletions commands/cmd_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ func (c *CmdBase) setCommonFlags(cmd *cobra.Command, flags []string) {
)
// keyFile and certFile are flags that all subcommands require,
// except for manage_config and `manage_config show`
if cmd.Name() != manageConfigSubCmd && // VER-92992: remove this line once manage_config is not runnable
cmd.Name() != configShowSubCmd {
if cmd.Name() != configShowSubCmd {
cmd.Flags().StringVar(
&globals.keyFile,
keyFileFlag,
Expand Down
5 changes: 4 additions & 1 deletion commands/cmd_list_all_nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ The --hosts option specifies one or more hosts that the program
should communicate with. The program will return the first response it
receives from any of the specified hosts.
The --db-name and --catalog-path options are only needed when VCluster cannot
obtain node information from a running database and the config file is not provided.
The only requirement for each host is that it is running the spread daemon.
Examples:
Expand All @@ -60,7 +63,7 @@ Examples:
vcluster list_allnodes --password testpassword \
--config /opt/vertica/config/vertica_cluster.yaml
`,
[]string{hostsFlag, passwordFlag, configFlag, outputFileFlag},
[]string{dbNameFlag, hostsFlag, passwordFlag, catalogPathFlag, configFlag, outputFileFlag},
)

return cmd
Expand Down
8 changes: 6 additions & 2 deletions vclusterops/fetch_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
type VFetchCoordinationDatabaseOptions struct {
DatabaseOptions
Overwrite bool // overwrite existing config file at the same location

// hidden option
readOnly bool // this should be only used if we don't want to update the config file
}

func VRecoverConfigOptionsFactory() VFetchCoordinationDatabaseOptions {
Expand Down Expand Up @@ -52,7 +55,7 @@ func (opt *VFetchCoordinationDatabaseOptions) analyzeOptions() error {
*opt.CatalogPrefix = util.GetCleanPath(*opt.CatalogPrefix)

// check existing config file at the same location
if !opt.Overwrite {
if !opt.readOnly && !opt.Overwrite {
if util.CanWriteAccessPath(opt.ConfigPath) == util.FileExist {
return fmt.Errorf("config file exists at %s. "+
"You can use --overwrite to overwrite this existing config file", opt.ConfigPath)
Expand Down Expand Up @@ -107,7 +110,7 @@ func (vcc VClusterCommands) VFetchCoordinationDatabase(options *VFetchCoordinati
// we use nmaVDB data to complete vdb
nmaVDB := clusterOpEngine.execContext.nmaVDatabase

if nmaVDB.CommunalStorageLocation != "" {
if !options.readOnly && nmaVDB.CommunalStorageLocation != "" {
vdb.IsEon = true
vdb.CommunalStorageLocation = nmaVDB.CommunalStorageLocation
// if depot path is not provided for an Eon DB,
Expand All @@ -125,6 +128,7 @@ func (vcc VClusterCommands) VFetchCoordinationDatabase(options *VFetchCoordinati
}
vnode.Subcluster = n.Subcluster.Name
vnode.StorageLocations = n.StorageLocations
vnode.IsPrimary = n.IsPrimary
}

return vdb, runError
Expand Down
46 changes: 45 additions & 1 deletion vclusterops/fetch_node_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,53 @@ func (vcc VClusterCommands) VFetchNodeState(options *VFetchNodeStateOptions) ([]
certs := httpsCerts{key: options.Key, cert: options.Cert, caCert: options.CaCert}
clusterOpEngine := makeClusterOpEngine(instructions, &certs)

// Give the instructions to the VClusterOpEngine to run
// give the instructions to the VClusterOpEngine to run
runError := clusterOpEngine.run(vcc.Log)
nodeStates := clusterOpEngine.execContext.nodesInfo
if runError == nil {
return nodeStates, nil
}

// if failed to get node info from a running database,
// we will try to get it by reading catalog editor
upNodeCount := 0
for _, n := range nodeStates {
if n.State == util.NodeUpState {
upNodeCount++
}
}

if upNodeCount == 0 {
const msg = "Cannot get node information from running database. " +
"Try to get node information by reading catalog editor."
fmt.Println(msg)
vcc.Log.PrintInfo(msg)

var downNodeStates []NodeInfo

var fetchDatabaseOptions VFetchCoordinationDatabaseOptions
fetchDatabaseOptions.DatabaseOptions = options.DatabaseOptions
fetchDatabaseOptions.readOnly = true

vdb, err := vcc.VFetchCoordinationDatabase(&fetchDatabaseOptions)
if err != nil {
return downNodeStates, err
}

for _, h := range vdb.HostList {
var nodeInfo NodeInfo
n := vdb.HostNodeMap[h]
nodeInfo.Address = n.Address
nodeInfo.Name = n.Name
nodeInfo.CatalogPath = n.CatalogPath
nodeInfo.Subcluster = n.Subcluster
nodeInfo.IsPrimary = n.IsPrimary
nodeInfo.State = util.NodeDownState
downNodeStates = append(downNodeStates, nodeInfo)
}

return downNodeStates, nil
}

return nodeStates, runError
}
Expand Down
2 changes: 2 additions & 0 deletions vclusterops/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (node *nodeStateInfo) asNodeInfoWoVer() (n NodeInfo) {
n.Name = node.Name
n.State = node.State
n.CatalogPath = node.CatalogPath
n.Subcluster = node.Subcluster
n.IsPrimary = node.IsPrimary
return
}

Expand Down
15 changes: 1 addition & 14 deletions vclusterops/https_check_node_state_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func makeHTTPSCheckNodeStateOp(hosts []string,
) (httpsCheckNodeStateOp, error) {
op := httpsCheckNodeStateOp{}
op.name = "HTTPCheckNodeStateOp"
op.description = "Check node state"
op.description = "Check node state from running database"
// The hosts are the ones we are going to talk to.
// They can be a subset of the actual host information that we return,
// as if any of the hosts is responsive, spread can give us the info of all nodes
Expand Down Expand Up @@ -131,19 +131,6 @@ func (op *httpsCheckNodeStateOp) processResult(execContext *opEngineExecContext)
return nil
}

// If none of the requests succeed on any node, we
// can assume that all nodes are down.
if respondingNodeCount == 0 {
// this list is built for Go client
var nodeStates []NodeInfo
for _, host := range op.hosts {
nodeInfo := NodeInfo{}
nodeInfo.Address = host
nodeInfo.State = "DOWN"
nodeStates = append(nodeStates, nodeInfo)
}
execContext.nodesInfo = nodeStates
}
return allErrs
}

Expand Down
2 changes: 2 additions & 0 deletions vclusterops/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type NodeInfo struct {
Name string `json:"name"` // vnode name, e.g., v_dbname_node0001
State string `json:"state"`
CatalogPath string `json:"catalog_path"`
Subcluster string `json:"subcluster"`
IsPrimary bool `json:"is_primary"`
Version string `json:"version"`
Revision string `json:"revision"`
}
Expand Down

0 comments on commit 29d822a

Please sign in to comment.