Skip to content

Commit

Permalink
server, session: Reduce noise from SELECT...FOR UPDATE NOWAIT (#26845)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Sep 14, 2021
1 parent 8ef93e1 commit 84ce75d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
20 changes: 12 additions & 8 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,14 +995,18 @@ func (cc *clientConn) Run(ctx context.Context) {
txnMode = cc.ctx.GetSessionVars().GetReadableTxnMode()
}
metrics.ExecuteErrorCounter.WithLabelValues(metrics.ExecuteErrorToLabel(err)).Inc()
logutil.Logger(ctx).Info("command dispatched failed",
zap.String("connInfo", cc.String()),
zap.String("command", mysql.Command2Str[data[0]]),
zap.String("status", cc.SessionStatusToString()),
zap.Stringer("sql", getLastStmtInConn{cc}),
zap.String("txn_mode", txnMode),
zap.String("err", errStrForLog(err, cc.ctx.GetSessionVars().EnableRedactLog)),
)
if storeerr.ErrLockAcquireFailAndNoWaitSet.Equal(err) {
logutil.Logger(ctx).Debug("Expected error for FOR UPDATE NOWAIT", zap.Error(err))
} else {
logutil.Logger(ctx).Info("command dispatched failed",
zap.String("connInfo", cc.String()),
zap.String("command", mysql.Command2Str[data[0]]),
zap.String("status", cc.SessionStatusToString()),
zap.Stringer("sql", getLastStmtInConn{cc}),
zap.String("txn_mode", txnMode),
zap.String("err", errStrForLog(err, cc.ctx.GetSessionVars().EnableRedactLog)),
)
}
err1 := cc.writeError(ctx, err)
terror.Log(err1)
}
Expand Down
11 changes: 9 additions & 2 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/statistics/handle"
storeerr "github.com/pingcap/tidb/store/driver/error"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/telemetry"
"github.com/pingcap/tidb/types"
Expand Down Expand Up @@ -670,7 +671,13 @@ func (m temporaryTableKVFilter) IsUnnecessaryKeyValue(key, value []byte, flags t
// of the errors defined in kv/error.go, these look to be clearly related to a client-inflicted issue,
// and the server is only responsible for handling the error correctly. It does not need to log.
func errIsNoisy(err error) bool {
return kv.ErrKeyExists.Equal(err)
if kv.ErrKeyExists.Equal(err) {
return true
}
if storeerr.ErrLockAcquireFailAndNoWaitSet.Equal(err) {
return true
}
return false
}

func (s *session) doCommitWithRetry(ctx context.Context) error {
Expand Down Expand Up @@ -1568,7 +1575,7 @@ func (s *session) ExecuteStmt(ctx context.Context, stmtNode ast.StmtNode) (sqlex
logStmt(stmt, s)
recordSet, err := runStmt(ctx, s, stmt)
if err != nil {
if !kv.ErrKeyExists.Equal(err) {
if !errIsNoisy(err) {
logutil.Logger(ctx).Warn("run statement failed",
zap.Int64("schemaVersion", s.GetInfoSchema().SchemaMetaVersion()),
zap.Error(err),
Expand Down

0 comments on commit 84ce75d

Please sign in to comment.