Skip to content

Commit

Permalink
Sync from server repo (3e78a0a727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Spilchen committed Oct 26, 2023
1 parent dd11a14 commit 6866bdf
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 33 deletions.
56 changes: 47 additions & 9 deletions vclusterops/cluster_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,20 @@ import (
)

const (
ConfigDirPerm = 0755
ConfigFilePerm = 0600
ConfigDirPerm = 0755
ConfigFilePerm = 0600
CurrentConfigFileVersion = 1
)

const ConfigFileName = "vertica_cluster.yaml"
const ConfigBackupName = "vertica_cluster.yaml.backup"

// VER-89599: add config file version
type Config struct {
Version int `yaml:"config_file_version"`
Databases ClusterConfig `yaml:"databases"`
}

// ClusterConfig holds information of the databases in the cluster
type ClusterConfig map[string]DatabaseConfig

type DatabaseConfig struct {
Expand Down Expand Up @@ -62,26 +68,48 @@ func MakeDatabaseConfig() DatabaseConfig {

// read config information from the YAML file
func ReadConfig(configDirectory string, log vlog.Printer) (ClusterConfig, error) {
clusterConfig := ClusterConfig{}

configFilePath := filepath.Join(configDirectory, ConfigFileName)
configBytes, err := os.ReadFile(configFilePath)
if err != nil {
return clusterConfig, fmt.Errorf("fail to read config file, details: %w", err)
return nil, fmt.Errorf("fail to read config file, details: %w", err)
}

err = yaml.Unmarshal(configBytes, &clusterConfig)
var config Config
err = yaml.Unmarshal(configBytes, &config)
if err != nil {
return clusterConfig, fmt.Errorf("fail to unmarshal config file, details: %w", err)
return nil, fmt.Errorf("fail to unmarshal config file, details: %w", err)
}

// the config file content will look like
/*
config_file_version: 1
databases:
test_db:
nodes:
- name: v_test_db_node0001
address: 192.168.1.101
subcluster: default_subcluster
catalog_path: /data
data_path: /data
depot_path: /data
...
eon_mode: false
communal_storage_location: ""
ipv6: false
*/

clusterConfig := config.Databases
log.PrintInfo("The content of cluster config: %+v\n", clusterConfig)
return clusterConfig, nil
}

// write config information to the YAML file
func (c *ClusterConfig) WriteConfig(configFilePath string) error {
configBytes, err := yaml.Marshal(&c)
var config Config
config.Version = CurrentConfigFileVersion
config.Databases = *c

configBytes, err := yaml.Marshal(&config)
if err != nil {
return fmt.Errorf("fail to marshal config data, details: %w", err)
}
Expand Down Expand Up @@ -186,3 +214,13 @@ func RemoveConfigFile(configDirectory string, log vlog.Printer) error {

return nil
}

// checkConfigFileExist checks whether config file exists under the given directory
func checkConfigFileExist(configDirectory *string) bool {
if configDirectory == nil {
return false
}

configPath := filepath.Join(*configDirectory, ConfigFileName)
return util.CheckPathExist(configPath)
}
10 changes: 9 additions & 1 deletion vclusterops/coordinator_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func (vnode *VCoordinationNode) SetFromNodeConfig(nodeConfig *NodeConfig, vdb *V
}
}

// WriteClusterConfig writes config information to a yaml file.
// WriteClusterConfig updates the yaml config file with the given vdb information
func (vdb *VCoordinationDatabase) WriteClusterConfig(configDir *string, log vlog.Printer) error {
/* build config information
*/
Expand All @@ -449,7 +449,15 @@ func (vdb *VCoordinationDatabase) WriteClusterConfig(configDir *string, log vlog
dbConfig.CommunalStorageLocation = vdb.CommunalStorageLocation
dbConfig.Ipv6 = vdb.Ipv6

// update cluster config with the given database info
clusterConfig := MakeClusterConfig()
if checkConfigFileExist(configDir) {
c, err := ReadConfig(*configDir, log)
if err != nil {
return err
}
clusterConfig = c
}
clusterConfig[vdb.Name] = dbConfig

/* write config to a YAML file
Expand Down
48 changes: 25 additions & 23 deletions vclusterops/test_data/vertica_cluster.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
practice_db:
nodes:
- name: node_name_1
address: ip_1
subcluster: default_subcluster
catalog_path: /data
data_path: /data
depot_path: /data
- name: node_name_2
address: ip_2
subcluster: default_subcluster
catalog_path: /data
data_path: /data
depot_path: /data
- name: node_name_3
address: ip_3
subcluster: default_subcluster
catalog_path: /data
data_path: /data
depot_path: /data
eon_mode: true
communal_storage_location: ""
ipv6: false
config_file_version: 1
databases:
practice_db:
nodes:
- name: node_name_1
address: ip_1
subcluster: default_subcluster
catalog_path: /data
data_path: /data
depot_path: /data
- name: node_name_2
address: ip_2
subcluster: default_subcluster
catalog_path: /data
data_path: /data
depot_path: /data
- name: node_name_3
address: ip_3
subcluster: default_subcluster
catalog_path: /data
data_path: /data
depot_path: /data
eon_mode: true
communal_storage_location: ""
ipv6: false

0 comments on commit 6866bdf

Please sign in to comment.