Skip to content

Commit 93a9760

Browse files
ZhengYa-0110SongZhen0704
authored andcommitted
fix: incorrect check of metadb enabled
1 parent 1d768d5 commit 93a9760

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

server/controller/config/config.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,25 @@ type Config struct {
120120
}
121121

122122
func (c *Config) Validate() error {
123-
if !c.ControllerConfig.MySqlCfg.Enabled && !c.ControllerConfig.PostgreSQLCfg.Enabled {
124-
return fmt.Errorf("mysql or postgresql must be enabled")
125-
}
126-
if c.ControllerConfig.MySqlCfg.Enabled && c.ControllerConfig.PostgreSQLCfg.Enabled {
127-
return fmt.Errorf("mysql and postgresql can not be enabled at the same time")
123+
if !c.exactlyOneMetadbEnabled() {
124+
return fmt.Errorf("only one metadb can be enabled at the same time")
128125
}
129126
return nil
130127
}
131128

129+
func (c *Config) exactlyOneMetadbEnabled() bool {
130+
count := 0
131+
for _, enabled := range []bool{c.ControllerConfig.MySqlCfg.Enabled, c.ControllerConfig.PostgreSQLCfg.Enabled, c.ControllerConfig.DMCfg.Enabled} {
132+
if enabled {
133+
count++
134+
if count > 1 {
135+
return false
136+
}
137+
}
138+
}
139+
return count == 1
140+
}
141+
132142
func (c *Config) Load(path string) {
133143
configBytes, err := os.ReadFile(path)
134144
if err != nil {

0 commit comments

Comments
 (0)