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

br: fix lightning split large csv file error and adjust s3 seek result #27769

Merged
merged 36 commits into from
Sep 8, 2021

Conversation

glorv
Copy link
Contributor

@glorv glorv commented Sep 2, 2021

What problem does this PR solve?

Fix the bug that lightning split large csv file may failed if the file size if slightly bigger the region-split-size and the csv has header.

close #27763

What is changed and how it works?

  • If the backend if s3, when the seek position >= file size, the seek will succeed and the reader will be replaced with a reader that always returns io.EOF
  • Add a check in lightning makeTableRegions, after preprocess the header line, if the remain file is smaller than region-split-size, directly return the result with 1 region.

Check List

Tests

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

Side effects

Documentation

Release note

Fix the bug that import from s3 may fail if the csv file size is similar to region-split-size(default is 256MiB)

@glorv glorv added type/bugfix This PR fixes a bug. sig/migrate needs-cherry-pick-release-5.2 component/lightning This issue is related to Lightning of TiDB. labels Sep 2, 2021
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 2, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • gozssky
  • kennytm

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 Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 2, 2021
}

r.reader = eofReader{}
return r.rangeInfo.Size, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

r.pos need to be updated in case subsequent seeks. Also, should we return realOffset rather than r.rangeInfo.Size? I didn't find any specifications for this behavior, but returning realOffset is more consistent with linux filesystem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I think we should return real position which is r.rangeInfo.Size, since the behavior isn't the same as linux fs. fs implement ReaderWriter and allow to write to a position that is larger that the current end and leave the file with a hole. But here we don't. Though there is no much difference.

@@ -648,6 +648,17 @@ func (r *s3ObjectReader) Close() error {
return r.reader.Close()
}

// eofReader is a io.ReaderClose Reader that always return io.EOF
type eofReader struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

(optional io.NopCloser(bytes.NewReader(nil))

@@ -268,7 +268,7 @@ func makeSourceFileRegion(
}
// If a csv file is overlarge, we need to split it into multiple regions.
// Note: We can only split a csv file whose format is strict.
if isCsvFile && dataFileSize > int64(cfg.Mydumper.MaxRegionSize) && cfg.Mydumper.StrictFormat {
if isCsvFile && cfg.Mydumper.StrictFormat && dataFileSize > int64(cfg.Mydumper.MaxRegionSize)*11/10 {
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the file size if slightly bigger the int64(cfg.Mydumper.MaxRegionSize)*11/10? 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then the file will be split by cfg.Mydumper.MaxRegionSize, so the second chunk size is about 1/10 * cfg.Mydumper.MaxRegionSize.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the file size is slightly bigger the int64(cfg.Mydumper.MaxRegionSize)* 2, the third chunk size is very small, will this be a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a big problem. The common case is that the data export tool (like dumpling or mydumper) set the exported file size with cfg.Mydumper.MaxRegionSize, but the output file size might be slightly bigger or smaller, so we can avoid split a lot of small chunks.

Copy link
Contributor

Choose a reason for hiding this comment

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

make that 11/10 a named constant...

Copy link
Contributor Author

@glorv glorv Sep 6, 2021

Choose a reason for hiding this comment

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

It will make the code a bit ugly because 11/10 is a float. I add a code comment to explain why the threshold need to be increased😅

Copy link
Contributor

Choose a reason for hiding this comment

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

you can make "10" a constant and set the upper limit to MaxRegionSize + MaxRegionSize/10.

@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 6, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 6, 2021
@glorv
Copy link
Contributor Author

glorv commented Sep 8, 2021

/run-check_dev_2

1 similar comment
@glorv
Copy link
Contributor Author

glorv commented Sep 8, 2021

/run-check_dev_2

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Sep 8, 2021
@glorv
Copy link
Contributor Author

glorv commented Sep 8, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 69a37a3

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 8, 2021
@glorv
Copy link
Contributor Author

glorv commented Sep 8, 2021

/run-check_dev_2

@niubell
Copy link
Contributor

niubell commented Apr 12, 2022

/remove-label needs-cherry-pick-5.2

@niubell
Copy link
Contributor

niubell commented Apr 12, 2022

/label needs-cherry-pick-5.2

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

cherry pick to release-5.2 in PR #33883

@niubell
Copy link
Contributor

niubell commented Apr 13, 2022

/remove-label needs-cherry-pick-5.2

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. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/migrate 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lightning: DBaaS import csv fails with InvalidRange if CSV file size is about 256MB when strict-format is true
6 participants