MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_row_img_parts_assertion.inc
1 #
2 # This is an include file that performs some assertions
3 # on behalf of rpl_row_img_sanity test case.
4 #
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)
8 #
9 # Expected values are arguments to this script and must be structured
10 # as follows:
11 #
12 # -- let $row_img_expected= 1:1 2:2 3:'a' 4:NULL | 1:2 4:10
13 #
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.
17 #
18 # The same resoning for the AFTER IMAGE that follows the image
19 # separator char '|'.
20 #
21 # Arguments:
22 #
23 # - $row_img_expected
24 # The expected values for BI and AI that we are searching for
25 # - $row_img_pos
26 # The start position in the binary log from which the searching
27 # will be done
28 #
29 # Sample usage:
30 #
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
34 #
35 
36 if (`SELECT LENGTH("$row_img_pos") = 0`)
37 {
38  -- echo $row_img_pos not defined: $row_img_pos
39  -- die Baiing out!
40 }
41 
42 if (`SELECT LENGTH("$row_img_expected") = 0`)
43 {
44  -- echo \$row_img_expected not defined: $row_img_expected
45  -- die Baiing out!
46 }
47 
48 -- let $_prefix= `SELECT UUID()`
49 -- let $TMP_FILE= $MYSQLTEST_VARDIR/tmp/$_prefix.tmp
50 
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
54 
55 -- let IMG_EXPECTED=$row_img_expected
56 -- let IMG_BINLOG_FILE= $TMP_FILE
57 
58 -- perl END_OF_FILE
59 
60 my $img = $ENV{'IMG_EXPECTED'};
61 my $file= $ENV{'IMG_BINLOG_FILE'};
62 
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.");
66 
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'";
70 
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
75 if ($ai)
76 {
77  if ($bi)
78  {
79  $pattern= "### UPDATE.*\n### WHERE\n$bi### SET\n$ai";
80  }
81  else
82  {
83  $pattern= "### INSERT.*\n### SET\n$ai";
84  }
85 }
86 else
87 {
88  $pattern= "### DELETE.*\n### WHERE\n$bi";
89 }
90 $match= ($contents =~ /$pattern/);
91 
92 if (!$match)
93 {
94  print "====================================================\n";
95  print "PATTERN FOR EXPECTED IMAGES DID NOT MATCH:\n";
96  print "====================================================\n";
97  print "$pattern";
98  print "====================================================\n\n";
99 
100  print "====================================================\n";
101  print "BINLOG CONTENTS\n";
102  print "====================================================\n";
103  print "$contents";
104  print "====================================================\n";
105 }
106 
107 END_OF_FILE
108 
109 -- let IMG_EXPECTED=
110 
111 -- remove_file $TMP_FILE
112