Skip to content

Conversation

dboyliao
Copy link
Collaborator

No description provided.

@dboyliao dboyliao requested a review from c9s May 19, 2025 08:53
}
if isMysqlDuplicateError(err, logger) {
// ignore duplicate error
logger.Infof("duplicate entry for %T, skipped: %+v", obj, obj)
Copy link
Owner

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

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)
Copy link
Owner

Choose a reason for hiding this comment

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

use %+v here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

// "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)
Copy link
Owner

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

}
}

matched, _ := regexp.MatchString("Duplicate entry", err.Error())
Copy link
Owner

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

@c9s c9s changed the title FIX: [sync_task] handle MySQL duplicate entry errors during record insertion FIX: [sync] handle MySQL duplicate entry errors during record insertion May 19, 2025
@dboyliao dboyliao force-pushed the dboy/sync-skip-duplicate-key branch from 8efe65c to a3dded2 Compare May 19, 2025 09:27
@dboyliao dboyliao requested a review from c9s May 19, 2025 09:28
@dboyliao dboyliao force-pushed the dboy/sync-skip-duplicate-key branch from a3dded2 to d53ab18 Compare May 19, 2025 09:32
@dboyliao dboyliao merged commit 955a43f into main May 19, 2025
3 checks passed
@dboyliao dboyliao deleted the dboy/sync-skip-duplicate-key branch May 19, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants