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

Merged
merged 3 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -290,16 +290,6 @@ func (a *ExecStmt) handleNoDelayExecutor(ctx context.Context, sctx sessionctx.Co
var err error
defer func() {
terror.Log(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 @@ -460,18 +460,12 @@ func (s *session) CommitTxn(ctx context.Context) error {
defer span1.Finish()
}

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)
s.sessionVars.TxnCtx.Cleanup()
s.recordTransactionCounter(err)
return err
Expand Down
13 changes: 9 additions & 4 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,21 @@ 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) {
func runStmt(ctx context.Context, sctx sessionctx.Context, s sqlexec.Statement) (rs sqlexec.RecordSet, err error) {
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
span1 := span.Tracer().StartSpan("session.runStmt", opentracing.ChildOf(span.Context()))
span1.LogKV("sql", s.OriginText())
defer span1.Finish()
}

var err error
var rs sqlexec.RecordSet
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