Skip to content

Commit

Permalink
Sync from server repo (acba5f67332)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Oct 13, 2023
1 parent 6fa6318 commit fa4852c
Show file tree
Hide file tree
Showing 28 changed files with 609 additions and 209 deletions.
2 changes: 1 addition & 1 deletion commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (c *CmdAddNode) Run(log vlog.Printer) error {
return addNodeError
}
// write cluster information to the YAML config file
err = vclusterops.WriteClusterConfig(&vdb, options.ConfigDirectory)
err = vdb.WriteClusterConfig(options.ConfigDirectory)
if err != nil {
vlog.LogPrintWarning("fail to write config file, details: %s", err)
}
Expand Down
20 changes: 4 additions & 16 deletions commands/cmd_create_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ import (
*/

type CmdCreateDB struct {
createDBOptions *vclusterops.VCreateDatabaseOptions
configParamListStr *string // raw input from user, need further processing
communalStorageParams *string // raw input from user, need further processing
createDBOptions *vclusterops.VCreateDatabaseOptions
configParamListStr *string // raw input from user, need further processing

CmdBase
}
Expand Down Expand Up @@ -69,8 +68,6 @@ func makeCmdCreateDB() *CmdCreateDB {
createDBOptions.CommunalStorageLocation = newCmd.parser.String("communal-storage-location", "",
util.GetEonFlagMsg("Location of communal storage"))
createDBOptions.ShardCount = newCmd.parser.Int("shard-count", 0, util.GetEonFlagMsg("Number of shards in the database"))
newCmd.communalStorageParams = newCmd.parser.String("communal-storage-params", "", util.GetOptionalFlagMsg(
"Comma-separated list of NAME=VALUE pairs for communal storage parameters"))
createDBOptions.DepotPrefix = newCmd.parser.String("depot-path", "", util.GetEonFlagMsg("Path to depot directory"))
createDBOptions.DepotSize = newCmd.parser.String("depot-size", "", util.GetEonFlagMsg("Size of depot"))
createDBOptions.GetAwsCredentialsFromEnv = newCmd.parser.Bool("get-aws-credentials-from-env-vars", false,
Expand Down Expand Up @@ -149,17 +146,8 @@ func (c *CmdCreateDB) Parse(inputArgv []string) error {
func (c *CmdCreateDB) validateParse() error {
vlog.LogInfoln("Called validateParse()")

// check the format of communal storage params string, and parse it into configParams
communalStorageParams, err := util.ParseConfigParams(*c.communalStorageParams)
if err != nil {
return err
}
if communalStorageParams != nil {
c.createDBOptions.CommunalStorageParameters = communalStorageParams
}

// parse raw host str input into a []string of createDBOptions
err = c.createDBOptions.ParseHostList(*c.hostListStr)
err := c.createDBOptions.ParseHostList(*c.hostListStr)
if err != nil {
return err
}
Expand Down Expand Up @@ -193,7 +181,7 @@ func (c *CmdCreateDB) Run(log vlog.Printer) error {
return createError
}
// write cluster information to the YAML config file
err := vclusterops.WriteClusterConfig(&vdb, c.createDBOptions.ConfigDirectory)
err := vdb.WriteClusterConfig(c.createDBOptions.ConfigDirectory)
if err != nil {
vlog.LogPrintWarning("fail to write config file, details: %s", err)
}
Expand Down
17 changes: 14 additions & 3 deletions commands/cmd_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import (
* Implements ClusterCommand interface
*/
type CmdInit struct {
Hosts *string
DBName *string
Hosts *string
ConfigHandler
}

Expand All @@ -48,6 +49,7 @@ func makeCmdInit() *CmdInit {
"The directory under which the config file will be created. "+
"By default the current directory will be used.",
)
newCmd.DBName = newCmd.parser.String("db-name", "", "Database name")
newCmd.Hosts = newCmd.parser.String("hosts", "", "Comma-separated list of hosts to participate in database")
return newCmd
}
Expand Down Expand Up @@ -106,12 +108,21 @@ func (c *CmdInit) Run(_ vlog.Printer) error {

// TODO: this will be improved later with more cluster info
// build cluster config information
clusterConfig := vclusterops.MakeClusterConfig()
dbConfig := vclusterops.MakeDatabaseConfig()

hosts, err := util.SplitHosts(*c.Hosts)
if err != nil {
return err
}
clusterConfig.Hosts = hosts

for _, h := range hosts {
nodeConfig := vclusterops.NodeConfig{}
nodeConfig.Address = h
dbConfig.Nodes = append(dbConfig.Nodes, nodeConfig)
}

clusterConfig := vclusterops.MakeClusterConfig()
clusterConfig[*c.DBName] = dbConfig

// write information to the YAML file
err = clusterConfig.WriteConfig(configFilePath)
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_remove_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *CmdRemoveNode) Run(log vlog.Printer) error {
vlog.LogPrintInfo("Successfully removed nodes %s from database %s", *c.hostToRemoveListStr, *options.DBName)

// write cluster information to the YAML config file.
err = vclusterops.WriteClusterConfig(&vdb, options.ConfigDirectory)
err = vdb.WriteClusterConfig(options.ConfigDirectory)
if err != nil {
vlog.LogPrintWarning("failed to write config file, details: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_remove_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *CmdRemoveSubcluster) Run(log vlog.Printer) error {
*c.removeScOptions.SubclusterToRemove, *c.removeScOptions.DBName)

// write cluster information to the YAML config file.
err = vclusterops.WriteClusterConfig(&vdb, c.removeScOptions.ConfigDirectory)
err = vdb.WriteClusterConfig(c.removeScOptions.ConfigDirectory)
if err != nil {
vcc.Log.PrintWarning("failed to write config file, details: %s", err)
}
Expand Down
16 changes: 8 additions & 8 deletions commands/cmd_revive_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
*/
type CmdReviveDB struct {
CmdBase
reviveDBOptions *vclusterops.VReviveDatabaseOptions
communalStorageParams *string // raw input from user, need further processing
reviveDBOptions *vclusterops.VReviveDatabaseOptions
configurationParams *string // raw input from user, need further processing
}

func makeCmdReviveDB() *CmdReviveDB {
Expand All @@ -35,8 +35,8 @@ func makeCmdReviveDB() *CmdReviveDB {

// optional flags
newCmd.ipv6 = newCmd.parser.Bool("ipv6", false, util.GetOptionalFlagMsg("Revive database with IPv6 hosts"))
newCmd.communalStorageParams = newCmd.parser.String("communal-storage-params", "", util.GetOptionalFlagMsg(
"Comma-separated list of NAME=VALUE pairs for communal storage parameters"))
newCmd.configurationParams = newCmd.parser.String("config-param", "", util.GetOptionalFlagMsg(
"Comma-separated list of NAME=VALUE pairs for configuration parameters"))
reviveDBOptions.ForceRemoval = newCmd.parser.Bool("force-removal", false,
util.GetOptionalFlagMsg("Force removal of existing database directories(exclude user storage directories) before reviving the database"))
reviveDBOptions.LoadCatalogTimeout = newCmd.parser.Uint("load-catalog-timeout", util.DefaultLoadCatalogTimeoutSeconds,
Expand Down Expand Up @@ -80,13 +80,13 @@ func (c *CmdReviveDB) Parse(inputArgv []string) error {
func (c *CmdReviveDB) validateParse() error {
vlog.LogInfo("[%s] Called validateParse()", c.CommandType())

// check the format of communal storage params string, and parse it into configParams
communalStorageParams, err := util.ParseConfigParams(*c.communalStorageParams)
// check the format of configuration params string, and parse it into configParams
configurationParams, err := util.ParseConfigParams(*c.configurationParams)
if err != nil {
return err
}
if communalStorageParams != nil {
c.reviveDBOptions.CommunalStorageParameters = communalStorageParams
if configurationParams != nil {
c.reviveDBOptions.ConfigurationParameters = configurationParams
}

// when --display-only is provided, we do not need to parse some base options like hostListStr
Expand Down
24 changes: 12 additions & 12 deletions commands/cmd_start_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type CmdStartDB struct {
CmdBase
startDBOptions *vclusterops.VStartDatabaseOptions

Force *bool // force cleanup to start the database
AllowFallbackKeygen *bool // Generate spread encryption key from Vertica. Use under support guidance only
IgnoreClusterLease *bool // ignore the cluster lease in communal storage
Unsafe *bool // Start database unsafely, skipping recovery.
Fast *bool // Attempt fast startup database
communalStorageParams *string // raw input from user, need further processing
Force *bool // force cleanup to start the database
AllowFallbackKeygen *bool // Generate spread encryption key from Vertica. Use under support guidance only
IgnoreClusterLease *bool // ignore the cluster lease in communal storage
Unsafe *bool // Start database unsafely, skipping recovery.
Fast *bool // Attempt fast startup database
configurationParams *string // raw input from user, need further processing
}

func makeCmdStartDB() *CmdStartDB {
Expand Down Expand Up @@ -57,8 +57,8 @@ func makeCmdStartDB() *CmdStartDB {
" Use it when you do not trust "+vclusterops.ConfigFileName))
startDBOptions.CommunalStorageLocation = newCmd.parser.String("communal-storage-location", "",
util.GetEonFlagMsg("Location of communal storage"))
newCmd.communalStorageParams = newCmd.parser.String("communal-storage-params", "", util.GetOptionalFlagMsg(
"Comma-separated list of NAME=VALUE pairs for communal storage parameters"))
newCmd.configurationParams = newCmd.parser.String("config-param", "", util.GetOptionalFlagMsg(
"Comma-separated list of NAME=VALUE pairs for configuration parameters"))

// hidden options
// TODO: the following options will be processed later
Expand Down Expand Up @@ -111,13 +111,13 @@ func (c *CmdStartDB) Parse(inputArgv []string) error {
func (c *CmdStartDB) validateParse() error {
vlog.LogInfo("[%s] Called validateParse()", c.CommandType())

// check the format of communal storage params string, and parse it into configParams
communalStorageParams, err := util.ParseConfigParams(*c.communalStorageParams)
// check the format of configuration params string, and parse it into configParams
configurationParams, err := util.ParseConfigParams(*c.configurationParams)
if err != nil {
return err
}
if communalStorageParams != nil {
c.startDBOptions.CommunalStorageParameters = communalStorageParams
if configurationParams != nil {
c.startDBOptions.ConfigurationParameters = configurationParams
}

return c.ValidateParseBaseOptions(&c.startDBOptions.DatabaseOptions)
Expand Down
11 changes: 9 additions & 2 deletions vclusterops/add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,18 @@ func (vcc *VClusterCommands) VAddNode(options *VAddNodeOptions) (VCoordinationDa
}

// get hosts from config file and options.
hosts := options.GetHosts(options.Config)
hosts, err := options.GetHosts(options.Config)
if err != nil {
return vdb, err
}

options.Hosts = hosts
// get depot and data prefix from config file or options.
// after VER-88122, we will able to get them from an https endpoint.
*options.DepotPrefix, *options.DataPrefix = options.getDepotAndDataPrefix(options.Config)
*options.DepotPrefix, *options.DataPrefix, err = options.getDepotAndDataPrefix(options.Config)
if err != nil {
return vdb, err
}

err = getVDBFromRunningDB(&vdb, &options.DatabaseOptions)
if err != nil {
Expand Down
12 changes: 10 additions & 2 deletions vclusterops/add_subcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ func (options *VAddSubclusterOptions) validateRequiredOptions() error {
}

func (options *VAddSubclusterOptions) validateEonOptions(config *ClusterConfig) error {
if !options.IsEonMode(config) {
isEon, err := options.IsEonMode(config)
if err != nil {
return err
}

if !isEon {
return fmt.Errorf("add subcluster is only supported in Eon mode")
}
return nil
Expand Down Expand Up @@ -194,7 +199,10 @@ func (vcc *VClusterCommands) VAddSubcluster(options *VAddSubclusterOptions) erro
ControlSetSize: *options.ControlSetSize,
CloneSC: *options.CloneSC,
}
addSubclusterInfo.DBName, addSubclusterInfo.Hosts = options.GetNameAndHosts(options.Config)
addSubclusterInfo.DBName, addSubclusterInfo.Hosts, err = options.GetNameAndHosts(options.Config)
if err != nil {
return err
}

instructions, err := produceAddSubclusterInstructions(&addSubclusterInfo, options)
if err != nil {
Expand Down
28 changes: 22 additions & 6 deletions vclusterops/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const (
const ConfigFileName = "vertica_cluster.yaml"
const ConfigBackupName = "vertica_cluster.yaml.backup"

type ClusterConfig struct {
DBName string `yaml:"db_name"`
Hosts []string `yaml:"hosts"`
// VER-89599: add config file version
type ClusterConfig map[string]DatabaseConfig

type DatabaseConfig struct {
Nodes []NodeConfig `yaml:"nodes"`
CatalogPath string `yaml:"catalog_path"`
DataPath string `yaml:"data_path"`
Expand All @@ -45,12 +46,17 @@ type ClusterConfig struct {
}

type NodeConfig struct {
Name string `yaml:"name"`
Address string `yaml:"address"`
Name string `yaml:"name"`
Address string `yaml:"address"`
Subcluster string `yaml:"subcluster"`
}

func MakeClusterConfig() ClusterConfig {
return ClusterConfig{}
return make(ClusterConfig)
}

func MakeDatabaseConfig() DatabaseConfig {
return DatabaseConfig{}
}

// read config information from the YAML file
Expand Down Expand Up @@ -86,6 +92,16 @@ func (c *ClusterConfig) WriteConfig(configFilePath string) error {
return nil
}

func (c *DatabaseConfig) GetHosts() []string {
var hostList []string

for _, vnode := range c.Nodes {
hostList = append(hostList, vnode.Address)
}

return hostList
}

func GetConfigFilePath(dbName string, inputConfigDir *string) (string, error) {
var configParentPath string

Expand Down
1 change: 0 additions & 1 deletion vclusterops/cluster_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func (status ResultStatus) getStatusString() string {
// log* implemented by embedding OpBase, but overrideable
type ClusterOp interface {
getName() string
setupClusterHTTPRequest(hosts []string) error
prepare(execContext *OpEngineExecContext) error
execute(execContext *OpEngineExecContext) error
finalize(execContext *OpEngineExecContext) error
Expand Down
Loading

0 comments on commit fa4852c

Please sign in to comment.