| 1 |
# === Purpose === |
| 2 |
# |
| 3 |
# This test validate that replication works when the replica has a GIPK |
| 4 |
# and the source does not. |
| 5 |
# |
| 6 |
# ==== Requirements ==== |
| 7 |
# |
| 8 |
# R1. If the replica contains a GIPK, replication from a source with no GIPK |
| 9 |
# should work seamlessly. |
| 10 |
# |
| 11 |
# === Implementation ==== |
| 12 |
# |
| 13 |
# 1. Enable the generation of GIPKs in the replica |
| 14 |
# 2. Create a table with no primary key in the source |
| 15 |
# Check it was created with a GIPK in the replica |
| 16 |
# 3. Add some rows to the table in the source |
| 17 |
# Check they are present in the replica with the expected auto generated values |
| 18 |
# 4. Update one of the row in the source and delete another |
| 19 |
# Check the changes are correctly propagated |
| 20 |
# 5. Cleanup |
| 21 |
# |
| 22 |
# === References === |
| 23 |
# |
| 24 |
# Wl#14639: Row-based replication between tables that differ in the existence of a generated invisible primary key |
| 25 |
# WL#15419: Make the replica_generate_invisible_primary_key option settable per channel |
| 26 |
# |
| 27 |
|
| 28 |
--let $rpl_skip_start_slave = 1 |
| 29 |
--source include/master-slave.inc |
| 30 |
|
| 31 |
--echo |
| 32 |
--echo ################################################## |
| 33 |
--echo # 1. Enable the generation of GIPKs in the replica |
| 34 |
|
| 35 |
--source include/rpl_connection_slave.inc |
| 36 |
|
| 37 |
# Store the default value |
| 38 |
--let $_pk_key_check_value = `SELECT require_table_primary_key_check FROM performance_schema.replication_applier_configuration WHERE channel_name=""` |
| 39 |
CHANGE REPLICATION SOURCE TO REQUIRE_TABLE_PRIMARY_KEY_CHECK = GENERATE; |
| 40 |
|
| 41 |
--source include/start_slave.inc |
| 42 |
|
| 43 |
--echo |
| 44 |
--echo ##################################################### |
| 45 |
--echo # 2. Create a table with no primary key in the source |
| 46 |
--echo # Check it was created with a GIPK in the replica |
| 47 |
|
| 48 |
--source include/rpl_connection_master.inc |
| 49 |
|
| 50 |
CREATE TABLE t1(f1 INT, f2 INT); |
| 51 |
|
| 52 |
--source include/sync_slave_sql_with_master.inc |
| 53 |
|
| 54 |
--source include/rpl_connection_slave.inc |
| 55 |
|
| 56 |
--let $column_count= `SELECT COUNT(*) FROM information_schema.columns WHERE table_name='t1';` |
| 57 |
--let $assert_text= The table contains 3 columns |
| 58 |
--let $assert_cond= $column_count = 3 |
| 59 |
--source include/assert.inc |
| 60 |
|
| 61 |
--let $pk_count= `SELECT COUNT(*) FROM information_schema.columns WHERE table_name='t1' and column_name='my_row_id';` |
| 62 |
--let $assert_text= The table contains a generated invisilble primary key |
| 63 |
--let $assert_cond= $pk_count = 1 |
| 64 |
--source include/assert.inc |
| 65 |
|
| 66 |
--echo |
| 67 |
--echo ############################################# |
| 68 |
--echo # 3. Add some rows to the table in the source |
| 69 |
--echo # Check they are present in the replica with the expected auto generated values |
| 70 |
|
| 71 |
--let $sysvars_to_save = [ "GLOBAL.replica_parallel_workers" ] |
| 72 |
--source include/save_sysvars.inc |
| 73 |
|
| 74 |
# Make the applier deterministic by having only 1 thread |
| 75 |
--source include/stop_slave_sql.inc |
| 76 |
SET @@GLOBAL.replica_parallel_workers= 1; |
| 77 |
--source include/start_slave_sql.inc |
| 78 |
|
| 79 |
--source include/rpl_connection_master.inc |
| 80 |
|
| 81 |
INSERT INTO t1 VALUES (1, 10); |
| 82 |
INSERT INTO t1 VALUES (2, 20); |
| 83 |
|
| 84 |
--source include/sync_slave_sql_with_master.inc |
| 85 |
|
| 86 |
--let $row_count= `SELECT COUNT(*) FROM t1 WHERE my_row_id = 1 AND f1 = 1 AND f2 = 10;` |
| 87 |
--let $assert_text= The table contains a row with generated key 1 |
| 88 |
--let $assert_cond= $row_count = 1 |
| 89 |
--source include/assert.inc |
| 90 |
|
| 91 |
--let $row_count= `SELECT COUNT(*) FROM t1 WHERE my_row_id = 2 AND f1 = 2 AND f2 = 20;` |
| 92 |
--let $assert_text= The table contains a row with generated key 2 |
| 93 |
--let $assert_cond= $row_count = 1 |
| 94 |
--source include/assert.inc |
| 95 |
|
| 96 |
# Add a row on the replica to make the auto increment value jump to 4 |
| 97 |
INSERT INTO t1 (my_row_id,f1,f2) VALUES (3, 3, 30); |
| 98 |
|
| 99 |
--source include/rpl_connection_master.inc |
| 100 |
|
| 101 |
INSERT INTO t1 VALUES (4, 40); |
| 102 |
|
| 103 |
--source include/sync_slave_sql_with_master.inc |
| 104 |
|
| 105 |
--let $row_count= `SELECT COUNT(*) FROM t1 WHERE my_row_id = 3 AND f1 = 3 AND f2 = 30;` |
| 106 |
--let $assert_text= The table contains a row with generated key 3 |
| 107 |
--let $assert_cond= $row_count = 1 |
| 108 |
--source include/assert.inc |
| 109 |
|
| 110 |
--let $row_count= `SELECT COUNT(*) FROM t1 WHERE my_row_id = 4 AND f1 = 4 AND f2 = 40;` |
| 111 |
--let $assert_text= The table contains a row with generated key 4 |
| 112 |
--let $assert_cond= $row_count = 1 |
| 113 |
--source include/assert.inc |
| 114 |
|
| 115 |
--echo |
| 116 |
--echo ########################################################### |
| 117 |
--echo # 4. Update one of the row in the source and delete another |
| 118 |
--echo # Check the changes are correctly propagated |
| 119 |
|
| 120 |
--source include/rpl_connection_master.inc |
| 121 |
|
| 122 |
UPDATE t1 SET t1.f2 = 60 WHERE t1.f1=2; |
| 123 |
|
| 124 |
DELETE FROM t1 WHERE t1.f1=1; |
| 125 |
|
| 126 |
--source include/sync_slave_sql_with_master.inc |
| 127 |
|
| 128 |
--source include/rpl_connection_slave.inc |
| 129 |
|
| 130 |
--let $row_count= `SELECT COUNT(*) FROM t1;` |
| 131 |
--let $assert_text= The table contains 3 row |
| 132 |
--let $assert_cond= $row_count = 3 |
| 133 |
--source include/assert.inc |
| 134 |
|
| 135 |
--let $row_count= `SELECT COUNT(*) FROM t1 WHERE t1.f2 = 60 ;` |
| 136 |
--let $assert_text= The table was updated |
| 137 |
--let $assert_cond= $row_count = 1 |
| 138 |
--source include/assert.inc |
| 139 |
|
| 140 |
--echo |
| 141 |
--echo ########################################################### |
| 142 |
--echo # 5. Cleanup |
| 143 |
|
| 144 |
--disable_warnings |
| 145 |
--source include/restore_sysvars.inc |
| 146 |
--enable_warnings |
| 147 |
|
| 148 |
--source include/stop_slave_sql.inc |
| 149 |
--replace_result $_pk_key_check_value PRIMARY_KEY_CHECK_VALUE |
| 150 |
--eval CHANGE REPLICATION SOURCE TO REQUIRE_TABLE_PRIMARY_KEY_CHECK = $_pk_key_check_value |
| 151 |
--source include/start_slave_sql.inc |
| 152 |
|
| 153 |
--source include/rpl_connection_master.inc |
| 154 |
|
| 155 |
DROP TABLE t1; |
| 156 |
|
| 157 |
--source include/rpl_end.inc |
| 158 |
|