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

sorter: fix Unified Sorter error handling & add more unit test cases #1619

Merged

Conversation

liuzix
Copy link
Contributor

@liuzix liuzix commented Apr 8, 2021

What problem does this PR solve?

  • Unified Sorter might return an unhelpful error ErrWorkerPoolHandleCancelled for some IO errors.
  • Some error handling code might cause data race.

What is changed and how it works?

  • Filter the ErrWorkerPoolHandleCancelled error.
  • Add appropriate synchronization to avoid races.
  • Add unit test cases for these fixes.

Check List

Tests

  • Unit test

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Fix Unified Sorter returning unhelpful error messages & other misc. fixes.

@liuzix liuzix requested review from zier-one and amyangfei April 8, 2021 09:42
@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 8, 2021
@liuzix liuzix added type/bugfix This PR fixes a bug. component/puller Puller component. status/ptal Could you please take a look? labels Apr 8, 2021
@ti-chi-bot ti-chi-bot requested a review from kennytm April 8, 2021 09:42
@liuzix
Copy link
Contributor Author

liuzix commented Apr 8, 2021

/run-all-tests

@codecov-io
Copy link

Codecov Report

Merging #1619 (e9170ca) into master (6c41167) will increase coverage by 0.1213%.
The diff coverage is 83.3333%.

@@               Coverage Diff                @@
##             master      #1619        +/-   ##
================================================
+ Coverage   52.9231%   53.0445%   +0.1213%     
================================================
  Files           152        152                
  Lines         16027      16045        +18     
================================================
+ Hits           8482       8511        +29     
+ Misses         6646       6641         -5     
+ Partials        899        893         -6     

@liuzix
Copy link
Contributor Author

liuzix commented Apr 8, 2021

/run-all-tests

dataSize int64
lastTs uint64 // for debugging TODO remove
canceller *asyncCanceller

isEmpty bool // ready only field
Copy link
Contributor

Choose a reason for hiding this comment

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

Should ready only be read only?

@@ -223,6 +224,11 @@ func (s *UnifiedSorter) Run(ctx context.Context) error {
default:
}
err := sorter.poolHandle.AddEvent(subctx, event)
if cerror.ErrWorkerPoolHandleCancelled.Equal(errors.Cause(err)) {
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
if cerror.ErrWorkerPoolHandleCancelled.Equal(errors.Cause(err)) {
if cerror.ErrWorkerPoolHandleCancelled.Equal(err) {

Equal will unwrap the err first

@@ -240,6 +246,11 @@ func (s *UnifiedSorter) Run(ctx context.Context) error {
default:
err := heapSorters[targetID].poolHandle.AddEvent(subctx, event)
if err != nil {
if cerror.ErrWorkerPoolHandleCancelled.Equal(errors.Cause(err)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Comment on lines +154 to +156
backEnd := task.GetBackEnd()
if backEnd != nil {
defer task.markDeallocated()
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

  1. In L154-L155, backEnd is not nil
  2. When calling pool.dealloc(backEnd), task is marked as deallocated and task.backend becomes nil, through backEnd is not nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dealloc will not race with itself, because dealloc calls from different goroutines are always synchronized by a write to finished channel.

@liuzix liuzix added the needs-cherry-pick-release-5.0 Should cherry pick this PR to release-5.0 branch. label Apr 12, 2021
@liuzix
Copy link
Contributor Author

liuzix commented Apr 12, 2021

/run-all-tests

@zier-one zier-one added this to the v5.0.1 milestone Apr 13, 2021
@amyangfei
Copy link
Contributor

/lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 13, 2021
@zier-one zier-one added the needs-cherry-pick-release-4.0 Should cherry pick this PR to release-4.0 branch. label Apr 14, 2021
@zier-one
Copy link
Contributor

/lgtm

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • amyangfei
  • leoppro

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 status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 15, 2021
@zier-one
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 988c07c

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 15, 2021
@amyangfei
Copy link
Contributor

unit tests are still unstable, PTAL @liuzix

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

liuzix commented Apr 15, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 1dd20c4

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 15, 2021
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Apr 15, 2021
@liuzix
Copy link
Contributor Author

liuzix commented Apr 15, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: e6c8a5a

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 15, 2021
Comment on lines 348 to 349
err := testSorter(ctx, c, sorter, 10000000, true)
c.Assert(err, check.ErrorMatches, ".*injected alloc error.*")
Copy link
Contributor

Choose a reason for hiding this comment

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

The timeout still happens, can we decrease the count 10000000

@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Apr 16, 2021
@zier-one
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 156e52e

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Apr 16, 2021
@zier-one
Copy link
Contributor

/run-integration-tests

@ti-chi-bot ti-chi-bot merged commit 2277431 into pingcap:master Apr 16, 2021
ti-srebot pushed a commit to ti-srebot/ticdc that referenced this pull request Apr 16, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #1677

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

cherry pick to release-5.0 in PR #1678

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/puller Puller component. needs-cherry-pick-release-4.0 Should cherry pick this PR to release-4.0 branch. needs-cherry-pick-release-5.0 Should cherry pick this PR to release-5.0 branch. 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. status/ptal Could you please take a look? type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants