Skip to content

Commit

Permalink
etcdserver: add more detailed traces on linearized reading
Browse files Browse the repository at this point in the history
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)`.
  • Loading branch information
PierreZ committed Sep 25, 2020
1 parent add86bb commit a9ad9a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions etcdserver/v3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"encoding/base64"
"encoding/binary"
"strconv"
"time"

"go.etcd.io/etcd/v3/auth"
Expand Down Expand Up @@ -715,6 +716,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.lg)
nextnr := newNotifier()

s.readMu.Lock()
Expand Down Expand Up @@ -775,6 +779,9 @@ func (s *EtcdServer) linearizableReadLoop() {
if !done {
continue
}
trace.Step("read index received")
trace.AddField(traceutil.Field{Key: "appliedIndex", Value: strconv.FormatUint(s.appliedIndex, 10)})
trace.AddField(traceutil.Field{Key: "readStateIndex", Value: rs.Index})

if ai := s.getAppliedIndex(); ai < rs.Index {
select {
Expand All @@ -785,6 +792,9 @@ func (s *EtcdServer) linearizableReadLoop() {
}
// 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)
}
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/traceutil/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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)
Expand Down

0 comments on commit a9ad9a9

Please sign in to comment.