Skip to content

Commit

Permalink
test: add CompactionSleepInterval in FakeStore's config
Browse files Browse the repository at this point in the history
After setting the ComparionSleepInterval, we can use time.Ticker
instead of time.After to optimize the scheduleComparison(),
otherwise it will fail in the 'TestStoreCompact(t)' test.

Signed-off-by: guozhao <guozhao@360.cn>
  • Loading branch information
guozhao authored and ahrtr committed Jan 19, 2023
1 parent 397e3fb commit fab8474
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions server/storage/mvcc/kvstore_compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal
binary.BigEndian.PutUint64(end, uint64(compactMainRev+1))

batchNum := s.cfg.CompactionBatchLimit
batchInterval := s.cfg.CompactionSleepInterval
batchTicker := time.NewTicker(s.cfg.CompactionSleepInterval)
defer batchTicker.Stop()
h := newKVHasher(prevCompactRev, compactMainRev, keep)
last := make([]byte, 8+1+8)
for {
Expand Down Expand Up @@ -84,7 +85,7 @@ func (s *store) scheduleCompaction(compactMainRev, prevCompactRev int64) (KeyVal
dbCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond))

select {
case <-time.After(batchInterval):
case <-batchTicker.C:
case <-s.stopc:
return KeyValueHash{}, fmt.Errorf("interrupted due to stop signal")
}
Expand Down
5 changes: 4 additions & 1 deletion server/storage/mvcc/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,10 @@ func newFakeStore(lg *zap.Logger) *store {
Recorder: &testutil.RecorderBuffered{},
rangeRespc: make(chan rangeResp, 5)}}
s := &store{
cfg: StoreConfig{CompactionBatchLimit: 10000},
cfg: StoreConfig{
CompactionBatchLimit: 10000,
CompactionSleepInterval: minimumBatchInterval,
},
b: b,
le: &lease.FakeLessor{},
kvindex: newFakeIndex(),
Expand Down

0 comments on commit fab8474

Please sign in to comment.