Skip to content

Commit

Permalink
Sync from server repo (b7544ad8cce)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed May 6, 2024
1 parent 1f30293 commit 78ff367
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
4 changes: 2 additions & 2 deletions commands/cmd_add_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func makeCmdAddNode() *cobra.Command {
"Add host(s) to an existing database",
`This subcommand adds one or more hosts to an existing database.
You must provide the --add option followed by one or more hosts to add as a
comma-separated list.
You must provide the --new-hosts option followed by one or more hosts to add as
a comma-separated list.
You cannot add hosts to a sandbox subcluster in an Eon Mode database.
Expand Down
40 changes: 38 additions & 2 deletions commands/cmd_sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,44 @@ func (c *CmdSandboxSubcluster) Run(vcc vclusterops.ClusterCommands) error {
options := c.sbOptions

err := vcc.VSandbox(&options)
vcc.PrintInfo("Completed method Run() for command " + sandboxSubCmd)
return err
if err != nil {
return err
}

defer vcc.PrintInfo("Successfully sandboxed subcluster " + c.sbOptions.SCName + " as " + c.sbOptions.SandboxName)
// Read and then update the sandbox information on config file
dbConfig, configErr := readConfig()
if configErr != nil {
vcc.PrintWarning("fail to read config file, skipping config file update", "error", configErr)
return nil
}
// Update config
updatedConfig := c.updateSandboxInfo(dbConfig)
if !updatedConfig {
vcc.PrintWarning("did not update node info for sandboxed sc " + c.sbOptions.SCName +
", info about the subcluster nodes are missing in config file, skipping config update")
return nil
}

writeErr := dbConfig.write(options.ConfigPath)
if writeErr != nil {
vcc.PrintWarning("fail to write the config file, details: " + writeErr.Error())
return nil
}
return nil
}

// updateSandboxInfo will update sandbox info for the sandboxed subcluster in the config object
// returns true if the info are updated, returns false if no info is updated
func (c *CmdSandboxSubcluster) updateSandboxInfo(dbConfig *DatabaseConfig) bool {
needToUpdate := false
for _, n := range dbConfig.Nodes {
if c.sbOptions.SCName == n.Subcluster {
n.Sandbox = c.sbOptions.SandboxName
needToUpdate = true
}
}
return needToUpdate
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdSandboxSubcluster
Expand Down
42 changes: 40 additions & 2 deletions commands/cmd_unsandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package commands

import (
"fmt"

"github.com/spf13/cobra"
"github.com/vertica/vcluster/vclusterops"
"github.com/vertica/vcluster/vclusterops/vlog"
Expand Down Expand Up @@ -129,8 +131,44 @@ func (c *CmdUnsandboxSubcluster) Run(vcc vclusterops.ClusterCommands) error {
options := c.usOptions

err := vcc.VUnsandbox(&options)
vcc.PrintInfo("Completed method Run() for command " + unsandboxSubCmd)
return err
if err != nil {
return err
}

defer vcc.PrintInfo("Successfully unsandboxed subcluster " + c.usOptions.SCName)
// Read and then update the sandbox information on config file
dbConfig, configErr := c.resetSandboxInfo()
if configErr != nil {
vcc.PrintWarning("fail to update config file : ", "error", configErr)
return nil
}

writeErr := dbConfig.write(options.ConfigPath)
if writeErr != nil {
vcc.PrintWarning("fail to write the config file, details: " + writeErr.Error())
return nil
}
return nil
}

// resetSandboxInfo will reset sandbox info for the unsandboxed subcluster to empty in the config object
func (c *CmdUnsandboxSubcluster) resetSandboxInfo() (*DatabaseConfig, error) {
writeRequired := false
dbConfig, err := readConfig()
if err != nil {
return nil, fmt.Errorf("fail to read config file: %v", err)
}
for _, n := range dbConfig.Nodes {
if c.usOptions.SCName == n.Subcluster {
n.Sandbox = ""
writeRequired = true
}
}
if !writeRequired {
return dbConfig, fmt.Errorf("node info for sc %s missing in config file",
c.usOptions.SCName)
}
return dbConfig, nil
}

// SetDatabaseOptions will assign a vclusterops.DatabaseOptions instance to the one in CmdUnsandboxSubcluster
Expand Down
2 changes: 2 additions & 0 deletions commands/vcluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type NodeConfig struct {
CatalogPath string `yaml:"catalogPath" mapstructure:"catalogPath"`
DataPath string `yaml:"dataPath" mapstructure:"dataPath"`
DepotPath string `yaml:"depotPath" mapstructure:"depotPath"`
Sandbox string `yaml:"sandbox" mapstructure:"sandbox"` // Name of the sandbox the node belongs to
}

// MakeDatabaseConfig() can create an instance of DatabaseConfig
Expand Down Expand Up @@ -243,6 +244,7 @@ func readVDBToDBConfig(vdb *vclusterops.VCoordinationDatabase) (DatabaseConfig,
nodeConfig.Name = vnode.Name
nodeConfig.Address = vnode.Address
nodeConfig.Subcluster = vnode.Subcluster
nodeConfig.Sandbox = vnode.Sandbox

// VER-91869 will replace the path prefixes with full paths
if vdb.CatalogPrefix == "" {
Expand Down
2 changes: 2 additions & 0 deletions vclusterops/http_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func (adapter *httpAdapter) sendRequest(request *hostHTTPRequest, resultChannel
resultChannel <- adapter.makeExceptionResult(err)
return
}
// close the connection after sending the request (for clients)
req.Close = true

// set username and password
// which is only used for HTTPS endpoints
Expand Down

0 comments on commit 78ff367

Please sign in to comment.