Skip to content

Commit

Permalink
session: add the transaction commit time to slow log (pingcap#10294)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp committed Apr 29, 2019
1 parent 0f6621d commit 08611a1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
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

0 comments on commit 08611a1

Please sign in to comment.