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

util/stmtsummary: remove import package tikv #24776

Merged
merged 5 commits into from
May 21, 2021
Merged
Changes from 1 commit
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
29 changes: 17 additions & 12 deletions util/stmtsummary/statement_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/stringutil"
)

var _ = Suite(&testStmtSummarySuite{})
Expand Down Expand Up @@ -62,6 +62,10 @@ func TestT(t *testing.T) {
TestingT(t)
}

const (
boTxnLockName = stringutil.StringerStr("txnlock")
)

// Test stmtSummaryByDigest.AddStatement.
func (s *testStmtSummarySuite) TestAddStatement(c *C) {
s.ssMap.Clear()
Expand Down Expand Up @@ -192,7 +196,7 @@ func (s *testStmtSummarySuite) TestAddStatement(c *C) {
sync.Mutex
BackoffTypes []fmt.Stringer
}{
BackoffTypes: []fmt.Stringer{tikv.BoTxnLock},
BackoffTypes: []fmt.Stringer{boTxnLockName},
},
ResolveLockTime: 10000,
WriteKeys: 100000,
Expand Down Expand Up @@ -268,7 +272,7 @@ func (s *testStmtSummarySuite) TestAddStatement(c *C) {
expectedSummaryElement.sumTxnRetry += int64(stmtExecInfo2.ExecDetail.CommitDetail.TxnRetry)
expectedSummaryElement.maxTxnRetry = stmtExecInfo2.ExecDetail.CommitDetail.TxnRetry
expectedSummaryElement.sumBackoffTimes += 1
expectedSummaryElement.backoffTypes[tikv.BoTxnLock] = 1
expectedSummaryElement.backoffTypes[boTxnLockName] = 1
expectedSummaryElement.sumMem += stmtExecInfo2.MemMax
expectedSummaryElement.maxMem = stmtExecInfo2.MemMax
expectedSummaryElement.sumDisk += stmtExecInfo2.DiskMax
Expand Down Expand Up @@ -319,7 +323,7 @@ func (s *testStmtSummarySuite) TestAddStatement(c *C) {
sync.Mutex
BackoffTypes []fmt.Stringer
}{
BackoffTypes: []fmt.Stringer{tikv.BoTxnLock},
BackoffTypes: []fmt.Stringer{boTxnLockName},
},
ResolveLockTime: 1000,
WriteKeys: 10000,
Expand Down Expand Up @@ -374,7 +378,7 @@ func (s *testStmtSummarySuite) TestAddStatement(c *C) {
expectedSummaryElement.sumPrewriteRegionNum += int64(stmtExecInfo3.ExecDetail.CommitDetail.PrewriteRegionNum)
expectedSummaryElement.sumTxnRetry += int64(stmtExecInfo3.ExecDetail.CommitDetail.TxnRetry)
expectedSummaryElement.sumBackoffTimes += 1
expectedSummaryElement.backoffTypes[tikv.BoTxnLock] = 2
expectedSummaryElement.backoffTypes[boTxnLockName] = 2
expectedSummaryElement.sumMem += stmtExecInfo3.MemMax
expectedSummaryElement.sumDisk += stmtExecInfo3.DiskMax
expectedSummaryElement.sumAffectedRows += stmtExecInfo3.StmtCtx.AffectedRows()
Expand Down Expand Up @@ -575,7 +579,7 @@ func generateAnyExecInfo() *StmtExecInfo {
sync.Mutex
BackoffTypes []fmt.Stringer
}{
BackoffTypes: []fmt.Stringer{tikv.BoTxnLock},
BackoffTypes: []fmt.Stringer{boTxnLockName},
},
ResolveLockTime: 2000,
WriteKeys: 20000,
Expand Down Expand Up @@ -650,7 +654,7 @@ func (s *testStmtSummarySuite) TestToDatum(c *C) {
stmtExecInfo1.ExecDetail.CommitDetail.WriteSize, stmtExecInfo1.ExecDetail.CommitDetail.WriteSize,
stmtExecInfo1.ExecDetail.CommitDetail.PrewriteRegionNum, stmtExecInfo1.ExecDetail.CommitDetail.PrewriteRegionNum,
stmtExecInfo1.ExecDetail.CommitDetail.TxnRetry, stmtExecInfo1.ExecDetail.CommitDetail.TxnRetry, 0, 0, 1,
"txnLock:1", stmtExecInfo1.MemMax, stmtExecInfo1.MemMax, stmtExecInfo1.DiskMax, stmtExecInfo1.DiskMax,
fmt.Sprintf("%s:1", boTxnLockName), stmtExecInfo1.MemMax, stmtExecInfo1.MemMax, stmtExecInfo1.DiskMax, stmtExecInfo1.DiskMax,
0, 0, 0, 0, 0, stmtExecInfo1.StmtCtx.AffectedRows(),
t, t, 0, 0, 0, stmtExecInfo1.OriginalSQL, stmtExecInfo1.PrevSQL, "plan_digest", ""}
match(c, datums[0], expectedDatum...)
Expand Down Expand Up @@ -959,12 +963,13 @@ func (s *testStmtSummarySuite) TestGetMoreThanOnceBindableStmt(c *C) {
func (s *testStmtSummarySuite) TestFormatBackoffTypes(c *C) {
backoffMap := make(map[fmt.Stringer]int)
c.Assert(formatBackoffTypes(backoffMap), IsNil)
bo1 := stringutil.StringerStr("pdrpc")
backoffMap[bo1] = 1
c.Assert(formatBackoffTypes(backoffMap), Equals, "pdrpc:1")
bo2 := stringutil.StringerStr("txnlock")
backoffMap[bo2] = 2

backoffMap[tikv.BoPDRPC] = 1
c.Assert(formatBackoffTypes(backoffMap), Equals, "pdRPC:1")

backoffMap[tikv.BoTxnLock] = 2
c.Assert(formatBackoffTypes(backoffMap), Equals, "txnLock:2,pdRPC:1")
c.Assert(formatBackoffTypes(backoffMap), Equals, "txnlock:2,pdrpc:1")
}

// Test refreshing current statement summary periodically.
Expand Down