Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

loader/syncer: filter context cancel error while executing sqls #355

Merged
merged 16 commits into from
Nov 28, 2019

Conversation

lichunzhu
Copy link
Contributor

What problem does this PR solve?

When an error occurs and the context in loader/syncer is canceled, the normally running sql will be canceled and return a context.Canceled error, which will confuse the users.

What is changed and how it works?

Filter all the context.Canceled in loader/syncer. Don't return error and don't print log.

Check List

Tests

  • Unit test
  • Integration test

Related changes

  • Need to cherry-pick to the release branch

@lichunzhu lichunzhu added priority/normal Minor change, requires approval from ≥1 primary reviewer status/PTAL This PR is ready for review. Add this label back after committing new changes needs-cherry-pick-release-1.0 This PR should be cherry-picked to release-1.0. Remove this label after cherry-picked to release-1.0 labels Nov 14, 2019
@lichunzhu lichunzhu added status/WIP This PR is still work in progress and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Nov 14, 2019
@codecov
Copy link

codecov bot commented Nov 14, 2019

Codecov Report

Merging #355 into master will increase coverage by 1.1016%.
The diff coverage is 16.6666%.

@@               Coverage Diff                @@
##             master       #355        +/-   ##
================================================
+ Coverage   56.5969%   57.6986%   +1.1016%     
================================================
  Files           163        162         -1     
  Lines         16697      16373       -324     
================================================
- Hits           9450       9447         -3     
+ Misses         6324       6001       -323     
- Partials        923        925         +2

@lichunzhu
Copy link
Contributor Author

@WangXiangUSTC @csuzhangxc PTAL

@lichunzhu
Copy link
Contributor Author

/run-all-tests tidb=release-3.0

@lichunzhu lichunzhu added status/PTAL This PR is ready for review. Add this label back after committing new changes and removed status/WIP This PR is still work in progress labels Nov 21, 2019
loader/db.go Outdated Show resolved Hide resolved
loader/loader.go Outdated
@@ -174,7 +174,11 @@ func (w *Worker) run(ctx context.Context, fileJobQueue chan *fileJob, runFatalCh
if err != nil {
// expect pause rather than exit
err = terror.WithScope(terror.Annotatef(err, "file %s", job.file), terror.ScopeDownstream)
runFatalChan <- unit.NewProcessError(pb.ErrorType_ExecSQL, err)
if utils.IsContextCanceledError(err) {
runFatalChan <- nil
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Contributor Author

@lichunzhu lichunzhu Nov 25, 2019

Choose a reason for hiding this comment

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

If we don't deal with runFatalChan, the user will still get cancel error from dmctl. Shall we revise unit.NewProcessError to filter that instead of this way?

Copy link
Contributor

Choose a reason for hiding this comment

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

if err is context cancel error, don't need to send nil to runFatalChan

@lichunzhu
Copy link
Contributor Author

/run-all-tests tidb=release-3.0

@csuzhangxc csuzhangxc added this to the v1.0.3 milestone Nov 25, 2019
pkg/log/log.go Outdated
@@ -130,7 +132,7 @@ func SetLevel(level zapcore.Level) zapcore.Level {
// just repeats known information. You should almost always use `ShortError`
// instead of `zap.Error`, unless the error is no longer propagated upwards.
func ShortError(err error) zap.Field {
if err == nil {
if err == nil || errors.Cause(err) == context.Canceled {
Copy link
Member

Choose a reason for hiding this comment

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

which one is better:

  1. update ShortError
  2. add a new function

@WangXiangUSTC what's your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think 2 is better

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean put err == nil || errors.Cause(err) == context.Canceled... into a new function?
@WangXiangUSTC

Copy link
Contributor

Choose a reason for hiding this comment

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

how about adding a new function to judge whether an error can be filter

func FilterError(err error) error {
    if errors.Cause(err) == context.Canceled {
         return nil
    }
    return err
}

then we can use ShortError(FilterError(err))

Copy link
Member

Choose a reason for hiding this comment

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

approve the method from @WangXiangUSTC, but maybe a meaningful name needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about FilterCancelError?

Copy link
Member

Choose a reason for hiding this comment

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

FilterCancelError LGTM

Copy link
Contributor Author

@lichunzhu lichunzhu Nov 28, 2019

Choose a reason for hiding this comment

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

@csuzhangxc
which one is better:

  1. return error. the usage would be log.ShortError(log.FilterCancelError(err))
  2. return zap.Field. the usage would be log.FilterCancelError(err)

pkg/log/log.go Outdated
@@ -136,6 +138,14 @@ func ShortError(err error) zap.Field {
return zap.String("error", err.Error())
}

// FilterCancelError will skip context.Canceled error
func FilterCancelError(err error) error {
if errors.Cause(err) == context.Canceled {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about use IsContextCanceledError?

@lichunzhu
Copy link
Contributor Author

/run-all-tests tidb=release-3.0

@lichunzhu
Copy link
Contributor Author

@csuzhangxc Revised, PTAL

Copy link
Member

@csuzhangxc csuzhangxc left a comment

Choose a reason for hiding this comment

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

LGTM

@csuzhangxc csuzhangxc added status/LGT1 One reviewer already commented LGTM and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Nov 28, 2019
Copy link
Contributor

@WangXiangUSTC WangXiangUSTC left a comment

Choose a reason for hiding this comment

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

LGTM

@WangXiangUSTC
Copy link
Contributor

/run-all-tests tidb=release-3.0

@lichunzhu lichunzhu merged commit 2ac7ad3 into pingcap:master Nov 28, 2019
@lichunzhu lichunzhu deleted the czli/filterContextCancelError branch November 28, 2019 07:15
@sre-bot
Copy link

sre-bot commented Nov 28, 2019

cherry pick to release-1.0 failed

@WangXiangUSTC WangXiangUSTC added status/LGT2 Two reviewers already commented LGTM, ready for merge and removed status/LGT1 One reviewer already commented LGTM labels Nov 29, 2019
lichunzhu added a commit that referenced this pull request Nov 29, 2019
* fix situations when there is extra msg in error.Error

* add deal for zap.Error and add UT
@ericsyh ericsyh removed this from the v1.0.3 milestone Dec 3, 2019
@csuzhangxc csuzhangxc added already-cherry-pick-1.0 The related PR is already cherry-picked to release-1.0. Add this label once the PR is cherry-picked and removed needs-cherry-pick-release-1.0 This PR should be cherry-picked to release-1.0. Remove this label after cherry-picked to release-1.0 labels Mar 13, 2020
lichunzhu added a commit to lichunzhu/dm that referenced this pull request Apr 6, 2020
…cap#355)

* add ErrorFilterContextCanceled to skip error log of context.Canceled
lichunzhu added a commit to lichunzhu/dm that referenced this pull request Apr 6, 2020
* fix situations when there is extra msg in error.Error

* add deal for zap.Error and add UT
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
already-cherry-pick-1.0 The related PR is already cherry-picked to release-1.0. Add this label once the PR is cherry-picked priority/normal Minor change, requires approval from ≥1 primary reviewer status/LGT2 Two reviewers already commented LGTM, ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants