Merge pull request #14240 from chaochn47/cherry-pick-12335

[3.4] etcdserver: add more detailed traces on linearized reading
This commit is contained in:
Benjamin Wang 2022-07-21 03:32:02 +08:00 committed by GitHub
commit 40ccb8b454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -710,6 +710,9 @@ func (s *EtcdServer) linearizableReadLoop() {
return 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() nextnr := newNotifier()
s.readMu.Lock() s.readMu.Lock()
@ -782,16 +785,26 @@ func (s *EtcdServer) linearizableReadLoop() {
if !done { if !done {
continue 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: ai})
if ai < index {
select { select {
case <-s.applyWait.Wait(rs.Index): case <-s.applyWait.Wait(index):
case <-s.stopping: case <-s.stopping:
return return
} }
} }
// unblock all l-reads requested at indices before rs.Index // unblock all l-reads requested at indices before rs.Index
nr.notify(nil) nr.notify(nil)
trace.Step("applied index is now lower than readState.Index")
trace.LogAllStepsIfLong(traceThreshold)
} }
} }

View File

@ -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 // LogWithStepThreshold only dumps step whose duration is longer than step threshold
func (t *Trace) LogWithStepThreshold(threshold time.Duration) { func (t *Trace) LogWithStepThreshold(threshold time.Duration) {
msg, fs := t.logInfo(threshold) msg, fs := t.logInfo(threshold)