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

executor: fix load data losing connection when batch_dml_size is set (#22724) #22736

Merged
merged 5 commits into from
Mar 9, 2021

Conversation

ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Feb 5, 2021

cherry-pick #22724 to release-4.0
You can switch your code base to this Pull Request by using git-extras:

# In tidb repo:
git pr https://github.com/pingcap/tidb/pull/22736

After apply modifications, you can push your change to this PR via:

git push [email protected]:ti-srebot/tidb.git pr/22736:release-4.0-8ddaf03db14a

What problem does this PR solve?

Issue Number: Fix #22540

Problem Summary:
When tidb_dml_batch_size is a relatively small(eg: 128/64), load data into a table which has a auto_random column may got lost connection error.

What is changed and how it works?

What's Changed:

  1. add InsertValues::isLoadData member
  2. add InsertValues::txnInUse (a mutex) member
  3. lock txnInUse when commit routine needs to refresh txn ctx
  4. lock txnInUse when process stream routine needs to generate auto random value

How it Works:

load data use two routine:

  1. process stream routine: parse file and generate batch insert task
  2. commit routine: read task from channel and do commit

Commit routine will invalid txn after task is committed. And before generate a new txn, process stream routine may use that invalid txn to generate audo random value. So we add a lock to protect txn, make sure process stream routine use a valid txn.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
    • TestLoadDataAutoRandom
  • Manual test (add detailed scripts or steps below)
    1. generate csv files(5W rows)
    2. set @@session.tidb_dml_batch_size = 128;
    3. drop table if exists t;
    4. create table t(c1 bigint auto_random primary key, c2 bigint, c3 bigint);
    5. load data local infile %q into table t (c2, c3);
  • No code

Side effects

  • Performance regression
    • add a lock when commit task and generate auto random, may got lock conflict and slow down load data performance.

Release note

  • fix load data lost connection error on tables with auto_random column

@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot added first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. sig/execution SIG execution sig/sql-infra SIG: SQL Infra type/4.0-cherry-pick type/bugfix This PR fixes a bug. labels Feb 5, 2021
@ti-srebot ti-srebot added this to the v4.0.11 milestone Feb 5, 2021
@ti-srebot
Copy link
Contributor Author

@guo-shaoge please accept the invitation then you can push to the cherry-pick pull requests.
https://github.com/ti-srebot/tidb/invitations

@guo-shaoge
Copy link
Collaborator

@AilinKid @XuHuaiyu

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 5, 2021
@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Feb 5, 2021

lgtm

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 5, 2021
@wshwsh12 wshwsh12 removed their request for review February 5, 2021 08:31
@XuHuaiyu
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor Author

Sorry @XuHuaiyu, this branch's release version is in progress, please contact zhouqiang-cl,shuke987,jebter,you06 for more details.

@tiancaiamao tiancaiamao added the priority/P0 The issue has P0 priority. label Mar 1, 2021
@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 4, 2021
@guo-shaoge
Copy link
Collaborator

@XuHuaiyu

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Mar 9, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 88b8ae1

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 9, 2021
@ti-chi-bot
Copy link
Member

@ti-srebot: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

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 merged commit c1ae2c6 into pingcap:release-4.0 Mar 9, 2021
@zhouqiang-cl zhouqiang-cl modified the milestones: v4.0.11, v4.0.12 Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. priority/P0 The issue has P0 priority. sig/execution SIG execution sig/sql-infra SIG: SQL Infra 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. type/bugfix This PR fixes a bug. type/4.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants