Skip to content

Commit da930c7

Browse files
committed
fix a compaction induce latency issue
The compaction behavior is changed in commit [02635](0263597) and introduces a latency issue. To be more speicific, the `ticker.C` acts as a fixed timer that triggers every 10ms, regardless of how long each batch of compaction takes. This means that if a previous compaction batch takes longer than 10ms, the next batch starts immediately, making compaction a blocking operation for etcd. To fix the issue, this commit revert the compaction to the previous behavior which ensures a 10ms delay between each batch of compaction, allowing other read and write operations to proceed smoothly. Signed-off-by: Miancheng Lin <[email protected]>
1 parent 6485d48 commit da930c7

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

server/mvcc/kvstore_compaction.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ 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()
4442
h := newKVHasher(prevCompactRev, compactMainRev, keep)
4543
last := make([]byte, 8+1+8)
4644

@@ -90,7 +88,7 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal
9088
dbCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond))
9189

9290
select {
93-
case <-batchTicker.C:
91+
case <-time.After(s.cfg.CompactionSleepInterval):
9492
case <-s.stopc:
9593
return KeyValueHash{}, fmt.Errorf("interrupted due to stop signal")
9694
}

0 commit comments

Comments
 (0)