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

transaction: fix union select for update race #19006

Merged
merged 8 commits into from
Aug 6, 2020

Conversation

coocood
Copy link
Member

@coocood coocood commented Aug 5, 2020

What problem does this PR solve?

union select for update statements are executed concurrently, so LockKeys is executed concurrently too, but
LockKeys is not thread-safe, cause unexpected result.

What is changed and how it works?

Lock the whole LockKeys method instead of map access.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Release note

  • fix union select for update race

@coocood coocood added type/bugfix This PR fixes a bug. priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/transaction SIG:Transaction labels Aug 5, 2020
@lysu
Copy link
Contributor

lysu commented Aug 5, 2020


[2020-08-05T08:31:00.375Z] Read at 0x00c01731a268 by goroutine 590:

[2020-08-05T08:31:00.375Z]   github.com/pingcap/tidb/sessionctx/variable.(*TransactionContext).UpdateDeltaForTable()

[2020-08-05T08:31:00.375Z]       /home/jenkins/agent/workspace/tidb_ghpr_unit_test/go/src/github.com/pingcap/tidb/sessionctx/variable/session.go:219 +0x61

[2020-08-05T08:31:00.375Z]   github.com/pingcap/tidb/executor.(*SelectLockExec).Next()

@coocood update stats delta also have data race - -

Copy link
Contributor

@lysu lysu 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 Aug 5, 2020
jackysp
jackysp previously approved these changes Aug 5, 2020
Copy link
Member

@jackysp jackysp 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 removed the status/LGT1 Indicates that a PR has LGTM 1. label Aug 5, 2020
ti-srebot
ti-srebot previously approved these changes Aug 5, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Aug 5, 2020
@jackysp
Copy link
Member

jackysp commented Aug 5, 2020

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 5, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

@coocood merge failed.

@codecov
Copy link

codecov bot commented Aug 5, 2020

Codecov Report

Merging #19006 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #19006   +/-   ##
===========================================
  Coverage   79.5048%   79.5048%           
===========================================
  Files           546        546           
  Lines        148606     148606           
===========================================
  Hits         118149     118149           
  Misses        20978      20978           
  Partials       9479       9479           

@coocood coocood dismissed stale reviews from ti-srebot and jackysp via 4fc0706 August 5, 2020 11:15
@coocood coocood requested a review from a team as a code owner August 5, 2020 11:15
@coocood coocood requested review from wshwsh12 and removed request for a team August 5, 2020 11:15
@coocood
Copy link
Member Author

coocood commented Aug 5, 2020

/run-all-tests

@coocood
Copy link
Member Author

coocood commented Aug 5, 2020

/run-unit-test

@coocood
Copy link
Member Author

coocood commented Aug 6, 2020

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

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

@ti-srebot ti-srebot added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Aug 6, 2020
@cfzjywxk
Copy link
Contributor

cfzjywxk commented Aug 6, 2020

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #19022

coocood added a commit to coocood/tidb that referenced this pull request Aug 6, 2020
* transaction: fix LockKeys race

* do not update delta for lock keys

* fix more race

* fix another race

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>
@coocood coocood deleted the fix-lock-keys-race branch August 6, 2020 03:10
ti-srebot added a commit that referenced this pull request Aug 6, 2020
* transaction: fix LockKeys race

* do not update delta for lock keys

* fix more race

* fix another race

Co-authored-by: ti-srebot <66930949+ti-srebot@users.noreply.github.com>

Co-authored-by: Evan Zhou <coocood@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/executor priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/transaction SIG:Transaction status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants