mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
server: Move reading KV index inside scheduleCompaction function
Makes it easier to test hash match between scheduleCompaction and HashByRev. Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
This commit is contained in:
parent
638ca1006a
commit
08a43178fa
@ -229,10 +229,7 @@ func (s *store) compact(trace *traceutil.Trace, rev int64) (<-chan struct{}, err
|
|||||||
s.compactBarrier(ctx, ch)
|
s.compactBarrier(ctx, ch)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
start := time.Now()
|
if err := s.scheduleCompaction(rev); err != nil {
|
||||||
keep := s.kvindex.Compact(rev)
|
|
||||||
indexCompactionPauseMs.Observe(float64(time.Since(start) / time.Millisecond))
|
|
||||||
if err := s.scheduleCompaction(rev, keep); err != nil {
|
|
||||||
s.lg.Warn("Failed compaction", zap.Error(err))
|
s.lg.Warn("Failed compaction", zap.Error(err))
|
||||||
s.compactBarrier(context.TODO(), ch)
|
s.compactBarrier(context.TODO(), ch)
|
||||||
return
|
return
|
||||||
|
@ -23,8 +23,12 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *store) scheduleCompaction(compactMainRev int64, keep map[revision]struct{}) error {
|
func (s *store) scheduleCompaction(compactMainRev int64) error {
|
||||||
totalStart := time.Now()
|
totalStart := time.Now()
|
||||||
|
keep := s.kvindex.Compact(compactMainRev)
|
||||||
|
indexCompactionPauseMs.Observe(float64(time.Since(totalStart) / time.Millisecond))
|
||||||
|
|
||||||
|
totalStart = time.Now()
|
||||||
defer func() { dbCompactionTotalMs.Observe(float64(time.Since(totalStart) / time.Millisecond)) }()
|
defer func() { dbCompactionTotalMs.Observe(float64(time.Since(totalStart) / time.Millisecond)) }()
|
||||||
keyCompactions := 0
|
keyCompactions := 0
|
||||||
defer func() { dbCompactionKeysCounter.Add(float64(keyCompactions)) }()
|
defer func() { dbCompactionKeysCounter.Add(float64(keyCompactions)) }()
|
||||||
|
@ -69,6 +69,10 @@ func TestScheduleCompaction(t *testing.T) {
|
|||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
b, tmpPath := betesting.NewDefaultTmpBackend(t)
|
b, tmpPath := betesting.NewDefaultTmpBackend(t)
|
||||||
s := NewStore(zaptest.NewLogger(t), b, &lease.FakeLessor{}, StoreConfig{})
|
s := NewStore(zaptest.NewLogger(t), b, &lease.FakeLessor{}, StoreConfig{})
|
||||||
|
fi := newFakeIndex()
|
||||||
|
fi.indexCompactRespc <- tt.keep
|
||||||
|
s.kvindex = fi
|
||||||
|
|
||||||
tx := s.b.BatchTx()
|
tx := s.b.BatchTx()
|
||||||
|
|
||||||
tx.Lock()
|
tx.Lock()
|
||||||
@ -79,7 +83,7 @@ func TestScheduleCompaction(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tx.Unlock()
|
tx.Unlock()
|
||||||
|
|
||||||
err := s.scheduleCompaction(tt.rev, tt.keep)
|
err := s.scheduleCompaction(tt.rev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -849,18 +849,11 @@ func newFakeStore(lg *zap.Logger) *store {
|
|||||||
b := &fakeBackend{&fakeBatchTx{
|
b := &fakeBackend{&fakeBatchTx{
|
||||||
Recorder: &testutil.RecorderBuffered{},
|
Recorder: &testutil.RecorderBuffered{},
|
||||||
rangeRespc: make(chan rangeResp, 5)}}
|
rangeRespc: make(chan rangeResp, 5)}}
|
||||||
fi := &fakeIndex{
|
|
||||||
Recorder: &testutil.RecorderBuffered{},
|
|
||||||
indexGetRespc: make(chan indexGetResp, 1),
|
|
||||||
indexRangeRespc: make(chan indexRangeResp, 1),
|
|
||||||
indexRangeEventsRespc: make(chan indexRangeEventsResp, 1),
|
|
||||||
indexCompactRespc: make(chan map[revision]struct{}, 1),
|
|
||||||
}
|
|
||||||
s := &store{
|
s := &store{
|
||||||
cfg: StoreConfig{CompactionBatchLimit: 10000},
|
cfg: StoreConfig{CompactionBatchLimit: 10000},
|
||||||
b: b,
|
b: b,
|
||||||
le: &lease.FakeLessor{},
|
le: &lease.FakeLessor{},
|
||||||
kvindex: fi,
|
kvindex: newFakeIndex(),
|
||||||
currentRev: 0,
|
currentRev: 0,
|
||||||
compactMainRev: -1,
|
compactMainRev: -1,
|
||||||
fifoSched: schedule.NewFIFOScheduler(),
|
fifoSched: schedule.NewFIFOScheduler(),
|
||||||
@ -871,6 +864,16 @@ func newFakeStore(lg *zap.Logger) *store {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newFakeIndex() *fakeIndex {
|
||||||
|
return &fakeIndex{
|
||||||
|
Recorder: &testutil.RecorderBuffered{},
|
||||||
|
indexGetRespc: make(chan indexGetResp, 1),
|
||||||
|
indexRangeRespc: make(chan indexRangeResp, 1),
|
||||||
|
indexRangeEventsRespc: make(chan indexRangeEventsResp, 1),
|
||||||
|
indexCompactRespc: make(chan map[revision]struct{}, 1),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type rangeResp struct {
|
type rangeResp struct {
|
||||||
keys [][]byte
|
keys [][]byte
|
||||||
vals [][]byte
|
vals [][]byte
|
||||||
|
Loading…
x
Reference in New Issue
Block a user