Skip to content

Commit

Permalink
session: add connection ID in retry log. (pingcap#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
coocood authored Jan 15, 2017
1 parent 42f570a commit c5c4f85
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (s *session) doCommitWithRetry() error {
}
s.cleanRetryInfo()
if err != nil {
log.Warnf("finished txn:%s, %v", s.txn, err)
log.Warnf("[%d] finished txn:%s, %v", s.sessionVars.ConnectionID, s.txn, err)
return errors.Trace(err)
}
return nil
Expand Down Expand Up @@ -298,8 +298,9 @@ func (s *session) isRetryableError(err error) bool {
}

func (s *session) retry(maxCnt int) error {
connID := s.sessionVars.ConnectionID
if s.sessionVars.TxnCtx.ForUpdate {
return errors.Errorf("can not retry select for update statement")
return errors.Errorf("[%d] can not retry select for update statement", connID)
}
s.sessionVars.RetryInfo.Retrying = true
retryCnt := 0
Expand All @@ -315,10 +316,7 @@ func (s *session) retry(maxCnt int) error {
for _, sr := range nh.history {
st := sr.st
txt := st.OriginText()
if len(txt) > sqlLogMaxLen {
txt = txt[:sqlLogMaxLen]
}
log.Warnf("Retry %s (len:%d)", txt, len(st.OriginText()))
log.Warnf("[%d] Retry %s", connID, sqlForLog(txt))
_, err = st.Exec(s)
if err != nil {
break
Expand All @@ -331,18 +329,26 @@ func (s *session) retry(maxCnt int) error {
}
}
if !s.isRetryableError(err) {
log.Warnf("session:%v, err:%v", s, err)
log.Warnf("[%d] session:%v, err:%v", connID, s, err)
return errors.Trace(err)
}
retryCnt++
if !s.unlimitedRetryCount && (retryCnt >= maxCnt) {
log.Warnf("[%id] Retry reached max count %d", connID, retryCnt)
return errors.Trace(err)
}
kv.BackOff(retryCnt)
}
return err
}

func sqlForLog(sql string) string {
if len(sql) > sqlLogMaxLen {
return sql[:sqlLogMaxLen] + fmt.Sprintf("(len:%d)", len(sql))
}
return sql
}

// ExecRestrictedSQL implements RestrictedSQLExecutor interface.
// This is used for executing some restricted sql statements, usually executed during a normal statement execution.
// Unlike normal Exec, it doesn't reset statement status, doesn't commit or rollback the current transaction
Expand Down

0 comments on commit c5c4f85

Please sign in to comment.