From 07e9fd6d84beb3bd9b91c6eb54083850a378a3ff Mon Sep 17 00:00:00 2001 From: Miancheng Lin Date: Wed, 12 Feb 2025 22:20:33 +0000 Subject: [PATCH] fix a compaction induce latency issue The compaction behavior is changed in commit [02635](https://github.com/etcd-io/etcd/commit/0263597ba84f65047948141696be926e53aa2429) 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. --- server/mvcc/kvstore_compaction.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/mvcc/kvstore_compaction.go b/server/mvcc/kvstore_compaction.go index ad8c5cb5bcfe..6f3d1e59a742 100644 --- a/server/mvcc/kvstore_compaction.go +++ b/server/mvcc/kvstore_compaction.go @@ -39,8 +39,6 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal binary.BigEndian.PutUint64(end, uint64(compactMainRev+1)) batchNum := s.cfg.CompactionBatchLimit - batchTicker := time.NewTicker(s.cfg.CompactionSleepInterval) - defer batchTicker.Stop() h := newKVHasher(prevCompactRev, compactMainRev, keep) last := make([]byte, 8+1+8) @@ -90,7 +88,7 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal dbCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond)) select { - case <-batchTicker.C: + case <-time.After(s.cfg.CompactionSleepInterval): case <-s.stopc: return KeyValueHash{}, fmt.Errorf("interrupted due to stop signal") }