2 # This is an include file that performs some assertions
3 # on behalf of rpl_row_img_sanity test case.
5 # It begins by dumping the current connection binary log
6 # and then compares it against the expected values (which
7 # are parameters to this include)
9 # Expected values are arguments to this script and must be structured
12 # -- let $row_img_expected= 1:1 2:2 3:'a' 4:NULL | 1:2 4:10
14 # This example means that BEFORE IMAGE contains values for columns
15 # with the given index in the original table 1, 2, 3, 4 and their
16 # values are 1,2,'a',NULL respectively.
18 # The same resoning for the AFTER IMAGE that follows the image
24 # The expected values for BI and AI that we are searching for
26 # The start position in the binary log from which the searching
31 # -- let $row_img_expected= 1:1 2:2 3:'a' 4:NULL | 1:2 4:10
32 # -- let $row_img_pos= 107
33 # -- source include/rpl_row_img_parts_assertion.inc
36 if (`SELECT LENGTH(
"$row_img_pos") = 0`)
38 -- echo $row_img_pos not defined: $row_img_pos
42 if (`SELECT LENGTH(
"$row_img_expected") = 0`)
44 -- echo \$row_img_expected not defined: $row_img_expected
48 -- let $_prefix= `SELECT UUID()`
49 -- let $TMP_FILE= $MYSQLTEST_VARDIR/tmp/$_prefix.tmp
51 -- let $binlog= query_get_value(SHOW MASTER
STATUS, File, 1)
52 -- let $MYSQLD_DATADIR= `select @@datadir;`
53 -- exec $MYSQL_BINLOG -v --start-pos=$row_img_pos $MYSQLD_DATADIR/$binlog > $TMP_FILE
55 -- let IMG_EXPECTED=$row_img_expected
56 -- let IMG_BINLOG_FILE= $TMP_FILE
60 my $img = $ENV{
'IMG_EXPECTED'};
61 my $file= $ENV{
'IMG_BINLOG_FILE'};
63 open(FILE, $file) or die("Unable
to open $binlog: $!\
n");
64 my $contents = do { local $/; <FILE> };
65 close(FILE) or die("Unable
to close
file.");
67 # Save IMG_EXPECTED in $img and check if it has correct format
68 $img =~ /^([0-9]+:\S+ )* *\| *( [0-9]+:\S+)*$/ or \
69 die
"Invalid format of IMG_EXPECTED parameter. GOT: '$img'";
71 # Turn $img into the format of the binlog, and get BI and AI
72 $img =~ s/ *([0-9]+):(\S*) */### \@$1=$2\n/g;
73 my ($bi, $ai)= split(/ *\| */, $img);
74 # Generate regular expression
79 $pattern=
"### UPDATE.*\n### WHERE\n$bi### SET\n$ai";
83 $pattern=
"### INSERT.*\n### SET\n$ai";
88 $pattern=
"### DELETE.*\n### WHERE\n$bi";
90 $match= ($contents =~ /$pattern/);
94 print
"====================================================\n";
95 print
"PATTERN FOR EXPECTED IMAGES DID NOT MATCH:\n";
96 print
"====================================================\n";
98 print
"====================================================\n\n";
100 print
"====================================================\n";
101 print
"BINLOG CONTENTS\n";
102 print
"====================================================\n";
104 print
"====================================================\n";
111 -- remove_file $TMP_FILE