Skip to content

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

Merged
XuHuaiyu merged 1 commit intopingcap:release-5.0-rcfrom
ti-srebot:release-5.0-rc-8ddaf03db14a
Feb 19, 2021
Merged

executor: fix load data losing connection when batch_dml_size is set (#22724)#22737
XuHuaiyu merged 1 commit intopingcap:release-5.0-rcfrom
ti-srebot:release-5.0-rc-8ddaf03db14a

Conversation

@ti-srebot
Copy link
Contributor

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

cherry-pick #22724 to release-5.0-rc
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/22737

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

git push git@github.com:ti-srebot/tidb.git pr/22737:release-5.0-rc-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

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot ti-srebot requested a review from a team as a code owner February 5, 2021 02:53
@ti-srebot ti-srebot requested review from XuHuaiyu and removed request for a team February 5, 2021 02:53
@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/5.0-rc-cherry-pick type/bugfix This PR fixes a bug. labels 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

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Feb 5, 2021

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 5, 2021
@wshwsh12 wshwsh12 removed their request for review February 5, 2021 08:31
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 status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 5, 2021
@XuHuaiyu XuHuaiyu merged commit d3a4e00 into pingcap:release-5.0-rc Feb 19, 2021
@XuHuaiyu XuHuaiyu deleted the release-5.0-rc-8ddaf03db14a branch February 19, 2021 03:49
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. sig/execution SIG execution sig/sql-infra SIG: SQL Infra status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants