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: Fix lock view cannot show key info correctly for partition table #27027

Merged

Conversation

MyonKeminta
Copy link
Contributor

What problem does this PR solve?

Problem Summary: Currently when using the data_lock_waits and deadlocks table of lock view, if it shows a key from a partitioned table, the key_info column may not show the key's information correctly. It's because Lock View didn't handle these kind of keys correctly. This PR fixes this problem.

What is changed and how it works?

Proposal: xxx

What's Changed: In util/keydecoder, which is specifically used by Lock View for finding information from keys: When failed to find a table by table ID, try to use it as a partition ID and try to find the partition info and its corresponding table info.

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)
/* init */ drop table if exists t;
-- init >> 0 rows affected
/* init */ create table t (id int primary key, uk int, v int, unique key i1 (uk, id)) partition by range (id) ( partition p0 values less than (10), partition p1 values less than maxvalue);
-- init >> 0 rows affected
/* init */ insert into t values (1, 1, 1), (2, 2, 2);
-- init >> 2 rows affected
/* t1:wait */ begin;
-- t1 >> 0 rows affected
/* t1 */ update t set v = v + 1 where id = 1;
-- t1 >> 1 rows affected
/* t2 */ begin;
-- t2 >> 0 rows affected
/* t2 */ update t set v = v + 1 where id = 1;
-- t2 >> blocked
/* t4 */ select * from information_schema.data_lock_waits;
-- t4 >> +----------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------------+
-- t4    |                  KEY                   |                                                                  KEY INFO                                                                  |       TRX ID       | CURRENT HOLDING TRX ID |                            SQL DIGEST                            |                SQL DIGEST TEXT                |
-- t4    +----------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------------+
-- t4    | 74800000000000004D5F728000000000000001 | {"db_id":1,"db_name":"test","table_id":76,"table_name":"t","partition_id":77,"partition_name":"p0","handle_type":"int","handle_value":"1"} | 426901898605101059 |     426901898605101057 | 06da614b93e62713bd282d4685fc5b88d688337f36e88fe55871726ce0eb80d7 | update `t` set `v` = `v` + ? where `id` = ? ; |
-- t4    +----------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------+--------------------+------------------------+------------------------------------------------------------------+-----------------------------------------------+
/* t1 */ rollback;
-- t1 >> 0 rows affected
-- t2 >> resumed
-- t2 >> 1 rows affected

Side effects

  • None

Documentation

  • None

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 9, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • cfzjywxk
  • youjiali1995

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 9, 2021
Copy link
Contributor

@youjiali1995 youjiali1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM.

util/keydecoder/keydecoder.go Outdated Show resolved Hide resolved
util/keydecoder/keydecoder.go Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 9, 2021
@purelind
Copy link
Contributor

purelind commented Aug 9, 2021

/run-build

Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@cfzjywxk
Copy link
Contributor

cfzjywxk commented Aug 9, 2021

/merge

@ti-chi-bot
Copy link
Member

@cfzjywxk: /merge in this pull request requires 2 approval(s).

In response to this:

/merge

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Aug 9, 2021
@MyonKeminta
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: edde822

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 9, 2021
@ti-chi-bot ti-chi-bot merged commit e539f9d into pingcap:master Aug 9, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Aug 9, 2021
@ti-srebot
Copy link
Contributor

cherry pick to release-5.2 in PR #27035

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.2 release-note-none Denotes a PR that doesn't merit a release note. sig/transaction SIG:Transaction size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants