Skip to content

Commit

Permalink
Revert "cherry pick pingcap#19547 to release-4.0"
Browse files Browse the repository at this point in the history
This reverts commit 9c355f9.
  • Loading branch information
crazycs520 committed Oct 9, 2020
1 parent 9c355f9 commit 6d72b72
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 581 deletions.
18 changes: 1 addition & 17 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,8 @@ func (a *ExecStmt) handlePessimisticDML(ctx context.Context, e Executor) error {
}
seVars := sctx.GetSessionVars()
lockCtx := newLockCtx(seVars, seVars.LockWaitTimeout)
var lockKeyStats *execdetails.LockKeysDetails
ctx = context.WithValue(ctx, execdetails.LockKeysDetailCtxKey, &lockKeyStats)
startLocking := time.Now()
err = txn.LockKeys(ctx, lockCtx, keys...)
if lockKeyStats != nil {
seVars.StmtCtx.MergeLockKeysExecDetails(lockKeyStats)
}
if err == nil {
return nil
}
Expand Down Expand Up @@ -799,21 +794,10 @@ func (a *ExecStmt) CloseRecordSet(txnStartTS uint64, lastErr error) {
// 3. record execute duration metric.
// 4. update the `PrevStmt` in session variable.
func (a *ExecStmt) FinishExecuteStmt(txnTS uint64, succ bool, hasMoreResults bool) {
sessVars := a.Ctx.GetSessionVars()
execDetail := sessVars.StmtCtx.GetExecDetails()
// Attach commit/lockKeys runtime stats to executor runtime stats.
if (execDetail.CommitDetail != nil || execDetail.LockKeysDetail != nil) && sessVars.StmtCtx.RuntimeStatsColl != nil {
stats := sessVars.StmtCtx.RuntimeStatsColl.GetRootStats(a.Plan.ID())
statsWithCommit := &execdetails.RuntimeStatsWithCommit{
RuntimeStats: stats,
Commit: execDetail.CommitDetail,
LockKeys: execDetail.LockKeysDetail,
}
sessVars.StmtCtx.RuntimeStatsColl.RegisterStats(a.Plan.ID(), statsWithCommit)
}
// `LowSlowQuery` and `SummaryStmt` must be called before recording `PrevStmt`.
a.LogSlowQuery(txnTS, succ, hasMoreResults)
a.SummaryStmt(succ)
sessVars := a.Ctx.GetSessionVars()
prevStmt := a.GetTextToLog()
if config.RedactLogEnabled() {
sessVars.PrevStmt = FormatSQL(prevStmt, nil)
Expand Down
8 changes: 1 addition & 7 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,13 +953,7 @@ func doLockKeys(ctx context.Context, se sessionctx.Context, lockCtx *kv.LockCtx,
if err != nil {
return err
}
var lockKeyStats *execdetails.LockKeysDetails
ctx = context.WithValue(ctx, execdetails.LockKeysDetailCtxKey, &lockKeyStats)
err = txn.LockKeys(sessionctx.SetCommitCtx(ctx, se), lockCtx, keys...)
if lockKeyStats != nil {
sctx.MergeLockKeysExecDetails(lockKeyStats)
}
return err
return txn.LockKeys(sessionctx.SetCommitCtx(ctx, se), lockCtx, keys...)
}

// LimitExec represents limit executor
Expand Down
41 changes: 0 additions & 41 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6003,47 +6003,6 @@ func (s *testSuite) TestIssue19372(c *C) {
tk.MustQuery("select (select t2.c_str from t2 where t2.c_str <= t1.c_str and t2.c_int in (1, 2) order by t2.c_str limit 1) x from t1 order by c_int;").Check(testkit.Rows("a", "a", "a"))
}

<<<<<<< HEAD
=======
func (s *testSuite) TestCollectDMLRuntimeStats(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (a int, b int, unique index (a))")

testSQLs := []string{
"insert ignore into t1 values (5,5);",
"insert into t1 values (5,5) on duplicate key update a=a+1;",
"replace into t1 values (5,6),(6,7)",
"update t1 set a=a+1 where a=6;",
}

getRootStats := func() string {
info := tk.Se.ShowProcess()
c.Assert(info, NotNil)
p, ok := info.Plan.(plannercore.Plan)
c.Assert(ok, IsTrue)
stats := tk.Se.GetSessionVars().StmtCtx.RuntimeStatsColl.GetRootStats(p.ID())
return stats.String()
}
for _, sql := range testSQLs {
tk.MustExec(sql)
c.Assert(getRootStats(), Matches, "time.*loops.*Get.*num_rpc.*total_time.*")
}

// Test for lock keys stats.
tk.MustExec("begin pessimistic")
tk.MustExec("update t1 set b=b+1")
c.Assert(getRootStats(), Matches, "time.*lock_keys.*time.* region.* keys.* lock_rpc:.* rpc_count.*")
tk.MustExec("rollback")

tk.MustExec("begin pessimistic")
tk.MustQuery("select * from t1 for update").Check(testkit.Rows("5 6", "7 7"))
c.Assert(getRootStats(), Matches, "time.*lock_keys.*time.* region.* keys.* lock_rpc:.* rpc_count.*")
tk.MustExec("rollback")
}

>>>>>>> 915d84d... executor: add pessimistic lock keys runtime information (#19547)
func (s *testSuite) TestIssue13758(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
5 changes: 0 additions & 5 deletions kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/store/tikv/oracle"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/memory"
)

Expand Down Expand Up @@ -236,11 +235,7 @@ type LockCtx struct {
Values map[string]ReturnedValue
ValuesLock sync.Mutex
LockExpired *uint32
<<<<<<< HEAD
CheckKeyExists map[string]struct{}
=======
Stats *execdetails.LockKeysDetails
>>>>>>> 915d84d... executor: add pessimistic lock keys runtime information (#19547)
}

// ReturnedValue pairs the Value and AlreadyLocked flag for PessimisticLock return values result.
Expand Down
11 changes: 0 additions & 11 deletions sessionctx/stmtctx/stmtctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,17 +497,6 @@ func (sc *StatementContext) MergeExecDetails(details *execdetails.ExecDetails, c
sc.mu.Unlock()
}

// MergeLockKeysExecDetails merges lock keys execution details into self.
func (sc *StatementContext) MergeLockKeysExecDetails(lockKeys *execdetails.LockKeysDetails) {
sc.mu.Lock()
if sc.mu.execDetails.LockKeysDetail == nil {
sc.mu.execDetails.LockKeysDetail = lockKeys
} else {
sc.mu.execDetails.LockKeysDetail.Merge(lockKeys)
}
sc.mu.Unlock()
}

// GetExecDetails gets the execution details for the statement.
func (sc *StatementContext) GetExecDetails() execdetails.ExecDetails {
var details execdetails.ExecDetails
Expand Down
8 changes: 1 addition & 7 deletions store/tikv/2pc.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,7 @@ func (c *twoPhaseCommitter) doActionOnGroupMutations(bo *Backoffer, action twoPh

var batches []batchMutations
var sizeFunc = c.keySize

switch act := action.(type) {
case actionPrewrite:
if _, ok := action.(actionPrewrite); ok {
// Do not update regionTxnSize on retries. They are not used when building a PrewriteRequest.
if len(bo.errors) == 0 {
for _, group := range groups {
Expand All @@ -566,10 +564,6 @@ func (c *twoPhaseCommitter) doActionOnGroupMutations(bo *Backoffer, action twoPh
}
sizeFunc = c.keyValueSize
atomic.AddInt32(&c.getDetail().PrewriteRegionNum, int32(len(groups)))
case actionPessimisticLock:
if act.LockCtx.Stats != nil {
act.LockCtx.Stats.RegionNum = int32(len(groups))
}
}

primaryIdx := -1
Expand Down
226 changes: 0 additions & 226 deletions store/tikv/pessimistic.go

This file was deleted.

Loading

0 comments on commit 6d72b72

Please sign in to comment.