为什么mysql INSERT ... ON DUPLICATE KEY UPDATE会破坏主/主配置上的RBR复制 [英] Why mysql INSERT ... ON DUPLICATE KEY UPDATE can break RBR replication on a master / master configuration

查看:82
本文介绍了为什么mysql INSERT ... ON DUPLICATE KEY UPDATE会破坏主/主配置上的RBR复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题出在这里

  • 2个MySQL 5.5服务器
  • 基于行的复制+主控主控
  • 写入在两台服务器上(均处于活动状态)
  • autoinc技巧(一台服务器为奇数,另一台为偶数)

我有一张桌子

byUserDailyStatistics:

byUserDailyStatistics:

  • id(PK + AUTO INC)
  • 日期
  • idUser
  • metric1
  • metric2
  • UNIQUE(idUser,date)

所有请求都是

INSERT INTO byEmailDailyStatistics
(date, idUser, metric1, metric2)
VALUES (:date, :user:, 1, 1)
ON DUPLICATE KEY UPDATE
metric1 = metric1 + 1,
metric2 = metric2 +1

有时,复制会中断,例如消息

And sometimes, the replication breaks with message like

could not execute Write_rows event on table stats.byUserDailyStatistics; Duplicate entry '6447412-2016-01-06' for key 'UNIQUE', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.035580, end_log_pos 279798813

此问题的起因是什么?

推荐答案

您正试图将相同的idUser, date对同时写入两个副本.

You are trying to write the same idUser, date pair to both your replicas at the same time.

  1. 一个客户端使用奇数主键写入master1
  2. 在同步首次写入之前,另一个客户端使用偶数主键写入master2
  3. 服务器尝试彼此同步

在最后一步中,两个服务器上的同一对存在不同的主键;不同的行,但是辅助唯一键是相同的.

In the last step the same pair exists on both server under different primary keys; different rows but the secondary unique key is the same.

这篇关于为什么mysql INSERT ... ON DUPLICATE KEY UPDATE会破坏主/主配置上的RBR复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆