| 1 |
################################################################################ |
| 2 |
# Validate that transactions run with group_replication_consistency= 'BEFORE' are |
| 3 |
# not affected by group GTIDs set manually on GTID_NEXT that concurrently were |
| 4 |
# used by other transactions. |
| 5 |
# |
| 6 |
# When using `group_replication_consistency=BEFORE`, a user client |
| 7 |
# ensures that all transactions that were accepted by the group when |
| 8 |
# the transaction started, get committed before it starts. To achieve |
| 9 |
# that, it broadcasts a message to the group, waits for it to be |
| 10 |
# received, reads `RECEIVED_TRANSACTION_SET` from |
| 11 |
# `group_replication_applier` channel, and waits for all those |
| 12 |
# transactions in `RECEIVED_TRANSACTION_SET` to be committed, i.e., |
| 13 |
# included in `GTID_EXECUTED`. |
| 14 |
# Only transactions originating on other members will go through the |
| 15 |
# applier pipeline. Transactions originating on the current member will |
| 16 |
# therefore not be added to `RECEIVED_TRANSACTION_SET` the usual way. |
| 17 |
# That leads to gaps in the GTID sequence. To prevent the number of |
| 18 |
# gaps from growing indefinitely, `RECEIVED_TRANSACTION_SET` on the |
| 19 |
# `group_replication_applier` channel is updated periodically by |
| 20 |
# adding `GTID_EXECUTED` to it. |
| 21 |
# The statement `SET gtid_next=GTID` adds the GTID to `gtid_owned`. It |
| 22 |
# is controlled in a mutually exclusive manner within the same server, |
| 23 |
# so that two concurrent clients on the same server cannot execute |
| 24 |
# `SET gtid_next=GTID` concurrently and with the same GTID. However, |
| 25 |
# in Group Replication, the statement may succeed and a transaction |
| 26 |
# execute with `gtid_next` set to a GTID that is concurrently used by |
| 27 |
# a transaction executing on another member. In this case, it is |
| 28 |
# possible for both transactions to reach commit. The first |
| 29 |
# transaction that is first in the total order will commit and the |
| 30 |
# second one has to rollback. |
| 31 |
# The commit pipeline executes in the following order: (1) add GTID to |
| 32 |
# gtid_owned; (2) write binlog; (3) commit; (4) atomically add GTID to |
| 33 |
# gtid_executed and remove GTID from gtid_owned. Therefore a a GTID to |
| 34 |
# be committed only needs to wait to be addted to gtid_executed. |
| 35 |
# |
| 36 |
# The following scenario can happen: |
| 37 |
# - Client 1 on member 1 issues SET gtid_next = X, where X uses the |
| 38 |
# group_replication_group_name for the UUID. |
| 39 |
# - Client 2 on member 1 commits a transaction that auto-generates |
| 40 |
# GTID X. |
| 41 |
# - Client 3 on member 1 begins a transaction while having |
| 42 |
# group_replication_consistency=BEFORE or BEFORE_AND_AFTER. |
| 43 |
# Now, Client 3 will (after broadcasting and receiving a message), |
| 44 |
# read `RECEIVED_TRANSACTION_SET`, which includes X. Then it waits for |
| 45 |
# X to be committed. The wait will observe that X is in gtid_executed |
| 46 |
# already. However, it will also wait for X to be removed from |
| 47 |
# gtid_owned. That will not happen, since client 1 holds ownership, |
| 48 |
# and the wait function waits for ownership to be released. |
| 49 |
# |
| 50 |
# To avoid the above issue, the waiting condition was modified to not |
| 51 |
# consider owned GTIDs, that is, only committed transactions are |
| 52 |
# accounted. |
| 53 |
# With the exception that if the executing session owns a GTID that |
| 54 |
# was concurrently committed, the transaction execution will error |
| 55 |
# out. |
| 56 |
# |
| 57 |
# Test: |
| 58 |
# 00. The test requires two servers: M1 and M2. |
| 59 |
# 01. Create a table on the group. |
| 60 |
# 02. Use the next GTID generated by the group on GTID_NEXT. |
| 61 |
# The GTID will be UUID:4. |
| 62 |
# 03. Commit a transaction on the group that will be logged |
| 63 |
# with GTID UUID:4. |
| 64 |
# 04. Wait until `received_transaction_set` from |
| 65 |
# is updated with the GTID_EXECUTED set. |
| 66 |
# 05. Perform a consistent read. |
| 67 |
# The read will not be blocked by the GTID_NEXT set on session server1. |
| 68 |
# 06. Clean up. |
| 69 |
################################################################################ |
| 70 |
|
| 71 |
--source include/big_test.inc |
| 72 |
--source include/have_group_replication_plugin.inc |
| 73 |
--source include/group_replication.inc |
| 74 |
|
| 75 |
--echo |
| 76 |
--echo ############################################################ |
| 77 |
--echo # 01. Create a table on the group. |
| 78 |
--let $rpl_connection_name= server1 |
| 79 |
--source include/rpl_connection.inc |
| 80 |
CREATE TABLE t1 (c1 INT NOT NULL PRIMARY KEY); |
| 81 |
|
| 82 |
|
| 83 |
--echo |
| 84 |
--echo ############################################################ |
| 85 |
--echo # 02. Use the next GTID generated by the group on GTID_NEXT. |
| 86 |
--echo # The GTID will be UUID:4. |
| 87 |
--let $assert_text= GTID_EXECUTED is UUID:1-3 |
| 88 |
--let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = "$group_replication_group_name:1-3" |
| 89 |
--source include/assert.inc |
| 90 |
|
| 91 |
--replace_result $group_replication_group_name GROUP_NAME |
| 92 |
--eval SET @@SESSION.GTID_NEXT= "$group_replication_group_name:4" |
| 93 |
|
| 94 |
|
| 95 |
--echo |
| 96 |
--echo ############################################################ |
| 97 |
--echo # 03. Commit a transaction on the group that will be logged |
| 98 |
--echo # with GTID UUID:4. |
| 99 |
--let $rpl_connection_name= server_1 |
| 100 |
--source include/rpl_connection.inc |
| 101 |
INSERT INTO t1 VALUES (1); |
| 102 |
|
| 103 |
--let $assert_text= GTID_EXECUTED is UUID:1-4 |
| 104 |
--let $assert_cond= "[SELECT @@GLOBAL.GTID_EXECUTED]" = "$group_replication_group_name:1-4" |
| 105 |
--source include/assert.inc |
| 106 |
|
| 107 |
|
| 108 |
--echo |
| 109 |
--echo ############################################################ |
| 110 |
--echo # 04. Wait until `received_transaction_set` from |
| 111 |
--echo # is updated with the GTID_EXECUTED set. |
| 112 |
--let $wait_condition= SELECT received_transaction_set="$group_replication_group_name:1-4" FROM performance_schema.replication_connection_status WHERE channel_name="group_replication_applier"; |
| 113 |
--source include/wait_condition.inc |
| 114 |
|
| 115 |
|
| 116 |
--echo |
| 117 |
--echo ############################################################ |
| 118 |
--echo # 05. Perform a consistent read. |
| 119 |
--echo # The read will not be blocked by the GTID_NEXT set on session server1. |
| 120 |
SET @@SESSION.group_replication_consistency= 'BEFORE'; |
| 121 |
SELECT * FROM t1; |
| 122 |
|
| 123 |
|
| 124 |
--echo |
| 125 |
--echo ############################################################ |
| 126 |
--echo # 06. Clean up. |
| 127 |
--let $rpl_connection_name= server_1 |
| 128 |
--source include/rpl_connection.inc |
| 129 |
SET @@SESSION.group_replication_consistency= DEFAULT; |
| 130 |
|
| 131 |
--let $rpl_connection_name= server1 |
| 132 |
--source include/rpl_connection.inc |
| 133 |
ROLLBACK; |
| 134 |
SET @@SESSION.GTID_NEXT= "AUTOMATIC"; |
| 135 |
|
| 136 |
DROP TABLE t1; |
| 137 |
|
| 138 |
--source include/group_replication_end.inc |