有天在看 Percona XtraDB Cluster (PXC) 101 簡報的時候
發現 PXC 如何處理 Update race condition 的疑問
索性就來做個實驗,也把看到的 Log 記錄下來分享
條件如下,
1. Generate 1 million rows test data.
CREATE TABLE t1 ( colume_1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY )
2. At the same time delete the data and then node1 and node2.
DELETE FROM t1 WHERE 1 LIMIT 500000;
3. node[1,2] mysqld.log will show the procedure.
$ cat mysqld_conflicts.log *** Priority TRANSACTION: TRANSACTION 5514, ACTIVE 0 sec starting index read mysql tables in use 1, locked 1 MySQL thread id 5, OS thread handle 139807762601728, query id 1472 System lock *** Victim TRANSACTION: TRANSACTION 5509, ACTIVE 7 sec updating or deleting mysql tables in use 1, locked 1 , undo log entries 452668 MySQL thread id 65, OS thread handle 139807629027072, query id 1461 node1.localhost 172.19.7.215 username updating delete from t1 where 1 limit 500000 *** WAITING FOR THIS LOCK TO BE GRANTED: RECORD LOCKS space id 31 page no 760 n bits 792 index PRIMARY of table `test`.`t1` trx id 5509 lock_mode X 2018-01-24T02:52:58.451550Z 5 [Note] WSREP: --------- CONFLICT DETECTED -------- 2018-01-24T02:52:58.451605Z 5 [Note] WSREP: cluster conflict due to high priority abort for threads: 2018-01-24T02:52:58.451835Z 5 [Note] WSREP: Winning thread: THD: 5, mode: applier, state: executing, conflict: no conflict, seqno: 58 SQL: (null) 2018-01-24T02:52:58.451929Z 5 [Note] WSREP: Victim thread: THD: 65, mode: local, state: executing, conflict: no conflict, seqno: -1 SQL: delete from t1 where 1 limit 500000
4. Just need to wait & no intervention.
5. Execute complete.
以前可能需要人為介入找到產生 Lock 的Queries,處理 Lock 的 Query ID,等等作業
而實作經驗上,我們也不樂見存取衝突產生的 Lock
所以 PXC 已經節省掉很多事情了
—-
結論怎麼弱成這樣?