Consider the following table structure in a MariaDB Galera cluster:

CREATE TABLE test (
  `name` varchar(100) NOT NULL,
  `master` tinyint(1) DEFAULT NULL,
  PRIMARY KEY (`name`),
  UNIQUE KEY `master` (`master`)
) ENGINE=InnoDB;

If this is running on a cluster with several nodes, and I then in parallell do:

INSERT INTO test (name, master) VALUES('node1', 1);

and on another node

INSERT INTO test (name, master) VALUES('node2', 1);

Can I trust that one query does not replace the other?

If both queries are ran exactly at the same time, will one of them still return with an error?

If the query does NOT return an error, can I trust no other INSERT can replace that row with another name?

有帮助吗?

解决方案

The unique constraint will be enforced. Galera uses optimistic locking and I'm not exactly sure if the query that gets to the cluster second would return the normal duplicate entry error or a different error about a transaction conflict but only one would be inserted.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top