-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbinsrv.test
More file actions
155 lines (124 loc) · 5.44 KB
/
binsrv.test
File metadata and controls
155 lines (124 loc) · 5.44 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
--source ../include/have_binsrv.inc
--source ../include/v80_v84_compatibility_defines.inc
# in case of --repeat=N, we need to start from a fresh binary log to make
# this test deterministic
--echo *** Resetting replication at the very beginning of the test.
--disable_query_log
eval $stmt_reset_binary_logs_and_gtids;
--enable_query_log
--echo
--echo *** Determining the first fresh binary log name.
--let $first_binlog = query_get_value($stmt_show_binary_log_status, File, 1)
--echo
--echo *** Creating a simple table and filling it with some data.
CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)) ENGINE=InnoDB;
INSERT INTO t1 VALUES(DEFAULT);
--echo
--echo *** Flushing the first binary log and switching to the second one.
FLUSH BINARY LOGS;
--echo
--echo *** Determining the second binary log name.
--let $second_binlog = query_get_value($stmt_show_binary_log_status, File, 1)
--echo
--echo *** Filling the table with some more data.
INSERT INTO t1 VALUES(DEFAULT);
# identifying backend storage type ('file' or 's3')
--source ../include/identify_storage_backend.inc
# identifying utility checksum mode from the conbination
--let $extracted_init_connect_variable_name = binsrv_checksum
--source ../include/extract_init_connect_variable_value.inc
# creating data directory, configuration file, etc.
--let $binsrv_connect_timeout = 20
--let $binsrv_read_timeout = 60
--let $binsrv_idle_time = 10
--let $binsrv_verify_checksum = $extracted_init_connect_variable_value
--let $binsrv_replication_mode = position
--let $binsrv_checkpoint_size = 1
--source ../include/set_up_binsrv_environment.inc
--echo
--echo *** Executing the Binlog Server utility to download all binlog data
--echo *** from the server to the <BINSRV_STORAGE_PATH> directory (second
--echo *** binlog is still open / in use).
--exec $BINSRV fetch $binsrv_config_file_path > /dev/null
--echo
--echo *** Checking that the Binlog Server utility detected an empty storage
--let $assert_text = Binlog storage must be initialized on an empty directory
--let $assert_file = $binsrv_log_path
--let $assert_count = 1
--let $assert_select = binlog storage initialized on an empty directory
--source include/assert_grep.inc
# At this point we have 2 binlog files $first_binlog (already closed/rotated
# by the server) and $second_binlog (currently open).
# The former can be compared as is.
--echo
--echo *** Comparing server and downloaded versions of the first binlog file.
--let $local_file = $binlog_base_dir/$first_binlog
--let $storage_object = $binsrv_storage_path/$first_binlog
--source ../include/diff_with_storage_object.inc
# Because the latter from the server is currently open for writing, it has one
# additional bit (LOG_EVENT_BINLOG_IN_USE_F = 0x1) set in the flags field of the
# common header section of the very first format description event.
# The expected offset of this change is 21 (4 bytes for magic binlog header
# "\xFEbin" + 17, the offset of the 'flags' field in the common header).
# So, here we create a copy of the second binlog file, patch this byte and
# perform diff on this patched copy.
--echo
--echo *** Patching the server version of the second binlog file to clear the
--echo *** LOG_EVENT_BINLOG_IN_USE_F (currently in use) flag.
--let PATCHED_BINLOG_FILE = $MYSQL_TMP_DIR/$second_binlog.patched
--copy_file $binlog_base_dir/$second_binlog $PATCHED_BINLOG_FILE
--perl
use strict;
use warnings;
use constant MAGIC_OFFSET => 21;
my $binlog_file_perl = $ENV{'PATCHED_BINLOG_FILE'};
open(my $fh, '+<:raw', $binlog_file_perl) or die "Failed to open file: $!";
seek($fh, MAGIC_OFFSET, 0);
my $byte;
read($fh, $byte, 1);
$byte = ord($byte) & 0xFE;
seek($fh, MAGIC_OFFSET, 0);
print $fh pack('C', $byte);
close($fh);
EOF
--echo
--echo *** Comparing server and downloaded versions of the second binlog file.
--let $local_file = $PATCHED_BINLOG_FILE
--let $storage_object = $binsrv_storage_path/$second_binlog
--source ../include/diff_with_storage_object.inc
--remove_file $PATCHED_BINLOG_FILE
--echo
--echo *** Filling the table with some more data and dropping the table.
INSERT INTO t1 VALUES(DEFAULT);
DROP TABLE t1;
--echo
--echo *** FLUSHING the binlog one more time to make sure that the second one
--echo *** is no longer open.
FLUSH BINARY LOGS;
--echo
--echo *** Executing the Binlog Server utility one more time (the second
--echo *** binlog is no longer open / in use). Here we should also continue
--echo *** streaming binlog events from the last saved position.
--exec $BINSRV fetch $binsrv_config_file_path > /dev/null
--echo
--echo *** Checking that the Binlog Server utility detected a previously
--echo *** initialized storage
--let $assert_text = Binlog storage must be initialized on a non-empty directory
--let $assert_file = $binsrv_log_path
--let $assert_count = 1
--let $assert_select = binlog storage initialized at
--source include/assert_grep.inc
--echo
--echo *** Comparing server and downloaded versions of the first binlog file
--echo *** one more time.
--let $local_file = $binlog_base_dir/$first_binlog
--let $storage_object = $binsrv_storage_path/$first_binlog
--source ../include/diff_with_storage_object.inc
--echo
--echo *** Comparing server and downloaded versions of the second binlog file
--echo *** (without patching) one more time.
--let $local_file = $binlog_base_dir/$second_binlog
--let $storage_object = $binsrv_storage_path/$second_binlog
--source ../include/diff_with_storage_object.inc
# cleaning up
--source ../include/tear_down_binsrv_environment.inc