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

lightning: sample files and pre-allocate rowID before restoring chunk #34288

Merged
merged 29 commits into from
Jun 16, 2022

Conversation

buchuitoudegou
Copy link
Contributor

@buchuitoudegou buchuitoudegou commented Apr 27, 2022

What problem does this PR solve?

Issue Number: close #28776

Problem Summary:

Currently, Lightning pre-allocates rowIDs for each row when populating chunks according to data file sizes. But it occurs that estimates of rowID are now conservatively too large so that Lightning usually pre-allocates a large number of rowIDs, which significantly exceeds what we need. This issue may result in:

  1. if the number of rows is relatively close to the maximum of the data type of its auto_increment field, Lightning is likely to allocate rowIDs that exceed this limit. (e.g. 2^31 rows of data may probably have 2^32 rowIDs, which exceeds the range of int32 if the auto_increment field is int32)
  2. Too much space of rowID is wasted because of over-estimate.

What is changed and how it works?

In this pr, I'm about to:

  1. sample rows from data files and do a better estimation.
  2. re-allocate ids when they are run out (due to bad estimation)
  3. early stop when the rowID overflows

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 27, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • D3Hunter
  • gozssky

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 submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. needs-cherry-pick-4.0 do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 27, 2022
@buchuitoudegou
Copy link
Contributor Author

/component lightning

@ti-chi-bot ti-chi-bot added the component/lightning This issue is related to Lightning of TiDB. label Apr 27, 2022
@CLAassistant
Copy link

CLAassistant commented Apr 27, 2022

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels May 5, 2022
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 6, 2022
@buchuitoudegou buchuitoudegou changed the title [WIP] lightning: sample files and pre-allocate rowID before restoring chunk lightning: sample files and pre-allocate rowID before restoring chunk May 7, 2022
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 7, 2022
@sre-bot
Copy link
Contributor

sre-bot commented May 7, 2022

@buchuitoudegou
Copy link
Contributor Author

/cc @gozssky @D3Hunter @Ehco1996

PTAL

@buchuitoudegou
Copy link
Contributor Author

/run-integration-br-test

@buchuitoudegou
Copy link
Contributor Author

ptal @gozssky

Comment on lines 476 to 481
case mysql.TypeLonglong:
if !isUnsigned {
return rowID > math.MaxInt64
}
// impossible for rowID exceeding MaxUint64
return uint64(rowID) > math.MaxUint64
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
case mysql.TypeLonglong:
if !isUnsigned {
return rowID > math.MaxInt64
}
// impossible for rowID exceeding MaxUint64
return uint64(rowID) > math.MaxUint64

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 16, 2022
@sleepymole
Copy link
Contributor

/hold

@ti-chi-bot ti-chi-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 16, 2022
@buchuitoudegou
Copy link
Contributor Author

/run-integration-br-test

@sleepymole
Copy link
Contributor

/unhold
/merge

@ti-chi-bot ti-chi-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 16, 2022
@ti-chi-bot
Copy link
Member

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

Commit hash: 5a839c9

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jun 16, 2022
@ti-chi-bot ti-chi-bot merged commit 674def3 into pingcap:master Jun 16, 2022
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Jun 16, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #35456

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Jun 16, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-6.0 in PR #35457

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Jun 16, 2022
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-6.1 in PR #35458

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/lightning This issue is related to Lightning of TiDB. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lightning] Estimate rowid might overflow when import data and auto fill int column.
7 participants