Skip to content

Commit

Permalink
Sync from server repo (27daeae2bfc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Apr 8, 2024
1 parent fff1224 commit 650f5e7
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 48 deletions.
1 change: 1 addition & 0 deletions commands/cluster_command_launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const (
outputFileFlag = "output-file"
outputFileKey = "outputFile"
subclusterFlag = "subcluster"
addNodeFlag = "new-hosts"
sandboxFlag = "sandbox"
)

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 @@ -82,7 +82,7 @@ Examples:
newCmd.setLocalFlags(cmd)

// require hosts to add
markFlagsRequired(cmd, []string{"add"})
markFlagsRequired(cmd, []string{addNodeFlag})

return cmd
}
Expand All @@ -91,7 +91,7 @@ Examples:
func (c *CmdAddNode) setLocalFlags(cmd *cobra.Command) {
cmd.Flags().StringSliceVar(
&c.addNodeOptions.NewHosts,
"add",
addNodeFlag,
[]string{},
"Comma-separated list of host(s) to add to the database",
)
Expand Down
66 changes: 64 additions & 2 deletions commands/cmd_add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
package commands

import (
"fmt"

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

Expand Down Expand Up @@ -63,11 +66,22 @@ Examples:
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 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
# 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
`,
)

// common db flags
newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, passwordFlag})
newCmd.setCommonFlags(cmd, []string{dbNameFlag, configFlag, hostsFlag, passwordFlag,
dataPathFlag, depotPathFlag})

// local flags
newCmd.setLocalFlags(cmd)
Expand Down Expand Up @@ -102,6 +116,30 @@ func (c *CmdAddSubcluster) setLocalFlags(cmd *cobra.Command) {
vclusterops.ControlSetSizeDefaultValue,
"The number of nodes that will run spread within the subcluster",
)
cmd.Flags().StringSliceVar(
&c.addSubclusterOptions.NewHosts,
addNodeFlag,
[]string{},
"Comma-separated list of host(s) to add to the new subcluster",
)
cmd.Flags().BoolVar(
c.addSubclusterOptions.ForceRemoval,
"force-removal",
false,
"Whether to force clean-up of existing directories before adding host(s)",
)
cmd.Flags().BoolVar(
c.addSubclusterOptions.SkipRebalanceShards,
"skip-rebalance-shards",
false,
util.GetEonFlagMsg("Skip the subcluster shards rebalancing"),
)
cmd.Flags().StringVar(
c.addSubclusterOptions.DepotSize,
"depot-size",
"",
util.GetEonFlagMsg("Size of depot"),
)
}

// setHiddenFlags will set the hidden flags the command has.
Expand Down Expand Up @@ -166,7 +204,31 @@ func (c *CmdAddSubcluster) Run(vcc vclusterops.ClusterCommands) error {
return err
}

vcc.PrintInfo("Added subcluster %s to database %s", *options.SCName, *options.DBName)
if len(options.NewHosts) > 0 {
fmt.Printf("Adding hosts %v to subcluster %s\n",
options.NewHosts, *options.SCName)

options.VAddNodeOptions.DatabaseOptions = c.addSubclusterOptions.DatabaseOptions
options.VAddNodeOptions.SCName = c.addSubclusterOptions.SCName

vdb, err := vcc.VAddNode(&options.VAddNodeOptions)
if err != nil {
vcc.LogError(err, "failed to add nodes into the new subcluster")
return err
}
// update db info in the config file
err = writeConfig(&vdb, vcc.GetLog())
if err != nil {
vcc.PrintWarning("fail to write config file, details: %s", err)
}
}

if len(options.NewHosts) > 0 {
vcc.PrintInfo("Added subcluster %s with nodes %v to database %s",
*options.SCName, options.NewHosts, *options.DBName)
} else {
vcc.PrintInfo("Added subcluster %s to database %s", *options.SCName, *options.DBName)
}
return nil
}

Expand Down
39 changes: 2 additions & 37 deletions commands/cmd_manage_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package commands

import (
"github.com/spf13/cobra"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
)

/* CmdManageConfig
Expand All @@ -28,48 +26,15 @@ import (
*
* Implements ClusterCommand interface
*/
type CmdManageConfig struct {
sOptions vclusterops.DatabaseOptions
cobraCmd *cobra.Command
CmdBase
}

func makeCmdManageConfig() *cobra.Command {
newCmd := &CmdManageConfig{}

cmd := makeBasicCobraCmd(
newCmd,
cmd := makeSimpleCobraCmd(
manageConfigSubCmd,
"Show or recover the content of the config file",
`This subcommand is used to print or recover the content of the config file.`,
[]string{configFlag},
)

// VER-92676: move some of the descriptions to the local flags
// e.g., --hosts
`This subcommand is used to print or recover the content of the config file.`)

cmd.AddCommand(makeCmdConfigShow())
cmd.AddCommand(makeCmdConfigRecover())

// this allows `vcluster manage_config` output the help info
newCmd.cobraCmd = cmd

return cmd
}

func (c *CmdManageConfig) Parse(_ []string, _ vlog.Printer) error {
return nil
}

func (c *CmdManageConfig) Run(_ vclusterops.ClusterCommands) error {
if c.cobraCmd != nil {
return c.cobraCmd.Help()
}

return nil
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdManageConfig
func (c *CmdManageConfig) SetDatabaseOptions(opt *vclusterops.DatabaseOptions) {
c.sOptions = *opt
}
8 changes: 5 additions & 3 deletions commands/cmd_re_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func makeCmdReIP() *cobra.Command {
opt := vclusterops.VReIPFactory()
newCmd.reIPOptions = &opt

// VER-91801: the examle below needs to be updated
// as we need a better example with config file
cmd := OldMakeBasicCobraCmd(
newCmd,
reIPSubCmd,
Expand All @@ -64,11 +62,15 @@ Examples:
# Alter the IP address of database nodes with user input
vcluster re_ip --db-name test_db --hosts 10.20.30.40,10.20.30.41,10.20.30.42 \
--catalog-path /data --re-ip-file /data/re_ip_map.json
# Alter the IP address of database nodes with config file
vcluster re_ip --db-name test_db --re-ip-file /data/re_ip_map.json \
--config /opt/vertica/config/vertica_cluster.yaml
`,
)

// common db flags
newCmd.setCommonFlags(cmd, []string{dbNameFlag, hostsFlag, catalogPathFlag, configFlag})
newCmd.setCommonFlags(cmd, []string{dbNameFlag, hostsFlag, catalogPathFlag, configParamFlag, configFlag})

// local flags
newCmd.setLocalFlags(cmd)
Expand Down
4 changes: 4 additions & 0 deletions vclusterops/add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type VAddSubclusterOptions struct {
IsPrimary *bool
ControlSetSize *int
CloneSC *string
// part 3: add node info
VAddNodeOptions
}

type VAddSubclusterInfo struct {
Expand All @@ -56,6 +58,8 @@ func VAddSubclusterOptionsFactory() VAddSubclusterOptions {
opt := VAddSubclusterOptions{}
// set default values to the params
opt.setDefaultValues()
// set default values for VAddNodeOptions
opt.VAddNodeOptions.setDefaultValues()

return opt
}
Expand Down
10 changes: 7 additions & 3 deletions vclusterops/re_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,25 @@ func (vcc VClusterCommands) VReIP(options *VReIPOptions) error {
return err
}

// VER-93369 may improve this if the CLI knows which nodes are primary
// from the config file
var pVDB *VCoordinationDatabase
// retrieve database information from cluster_config.json for Eon databases
if isEon {
const warningMsg = " for an Eon database, re_ip after revive_db could fail " +
"because we cannot retrieve the correct database information"
if *options.CommunalStorageLocation != "" {
vdb, e := options.getVDBWhenDBIsDown(vcc)
if e != nil {
return e
// show a warning message if we cannot get VDB from a down database
vcc.Log.PrintWarning("failed to retrieve the communal storage location" + warningMsg)
}
pVDB = &vdb
} else {
// When communal storage location is missing, we only log a debug message
// because re-ip only fails in between revive_db and first start_db.
// We should not ran re-ip in that case because revive_db has already done the re-ip work.
vcc.Log.V(1).Info("communal storage location is not specified for an eon database," +
" re_ip after revive_db could fail because we cannot retrieve the correct database information")
vcc.Log.V(1).Info("communal storage location is not specified" + warningMsg)
}
}

Expand Down
4 changes: 3 additions & 1 deletion vclusterops/start_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ func (vcc VClusterCommands) VStartDatabase(options *VStartDatabaseOptions) (vdbP
return nil, err
}

// VER-93369 may improve this if the CLI knows which nodes are primary
// from the config file
var vdb VCoordinationDatabase
// retrieve database information from cluster_config.json for Eon databases
if isEon {
const warningMsg = " for an Eon database, start_db after revive_db could fail " +
"because we cannot retrieve the correct database information\n"
"because we cannot retrieve the correct database information"
if *options.CommunalStorageLocation != "" {
vdbNew, e := options.getVDBWhenDBIsDown(vcc)
if e != nil {
Expand Down

0 comments on commit 650f5e7

Please sign in to comment.