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

Updating non-index column by point-getting on unique index may cause too many Lock records in Write CF #33393

Closed
MyonKeminta opened this issue Mar 24, 2022 · 3 comments
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 may-affects-4.0 This bug maybe affects 4.0.x versions. severity/moderate sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@MyonKeminta
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

The problem

It's actually the same problem as stated in #25659 . It's partially fixed by the workaround PR #25730 , However it only optimized the case where the row exists (by changing the Lock records on unique-index key into Put records), and Lock records will still cumulate when trying to update non-exist rows.

We notice that in an inactive TiDB cluster, it keeps updating statistics info internally while there's no user query:

UPDATE mysql.stats_meta SET version = 432042759841644547, count = count + 11, modify_count = modify_count + 12227 WHERE table_id = 17;

The table id 17 belongs to mysql.tidb, and the row doesn't exist.

There are many lock records accumulated on the corresponding unique index key:

$ curl http://172.16.4.171:10081/mvcc/index/mysql/stats_meta/tbl/0?table_id=17
{
 "key": "7480000000000000155F698000000000000002038000000000000011",
 "region_id": 3,
 "value": {
  "info": {
   "writes": [
    {
     "type": 2,
     "start_ts": 432042791299186690,
     "commit_ts": 432042791299186692
    },
    {
     "type": 2,
     "start_ts": 432042775570284546,
     "commit_ts": 432042775570284549
    },
    {
     "type": 2,
     "start_ts": 432042759841644547,
     "commit_ts": 432042759841644549
    },
    {
     "type": 2,
     "start_ts": 432042744113266690,
     "commit_ts": 432042744113266692
    },
    {
     "type": 2,
     "start_ts": 432042728384626690,
     "commit_ts": 432042728384626693
    },
    {
     "type": 2,
     "start_ts": 432042712655986690,
     "commit_ts": 432042712655986692
    },
.....

and in metrics of Scheduler - acquire_pessimisitc_lock:

origin_img_v2_854f0e4c-6885-47d8-a8c2-5e1d73901dbg

It seems that the lock records are not GC-ed because compaction is run very infrequently when the cluster is idle.

We didn't find this problem affect any user for now, but it's a problem and has potential risks.

What is your TiDB version?

4.0.10+, 5.x, master

@MyonKeminta MyonKeminta added the type/bug The issue is confirmed as a bug. label Mar 24, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.0 labels Mar 24, 2022
@seiya-annie seiya-annie added affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 and removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. labels Mar 24, 2022
@seiya-annie seiya-annie added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.0 and removed affects-6.0 labels Mar 24, 2022
@jebter jebter added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 labels Mar 24, 2022
@ti-chi-bot ti-chi-bot removed may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-6.0 labels Mar 24, 2022
@ekexium
Copy link
Contributor

ekexium commented Jun 14, 2022

How about writing delete records instead of locks for non-existent keys?

@MyonKeminta
Copy link
Contributor Author

How about writing delete records instead of locks for non-existent keys?

It's ok to fix it in this way, if this problem does impact any users. We are just thinking about figuring out a way to fix the problems about Lock records completely.

@MyonKeminta
Copy link
Contributor Author

Close due to being solved in tikv/tikv#13694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 may-affects-4.0 This bug maybe affects 4.0.x versions. severity/moderate sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

7 participants