mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: add more detailed traces on linearized reading
To improve debuggability of `agreement among raft nodes before linearized reading`, we added some tracing inside `linearizableReadLoop`. This will allow us to know the timing of `s.r.ReadIndex` vs `s.applyWait.Wait(rs.Index)`. Signed-off-by: Chao Chen <chaochn@amazon.com>
This commit is contained in:
parent
d58a0c0434
commit
3f9fba9112
@ -18,6 +18,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.etcd.io/etcd/auth"
|
||||
@ -710,6 +711,9 @@ func (s *EtcdServer) linearizableReadLoop() {
|
||||
return
|
||||
}
|
||||
|
||||
// as a single loop is can unlock multiple reads, it is not very useful
|
||||
// to propagate the trace from Txn or Range.
|
||||
trace := traceutil.New("linearizableReadLoop", s.getLogger())
|
||||
nextnr := newNotifier()
|
||||
|
||||
s.readMu.Lock()
|
||||
@ -782,16 +786,26 @@ func (s *EtcdServer) linearizableReadLoop() {
|
||||
if !done {
|
||||
continue
|
||||
}
|
||||
trace.Step("read index received")
|
||||
|
||||
if ai := s.getAppliedIndex(); ai < rs.Index {
|
||||
index := rs.Index
|
||||
trace.AddField(traceutil.Field{Key: "readStateIndex", Value: index})
|
||||
|
||||
ai := s.getAppliedIndex()
|
||||
trace.AddField(traceutil.Field{Key: "appliedIndex", Value: strconv.FormatUint(ai, 10)})
|
||||
|
||||
if ai < index {
|
||||
select {
|
||||
case <-s.applyWait.Wait(rs.Index):
|
||||
case <-s.applyWait.Wait(index):
|
||||
case <-s.stopping:
|
||||
return
|
||||
}
|
||||
}
|
||||
// unblock all l-reads requested at indices before rs.Index
|
||||
nr.notify(nil)
|
||||
trace.Step("applied index is now lower than readState.Index")
|
||||
|
||||
trace.LogAllStepsIfLong(traceThreshold)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,6 +138,13 @@ func (t *Trace) LogIfLong(threshold time.Duration) {
|
||||
}
|
||||
}
|
||||
|
||||
// LogAllStepsIfLong dumps all logs if the duration is longer than threshold
|
||||
func (t *Trace) LogAllStepsIfLong(threshold time.Duration) {
|
||||
if time.Since(t.startTime) > threshold {
|
||||
t.LogWithStepThreshold(0)
|
||||
}
|
||||
}
|
||||
|
||||
// LogWithStepThreshold only dumps step whose duration is longer than step threshold
|
||||
func (t *Trace) LogWithStepThreshold(threshold time.Duration) {
|
||||
msg, fs := t.logInfo(threshold)
|
||||
|
Loading…
x
Reference in New Issue
Block a user