Skip to content

Commit

Permalink
migrate to use corrupt-check-time flag
Browse files Browse the repository at this point in the history
Signed-off-by: Gang Li <[email protected]>
  • Loading branch information
gangli113 committed Jan 9, 2025
1 parent aac7ef6 commit 12d8e79
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 3 deletions.
9 changes: 8 additions & 1 deletion server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ var (
// TODO: delete in v3.7
experimentalNonBoolFlagMigrationMap = map[string]string{
"experimental-compact-hash-check-time": "compact-hash-check-time",
"experimental-corrupt-check-time": "corrupt-check-time",
}
)

Expand Down Expand Up @@ -364,7 +365,11 @@ type Config struct {
AuthTokenTTL uint `json:"auth-token-ttl"`

ExperimentalInitialCorruptCheck bool `json:"experimental-initial-corrupt-check"`
// ExperimentalCorruptCheckTime is the duration of time between cluster corruption check passes.
// Deprecated in v3.6 and will be decommissioned in v3.7.
// TODO: delete in v3.7
ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time"`
CorruptCheckTime time.Duration `json:"corrupt-check-time"`
// ExperimentalCompactHashCheckEnabled enables leader to periodically check followers compaction hashes.
// Deprecated in v3.6 and will be decommissioned in v3.7.
// TODO: delete in v3.7
Expand Down Expand Up @@ -771,7 +776,9 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {

// experimental
fs.BoolVar(&cfg.ExperimentalInitialCorruptCheck, "experimental-initial-corrupt-check", cfg.ExperimentalInitialCorruptCheck, "Enable to check data corruption before serving any client/peer traffic.")
fs.DurationVar(&cfg.ExperimentalCorruptCheckTime, "experimental-corrupt-check-time", cfg.ExperimentalCorruptCheckTime, "Duration of time between cluster corruption check passes.")
// TODO: delete in v3.7
fs.DurationVar(&cfg.ExperimentalCorruptCheckTime, "experimental-corrupt-check-time", cfg.ExperimentalCorruptCheckTime, "Duration of time between cluster corruption check passes. Deprecated in v3.6 and will be decommissioned in v3.7. Use --corrupt-check-time instead")
fs.DurationVar(&cfg.CorruptCheckTime, "corrupt-check-time", cfg.CorruptCheckTime, "Duration of time between cluster corruption check passes.")
// TODO: delete in v3.7
fs.BoolVar(&cfg.ExperimentalCompactHashCheckEnabled, "experimental-compact-hash-check-enabled", cfg.ExperimentalCompactHashCheckEnabled, "Enable leader to periodically check followers compaction hashes. Deprecated in v3.6 and will be decommissioned in v3.7. Use '--feature-gates=CompactHashCheck=true' instead")
fs.DurationVar(&cfg.ExperimentalCompactHashCheckTime, "experimental-compact-hash-check-time", cfg.ExperimentalCompactHashCheckTime, "Duration of time between leader checks followers compaction hashes. Deprecated in v3.6 and will be decommissioned in v3.7. Use --compact-hash-check-time instead.")
Expand Down
2 changes: 1 addition & 1 deletion server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
TokenTTL: cfg.AuthTokenTTL,
CORS: cfg.CORS,
HostWhitelist: cfg.HostWhitelist,
CorruptCheckTime: cfg.ExperimentalCorruptCheckTime,
CorruptCheckTime: cfg.CorruptCheckTime,
CompactHashCheckTime: cfg.CompactHashCheckTime,
PreVote: cfg.PreVote,
Logger: cfg.logger,
Expand Down
5 changes: 5 additions & 0 deletions server/etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var (
"experimental-compact-hash-check-enabled": "--experimental-compact-hash-check-enabled is deprecated in 3.6 and will be decommissioned in 3.7. Use '--feature-gates=CompactHashCheck=true' instead.",
"experimental-compact-hash-check-time": "--experimental-compact-hash-check-time is deprecated in 3.6 and will be decommissioned in 3.7. Use '--compact-hash-check-time' instead.",
"experimental-txn-mode-write-with-shared-buffer": "--experimental-txn-mode-write-with-shared-buffer is deprecated in v3.6 and will be decommissioned in v3.7. Use '--feature-gates=TxnModeWriteWithSharedBuffer=true' instead.",
"experimental-corrupt-check-time": "--experimental-corrupt-check-time is deprecated in v3.6 and will be decommissioned in v3.7. Use '--corrupt-check-time' instead.",
}
)

Expand Down Expand Up @@ -174,6 +175,10 @@ func (cfg *config) parse(arguments []string) error {
cfg.ec.CompactHashCheckTime = cfg.ec.ExperimentalCompactHashCheckTime
}

if cfg.ec.FlagsExplicitlySet["experimental-corrupt-check-time"] {
cfg.ec.CorruptCheckTime = cfg.ec.ExperimentalCorruptCheckTime
}

// `V2Deprecation` (--v2-deprecation) is deprecated and scheduled for removal in v3.8. The default value is enforced, ignoring user input.
cfg.ec.V2Deprecation = cconfig.V2DeprDefault

Expand Down
89 changes: 89 additions & 0 deletions server/etcdmain/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,95 @@ func TestCompactHashCheckTimeFlagMigration(t *testing.T) {
}
}

// TestCorruptCheckTimeFlagMigration tests the migration from
// --experimental-corrupt-check-time to --corrupt-check-time
// TODO: delete in v3.7
func TestCorruptCheckTimeFlagMigration(t *testing.T) {
testCases := []struct {
name string
corruptCheckTime string
experimentalCorruptCheckTime string
useConfigFile bool
expectErr bool
expectedCorruptCheckTime time.Duration
}{
{
name: "cannot set both experimental flag and non experimental flag",
corruptCheckTime: "2m",
experimentalCorruptCheckTime: "3m",
expectErr: true,
},
{
name: "can set experimental flag",
experimentalCorruptCheckTime: "3m",
expectedCorruptCheckTime: 3 * time.Minute,
},
{
name: "can set non experimental flag",
corruptCheckTime: "2m",
expectedCorruptCheckTime: 2 * time.Minute,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
cmdLineArgs := []string{}
yc := struct {
ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time,omitempty"`
CorruptCheckTime time.Duration `json:"corrupt-check-time,omitempty"`
}{}

if tc.corruptCheckTime != "" {
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--corrupt-check-time=%s", tc.corruptCheckTime))
corruptCheckTime, err := time.ParseDuration(tc.corruptCheckTime)
if err != nil {
t.Fatal(err)
}
yc.CorruptCheckTime = corruptCheckTime
}

if tc.experimentalCorruptCheckTime != "" {
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--experimental-corrupt-check-time=%s", tc.experimentalCorruptCheckTime))
experimentalCorruptCheckTime, err := time.ParseDuration(tc.experimentalCorruptCheckTime)
if err != nil {
t.Fatal(err)
}
yc.ExperimentalCorruptCheckTime = experimentalCorruptCheckTime
}

b, err := yaml.Marshal(&yc)
if err != nil {
t.Fatal(err)
}

tmpfile := mustCreateCfgFile(t, b)
defer os.Remove(tmpfile.Name())

cfgFromCmdLine := newConfig()
errFromCmdLine := cfgFromCmdLine.parse(cmdLineArgs)

cfgFromFile := newConfig()
errFromFile := cfgFromFile.parse([]string{fmt.Sprintf("--config-file=%s", tmpfile.Name())})

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

if cfgFromCmdLine.ec.CorruptCheckTime != tc.expectedCorruptCheckTime {
t.Errorf("expected CorruptCheckTime=%v, got %v", tc.expectedCorruptCheckTime, cfgFromCmdLine.ec.CorruptCheckTime)
}
if cfgFromFile.ec.CorruptCheckTime != tc.expectedCorruptCheckTime {
t.Errorf("expected CorruptCheckTime=%v, got %v", tc.expectedCorruptCheckTime, cfgFromFile.ec.CorruptCheckTime)
}
})
}
}

func mustCreateCfgFile(t *testing.T, b []byte) *os.File {
tmpfile, err := os.CreateTemp("", "servercfg")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Experimental feature:
--experimental-initial-corrupt-check 'false'. It's deprecated, and will be decommissioned in v3.7. Use '--feature-gates=InitialCorruptCheck=true' instead.
Enable to check data corruption before serving any client/peer traffic.
--experimental-corrupt-check-time '0s'
Duration of time between cluster corruption check passes.
Duration of time between cluster corruption check passes. Deprecated in v3.6 and will be decommissioned in v3.7. Use 'corrupt-check-time' instead.
--experimental-compact-hash-check-enabled 'false'. Deprecated in v3.6 and will be decommissioned in v3.7. Use '--feature-gates=CompactHashCheck=true' instead.
Enable leader to periodically check followers compaction hashes.
--experimental-compact-hash-check-time '1m'
Expand Down

0 comments on commit 12d8e79

Please sign in to comment.