File: rpl_row_img_parts_assertion.inc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (112 lines) | stat: -rw-r--r-- 3,092 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# 
# This is an include file that performs some assertions
# on behalf of rpl_row_img_sanity test case.
#
# It begins by dumping the current connection binary log
# and then compares it against the expected values (which
# are parameters to this include) 
#
# Expected values are arguments to this script and must be structured
# as follows:
#
#  -- let $row_img_expected= 1:1 2:2 3:'a' 4:NULL | 1:2 4:10
#
# This example means that BEFORE IMAGE contains values for columns
# with the given index in the original table 1, 2, 3, 4 and their
# values are 1,2,'a',NULL respectively.
#
# The same resoning for the AFTER IMAGE that follows the image
#  separator char '|'.
#
# Arguments:
#
#  - $row_img_expected 
#    The expected values for BI and AI that we are searching for
#  - $row_img_pos
#    The start position in the binary log from which the searching
#    will be done
#
# Sample usage:
#
#   -- let $row_img_expected= 1:1 2:2 3:'a' 4:NULL | 1:2 4:10
#   -- let $row_img_pos= 107
#   -- source include/rpl_row_img_parts_assertion.inc
#  

if (`SELECT LENGTH("$row_img_pos") = 0`)
{
  -- echo $row_img_pos not defined: $row_img_pos
  -- die Baiing out!
}

if (`SELECT LENGTH("$row_img_expected") = 0`)
{
  -- echo \$row_img_expected not defined: $row_img_expected
  -- die Baiing out!
}

-- let $_prefix= `SELECT UUID()`
-- let $TMP_FILE= $MYSQLTEST_VARDIR/tmp/$_prefix.tmp

-- let $binlog= query_get_value(SHOW MASTER STATUS, File, 1)
-- let $MYSQLD_DATADIR= `select @@datadir;`
-- exec $MYSQL_BINLOG -v --start-position=$row_img_pos $MYSQLD_DATADIR/$binlog > $TMP_FILE

-- let IMG_EXPECTED=$row_img_expected
-- let IMG_BINLOG_FILE= $TMP_FILE

-- perl END_OF_FILE

my $img = $ENV{'IMG_EXPECTED'};
my $file= $ENV{'IMG_BINLOG_FILE'};

open(FILE, $file) or die("Unable to open $binlog: $!\n");
my $contents = do { local $/; <FILE> };
close(FILE) or die("Unable to close file.");

# Save IMG_EXPECTED in $img and check if it has correct format
$img =~ /^([0-9]+:\S+ )* *\| *( [0-9]+:\S+)*$/ or \
        die "Invalid format of IMG_EXPECTED parameter. GOT: '$img'";

# Turn $img into the format of the binlog, and get BI and AI
$img =~ s/ *([0-9]+):(\S*) */###   \@$1=$2\n/g;
my ($bi, $ai)= split(/ *\| */, $img);
# Generate regular expression
if ($ai)
{
  if ($bi)
  {
    $pattern= "### UPDATE.*\n### WHERE\n$bi### SET\n$ai";
  }
  else
  {
    $pattern= "### INSERT.*\n### SET\n$ai";
  }
}
else
{
    $pattern= "### DELETE.*\n### WHERE\n$bi";
}
$match= ($contents =~ /$pattern/);

if (!$match)
{
  print "====================================================\n";
  print "PATTERN FOR EXPECTED IMAGES DID NOT MATCH:\n";
  print "====================================================\n";
  print "$pattern";
  print "====================================================\n\n";

  print "====================================================\n";
  print "BINLOG CONTENTS\n";
  print "====================================================\n";
  print "$contents";
  print "====================================================\n";
}

END_OF_FILE

-- let IMG_EXPECTED= 

-- remove_file $TMP_FILE