Skip to content

Commit

Permalink
Address comments and fix unexpected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
MyonKeminta committed Aug 2, 2021
1 parent df3f6ac commit 08a4f80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 12 additions & 3 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,9 @@ func (r *dataLockWaitsTableRetriever) retrieve(ctx context.Context, sctx session
for i, lockWait := range r.lockWaits {
digest, err := resourcegrouptag.DecodeResourceGroupTag(lockWait.ResourceGroupTag)
if err != nil {
logutil.BgLogger().Warn("failed to decode resource group tag", zap.Error(err))
// Ignore the error if failed to decode the digest from resource_group_tag. We still want to show
// as much information as possible even we can't retrieve some of them.
logutil.Logger(ctx).Warn("failed to decode resource group tag", zap.Error(err))
} else {
digests[i] = hex.EncodeToString(digest)
}
Expand All @@ -2278,7 +2280,9 @@ func (r *dataLockWaitsTableRetriever) retrieve(ctx context.Context, sctx session
if needSQLText {
sqlRetriever = NewSQLDigestTextRetriever()
for _, digest := range digests {
sqlRetriever.SQLDigestsMap[digest] = ""
if len(digest) > 0 {
sqlRetriever.SQLDigestsMap[digest] = ""
}
}
err := sqlRetriever.RetrieveGlobal(ctx, sctx)
if err != nil {
Expand Down Expand Up @@ -2315,7 +2319,12 @@ func (r *dataLockWaitsTableRetriever) retrieve(ctx context.Context, sctx session
case infoschema.DataLockWaitsColumnCurrentHoldingTrxID:
row = append(row, types.NewDatum(lockWait.WaitForTxn))
case infoschema.DataLockWaitsColumnSQLDigest:
row = append(row, types.NewDatum(digests[rowIdx]))
digest := digests[rowIdx]
if len(digest) == 0 {
row = append(row, types.NewDatum(nil))
} else {
row = append(row, types.NewDatum(digest))
}
case infoschema.DataLockWaitsColumnSQLDigestText:
text := sqlRetriever.SQLDigestsMap[digests[rowIdx]]
if len(text) > 0 {
Expand Down
15 changes: 9 additions & 6 deletions infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1724,21 +1724,24 @@ func (s *testClusterTableSuite) TestDataLockWaits(c *C) {
_, digest1 := parser.NormalizeDigest("select * from test_data_lock_waits for update")
_, digest2 := parser.NormalizeDigest("update test_data_lock_waits set f1=1 where id=2")
s.store.(mockstorage.MockLockWaitSetter).SetMockLockWaits([]*deadlock.WaitForEntry{
{Txn: 1, WaitForTxn: 2, KeyHash: 3, Key: []byte("key1"), ResourceGroupTag: resourcegrouptag.EncodeResourceGroupTag(digest1, nil)},
{Txn: 4, WaitForTxn: 5, KeyHash: 6, Key: []byte("key2"), ResourceGroupTag: resourcegrouptag.EncodeResourceGroupTag(digest2, nil)},
{Txn: 1, WaitForTxn: 2, Key: []byte("key1"), ResourceGroupTag: resourcegrouptag.EncodeResourceGroupTag(digest1, nil)},
{Txn: 3, WaitForTxn: 4, Key: []byte("key2"), ResourceGroupTag: resourcegrouptag.EncodeResourceGroupTag(digest2, nil)},
// Invalid digests
{Txn: 5, WaitForTxn: 6, Key: []byte("key3"), ResourceGroupTag: resourcegrouptag.EncodeResourceGroupTag(nil, nil)},
{Txn: 7, WaitForTxn: 8, Key: []byte("key4"), ResourceGroupTag: []byte("asdfghjkl")},
})

keyHex1 := "6B657931"
keyHex2 := "6B657932"
tk := s.newTestKitWithRoot(c)

// Execute one of the query once so it's stored into statements_summary.
tk.MustExec("create table test_data_lock_waits (id int primary key, f1 int)")
tk.MustExec("select * from test_data_lock_waits for update")

tk.MustQuery("select * from information_schema.DATA_LOCK_WAITS").Check(testkit.Rows(
keyHex1+" <nil> 1 2 "+digest1.String()+" select * from `test_data_lock_waits` for update",
keyHex2+" <nil> 4 5 "+digest2.String()+" <nil>"))
"6B657931 <nil> 1 2 "+digest1.String()+" select * from `test_data_lock_waits` for update",
"6B657932 <nil> 3 4 "+digest2.String()+" <nil>",
"6B657933 <nil> 5 6 <nil> <nil>",
"6B657934 <nil> 7 8 <nil> <nil>"))
}

func (s *testClusterTableSuite) TestDataLockWaitsPrivilege(c *C) {
Expand Down

0 comments on commit 08a4f80

Please sign in to comment.