Why mysql INSERT … ON DUPLICATE KEY UPDATE can break RBR replication on a master / master configuration

泄露秘密 提交于 2019-12-05 16:42:39

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

  1. One client writes to master1 using an odd primary key
  2. Another client writes to master2 using an even primary key, before the first write was synced
  3. The servers try to sync up with each other

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.

Let's make the statement more general: "Simultaneously acting on the same row in both Masters is unsafe." It is not only IODKU. Also, INSERTing rows with the same unique key (especially if they have different values in other columns) will cause errors.

Galera avoids the problem by checking with other nodes at COMMIT time.

NDB Cluster avoids the problem by implementing "eventual consistency".

Off-the-shelf Master-Master is full of problems; you have identified only one of them. Most of the problems can be avoided, as Mike points out, but only writing to one Master.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!