Skip to content

Commit 1d4372a

Browse files
authored
Merge pull request #18514 from JalinWang/backport/release-3.5
[3.5] Introduce the CompactionSleepInterval flag
2 parents 82994d1 + 0263597 commit 1d4372a

File tree

9 files changed

+34
-10
lines changed

9 files changed

+34
-10
lines changed

server/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type ServerConfig struct {
114114
AutoCompactionRetention time.Duration
115115
AutoCompactionMode string
116116
CompactionBatchLimit int
117+
CompactionSleepInterval time.Duration
117118
QuotaBackendBytes int64
118119
MaxTxnOps uint
119120

server/embed/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,11 @@ type Config struct {
334334
// Requires experimental-enable-lease-checkpoint to be enabled.
335335
// Deprecated in v3.6.
336336
// TODO: Delete in v3.7
337-
ExperimentalEnableLeaseCheckpointPersist bool `json:"experimental-enable-lease-checkpoint-persist"`
338-
ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit"`
339-
ExperimentalWatchProgressNotifyInterval time.Duration `json:"experimental-watch-progress-notify-interval"`
337+
ExperimentalEnableLeaseCheckpointPersist bool `json:"experimental-enable-lease-checkpoint-persist"`
338+
ExperimentalCompactionBatchLimit int `json:"experimental-compaction-batch-limit"`
339+
// ExperimentalCompactionSleepInterval is the sleep interval between every etcd compaction loop.
340+
ExperimentalCompactionSleepInterval time.Duration `json:"experimental-compaction-sleep-interval"`
341+
ExperimentalWatchProgressNotifyInterval time.Duration `json:"experimental-watch-progress-notify-interval"`
340342
// ExperimentalWarningApplyDuration is the time duration after which a warning is generated if applying request
341343
// takes more time than this value.
342344
ExperimentalWarningApplyDuration time.Duration `json:"experimental-warning-apply-duration"`

server/embed/etcd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
218218
EnableLeaseCheckpoint: cfg.ExperimentalEnableLeaseCheckpoint,
219219
LeaseCheckpointPersist: cfg.ExperimentalEnableLeaseCheckpointPersist,
220220
CompactionBatchLimit: cfg.ExperimentalCompactionBatchLimit,
221+
CompactionSleepInterval: cfg.ExperimentalCompactionSleepInterval,
221222
WatchProgressNotifyInterval: cfg.ExperimentalWatchProgressNotifyInterval,
222223
DowngradeCheckTime: cfg.ExperimentalDowngradeCheckTime,
223224
WarningApplyDuration: cfg.ExperimentalWarningApplyDuration,

server/etcdmain/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func newConfig() *config {
296296
// TODO: delete in v3.7
297297
fs.BoolVar(&cfg.ec.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.")
298298
fs.IntVar(&cfg.ec.ExperimentalCompactionBatchLimit, "experimental-compaction-batch-limit", cfg.ec.ExperimentalCompactionBatchLimit, "Sets the maximum revisions deleted in each compaction batch.")
299+
fs.DurationVar(&cfg.ec.ExperimentalCompactionSleepInterval, "experimental-compaction-sleep-interval", cfg.ec.ExperimentalCompactionSleepInterval, "Sets the sleep interval between each compaction batch.")
299300
fs.DurationVar(&cfg.ec.ExperimentalWatchProgressNotifyInterval, "experimental-watch-progress-notify-interval", cfg.ec.ExperimentalWatchProgressNotifyInterval, "Duration of periodic watch progress notifications.")
300301
fs.DurationVar(&cfg.ec.ExperimentalDowngradeCheckTime, "experimental-downgrade-check-time", cfg.ec.ExperimentalDowngradeCheckTime, "Duration of time between two downgrade status check.")
301302
fs.DurationVar(&cfg.ec.ExperimentalWarningApplyDuration, "experimental-warning-apply-duration", cfg.ec.ExperimentalWarningApplyDuration, "Time duration after which a warning is generated if request takes more time.")

server/etcdmain/help.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ Experimental feature:
268268
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.
269269
--experimental-compaction-batch-limit 1000
270270
ExperimentalCompactionBatchLimit sets the maximum revisions deleted in each compaction batch.
271+
--experimental-compaction-sleep-interval '10ms'
272+
ExperimentalCompactionSleepInterval sets the sleep interval between each compaction batch.
271273
--experimental-peer-skip-client-san-verification 'false'
272274
Skip verification of SAN field in client certificate for peer connections.
273275
--experimental-watch-progress-notify-interval '10m'

server/etcdserver/server.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,16 @@ func NewServer(cfg config.ServerConfig) (srv *EtcdServer, err error) {
615615
cfg.Logger.Warn("failed to create token provider", zap.Error(err))
616616
return nil, err
617617
}
618-
srv.kv = mvcc.New(srv.Logger(), srv.be, srv.lessor, mvcc.StoreConfig{CompactionBatchLimit: cfg.CompactionBatchLimit})
618+
619+
mvccStoreConfig := mvcc.StoreConfig{
620+
CompactionBatchLimit: cfg.CompactionBatchLimit,
621+
CompactionSleepInterval: cfg.CompactionSleepInterval,
622+
}
623+
srv.kv = mvcc.New(srv.Logger(), srv.be, srv.lessor, mvccStoreConfig)
619624

620625
kvindex := ci.ConsistentIndex()
621626
srv.lg.Debug("restore consistentIndex", zap.Uint64("index", kvindex))
627+
622628
if beExist {
623629
// TODO: remove kvindex != 0 checking when we do not expect users to upgrade
624630
// etcd from pre-3.0 release.

server/mvcc/kvstore.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ const (
5050
)
5151

5252
var restoreChunkKeys = 10000 // non-const for testing
53-
var defaultCompactBatchLimit = 1000
53+
var defaultCompactionBatchLimit = 1000
54+
var defaultCompactionSleepInterval = 10 * time.Millisecond
5455

5556
type StoreConfig struct {
56-
CompactionBatchLimit int
57+
CompactionBatchLimit int
58+
CompactionSleepInterval time.Duration
5759
}
5860

5961
type store struct {
@@ -94,7 +96,10 @@ func NewStore(lg *zap.Logger, b backend.Backend, le lease.Lessor, cfg StoreConfi
9496
lg = zap.NewNop()
9597
}
9698
if cfg.CompactionBatchLimit == 0 {
97-
cfg.CompactionBatchLimit = defaultCompactBatchLimit
99+
cfg.CompactionBatchLimit = defaultCompactionBatchLimit
100+
}
101+
if cfg.CompactionSleepInterval == 0 {
102+
cfg.CompactionSleepInterval = defaultCompactionSleepInterval
98103
}
99104
s := &store{
100105
cfg: cfg,

server/mvcc/kvstore_compaction.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal
3939
binary.BigEndian.PutUint64(end, uint64(compactMainRev+1))
4040

4141
batchNum := s.cfg.CompactionBatchLimit
42+
batchTicker := time.NewTicker(s.cfg.CompactionSleepInterval)
43+
defer batchTicker.Stop()
4244
h := newKVHasher(prevCompactRev, compactMainRev, keep)
4345
last := make([]byte, 8+1+8)
46+
4447
for {
4548
var rev revision
4649

@@ -58,7 +61,7 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal
5861
h.WriteKeyValue(keys[i], values[i])
5962
}
6063

61-
if len(keys) < s.cfg.CompactionBatchLimit {
64+
if len(keys) < batchNum {
6265
// gofail: var compactBeforeSetFinishedCompact struct{}
6366
rbytes := make([]byte, 8+1+8)
6467
revToBytes(revision{main: compactMainRev}, rbytes)
@@ -87,7 +90,7 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal
8790
dbCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond))
8891

8992
select {
90-
case <-time.After(10 * time.Millisecond):
93+
case <-batchTicker.C:
9194
case <-s.stopc:
9295
return KeyValueHash{}, fmt.Errorf("interrupted due to stop signal")
9396
}

server/mvcc/kvstore_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,10 @@ func newFakeStore() *store {
910910
Recorder: &testutil.RecorderBuffered{},
911911
rangeRespc: make(chan rangeResp, 5)}}
912912
s := &store{
913-
cfg: StoreConfig{CompactionBatchLimit: 10000},
913+
cfg: StoreConfig{
914+
CompactionBatchLimit: 10000,
915+
CompactionSleepInterval: defaultCompactionSleepInterval,
916+
},
914917
b: b,
915918
le: &lease.FakeLessor{},
916919
kvindex: newFakeIndex(),

0 commit comments

Comments
 (0)