Skip to content

Commit 959d898

Browse files
committed
TestConfigFileDeprecatedOptions
1 parent 76d836f commit 959d898

File tree

9 files changed

+132
-41
lines changed

9 files changed

+132
-41
lines changed

server/embed/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ var (
135135
experimentalNonBoolFlagMigrationMap = map[string]string{
136136
"experimental-compact-hash-check-time": "compact-hash-check-time",
137137
"experimental-corrupt-check-time": "corrupt-check-time",
138+
"experimental-compaction-batch-limit": "compaction-batch-limit",
138139
}
139140
)
140141

@@ -387,7 +388,11 @@ type Config struct {
387388
// Deprecated in v3.6.
388389
// TODO: Delete in v3.7
389390
ExperimentalEnableLeaseCheckpointPersist bool `json:"experimental-enable-lease-checkpoint-persist"`
390-
ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit"`
391+
// ExperimentalCompactionBatchLimit Sets the maximum revisions deleted in each compaction batch.
392+
// Deprecated in v3.6 and will be decommissioned in v3.7.
393+
// TODO: Delete in v3.7
394+
ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit"`
395+
CompactionBatchLimit int `json:"compaction-batch-limit"`
391396
// ExperimentalCompactionSleepInterval is the sleep interval between every etcd compaction loop.
392397
ExperimentalCompactionSleepInterval time.Duration `json:"experimental-compaction-sleep-interval"`
393398
ExperimentalWatchProgressNotifyInterval time.Duration `json:"experimental-watch-progress-notify-interval"`
@@ -788,7 +793,9 @@ func (cfg *Config) AddFlags(fs *flag.FlagSet) {
788793
fs.BoolVar(&cfg.ExperimentalEnableLeaseCheckpoint, "experimental-enable-lease-checkpoint", false, "Enable leader to send regular checkpoints to other members to prevent reset of remaining TTL on leader change.")
789794
// TODO: delete in v3.7
790795
fs.BoolVar(&cfg.ExperimentalEnableLeaseCheckpointPersist, "experimental-enable-lease-checkpoint-persist", false, "Enable persisting remainingTTL to prevent indefinite auto-renewal of long lived leases. Always enabled in v3.6. Should be used to ensure smooth upgrade from v3.5 clusters with this feature enabled. Requires experimental-enable-lease-checkpoint to be enabled.")
791-
fs.IntVar(&cfg.ExperimentalCompactionBatchLimit, "experimental-compaction-batch-limit", cfg.ExperimentalCompactionBatchLimit, "Sets the maximum revisions deleted in each compaction batch.")
796+
// TODO: delete in v3.7
797+
fs.IntVar(&cfg.ExperimentalCompactionBatchLimit, "experimental-compaction-batch-limit", cfg.ExperimentalCompactionBatchLimit, "Sets the maximum revisions deleted in each compaction batch. Deprecated in v3.6 and will be decommissioned in v3.7. Use --compaction-batch-limit instead.")
798+
fs.IntVar(&cfg.CompactionBatchLimit, "compaction-batch-limit", cfg.CompactionBatchLimit, "Sets the maximum revisions deleted in each compaction batch.")
792799
fs.DurationVar(&cfg.ExperimentalCompactionSleepInterval, "experimental-compaction-sleep-interval", cfg.ExperimentalCompactionSleepInterval, "Sets the sleep interval between each compaction batch.")
793800
fs.DurationVar(&cfg.ExperimentalWatchProgressNotifyInterval, "experimental-watch-progress-notify-interval", cfg.ExperimentalWatchProgressNotifyInterval, "Duration of periodic watch progress notifications.")
794801
fs.DurationVar(&cfg.ExperimentalDowngradeCheckTime, "experimental-downgrade-check-time", cfg.ExperimentalDowngradeCheckTime, "Duration of time between two downgrade status checks.")

server/embed/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
215215
UnsafeNoFsync: cfg.UnsafeNoFsync,
216216
EnableLeaseCheckpoint: cfg.ExperimentalEnableLeaseCheckpoint,
217217
LeaseCheckpointPersist: cfg.ExperimentalEnableLeaseCheckpointPersist,
218-
CompactionBatchLimit: cfg.ExperimentalCompactionBatchLimit,
218+
CompactionBatchLimit: cfg.CompactionBatchLimit,
219219
CompactionSleepInterval: cfg.ExperimentalCompactionSleepInterval,
220220
WatchProgressNotifyInterval: cfg.ExperimentalWatchProgressNotifyInterval,
221221
DowngradeCheckTime: cfg.ExperimentalDowngradeCheckTime,

server/etcdmain/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var (
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.",
6868
"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.",
69+
"experimental-compaction-batch-limit": "--experimental-compaction-batch-limit is deprecated in v3.6 and will be decommissioned in v3.7. Use '--compaction-batch-limit' instead.",
6970
}
7071
)
7172

@@ -179,6 +180,10 @@ func (cfg *config) parse(arguments []string) error {
179180
cfg.ec.CorruptCheckTime = cfg.ec.ExperimentalCorruptCheckTime
180181
}
181182

183+
if cfg.ec.FlagsExplicitlySet["experimental-compaction-batch-limit"] {
184+
cfg.ec.CompactionBatchLimit = cfg.ec.ExperimentalCompactionBatchLimit
185+
}
186+
182187
// `V2Deprecation` (--v2-deprecation) is deprecated and scheduled for removal in v3.8. The default value is enforced, ignoring user input.
183188
cfg.ec.V2Deprecation = cconfig.V2DeprDefault
184189

server/etcdmain/config_test.go

Lines changed: 93 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ func TestCompactHashCheckTimeFlagMigration(t *testing.T) {
485485
name string
486486
compactHashCheckTime string
487487
experimentalCompactHashCheckTime string
488-
useConfigFile bool
489488
expectErr bool
490489
expectedCompactHashCheckTime time.Duration
491490
}{
@@ -536,19 +535,7 @@ func TestCompactHashCheckTimeFlagMigration(t *testing.T) {
536535
yc.ExperimentalCompactHashCheckTime = experimentalCompactHashCheckTime
537536
}
538537

539-
b, err := yaml.Marshal(&yc)
540-
if err != nil {
541-
t.Fatal(err)
542-
}
543-
544-
tmpfile := mustCreateCfgFile(t, b)
545-
defer os.Remove(tmpfile.Name())
546-
547-
cfgFromCmdLine := newConfig()
548-
errFromCmdLine := cfgFromCmdLine.parse(cmdLineArgs)
549-
550-
cfgFromFile := newConfig()
551-
errFromFile := cfgFromFile.parse([]string{fmt.Sprintf("--config-file=%s", tmpfile.Name())})
538+
cfgFromCmdLine, errFromCmdLine, cfgFromFile, errFromFile := generateCfgsFromFileAndCmdLine(t, yc, cmdLineArgs)
552539

553540
if tc.expectErr {
554541
if errFromCmdLine == nil || errFromFile == nil {
@@ -557,7 +544,7 @@ func TestCompactHashCheckTimeFlagMigration(t *testing.T) {
557544
return
558545
}
559546
if errFromCmdLine != nil || errFromFile != nil {
560-
t.Fatal(err)
547+
t.Fatal("error parsing config")
561548
}
562549

563550
if cfgFromCmdLine.ec.CompactHashCheckTime != tc.expectedCompactHashCheckTime {
@@ -578,7 +565,6 @@ func TestCorruptCheckTimeFlagMigration(t *testing.T) {
578565
name string
579566
corruptCheckTime string
580567
experimentalCorruptCheckTime string
581-
useConfigFile bool
582568
expectErr bool
583569
expectedCorruptCheckTime time.Duration
584570
}{
@@ -625,19 +611,7 @@ func TestCorruptCheckTimeFlagMigration(t *testing.T) {
625611
yc.ExperimentalCorruptCheckTime = experimentalCorruptCheckTime
626612
}
627613

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())})
614+
cfgFromCmdLine, errFromCmdLine, cfgFromFile, errFromFile := generateCfgsFromFileAndCmdLine(t, yc, cmdLineArgs)
641615

642616
if tc.expectErr {
643617
if errFromCmdLine == nil || errFromFile == nil {
@@ -646,7 +620,7 @@ func TestCorruptCheckTimeFlagMigration(t *testing.T) {
646620
return
647621
}
648622
if errFromCmdLine != nil || errFromFile != nil {
649-
t.Fatal(err)
623+
t.Fatal("error parsing config")
650624
}
651625

652626
if cfgFromCmdLine.ec.CorruptCheckTime != tc.expectedCorruptCheckTime {
@@ -659,6 +633,92 @@ func TestCorruptCheckTimeFlagMigration(t *testing.T) {
659633
}
660634
}
661635

636+
// TestCompactionBatchLimitFlagMigration tests the migration from
637+
// --experimental-compaction-batch-limit to --compaction-batch-limit
638+
// TODO: delete in v3.7
639+
func TestCompactionBatchLimitFlagMigration(t *testing.T) {
640+
testCases := []struct {
641+
name string
642+
compactionBatchLimit int
643+
experimentalCompactionBatchLimit int
644+
expectErr bool
645+
expectedCompactionBatchLimit int
646+
}{
647+
{
648+
name: "cannot set both experimental flag and non experimental flag",
649+
compactionBatchLimit: 1,
650+
experimentalCompactionBatchLimit: 2,
651+
expectErr: true,
652+
},
653+
{
654+
name: "can set experimental flag",
655+
experimentalCompactionBatchLimit: 2,
656+
expectedCompactionBatchLimit: 2,
657+
},
658+
{
659+
name: "can set non experimental flag",
660+
compactionBatchLimit: 1,
661+
expectedCompactionBatchLimit: 1,
662+
},
663+
}
664+
for _, tc := range testCases {
665+
t.Run(tc.name, func(t *testing.T) {
666+
cmdLineArgs := []string{}
667+
yc := struct {
668+
ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit,omitempty"`
669+
CompactionBatchLimit int `json:"compaction-batch-limit,omitempty"`
670+
}{}
671+
672+
if tc.compactionBatchLimit != 0 {
673+
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--compaction-batch-limit=%d", tc.compactionBatchLimit))
674+
yc.CompactionBatchLimit = tc.compactionBatchLimit
675+
}
676+
677+
if tc.experimentalCompactionBatchLimit != 0 {
678+
cmdLineArgs = append(cmdLineArgs, fmt.Sprintf("--experimental-compaction-batch-limit=%d", tc.experimentalCompactionBatchLimit))
679+
yc.ExperimentalCompactionBatchLimit = tc.experimentalCompactionBatchLimit
680+
}
681+
682+
cfgFromCmdLine, errFromCmdLine, cfgFromFile, errFromFile := generateCfgsFromFileAndCmdLine(t, yc, cmdLineArgs)
683+
684+
if tc.expectErr {
685+
if errFromCmdLine == nil || errFromFile == nil {
686+
t.Fatal("expect parse error")
687+
}
688+
return
689+
}
690+
if errFromCmdLine != nil || errFromFile != nil {
691+
t.Fatal("error parsing config")
692+
}
693+
694+
if cfgFromCmdLine.ec.CompactionBatchLimit != tc.expectedCompactionBatchLimit {
695+
t.Errorf("expected CorruptCheckTime=%v, got %v", tc.expectedCompactionBatchLimit, cfgFromCmdLine.ec.CompactionBatchLimit)
696+
}
697+
if cfgFromFile.ec.CompactionBatchLimit != tc.expectedCompactionBatchLimit {
698+
t.Errorf("expected CorruptCheckTime=%v, got %v", tc.expectedCompactionBatchLimit, cfgFromFile.ec.CompactionBatchLimit)
699+
}
700+
})
701+
}
702+
}
703+
704+
// TODO delete in v3.7
705+
func generateCfgsFromFileAndCmdLine(t *testing.T, yc interface{}, cmdLineArgs []string) (*config, error, *config, error) {
706+
b, err := yaml.Marshal(&yc)
707+
if err != nil {
708+
t.Fatal(err)
709+
}
710+
711+
tmpfile := mustCreateCfgFile(t, b)
712+
defer os.Remove(tmpfile.Name())
713+
714+
cfgFromCmdLine := newConfig()
715+
errFromCmdLine := cfgFromCmdLine.parse(cmdLineArgs)
716+
717+
cfgFromFile := newConfig()
718+
errFromFile := cfgFromFile.parse([]string{fmt.Sprintf("--config-file=%s", tmpfile.Name())})
719+
return cfgFromCmdLine, errFromCmdLine, cfgFromFile, errFromFile
720+
}
721+
662722
func mustCreateCfgFile(t *testing.T, b []byte) *os.File {
663723
tmpfile, err := os.CreateTemp("", "servercfg")
664724
if err != nil {
@@ -753,6 +813,7 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
753813
ExperimentalCompactHashCheckTime time.Duration `json:"experimental-compact-hash-check-time,omitempty"`
754814
ExperimentalWarningUnaryRequestDuration time.Duration `json:"experimental-warning-unary-request-duration,omitempty"`
755815
ExperimentalCorruptCheckTime time.Duration `json:"experimental-corrupt-check-time,omitempty"`
816+
ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit,omitempty"`
756817
}
757818

758819
testCases := []struct {
@@ -772,11 +833,13 @@ func TestConfigFileDeprecatedOptions(t *testing.T) {
772833
ExperimentalCompactHashCheckTime: 2 * time.Minute,
773834
ExperimentalWarningUnaryRequestDuration: time.Second,
774835
ExperimentalCorruptCheckTime: time.Minute,
836+
ExperimentalCompactionBatchLimit: 1,
775837
},
776838
expectedFlags: map[string]struct{}{
777839
"experimental-compact-hash-check-enabled": {},
778840
"experimental-compact-hash-check-time": {},
779841
"experimental-corrupt-check-time": {},
842+
"experimental-compaction-batch-limit": {},
780843
},
781844
},
782845
{

server/etcdmain/help.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ Experimental feature:
288288
--experimental-enable-lease-checkpoint 'false'
289289
ExperimentalEnableLeaseCheckpoint enables primary lessor to persist lease remainingTTL to prevent indefinite auto-renewal of long lived leases.
290290
--experimental-compaction-batch-limit 1000
291-
ExperimentalCompactionBatchLimit sets the maximum revisions deleted in each compaction batch.
291+
ExperimentalCompactionBatchLimit sets the maximum revisions deleted in each compaction batch. Deprecated in v3.6 and will be decommissioned in v3.7. Use 'compaction-batch-limit' instead.
292+
--compaction-batch-limit 1000
293+
CompactionBatchLimit sets the maximum revisions deleted in each compaction batch.
292294
--experimental-peer-skip-client-san-verification 'false'
293295
Skip verification of SAN field in client certificate for peer connections.
294296
--experimental-watch-progress-notify-interval '10m'

tests/e2e/corrupt_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,18 @@ func testCompactHashCheckDetectCorruption(t *testing.T, useFeatureGate bool) {
294294
}
295295

296296
func TestCompactHashCheckDetectCorruptionInterrupt(t *testing.T) {
297-
testCompactHashCheckDetectCorruptionInterrupt(t, false)
297+
testCompactHashCheckDetectCorruptionInterrupt(t, false, false)
298298
}
299299

300300
func TestCompactHashCheckDetectCorruptionInterruptWithFeatureGate(t *testing.T) {
301-
testCompactHashCheckDetectCorruptionInterrupt(t, true)
301+
testCompactHashCheckDetectCorruptionInterrupt(t, true, false)
302302
}
303303

304-
func testCompactHashCheckDetectCorruptionInterrupt(t *testing.T, useFeatureGate bool) {
304+
func TestCompactHashCheckDetectCorruptionInterruptWithExperimentalFlag(t *testing.T) {
305+
testCompactHashCheckDetectCorruptionInterrupt(t, true, true)
306+
}
307+
308+
func testCompactHashCheckDetectCorruptionInterrupt(t *testing.T, useFeatureGate bool, useExperimentalFlag bool) {
305309
checkTime := time.Second
306310
e2e.BeforeTest(t)
307311
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
@@ -325,14 +329,20 @@ func testCompactHashCheckDetectCorruptionInterrupt(t *testing.T, useFeatureGate
325329
} else {
326330
opts = append(opts, e2e.WithCompactHashCheckEnabled(true))
327331
}
332+
var compactionBatchLimit e2e.EPClusterOption
333+
if useExperimentalFlag {
334+
compactionBatchLimit = e2e.WithExperimentalCompactionBatchLimit(1)
335+
} else {
336+
compactionBatchLimit = e2e.WithCompactionBatchLimit(1)
337+
}
328338

329339
cfg := e2e.NewConfig(opts...)
330340
epc, err := e2e.InitEtcdProcessCluster(t, cfg)
331341
require.NoError(t, err)
332342

333343
// Assign a node a very slow compaction speed, so that its compaction can be interrupted.
334344
err = epc.UpdateProcOptions(slowCompactionNodeIndex, t,
335-
e2e.WithCompactionBatchLimit(1),
345+
compactionBatchLimit,
336346
e2e.WithCompactionSleepInterval(1*time.Hour),
337347
)
338348
require.NoError(t, err)

tests/framework/e2e/cluster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ func WithServerFeatureGate(featureName string, val bool) EPClusterOption {
373373
}
374374

375375
func WithCompactionBatchLimit(limit int) EPClusterOption {
376+
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.CompactionBatchLimit = limit }
377+
}
378+
379+
func WithExperimentalCompactionBatchLimit(limit int) EPClusterOption {
376380
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.ExperimentalCompactionBatchLimit = limit }
377381
}
378382

tests/robustness/failpoint/trigger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (t triggerCompact) Trigger(ctx context.Context, _ *testing.T, member e2e.Et
7575
}
7676
rev = resp.Header.Revision
7777

78-
if !t.multiBatchCompaction || rev > int64(clus.Cfg.ServerConfig.ExperimentalCompactionBatchLimit) {
78+
if !t.multiBatchCompaction || rev > int64(clus.Cfg.ServerConfig.CompactionBatchLimit) {
7979
break
8080
}
8181
time.Sleep(50 * time.Millisecond)
@@ -99,7 +99,7 @@ func (t triggerCompact) Available(config e2e.EtcdProcessClusterConfig, _ e2e.Etc
9999
// For multiBatchCompaction we need to guarantee that there are enough revisions between two compaction requests.
100100
// With addition of compaction requests to traffic this might be hard if experimental-compaction-batch-limit is too high.
101101
if t.multiBatchCompaction {
102-
return config.ServerConfig.ExperimentalCompactionBatchLimit <= 10
102+
return config.ServerConfig.CompactionBatchLimit <= 10
103103
}
104104
return true
105105
}

tests/robustness/options/server_config_options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func WithSnapshotCount(input ...uint64) e2e.EPClusterOption {
2828

2929
func WithCompactionBatchLimit(input ...int) e2e.EPClusterOption {
3030
return func(c *e2e.EtcdProcessClusterConfig) {
31-
c.ServerConfig.ExperimentalCompactionBatchLimit = input[internalRand.Intn(len(input))]
31+
c.ServerConfig.CompactionBatchLimit = input[internalRand.Intn(len(input))]
3232
}
3333
}
3434

0 commit comments

Comments
 (0)