-
Notifications
You must be signed in to change notification settings - Fork 188
loader/syncer: filter context cancel error while executing sqls #355
loader/syncer: filter context cancel error while executing sqls #355
Conversation
Codecov Report
@@ 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 |
/run-all-tests tidb=release-3.0 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
…chunzhu/dm into czli/filterContextCancelError
/run-all-tests tidb=release-3.0 |
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about FilterCancelError
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FilterCancelError
LGTM
There was a problem hiding this comment.
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:
- return
error
. the usage would belog.ShortError(log.FilterCancelError(err))
- return
zap.Field
. the usage would belog.FilterCancelError(err)
…erContextCancelError
…chunzhu/dm into czli/filterContextCancelError
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about use IsContextCanceledError
?
/run-all-tests tidb=release-3.0 |
@csuzhangxc Revised, PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests tidb=release-3.0 |
cherry pick to release-1.0 failed |
…cap#355) * add ErrorFilterContextCanceled to skip error log of context.Canceled
* fix situations when there is extra msg in error.Error * add deal for zap.Error and add UT
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
Related changes