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

session: add the transaction commit time to slow log (#10294) #10310

Merged
merged 3 commits into from
Apr 30, 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
10 changes: 0 additions & 10 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,6 @@ func (a *ExecStmt) handleNoDelayExecutor(ctx context.Context, sctx sessionctx.Co
pi.SetProcessInfo("")
}
terror.Log(errors.Trace(e.Close()))
txnTS := uint64(0)
// Don't active pending txn here.
if txn, err1 := sctx.Txn(false); err1 != nil {
logutil.Logger(ctx).Error("get current transaction failed", zap.Error(err))
} else {
if txn.Valid() {
txnTS = txn.StartTS()
}
}
a.LogSlowQuery(txnTS, err == nil)
a.logAudit()
}()

Expand Down
6 changes: 0 additions & 6 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,12 @@ func (s *session) doCommitWithRetry(ctx context.Context) error {
}

func (s *session) CommitTxn(ctx context.Context) error {
stmt := executor.ExecStmt{
Text: "commitTxn",
Ctx: s,
StartTime: time.Now(),
}
var commitDetail *execdetails.CommitDetails
ctx = context.WithValue(ctx, execdetails.CommitDetailCtxKey, &commitDetail)
err := s.doCommitWithRetry(ctx)
if commitDetail != nil {
s.sessionVars.StmtCtx.MergeExecDetails(nil, commitDetail)
}
stmt.LogSlowQuery(s.sessionVars.TxnCtx.StartTS, err == nil)
label := metrics.LblOK
if err != nil {
label = metrics.LblError
Expand Down
12 changes: 9 additions & 3 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,16 @@ func checkStmtLimit(ctx context.Context, sctx sessionctx.Context, se *session, s
}

// runStmt executes the sqlexec.Statement and commit or rollback the current transaction.
func runStmt(ctx context.Context, sctx sessionctx.Context, s sqlexec.Statement) (sqlexec.RecordSet, error) {
var err error
var rs sqlexec.RecordSet
func runStmt(ctx context.Context, sctx sessionctx.Context, s sqlexec.Statement) (rs sqlexec.RecordSet, err error) {
se := sctx.(*session)
defer func() {
// If it is not a select statement, we record its slow log here,
// then it could include the transaction commit time.
if rs == nil {
s.(*executor.ExecStmt).LogSlowQuery(se.GetSessionVars().TxnCtx.StartTS, err != nil)
}
}()

err = se.checkTxnAborted(s)
if err != nil {
return nil, err
Expand Down