Skip to content

Commit 5813dce

Browse files
authored
Merge pull request #19156 from gangli113/experimentalFlag
migrate flag experimental-corrupt-check-time to use corrupt-check-time
2 parents ccda73a + c6f817e commit 5813dce

File tree

7 files changed

+129
-5
lines changed

7 files changed

+129
-5
lines changed

server/embed/config.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ var (
134134
// TODO: delete in v3.7
135135
experimentalNonBoolFlagMigrationMap = map[string]string{
136136
"experimental-compact-hash-check-time": "compact-hash-check-time",
137+
"experimental-corrupt-check-time": "corrupt-check-time",
137138
}
138139
)
139140

@@ -363,8 +364,12 @@ type Config struct {
363364
// AuthTokenTTL in seconds of the simple token
364365
AuthTokenTTL uint `json:"auth-token-ttl"`
365366

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

772777
// experimental
773778
fs.BoolVar(&cfg.ExperimentalInitialCorruptCheck, "experimental-initial-corrupt-check", cfg.ExperimentalInitialCorruptCheck, "Enable to check data corruption before serving any client/peer traffic.")
774-
fs.DurationVar(&cfg.ExperimentalCorruptCheckTime, "experimental-corrupt-check-time", cfg.ExperimentalCorruptCheckTime, "Duration of time between cluster corruption check passes.")
779+
// TODO: delete in v3.7
780+
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")
781+
fs.DurationVar(&cfg.CorruptCheckTime, "corrupt-check-time", cfg.CorruptCheckTime, "Duration of time between cluster corruption check passes.")
775782
// TODO: delete in v3.7
776783
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")
777784
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.")

server/embed/etcd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
205205
TokenTTL: cfg.AuthTokenTTL,
206206
CORS: cfg.CORS,
207207
HostWhitelist: cfg.HostWhitelist,
208-
CorruptCheckTime: cfg.ExperimentalCorruptCheckTime,
208+
CorruptCheckTime: cfg.CorruptCheckTime,
209209
CompactHashCheckTime: cfg.CompactHashCheckTime,
210210
PreVote: cfg.PreVote,
211211
Logger: cfg.logger,

server/etcdmain/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ var (
6565
"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.",
6666
"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.",
6767
"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.",
68+
"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.",
6869
}
6970
)
7071

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

178+
if cfg.ec.FlagsExplicitlySet["experimental-corrupt-check-time"] {
179+
cfg.ec.CorruptCheckTime = cfg.ec.ExperimentalCorruptCheckTime
180+
}
181+
177182
// `V2Deprecation` (--v2-deprecation) is deprecated and scheduled for removal in v3.8. The default value is enforced, ignoring user input.
178183
cfg.ec.V2Deprecation = cconfig.V2DeprDefault
179184

server/etcdmain/config_test.go

+92
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,95 @@ func TestCompactHashCheckTimeFlagMigration(t *testing.T) {
570570
}
571571
}
572572

573+
// TestCorruptCheckTimeFlagMigration tests the migration from
574+
// --experimental-corrupt-check-time to --corrupt-check-time
575+
// TODO: delete in v3.7
576+
func TestCorruptCheckTimeFlagMigration(t *testing.T) {
577+
testCases := []struct {
578+
name string
579+
corruptCheckTime string
580+
experimentalCorruptCheckTime string
581+
useConfigFile bool
582+
expectErr bool
583+
expectedCorruptCheckTime time.Duration
584+
}{
585+
{
586+
name: "cannot set both experimental flag and non experimental flag",
587+
corruptCheckTime: "2m",
588+
experimentalCorruptCheckTime: "3m",
589+
expectErr: true,
590+
},
591+
{
592+
name: "can set experimental flag",
593+
experimentalCorruptCheckTime: "3m",
594+
expectedCorruptCheckTime: 3 * time.Minute,
595+
},
596+
{
597+
name: "can set non experimental flag",
598+
corruptCheckTime: "2m",
599+
expectedCorruptCheckTime: 2 * time.Minute,
600+
},
601+
}
602+
for _, tc := range testCases {
603+
t.Run(tc.name, func(t *testing.T) {
604+
cmdLineArgs := []string{}
605+
yc := struct {
606+
ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time,omitempty"`
607+
CorruptCheckTime time.Duration `json:"corrupt-check-time,omitempty"`
608+
}{}
609+
610+
if tc.corruptCheckTime != "" {
611+
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--corrupt-check-time=%s", tc.corruptCheckTime))
612+
corruptCheckTime, err := time.ParseDuration(tc.corruptCheckTime)
613+
if err != nil {
614+
t.Fatal(err)
615+
}
616+
yc.CorruptCheckTime = corruptCheckTime
617+
}
618+
619+
if tc.experimentalCorruptCheckTime != "" {
620+
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--experimental-corrupt-check-time=%s", tc.experimentalCorruptCheckTime))
621+
experimentalCorruptCheckTime, err := time.ParseDuration(tc.experimentalCorruptCheckTime)
622+
if err != nil {
623+
t.Fatal(err)
624+
}
625+
yc.ExperimentalCorruptCheckTime = experimentalCorruptCheckTime
626+
}
627+
628+
b, err := yaml.Marshal(&yc)
629+
if err != nil {
630+
t.Fatal(err)
631+
}
632+
633+
tmpfile := mustCreateCfgFile(t, b)
634+
defer os.Remove(tmpfile.Name())
635+
636+
cfgFromCmdLine := newConfig()
637+
errFromCmdLine := cfgFromCmdLine.parse(cmdLineArgs)
638+
639+
cfgFromFile := newConfig()
640+
errFromFile := cfgFromFile.parse([]string{fmt.Sprintf("--config-file=%s", tmpfile.Name())})
641+
642+
if tc.expectErr {
643+
if errFromCmdLine == nil || errFromFile == nil {
644+
t.Fatal("expect parse error")
645+
}
646+
return
647+
}
648+
if errFromCmdLine != nil || errFromFile != nil {
649+
t.Fatal(err)
650+
}
651+
652+
if cfgFromCmdLine.ec.CorruptCheckTime != tc.expectedCorruptCheckTime {
653+
t.Errorf("expected CorruptCheckTime=%v, got %v", tc.expectedCorruptCheckTime, cfgFromCmdLine.ec.CorruptCheckTime)
654+
}
655+
if cfgFromFile.ec.CorruptCheckTime != tc.expectedCorruptCheckTime {
656+
t.Errorf("expected CorruptCheckTime=%v, got %v", tc.expectedCorruptCheckTime, cfgFromFile.ec.CorruptCheckTime)
657+
}
658+
})
659+
}
660+
}
661+
573662
func mustCreateCfgFile(t *testing.T, b []byte) *os.File {
574663
tmpfile, err := os.CreateTemp("", "servercfg")
575664
if err != nil {
@@ -663,6 +752,7 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
663752
ExperimentalCompactHashCheckEnabled bool `json:"experimental-compact-hash-check-enabled,omitempty"`
664753
ExperimentalCompactHashCheckTime time.Duration `json:"experimental-compact-hash-check-time,omitempty"`
665754
ExperimentalWarningUnaryRequestDuration time.Duration `json:"experimental-warning-unary-request-duration,omitempty"`
755+
ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time,omitempty"`
666756
}
667757

668758
testCases := []struct {
@@ -681,10 +771,12 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
681771
ExperimentalCompactHashCheckEnabled: true,
682772
ExperimentalCompactHashCheckTime: 2 * time.Minute,
683773
ExperimentalWarningUnaryRequestDuration: time.Second,
774+
ExperimentalCorruptCheckTime: time.Minute,
684775
},
685776
expectedFlags: map[string]struct{}{
686777
"experimental-compact-hash-check-enabled": {},
687778
"experimental-compact-hash-check-time": {},
779+
"experimental-corrupt-check-time": {},
688780
},
689781
},
690782
{

server/etcdmain/help.go

+2
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ Experimental feature:
276276
--experimental-initial-corrupt-check 'false'. It's deprecated, and will be decommissioned in v3.7. Use '--feature-gates=InitialCorruptCheck=true' instead.
277277
Enable to check data corruption before serving any client/peer traffic.
278278
--experimental-corrupt-check-time '0s'
279+
Duration of time between cluster corruption check passes. Deprecated in v3.6 and will be decommissioned in v3.7. Use 'corrupt-check-time' instead.
280+
--corrupt-check-time '0s'
279281
Duration of time between cluster corruption check passes.
280282
--experimental-compact-hash-check-enabled 'false'. Deprecated in v3.6 and will be decommissioned in v3.7. Use '--feature-gates=CompactHashCheck=true' instead.
281283
Enable leader to periodically check followers compaction hashes.

tests/e2e/corrupt_test.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,27 @@ func TestInPlaceRecovery(t *testing.T) {
188188
}
189189

190190
func TestPeriodicCheckDetectsCorruption(t *testing.T) {
191+
testPeriodicCheckDetectsCorruption(t, false)
192+
}
193+
194+
func TestPeriodicCheckDetectsCorruptionWithExperimentalFlag(t *testing.T) {
195+
testPeriodicCheckDetectsCorruption(t, true)
196+
}
197+
198+
func testPeriodicCheckDetectsCorruption(t *testing.T, useExperimentalFlag bool) {
191199
checkTime := time.Second
192200
e2e.BeforeTest(t)
193201
ctx, cancel := context.WithCancel(context.Background())
194202
defer cancel()
203+
var corruptCheckTime e2e.EPClusterOption
204+
if useExperimentalFlag {
205+
corruptCheckTime = e2e.WithExperimentalCorruptCheckTime(time.Second)
206+
} else {
207+
corruptCheckTime = e2e.WithCorruptCheckTime(time.Second)
208+
}
195209
epc, err := e2e.NewEtcdProcessCluster(ctx, t,
196210
e2e.WithKeepDataDir(true),
197-
e2e.WithCorruptCheckTime(time.Second),
211+
corruptCheckTime,
198212
)
199213
if err != nil {
200214
t.Fatalf("could not start etcd process cluster (%v)", err)

tests/framework/e2e/cluster.go

+4
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ func WithLogLevel(level string) EPClusterOption {
313313
}
314314

315315
func WithCorruptCheckTime(time time.Duration) EPClusterOption {
316+
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.CorruptCheckTime = time }
317+
}
318+
319+
func WithExperimentalCorruptCheckTime(time time.Duration) EPClusterOption {
316320
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.ExperimentalCorruptCheckTime = time }
317321
}
318322

0 commit comments

Comments
 (0)