Debian Codegraph @

mysql-test/suite/rpl_gtid/t/rpl_verify_delay_time.test

raw
1 #
2 # ==== Purpose ====
3 # Test to verify that the delay is relative to the transaction's
4 # immediate_commit_timestamp and not with respect to when it started.
5 #
6 # ==== Implementation ====
7 # In a master->slave topology it verifies that the delay of transaction
8 # on slave is relative to the commit event time on master and not relative
9 # to the begining of the transaction by sleeping for a time equal to $delay
10 # before the commit event. It uses the timestamps of events in the mysqld
11 # log of master and slave.
12 #
13 # ==== References ====
14 #
15 # WL#7318 Delayed Replication: GTID based and relative to immediate master commit
16
17 --source include/have_binlog_format_statement.inc
18 --source include/master-slave.inc
19
20 --let $delay= 10
21
22 --source include/rpl_connection_slave.inc
23 --source include/stop_slave.inc
24 --eval CHANGE REPLICATION SOURCE TO SOURCE_DELAY= $delay
25 --source include/start_slave.inc
26
27 --source include/rpl_connection_master.inc
28 CREATE TABLE t1 (a varchar(50));
29
30 BEGIN;
31 INSERT INTO t1 VALUES ("1");
32 --sleep $delay
33 COMMIT;
34
35 --source include/sync_slave_sql_with_master.inc
36
37 --source include/rpl_connection_master.inc
38
39 --let $out_file_1= $MYSQLTEST_VARDIR/mysqld.1/mysqld.log
40 --let $out_file_2= $MYSQLTEST_VARDIR/mysqld.2/mysqld.log
41 --let FOUTFILE = $out_file_1
42 --let SOUTFILE = $out_file_2
43
44
45 perl;
46 use strict;
47 my $outfile1 = $ENV{'FOUTFILE'} or die "OUTFILE not set";
48 my $outfile2 = $ENV{'SOUTFILE'} or die "OUTFILE not set";
49 open(FILE, "$outfile1") or die("Unable to open $outfile1: $!\n");
50
51 my $next_stmt;
52 my $insert_event;
53 my $commit_event;
54
55 #obtain the timestamp of INSERT event by using regex.
56
57 while (my $next_stmt = <FILE>)
58 {
59 chomp $next_stmt;
60 if ($next_stmt =~ /COMMIT/)
61 {
62 last;
63 }
64 $insert_event=$next_stmt;
65 }
66
67 $insert_event =~ s/.*([0-9][0-9]:[0-9][0-9]:[0-9][0-9]).*/\1/;
68
69 open(FILE, "$outfile2") or die("Unable to open $outfile2: $!\n");
70
71 my $next_stmt_slave;
72 my $insert_event_slave;
73
74 #obtain the timestamp of BEGIN event by using regex. note that the
75 #the timestamps of BEGIN and INSERT events are almost same.
76
77 while (my $next_stmt_slave = <FILE>)
78 {
79 chomp $next_stmt_slave;
80 $insert_event_slave= $next_stmt_slave;
81 if ($next_stmt_slave =~ /BEGIN/)
82 {
83 last;
84 }
85 }
86
87 $insert_event_slave =~ s/.*([0-9][0-9]:[0-9][0-9]:[0-9][0-9]).*/\1/;
88
89 my $dir = $ENV{'MYSQLTEST_VARDIR'};
90 open (OUTPUT, ">$dir/tmp/tar.inc") ;
91 print OUTPUT "--let \$insert_timestamp = $insert_event\n";
92 print OUTPUT "--let \$insert_timestamp2 = $insert_event_slave\n";
93 close (OUTPUT);
94
95 EOF
96
97 --source $MYSQLTEST_VARDIR/tmp/tar.inc
98 --remove_file $MYSQLTEST_VARDIR/tmp/tar.inc
99
100 # Obtain the immediate commit timestamp in human readable format for INSERT transaction.
101 --let $server_uuid= query_get_value(select @@global.server_uuid, @@global.server_uuid, 1)
102 --let $gtid= $server_uuid:2
103 --let $readable= 1
104 --source include/get_immediate_commit_timestamp.inc
105 --let $readable= 0
106
107 # Convert the ICT value in human readable format in UTC timezone.
108
109 --let $ICT_UTC= `SELECT CONVERT_TZ('$immediate_commit_timestamp','SYSTEM','+00:00')`
110 --let $ICT_sec= `SELECT TIME_TO_SEC('$ICT_UTC')`
111 --let $insert_slave_sec= `SELECT TIME_TO_SEC('$insert_timestamp2')`
112 --let $insert_master_sec= `SELECT TIME_TO_SEC('$insert_timestamp')`
113
114 # verify that the delay is relative to the ICT and not relative to BEGIN or INSERT event.
115 --let $assert_text= Assert that the delay is relative to the immediate_commit_timestamp..
116 --let $assert_cond= $insert_slave_sec >= $ICT_sec + $delay
117 --source include/assert.inc
118
119 --let $assert_text= Assert that the delay is not relative to the insert event timestamp or begining of transaction..
120 --let $assert_cond= $insert_slave_sec >= $insert_master_sec + 2 * $delay
121 --source include/assert.inc
122
123 # Cleanup
124 DROP TABLE t1;
125 --source include/sync_slave_sql_with_master.inc
126 --source include/stop_slave_sql.inc
127 CHANGE REPLICATION SOURCE TO SOURCE_DELAY= 0;
128 --source include/start_slave_sql.inc
129
130 --source include/rpl_end.inc