Skip to content

Commit

Permalink
Do not allow both exprimental flag and non-expriemntal flag to be set at
Browse files Browse the repository at this point in the history
the same time.

Signed-off-by: Jiayin Mao <jiayin.mao@datadoghq.com>
  • Loading branch information
jmao-dd committed Feb 1, 2025
1 parent 8d5be6e commit f541d78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ var (
// in 3.6, we are migration all the --experimental flags to feature gate and flags without the prefix.
// This is the mapping from the non boolean `experimental-` to the new flags.
// TODO: delete in v3.7
experimentalNonBoolFlagMigrationMap = map[string]string{
experimentalFlagMigrationMap = map[string]string{
"experimental-compact-hash-check-time": "compact-hash-check-time",
"experimental-corrupt-check-time": "corrupt-check-time",
"experimental-compaction-batch-limit": "compaction-batch-limit",
"experimental-watch-progress-notify-interval": "watch-progress-notify-interval",
"experimental-warning-apply-duration": "warning-apply-duration",
"experimental-bootstrap-defrag-threshold-megabytes": "bootstrap-defrag-threshold-megabytes",
"experimental-max-learners": "max-learners",
"experimental-memory-mlock": "memory-mlock",
}
)

Expand Down Expand Up @@ -1056,7 +1057,7 @@ func updateMinMaxVersions(info *transport.TLSInfo, min, max string) {
func (cfg *Config) Validate() error {
// make sure there is no conflict in the flag settings in the ExperimentalNonBoolFlagMigrationMap
// TODO: delete in v3.7
for oldFlag, newFlag := range experimentalNonBoolFlagMigrationMap {
for oldFlag, newFlag := range experimentalFlagMigrationMap {
if cfg.FlagsExplicitlySet[oldFlag] && cfg.FlagsExplicitlySet[newFlag] {
return fmt.Errorf("cannot set --%s and --%s at the same time, please use --%s only", oldFlag, newFlag, newFlag)
}
Expand Down
14 changes: 14 additions & 0 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,18 @@ func TestMemoryMlockFlagMigration(t *testing.T) {
memoryMlock bool
experimentalMemoryMlock bool
expectedMemoryMlock bool
expectErr bool
}{
{
name: "default",
expectedMemoryMlock: false,
},
{
name: "cannot set both experimental flag and non experimental flag",
memoryMlock: true,
experimentalMemoryMlock: true,
expectErr: true,
},
{
name: "can set experimental flag",
experimentalMemoryMlock: true,
Expand Down Expand Up @@ -991,6 +998,13 @@ func TestMemoryMlockFlagMigration(t *testing.T) {

cfgFromCmdLine, errFromCmdLine, cfgFromFile, errFromFile := generateCfgsFromFileAndCmdLine(t, yc, cmdLineArgs)

if tc.expectErr {
if errFromCmdLine == nil || errFromFile == nil {
t.Fatal("expect parse error")
}
return
}

if errFromCmdLine != nil || errFromFile != nil {
t.Fatal("error parsing config")
}
Expand Down

0 comments on commit f541d78

Please sign in to comment.