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

infoschema: fix the issue txn state size is not defined (#53801) #53823

Merged
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
2 changes: 1 addition & 1 deletion infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ var tableTiDBTrxCols = []columnInfo{
{name: txninfo.StartTimeStr, tp: mysql.TypeTimestamp, decimal: 6, size: 26, comment: "Start time of the transaction"},
{name: txninfo.CurrentSQLDigestStr, tp: mysql.TypeVarchar, size: 64, comment: "Digest of the sql the transaction are currently running"},
{name: txninfo.CurrentSQLDigestTextStr, tp: mysql.TypeBlob, size: types.UnspecifiedLength, comment: "The normalized sql the transaction are currently running"},
{name: txninfo.StateStr, tp: mysql.TypeEnum, enumElems: txninfo.TxnRunningStateStrs, comment: "Current running state of the transaction"},
{name: txninfo.StateStr, tp: mysql.TypeEnum, size: 16, enumElems: txninfo.TxnRunningStateStrs, comment: "Current running state of the transaction"},
{name: txninfo.WaitingStartTimeStr, tp: mysql.TypeTimestamp, decimal: 6, size: 26, comment: "Current lock waiting's start time"},
{name: txninfo.MemBufferKeysStr, tp: mysql.TypeLonglong, size: 64, comment: "How many entries are in MemDB"},
{name: txninfo.MemBufferBytesStr, tp: mysql.TypeLonglong, size: 64, comment: "MemDB used memory"},
Expand Down
26 changes: 23 additions & 3 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,8 @@ func TestTiDBTrx(t *testing.T) {
memDBTracker := memory.NewTracker(memory.LabelForMemDB, -1)
memDBTracker.Consume(19)
tk.Session().GetSessionVars().MemDBFootprint = memDBTracker
t1 := time.Date(2021, 5, 7, 4, 56, 48, 1000000, time.UTC)
t2 := time.Date(2021, 5, 20, 13, 16, 35, 778000000, time.UTC)
sm.TxnInfo[0] = &txninfo.TxnInfo{
StartTS: 424768545227014155,
CurrentSQLDigest: digest.String(),
Expand All @@ -1588,9 +1590,27 @@ func TestTiDBTrx(t *testing.T) {
sm.TxnInfo[1].BlockStartTime.Time = blockTime2
tk.Session().SetSessionManager(sm)

tk.MustQuery("select * from information_schema.TIDB_TRX;").Check(testkit.Rows(
"424768545227014155 2021-05-07 12:56:48.001000 "+digest.String()+" update `test_tidb_trx` set `i` = `i` + ? Idle <nil> 1 19 2 root test [] ",
"425070846483628033 2021-05-20 21:16:35.778000 <nil> <nil> LockWaiting 2021-05-20 13:18:30.123456 0 19 10 user1 db1 [\"sql1\",\"sql2\",\""+digest.String()+"\"] "))
tk.MustQuery(`select ID,
START_TIME,
CURRENT_SQL_DIGEST,
CURRENT_SQL_DIGEST_TEXT,
STATE,
WAITING_START_TIME,
MEM_BUFFER_KEYS,
MEM_BUFFER_BYTES,
SESSION_ID,
USER,
DB,
ALL_SQL_DIGESTS,
RELATED_TABLE_IDS
from information_schema.TIDB_TRX`).Check(testkit.Rows(
"424768545227014155 "+t1.Local().Format(types.TimeFSPFormat)+" "+digest.String()+" update `test_tidb_trx` set `i` = `i` + ? Idle <nil> 1 19 2 root test [] ",
"425070846483628033 "+t2.Local().Format(types.TimeFSPFormat)+" <nil> <nil> LockWaiting "+
// `WAITING_START_TIME` will not be affected by time_zone, it is in memory and we assume that the system time zone will not change.
blockTime2.Format(types.TimeFSPFormat)+
" 0 19 10 user1 db1 [\"sql1\",\"sql2\",\""+digest.String()+"\"] "))
tk.MustQuery(`select state from information_schema.tidb_trx as trx union select state from information_schema.tidb_trx as trx`).Sort().
Check(testkit.Rows(txninfo.TxnRunningStateStrs[txninfo.TxnIdle], txninfo.TxnRunningStateStrs[txninfo.TxnLockAcquiring]))

// Test the all_sql_digests column can be directly passed to the tidb_decode_sql_digests function.
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/expression/sqlDigestRetrieverSkipRetrieveGlobal", "return"))
Expand Down