Skip to content

Commit

Permalink
log: move autocommit varable value into connection info (#12310) (#12565
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Lingyu Song authored and sre-bot committed Oct 13, 2019
1 parent df8376d commit 823eae7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e
valStr, err = value.ToString()
terror.Log(err)
}
logutil.Logger(context.Background()).Info("set session var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", valStr))
if name != variable.AutoCommit {
logutil.Logger(context.Background()).Info("set session var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", valStr))
} else {
// Some applications will set `autocommit` variable before query.
// This will print too many unnecessary log info.
logutil.Logger(context.Background()).Debug("set session var", zap.Uint64("conn", sessionVars.ConnectionID), zap.String("name", name), zap.String("val", valStr))
}
}

if name == variable.TiDBEnableStmtSummary {
Expand Down
18 changes: 17 additions & 1 deletion server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ type clientConn struct {

func (cc *clientConn) String() string {
collationStr := mysql.Collations[cc.collation]
return fmt.Sprintf("id:%d, addr:%s status:%d, collation:%s, user:%s",
return fmt.Sprintf("id:%d, addr:%s status:%b, collation:%s, user:%s",
cc.connectionID, cc.bufReadConn.RemoteAddr(), cc.ctx.Status(), collationStr, cc.user,
)
}
Expand Down Expand Up @@ -533,6 +533,20 @@ func (cc *clientConn) readOptionalSSLRequestAndHandshakeResponse(ctx context.Con
return err
}

func (cc *clientConn) SessionStatusToString() string {
status := cc.ctx.Status()
inTxn, autoCommit := 0, 0
if status&mysql.ServerStatusInTrans > 0 {
inTxn = 1
}
if status&mysql.ServerStatusAutocommit > 0 {
autoCommit = 1
}
return fmt.Sprintf("inTxn:%d, autocommit:%d",
inTxn, autoCommit,
)
}

func (cc *clientConn) openSessionAndDoAuth(authData []byte) error {
var tlsStatePtr *tls.ConnectionState
if cc.tlsConn != nil {
Expand Down Expand Up @@ -667,6 +681,8 @@ func (cc *clientConn) Run(ctx context.Context) {
}
logutil.Logger(ctx).Warn("dispatch error",
zap.String("connInfo", cc.String()),
zap.String("command", mysql.Command2Str[data[0]]),
zap.String("status", cc.SessionStatusToString()),
zap.String("sql", queryStrForLog(string(data[1:]))),
zap.String("err", errStrForLog(err)),
)
Expand Down

0 comments on commit 823eae7

Please sign in to comment.