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

prefetch: fix underlying unexpected-eof taken as EOF #59752

Merged
merged 10 commits into from
Mar 5, 2025

Conversation

D3Hunter
Copy link
Contributor

@D3Hunter D3Hunter commented Feb 25, 2025

What problem does this PR solve?

Issue Number: ref #59495

Problem Summary:

What changed and how does it work?

the underlying reader might also return unexpected-eof, we need different between them, introduced in #59496

  • add rangeSize to prefetch.Reader to determine where UnexpectedEOF comes from
  • check error equals using goerrors.Is instead of ==. we might add stack to the error to help debug
    • Note: for the implementation of io.Reader, we still follow the API definition to return the io.EOF directly without stack, our byteReader doesn't follow the API of io.Reader, so it's ok to add stack to the error
    • And to unify code, we always use goerrors.Is to check io.EOF even for errors from io.Reader
  • avoid retry when context cancel

Check List

Tests

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

same test in #50451, before it will fail with unexpected-eof, now success

  • No need to test
    • I checked and no code files have been changed.

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 ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 25, 2025
Copy link

tiprow bot commented Feb 25, 2025

Hi @D3Hunter. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes-sigs/prow repository.

@@ -87,13 +86,7 @@ func (r *concurrentFileReader) read(bufs [][]byte) ([][]byte, error) {
buf,
)
if err != nil {
log.FromContext(r.ctx).Error(
Copy link
Contributor Author

@D3Hunter D3Hunter Feb 25, 2025

Choose a reason for hiding this comment

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

it prints too many logs when context cancel due to some goroutine in the same group failed, it's not needed, there is no further usefully info in it.

@@ -977,7 +983,7 @@ func (r *s3ObjectReader) Read(p []byte) (n int, err error) {
n, err = r.reader.Read(p[:maxCnt])
// TODO: maybe we should use !errors.Is(err, io.EOF) here to avoid error lint, but currently, pingcap/errors
// doesn't implement this method yet.
for err != nil && errors.Cause(err) != io.EOF && retryCnt < maxErrorRetries { //nolint:errorlint
for err != nil && errors.Cause(err) != io.EOF && r.ctx.Err() == nil && retryCnt < maxErrorRetries { //nolint:errorlint
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need to retry on context cancel

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 83.58209% with 11 lines in your changes missing coverage. Please review.

Project coverage is 75.5231%. Comparing base (a5d433a) to head (4d4b432).
Report is 52 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #59752        +/-   ##
================================================
+ Coverage   72.9537%   75.5231%   +2.5693%     
================================================
  Files          1697       1746        +49     
  Lines        468912     486378     +17466     
================================================
+ Hits         342089     367328     +25239     
+ Misses       105752      96490      -9262     
- Partials      21071      22560      +1489     
Flag Coverage Δ
integration 49.6930% <0.0000%> (?)
unit 72.7725% <83.5820%> (+0.6235%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 63.6838% <62.5000%> (+18.5844%) ⬆️

@lance6716 lance6716 requested a review from Copilot February 26, 2025 03:43

Choose a reason for hiding this comment

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

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

pkg/util/prefetch/reader.go:71

  • Converting io.ErrUnexpectedEOF to io.EOF only when readSize equals r.rangeSize assumes that the underlying reader has read the full expected range. Please verify that this invariant holds in all cases to avoid masking incomplete reads.
if errors.Is(err, io.ErrUnexpectedEOF) && readSize == r.rangeSize {

br/pkg/storage/s3.go:986

  • The addition of the r.ctx.Err() == nil check prevents retries once the context is cancelled; please ensure that there are tests covering mid-read cancellation scenarios so that this behavior is fully validated.
for err != nil && errors.Cause(err) != io.EOF && r.ctx.Err() == nil && retryCnt < maxErrorRetries { //nolint:errorlint

br/pkg/storage/ks3.go:446

  • Passing r.RangeSize() as the second parameter to NewReader requires that its value is valid and non-negative. It would be good to ensure that r.RangeSize() is properly validated before using it in production code.
reader = prefetch.NewReader(reader, r.RangeSize(), prefetchSize)
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 26, 2025
Copy link

ti-chi-bot bot commented Mar 5, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lance6716, tangenta

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Mar 5, 2025
Copy link

ti-chi-bot bot commented Mar 5, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-02-26 12:19:33.249481848 +0000 UTC m=+444721.202640115: ☑️ agreed by lance6716.
  • 2025-03-05 06:07:45.313305898 +0000 UTC m=+421778.442225635: ☑️ agreed by tangenta.

@ti-chi-bot ti-chi-bot bot merged commit 0f5ba8f into pingcap:master Mar 5, 2025
25 of 31 checks passed
@D3Hunter D3Hunter deleted the fix-unexpected-eof branch March 6, 2025 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants