Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: move autocommit varable value into connection info (#12310) #12568

Merged
merged 3 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e
valStr, err = value.ToString()
terror.Log(errors.Trace(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.AutocommitVar {
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))
}
}

return nil
Expand Down
18 changes: 17 additions & 1 deletion server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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 @@ -394,6 +394,20 @@ func (cc *clientConn) readOptionalSSLRequestAndHandshakeResponse(ctx context.Con
return errors.Trace(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 @@ -520,6 +534,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