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

planner, sessionvar: avoid sending same task id to TiFlash #23747

Merged
merged 4 commits into from
Apr 9, 2021

Conversation

hanfei1991
Copy link
Member

What problem does this PR solve?

Issue Number: close pingcap/tiflash#1706

For queries in same txn, the task ids sent to TiFlash might be same. I will cause some errors with a very small probability.

What is changed and how it works?

What's Changed:
Like AllocColumnID, we add a AllocMPPTaskID function in SessionVars. If the start_ts varies, the task id will reset.

Check List

Tests

  • Unit test

Release note

  • planner, sessionvar: avoid sending same task id to TiFlash

@hanfei1991 hanfei1991 requested review from a team as code owners March 31, 2021 09:53
@hanfei1991 hanfei1991 requested review from lzmhhh123 and removed request for a team March 31, 2021 09:53
@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 31, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Mar 31, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 1, 2021
Copy link
Contributor

@fzhedu fzhedu left a comment

Choose a reason for hiding this comment

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

  1. different tidb server may also conflict on task id if getting the timestamp at the same time.
  2. due to killing queries by the query id, i.e. start ts, all queries in a transaction will be cancelled if just killing one of them.

@ti-chi-bot ti-chi-bot removed the status/LGT1 Indicates that a PR has LGTM 1. label Apr 7, 2021
@@ -820,6 +826,18 @@ type SessionVars struct {
AllowFallbackToTiKV map[kv.StoreType]struct{}
}

// AllocMPPTaskID allocates task id for mpp tasks. It will reset the task id if the query's
// startTs is different.
func (s *SessionVars) AllocMPPTaskID(startTS uint64) int64 {
Copy link
Contributor

Choose a reason for hiding this comment

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

need a mutex to avoid write conflicts?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's only required by one session. You can notice that every variable in SessionVars is vulnerable.

@hanfei1991
Copy link
Member Author

  1. different tidb server may also conflict on task id if getting the timestamp at the same time.
  2. due to killing queries by the query id, i.e. start ts, all queries in a transaction will be cancelled if just killing one of them.

It's impossible that two transaction shared same timestamp.

Copy link
Contributor

@fzhedu fzhedu 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-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • fzhedu

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 writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 9, 2021
@fzhedu
Copy link
Contributor

fzhedu commented Apr 9, 2021

/merge

@ti-chi-bot
Copy link
Member

@fzhedu: /merge in this pull request requires 2 /lgtm.

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.

@fzhedu
Copy link
Contributor

fzhedu commented Apr 9, 2021

/lgtm

@hanfei1991
Copy link
Member Author

/run-sqllogic-test-1

@hanfei1991
Copy link
Member Author

/merge

@ti-chi-bot
Copy link
Member

@hanfei1991: /merge in this pull request requires 2 /lgtm.

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.

@hanfei1991 hanfei1991 merged commit 9bbda60 into pingcap:master Apr 9, 2021
@hanfei1991 hanfei1991 deleted the hanfei/fix-dup-taskid branch April 9, 2021 12:22
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Apr 9, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.0 in PR #23935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate MPP task
5 participants