문제

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