-
-
Notifications
You must be signed in to change notification settings - Fork 344
FIX: [sync] handle MySQL duplicate entry errors during record insertion #2037
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
Conversation
pkg/service/sync_task.go
Outdated
} | ||
if isMysqlDuplicateError(err, logger) { | ||
// ignore duplicate error | ||
logger.Infof("duplicate entry for %T, skipped: %+v", obj, obj) |
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.
using Warnf should be okay
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.
done.
pkg/service/sync_task.go
Outdated
logger.Infof("duplicate entry for %T, skipped: %+v", obj, obj) | ||
continue | ||
} else if err != nil { | ||
logger.WithError(err).Errorf("can not insert record: %v", obj) |
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.
use %+v here
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.
done.
pkg/service/sync_task.go
Outdated
// "Error 1062 (23000): Duplicate entry" | ||
if parentErr := errors.Unwrap(err); parentErr != nil { | ||
if mysqlErr, ok := parentErr.(*mysql.MySQLError); ok { | ||
logger.Errorf("matched MySQLError: %+v", mysqlErr) |
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.
we can remove this line?
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.
done.
pkg/service/sync_task.go
Outdated
} | ||
} | ||
|
||
matched, _ := regexp.MatchString("Duplicate entry", err.Error()) |
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.
can we pre-compile the pattern?
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.
done.
8efe65c
to
a3dded2
Compare
a3dded2
to
d53ab18
Compare
No description provided.