Skip to content

Commit 07e0735

Browse files
author
Dhruthi K V
committed
WL#11046 Improve test coverage for online alter index and multiple triggers on a single table in RPL & GR
Replication and GR use distributed environment and its essential we ensure this works. Currently we have no coverage for on-line alter index and limited for multiple triggers (part of 5.7) with replication and GR.
1 parent b6e0847 commit 07e0735

File tree

10 files changed

+588
-0
lines changed

10 files changed

+588
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
################################################################################
2+
# This is an auxillary file used by rpl_multiple_trigger.test and
3+
# gr_multiple_trigger.test to test multiple triggers with GR and rpl.
4+
#
5+
# Steps:
6+
# 1. Create tables and a trigger t1_b on master.
7+
# 2. Check that action_order attribute of trigger t1_b is same on both servers.
8+
# 3. Create another trigger t1_a on same table for same action event
9+
# and timing.
10+
# 4. Check that CREATED, ACTION_ORDER attributes are same on both servers.
11+
# 5. Insert some data to the table on master.
12+
# 6. Ensure that data is consistent on both the servers.
13+
# 7. Clean-up
14+
#
15+
# Usage:
16+
# --let $master= server1
17+
# --let $slave = server2
18+
# --source extra/rpl_tests/rpl_multiple_trigger.inc
19+
#
20+
# $master - master server.
21+
# $slave - slave server.
22+
################################################################################
23+
24+
--echo
25+
--echo #1. Create tables and a trigger t1_b on master.
26+
--let $rpl_connection_name= $master
27+
--source include/rpl_connection.inc
28+
CREATE TABLE t1 (a INT PRIMARY KEY);
29+
CREATE TABLE t2 (a INT PRIMARY KEY, b INT DEFAULT 0);
30+
31+
DELIMITER |;
32+
create trigger t1_b
33+
after insert on t1
34+
for each row
35+
BEGIN
36+
INSERT INTO t2 VALUES (New.a, @value1);
37+
END|
38+
DELIMITER ;|
39+
--source include/rpl_sync.inc
40+
41+
--echo
42+
--echo #2. Check that action_order attribute of trigger t1_b is same on both servers.
43+
--let $assert_text= action_order for trigger t1_b must be 1.
44+
--let $assert_cond= [SELECT ACTION_ORDER FROM information_schema.triggers WHERE trigger_schema="test" AND EVENT_OBJECT_TABLE="t1" AND trigger_name="t1_b"]=1;
45+
--source include/assert.inc
46+
47+
--let $rpl_connection_name= $slave
48+
--source include/rpl_connection.inc
49+
--let $assert_text= action_order for trigger t1_b must be 1.
50+
--let $assert_cond= [SELECT ACTION_ORDER FROM information_schema.triggers WHERE trigger_schema="test" AND EVENT_OBJECT_TABLE="t1" AND trigger_name="t1_b"]=1;
51+
--source include/assert.inc
52+
53+
--let $rpl_connection_name= $master
54+
--source include/rpl_connection.inc
55+
56+
--echo
57+
--echo #3. Create another trigger t1_a on t1 for same action event and timing.
58+
DELIMITER |;
59+
create trigger t1_a
60+
after insert on t1
61+
for each row PRECEDES t1_b
62+
BEGIN
63+
SET @value1:= New.a * 2;
64+
END|
65+
DELIMITER ;|
66+
--source include/rpl_sync.inc
67+
68+
# Save CREATED attribute on master.
69+
--let $t1a_created1 = `SELECT CREATED FROM information_schema.triggers WHERE trigger_schema='test' AND EVENT_OBJECT_TABLE='t1' AND trigger_name='t1_a'`
70+
71+
--echo
72+
--echo #4. Check that CREATED, ACTION_ORDER attributes are same on both servers.
73+
--let $assert_text= action_order for trigger t1_a must be 1.
74+
--let $assert_cond= [SELECT ACTION_ORDER FROM information_schema.triggers WHERE trigger_schema="test" AND EVENT_OBJECT_TABLE="t1" AND trigger_name="t1_a"]=1;
75+
--source include/assert.inc
76+
77+
--let $assert_text= action_order for trigger t1_b must be 2.
78+
--let $assert_cond= [SELECT ACTION_ORDER FROM information_schema.triggers WHERE trigger_schema="test" AND EVENT_OBJECT_TABLE="t1" AND trigger_name="t1_b"]=2;
79+
--source include/assert.inc
80+
81+
--let $rpl_connection_name= $slave
82+
--source include/rpl_connection.inc
83+
--let $assert_text= action_order for trigger t1_a must be 1.
84+
--let $assert_cond= [SELECT ACTION_ORDER FROM information_schema.triggers WHERE trigger_schema="test" AND EVENT_OBJECT_TABLE="t1" AND trigger_name="t1_a"]=1;
85+
--source include/assert.inc
86+
87+
--let $assert_text= action_order for trigger t1_b must be 2.
88+
--let $assert_cond= [SELECT ACTION_ORDER FROM information_schema.triggers WHERE trigger_schema="test" AND EVENT_OBJECT_TABLE="t1" AND trigger_name="t1_b"]=2;
89+
--source include/assert.inc
90+
91+
--let $t1a_created2 = `SELECT CREATED FROM information_schema.triggers WHERE trigger_schema='test' AND EVENT_OBJECT_TABLE='t1' AND trigger_name='t1_a'`
92+
93+
# Check that both servers has same CREATED attribute.
94+
--let $assert_text= Created attribute for a trigger must be same on both the servers
95+
--let $assert_cond= "$t1a_created2"="$t1a_created1"
96+
--source include/assert.inc
97+
98+
--echo
99+
--echo #5. Insert some data to the table on master.
100+
--let $rpl_connection_name= $master
101+
--source include/rpl_connection.inc
102+
INSERT INTO t1 (a) values (1),(2);
103+
104+
# Delete trigger t1_b
105+
DROP TRIGGER test.t1_b;
106+
107+
INSERT INTO t1 (a) values (3);
108+
109+
--echo
110+
--echo #6. Ensure that data is consistent on both the servers.
111+
--source include/rpl_sync.inc
112+
--let $diff_tables=$master:t1,$slave:t1
113+
--source include/diff_tables.inc
114+
115+
--let $diff_tables=$master:t2,$slave:t2
116+
--source include/diff_tables.inc
117+
118+
--echo
119+
--echo #7. Clean-up
120+
DROP TRIGGER test.t1_a;
121+
DROP TABLE t1;
122+
DROP TABLE t2;
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
################################################################################
2+
# This is an auxillary file used by rpl_rename_index.test and
3+
# gr_rename_index.test to test index rename with GR and rpl.
4+
#
5+
# Steps:
6+
# 1. Create table on master with index (FULLTEXT/SPATIAL/SIMPLE INDEX).
7+
# 2. Rename the index using ALTER TABLE..RENAME INDEX command.
8+
# 3. Check that index is renamed sucessfully on both the servers.
9+
# 4. Clean-up
10+
#
11+
# Usage:
12+
# --let $master= server1
13+
# --let $slave = server2
14+
# --source extra/rpl_tests/rpl_rename_index.inc
15+
#
16+
# $master - master server.
17+
# $slave - slave server.
18+
################################################################################
19+
20+
--let $rename_index= 0
21+
while ($rename_index < 3)
22+
{
23+
24+
--echo
25+
--echo #1. Create table on master with index
26+
--let $rpl_connection_name= $master
27+
--source include/rpl_connection.inc
28+
if ($rename_index == 0)
29+
{
30+
CREATE TABLE t1 (a int PRIMARY KEY, b char(10), FULLTEXT KEY (b));
31+
INSERT INTO t1 VALUES (1,'abc'), (2, 'def'), (3,'ghi');
32+
--let $update_query= UPDATE t1 SET b='mysql' WHERE b='abc'
33+
}
34+
35+
if ($rename_index == 1)
36+
{
37+
CREATE TABLE t1 (a int PRIMARY KEY, b GEOMETRY NOT NULL SRID 0);
38+
CREATE SPATIAL INDEX b ON t1 (b);
39+
INSERT INTO t1 VALUES (1, ST_GEOMFROMText('POINT(1 1)')),
40+
(2, ST_GEOMFROMTEXT('POLYGON((1 2,5 4,9 9,1 9,1 2))')),
41+
(3, ST_GEOMFROMTEXT('LINESTRING(0 0,10 10)'));
42+
--let $update_query= UPDATE t1 SET b=ST_GEOMFROMText('POINT(5 5)') WHERE b=ST_GEOMFROMTEXT('LINESTRING(0 0,10 10)')
43+
}
44+
45+
if ($rename_index == 2)
46+
{
47+
CREATE TABLE t1 ( a INT PRIMARY KEY, b int, KEY (b));
48+
INSERT INTO t1 VALUES (1,10),(2,20),(3,30);
49+
--let $update_query= UPDATE t1 SET b=11 WHERE b=10
50+
}
51+
52+
# Check that t1 has a index named b on both the servers.
53+
--let $assert_text= There should be a index named b on table t1.
54+
--let $assert_cond= [SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = "test" AND TABLE_NAME = "t1" AND INDEX_NAME= "b"]=1;
55+
--source include/assert.inc
56+
57+
--source include/rpl_sync.inc
58+
59+
--let $rpl_connection_name= $slave
60+
--source include/rpl_connection.inc
61+
62+
--let $assert_text= There should be a index named b on table t1.
63+
--let $assert_cond= [SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = "test" AND TABLE_NAME = "t1" AND INDEX_NAME= "b"]=1;
64+
--source include/assert.inc
65+
66+
--echo
67+
--echo #2. Rename the index using ALTER TABLE..RENAME INDEX command.
68+
--let $rpl_connection_name= $master
69+
--source include/rpl_connection.inc
70+
ALTER TABLE t1 RENAME index b to idx;
71+
72+
--echo
73+
--echo #3. Check that index is renamed sucessfully on both the servers.
74+
--let $assert_text= There should not be a index named b on table t1.
75+
--let $assert_cond= [SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = "test" AND TABLE_NAME = "t1" AND INDEX_NAME= "b"]=0;
76+
--source include/assert.inc
77+
78+
--let $assert_text= There should be a index named idx on table t1.
79+
--let $assert_cond= [SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = "test" AND TABLE_NAME = "t1" AND INDEX_NAME= "idx" ]=1;
80+
--source include/assert.inc
81+
82+
--source include/rpl_sync.inc
83+
84+
--let $rpl_connection_name= $slave
85+
--source include/rpl_connection.inc
86+
87+
--let $assert_text= There should not be a index named b on table t1.
88+
--let $assert_cond= [SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = "test" AND TABLE_NAME = "t1" AND INDEX_NAME= "b" ]=0;
89+
--source include/assert.inc
90+
91+
--let $assert_text= There should be a index named idx on table t1.
92+
--let $assert_cond= [SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = "test" AND TABLE_NAME = "t1" AND INDEX_NAME= "idx" ]=1;
93+
--source include/assert.inc
94+
95+
# Perform another dml operation on t1.
96+
--let $rpl_connection_name= $master
97+
--source include/rpl_connection.inc
98+
--eval $update_query
99+
100+
# Ensure that data is consistent on both the servers
101+
--source include/rpl_sync.inc
102+
--let $diff_tables=$master:t1, $slave:t1
103+
--source include/diff_tables.inc
104+
105+
--echo
106+
--echo #4. Clean-up
107+
DROP TABLE t1;
108+
109+
--source include/rpl_sync.inc
110+
111+
--inc $rename_index
112+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
7+
#1. Create tables and a trigger t1_b on master.
8+
[connection master]
9+
CREATE TABLE t1 (a INT PRIMARY KEY);
10+
CREATE TABLE t2 (a INT PRIMARY KEY, b INT DEFAULT 0);
11+
create trigger t1_b
12+
after insert on t1
13+
for each row
14+
BEGIN
15+
INSERT INTO t2 VALUES (New.a, @value1);
16+
END|
17+
include/rpl_sync.inc
18+
19+
#2. Check that action_order attribute of trigger t1_b is same on both servers.
20+
include/assert.inc [action_order for trigger t1_b must be 1.]
21+
[connection slave]
22+
include/assert.inc [action_order for trigger t1_b must be 1.]
23+
[connection master]
24+
25+
#3. Create another trigger t1_a on t1 for same action event and timing.
26+
create trigger t1_a
27+
after insert on t1
28+
for each row PRECEDES t1_b
29+
BEGIN
30+
SET @value1:= New.a * 2;
31+
END|
32+
include/rpl_sync.inc
33+
34+
#4. Check that CREATED, ACTION_ORDER attributes are same on both servers.
35+
include/assert.inc [action_order for trigger t1_a must be 1.]
36+
include/assert.inc [action_order for trigger t1_b must be 2.]
37+
[connection slave]
38+
include/assert.inc [action_order for trigger t1_a must be 1.]
39+
include/assert.inc [action_order for trigger t1_b must be 2.]
40+
include/assert.inc [Created attribute for a trigger must be same on both the servers]
41+
42+
#5. Insert some data to the table on master.
43+
[connection master]
44+
INSERT INTO t1 (a) values (1),(2);
45+
DROP TRIGGER test.t1_b;
46+
INSERT INTO t1 (a) values (3);
47+
48+
#6. Ensure that data is consistent on both the servers.
49+
include/rpl_sync.inc
50+
include/diff_tables.inc [master:t1,slave:t1]
51+
include/diff_tables.inc [master:t2,slave:t2]
52+
53+
#7. Clean-up
54+
DROP TRIGGER test.t1_a;
55+
DROP TABLE t1;
56+
DROP TABLE t2;
57+
include/rpl_end.inc
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
include/master-slave.inc
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection master]
6+
7+
#1. Create table on master with index
8+
[connection master]
9+
CREATE TABLE t1 (a int PRIMARY KEY, b char(10), FULLTEXT KEY (b));
10+
INSERT INTO t1 VALUES (1,'abc'), (2, 'def'), (3,'ghi');
11+
include/assert.inc [There should be a index named b on table t1.]
12+
include/rpl_sync.inc
13+
[connection slave]
14+
include/assert.inc [There should be a index named b on table t1.]
15+
16+
#2. Rename the index using ALTER TABLE..RENAME INDEX command.
17+
[connection master]
18+
ALTER TABLE t1 RENAME index b to idx;
19+
20+
#3. Check that index is renamed sucessfully on both the servers.
21+
include/assert.inc [There should not be a index named b on table t1.]
22+
include/assert.inc [There should be a index named idx on table t1.]
23+
include/rpl_sync.inc
24+
[connection slave]
25+
include/assert.inc [There should not be a index named b on table t1.]
26+
include/assert.inc [There should be a index named idx on table t1.]
27+
[connection master]
28+
UPDATE t1 SET b='mysql' WHERE b='abc';
29+
include/rpl_sync.inc
30+
include/diff_tables.inc [master:t1, slave:t1]
31+
32+
#4. Clean-up
33+
DROP TABLE t1;
34+
include/rpl_sync.inc
35+
36+
#1. Create table on master with index
37+
[connection master]
38+
CREATE TABLE t1 (a int PRIMARY KEY, b GEOMETRY NOT NULL SRID 0);
39+
CREATE SPATIAL INDEX b ON t1 (b);
40+
INSERT INTO t1 VALUES (1, ST_GEOMFROMText('POINT(1 1)')),
41+
(2, ST_GEOMFROMTEXT('POLYGON((1 2,5 4,9 9,1 9,1 2))')),
42+
(3, ST_GEOMFROMTEXT('LINESTRING(0 0,10 10)'));
43+
include/assert.inc [There should be a index named b on table t1.]
44+
include/rpl_sync.inc
45+
[connection slave]
46+
include/assert.inc [There should be a index named b on table t1.]
47+
48+
#2. Rename the index using ALTER TABLE..RENAME INDEX command.
49+
[connection master]
50+
ALTER TABLE t1 RENAME index b to idx;
51+
52+
#3. Check that index is renamed sucessfully on both the servers.
53+
include/assert.inc [There should not be a index named b on table t1.]
54+
include/assert.inc [There should be a index named idx on table t1.]
55+
include/rpl_sync.inc
56+
[connection slave]
57+
include/assert.inc [There should not be a index named b on table t1.]
58+
include/assert.inc [There should be a index named idx on table t1.]
59+
[connection master]
60+
UPDATE t1 SET b=ST_GEOMFROMText('POINT(5 5)') WHERE b=ST_GEOMFROMTEXT('LINESTRING(0 0,10 10)');
61+
include/rpl_sync.inc
62+
include/diff_tables.inc [master:t1, slave:t1]
63+
64+
#4. Clean-up
65+
DROP TABLE t1;
66+
include/rpl_sync.inc
67+
68+
#1. Create table on master with index
69+
[connection master]
70+
CREATE TABLE t1 ( a INT PRIMARY KEY, b int, KEY (b));
71+
INSERT INTO t1 VALUES (1,10),(2,20),(3,30);
72+
include/assert.inc [There should be a index named b on table t1.]
73+
include/rpl_sync.inc
74+
[connection slave]
75+
include/assert.inc [There should be a index named b on table t1.]
76+
77+
#2. Rename the index using ALTER TABLE..RENAME INDEX command.
78+
[connection master]
79+
ALTER TABLE t1 RENAME index b to idx;
80+
81+
#3. Check that index is renamed sucessfully on both the servers.
82+
include/assert.inc [There should not be a index named b on table t1.]
83+
include/assert.inc [There should be a index named idx on table t1.]
84+
include/rpl_sync.inc
85+
[connection slave]
86+
include/assert.inc [There should not be a index named b on table t1.]
87+
include/assert.inc [There should be a index named idx on table t1.]
88+
[connection master]
89+
UPDATE t1 SET b=11 WHERE b=10;
90+
include/rpl_sync.inc
91+
include/diff_tables.inc [master:t1, slave:t1]
92+
93+
#4. Clean-up
94+
DROP TABLE t1;
95+
include/rpl_sync.inc
96+
include/rpl_end.inc

0 commit comments

Comments
 (0)