Skip to content

Commit 1949d8c

Browse files
author
Libing Song
committed
WL#10956 Binlog Access API - Step3 Relaylog Applier Reader
This patch replaced the last Log_event::read_log_event() call to Relaylog_file_reader which was introduced in Step2 patch. So Log_event::read_log_event() was finally removed from the code. It also did some refacotring - It created Rpl_applier_reader class which is responsible for reading events from relaylog files. - The code of next_event was moved into Rpl_applier_reader class and separated into a few functions. - The applier reader is only need when applier is online. It is used as a local variable of handle_slave_sql(). - change_master and purge_relay_logs don't need to reopen or reinitialize the applier read anymore. So rli::init_relay_log_pos is reorganized as group_relay_log_is_valid() to verify group_relay_log_name existing. - rli::event_relay_log_pos and rli::event_relay_log_name are only used when applying events. So they just need to be intilaized in Rpl_applier_reader class. - Moved the code period checking out mts_checkpoint_routine. It was encapsulated into a new function called rli::is_time_for_mts_checkpoint
1 parent 191b1d1 commit 1949d8c

32 files changed

+1027
-1384
lines changed

client/mysqlbinlog.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1964,8 +1964,7 @@ static Exit_status dump_multiple_logs(int argc, char **argv) {
19641964
When reading a remote binlog, this function is used to grab the
19651965
Format_description_log_event in the beginning of the stream.
19661966
1967-
This is not as smart as check_header() (used for local log); it will
1968-
not work for a binlog which mixes format. TODO: fix this.
1967+
It will not work for a binlog which mixes format. TODO: fix this.
19691968
19701969
@retval ERROR_STOP An error occurred - the program should terminate.
19711970
@retval OK_CONTINUE No error, the program should continue.
@@ -2399,11 +2398,13 @@ class Stdin_binlog_istream : public Basic_seekable_istream,
23992398
return false;
24002399
}
24012400

2401+
/* purecov: begin inspected */
24022402
/** Stdin has no length. It should never be called. */
24032403
my_off_t length() override {
24042404
DBUG_ASSERT(0);
24052405
return 0;
24062406
};
2407+
/* purecov: end */
24072408

24082409
private:
24092410
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
call mtr.add_suppression("Binary logging not possible");
2+
call mtr.add_suppression("Attempting backtrace");
3+
RESET MASTER;
4+
CREATE TABLE t1(c1 INT);
5+
SET debug = "+d,simulate_init_io_cache_failure";
6+
SHOW BINLOG EVENTS;
7+
ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Could not open log file
8+
SET debug = "-d,simulate_init_io_cache_failure";
9+
SET debug = "+d,simulate_allocate_failure";
10+
SHOW BINLOG EVENTS;
11+
ERROR HY000: Error when executing command SHOW BINLOG EVENTS: memory allocation failed reading log event
12+
SET debug = "-d,simulate_allocate_failure";
13+
SET debug = "+d,simulate_seek_failure";
14+
SHOW BINLOG EVENTS FROM 337;
15+
ERROR HY000: Error when executing command SHOW BINLOG EVENTS: I/O error reading log event
16+
SET debug = "-d,simulate_seek_failure";
17+
SET debug = "+d,simulate_ostream_write_failure";
18+
INSERT INTO t1 VALUES(1);
19+
ERROR HY000: Binary logging not possible. Message: An error occurred during flush stage of the commit. 'binlog_error_action' is set to 'ABORT_SERVER'. Hence aborting the server.
20+
DROP TABLE t1;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Coverage Tests for WL#10956
2+
--source include/not_valgrind.inc
3+
--source include/have_debug.inc
4+
--source include/have_binlog_format_row.inc
5+
call mtr.add_suppression("Binary logging not possible");
6+
call mtr.add_suppression("Attempting backtrace");
7+
RESET MASTER;
8+
9+
CREATE TABLE t1(c1 INT);
10+
--let $start_pos = query_get_value(SHOW MASTER STATUS, Position, 1)
11+
12+
SET debug = "+d,simulate_init_io_cache_failure";
13+
--error ER_ERROR_WHEN_EXECUTING_COMMAND
14+
SHOW BINLOG EVENTS;
15+
SET debug = "-d,simulate_init_io_cache_failure";
16+
17+
SET debug = "+d,simulate_allocate_failure";
18+
--error ER_ERROR_WHEN_EXECUTING_COMMAND
19+
SHOW BINLOG EVENTS;
20+
SET debug = "-d,simulate_allocate_failure";
21+
22+
SET debug = "+d,simulate_seek_failure";
23+
--error ER_ERROR_WHEN_EXECUTING_COMMAND
24+
eval SHOW BINLOG EVENTS FROM $start_pos;
25+
SET debug = "-d,simulate_seek_failure";
26+
27+
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
28+
SET debug = "+d,simulate_ostream_write_failure";
29+
--error ER_BINLOG_LOGGING_IMPOSSIBLE
30+
INSERT INTO t1 VALUES(1);
31+
32+
--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
33+
--enable_reconnect
34+
--source include/wait_until_connected_again.inc
35+
36+
--error 1
37+
--exec $MYSQL_BINLOG file_not_exist >/dev/null
38+
39+
--error 1,12
40+
--exec $MYSQL_BINLOG -#d,simulate_init_io_cache_failure - > /dev/null 2>&1
41+
42+
--error 1,12
43+
--exec $MYSQL_BINLOG -#d,simulate_init_io_cache_failure binlog.000001 > /dev/null 2>&1
44+
45+
--error 1,12
46+
--exec $MYSQL_BINLOG --start-position=100000000 binlog.000001 > /dev/null 2>&1
47+
DROP TABLE t1;
48+

mysql-test/suite/ndb_rpl/r/ndb_rpl_checksum.result

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ include/start_slave.inc
7777
set @@global.master_verify_checksum = 1;
7878
set @@session.debug='d,simulate_checksum_test_failure';
7979
show binlog events;
80-
ERROR HY000: Error when executing command SHOW BINLOG EVENTS: Wrong offset or I/O error
80+
ERROR HY000: Error when executing command SHOW BINLOG EVENTS: event read from binlog did not pass crc check
8181
set @@session.debug='';
8282
set @@global.master_verify_checksum = default;
8383
include/stop_slave.inc
@@ -92,7 +92,7 @@ set @@global.slave_sql_verify_checksum = 1;
9292
set @@global.debug='d,simulate_checksum_test_failure';
9393
start slave sql_thread;
9494
include/wait_for_slave_sql_error.inc [errno=13117]
95-
Last_SQL_Error = 'Error initializing relay log position: I/O error reading event at position 4'
95+
Last_SQL_Error = 'Error initializing relay log position: event read from binlog did not pass crc check'
9696
include/stop_slave.inc
9797
set @@global.debug='';
9898
include/start_slave.inc

mysql-test/suite/rpl/r/rpl_multi_source_channel_map_stress.result

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Note #### Storing MySQL user name or password information in the master info rep
77
CALL mtr.add_suppression('Slave failed to initialize master info structure from the repository');
88
CALL mtr.add_suppression('This operation cannot be performed with a running slave');
99
CALL mtr.add_suppression('Could not find target log file mentioned in relay log info in the index file');
10+
CALL mtr.add_suppression('Could not find relay log file');
1011
CALL mtr.add_suppression('A slave with the same server_uuid/server_id as this slave has connected to the master');
1112
SET @saved_event_scheduler= @@GLOBAL.event_scheduler;
1213
SET @saved_relay_log_purge= @@GLOBAL.relay_log_purge;

mysql-test/suite/rpl/r/rpl_reset_slave_fail.result

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ call mtr.add_suppression("Could not find target log file mentioned in relay log
2222
call mtr.add_suppression("Failed to initialize the relay-log-info structure");
2323
call mtr.add_suppression("Failed to initialize the master info structure");
2424
call mtr.add_suppression("Failed to create or recover replication info repositories");
25+
call mtr.add_suppression("listed in the index, but failed to stat");
26+
call mtr.add_suppression("Error counting relay log space");
2527
include/rpl_stop_server.inc [server_number=2]
2628
# Removing file(s)
2729
include/rpl_start_server.inc [server_number=2]

mysql-test/suite/rpl/t/rpl_multi_source_channel_map_stress.test

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
CALL mtr.add_suppression('Slave failed to initialize master info structure from the repository');
2727
CALL mtr.add_suppression('This operation cannot be performed with a running slave');
2828
CALL mtr.add_suppression('Could not find target log file mentioned in relay log info in the index file');
29+
# For case:
30+
# STOP SLAVE SQL_THREAD; // IO_THREAD is running
31+
# CHANGE MASTER TO relay_log_name = 'non-existing relay log name',...;
32+
# While CHANGE MASTER throwns an error, group_relay_log_name is changed to the
33+
# non-existing file name.
34+
# START SLAVE SQL_THREAD; // It will log below error.
35+
CALL mtr.add_suppression('Could not find relay log file');
2936
CALL mtr.add_suppression('A slave with the same server_uuid/server_id as this slave has connected to the master');
3037

3138
# Save current event scheduler status

mysql-test/suite/rpl/t/rpl_multi_source_slave_files.cnf

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ relay-log-purge=0
1212
relay-log-recovery=1
1313
sync_relay_log=10
1414
max-relay-log-size=1073741824
15-
relay-log-space-limit=1073741824
1615
relay-log=relaylog-msr
1716
relay-log-index=relaylog-msr.index
1817
sync-master-info=10

mysql-test/suite/rpl/t/rpl_reset_slave_fail.test

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ call mtr.add_suppression("Could not find target log file mentioned in relay log
4141
call mtr.add_suppression("Failed to initialize the relay-log-info structure");
4242
call mtr.add_suppression("Failed to initialize the master info structure");
4343
call mtr.add_suppression("Failed to create or recover replication info repositories");
44+
call mtr.add_suppression("listed in the index, but failed to stat");
45+
call mtr.add_suppression("Error counting relay log space");
4446

4547
# Stop slave
4648
--let $rpl_server_number= 2

mysql-test/suite/rpl_nogtid/r/rpl_checksum.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ set @@global.slave_sql_verify_checksum = 1;
9292
set @@global.debug='d,simulate_checksum_test_failure';
9393
start slave sql_thread;
9494
include/wait_for_slave_sql_error.inc [errno=13117]
95-
Last_SQL_Error = 'Error initializing relay log position: I/O error reading event at position 4'
95+
Last_SQL_Error = 'Event crc check failed! Most likely there is event corruption.'
9696
include/stop_slave.inc
9797
set @@global.debug='';
9898
include/start_slave.inc

mysys/mf_iocache.cc

+2
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ int init_io_cache_ext(IO_CACHE *info, File file, size_t cachesize,
179179
DBUG_PRINT("enter", ("cache: %p type: %d pos: %ld", info, (int)type,
180180
(ulong)seek_offset));
181181

182+
DBUG_EXECUTE_IF("simulate_init_io_cache_failure", DBUG_RETURN(1););
183+
182184
info->file = file;
183185
info->file_key = file_key;
184186
info->type = TYPE_NOT_SET; /* Don't set it until mutex are created */

share/errmsg-utf8.txt

+6-3
Original file line numberDiff line numberDiff line change
@@ -10999,10 +10999,10 @@ ER_BINLOG_FILE_BEING_READ_NOT_PURGED
1099910999
ER_BINLOG_IO_ERROR_READING_HEADER
1100011000
eng "I/O error reading the header from the binary log, errno=%d, io cache code=%d"
1100111001

11002-
ER_BINLOG_CANT_OPEN_LOG
11002+
OBSOLETE_ER_BINLOG_CANT_OPEN_LOG
1100311003
eng "Failed to open log (file '%s', errno %d)"
1100411004

11005-
ER_BINLOG_CANT_CREATE_CACHE_FOR_LOG
11005+
OBSOLETE_ER_BINLOG_CANT_CREATE_CACHE_FOR_LOG
1100611006
eng "Failed to create a cache on log (file '%s')"
1100711007

1100811008
ER_BINLOG_FILE_EXTENSION_NUMBER_EXHAUSTED
@@ -11068,7 +11068,7 @@ ER_BINLOG_CANT_SET_TMP_INDEX_NAME
1106811068
ER_BINLOG_FAILED_TO_OPEN_TEMPORARY_INDEX_FILE
1106911069
eng "MYSQL_BIN_LOG::open_crash_safe_index_file failed to open temporary index file."
1107011070

11071-
ER_BINLOG_ERROR_GETTING_NEXT_LOG_FROM_INDEX
11071+
OBSOLETE_ER_BINLOG_ERROR_GETTING_NEXT_LOG_FROM_INDEX
1107211072
eng "next log error: %d offset: %s log: %s included: %d"
1107311073

1107411074
ER_BINLOG_CANT_OPEN_TMP_INDEX
@@ -18182,6 +18182,9 @@ ER_CANT_SET_ERROR_SUPPRESSION_LIST_FROM_COMMAND_LINE
1818218182
ER_INVALID_VALUE_OF_BIND_ADDRESSES
1818318183
eng "Invalid value for command line option bind-addresses: '%s'"
1818418184

18185+
ER_RELAY_LOG_SPACE_LIMIT_DISABLED
18186+
eng "Ignoring the @@global.relay_log_space_limit option because @@global.relay_log_purge is disabled."
18187+
1818518188
#
1818618189
# End of 8.0 Server error messages.
1818718190
# (Please read comments from the header of this section before adding error

sql/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ SET (SLAVE_SOURCE rpl_slave.cc rpl_reporting.cc rpl_mi.cc rpl_rli.cc
722722
rpl_rli_pdb.cc rpl_info_dummy.cc rpl_mts_submode.cc
723723
rpl_slave_commit_order_manager.cc rpl_msr.cc
724724
rpl_trx_boundary_parser.cc rpl_channel_service_interface.cc
725-
rpl_slave_until_options.cc)
725+
rpl_slave_until_options.cc rpl_applier_reader.cc)
726726
ADD_CONVENIENCE_LIBRARY(slave ${SLAVE_SOURCE})
727727
ADD_DEPENDENCIES(slave GenError)
728728

sql/basic_istream.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
#include <my_sys.h>
1919
#include <mysql/psi/mysql_file.h>
2020

21-
IO_CACHE_istream::IO_CACHE_istream() {
22-
memset(&m_io_cache, 0, sizeof(m_io_cache));
23-
}
21+
IO_CACHE_istream::IO_CACHE_istream() {}
2422

2523
IO_CACHE_istream::~IO_CACHE_istream() { close(); }
2624

@@ -63,11 +61,12 @@ ssize_t IO_CACHE_istream::read(unsigned char *buffer, size_t length) {
6361
}
6462

6563
bool IO_CACHE_istream::seek(my_off_t offset) {
64+
DBUG_EXECUTE_IF("simulate_seek_failure", return true;);
6665
my_b_seek(&m_io_cache, offset);
6766
return false;
6867
}
6968

70-
Stdin_istream::Stdin_istream() { memset(&m_io_cache, 0, sizeof(m_io_cache)); }
69+
Stdin_istream::Stdin_istream() {}
7170

7271
Stdin_istream::~Stdin_istream() { close(); }
7372

sql/basic_ostream.cc

+2-8
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
#include "mysqld_error.h"
2121
#include "sql/log.h"
2222

23-
IO_CACHE_ostream::IO_CACHE_ostream() {
24-
memset(&m_io_cache, 0, sizeof(m_io_cache));
25-
}
23+
IO_CACHE_ostream::IO_CACHE_ostream() {}
2624
IO_CACHE_ostream::~IO_CACHE_ostream() { close(); }
2725

2826
bool IO_CACHE_ostream::open(
@@ -52,18 +50,14 @@ bool IO_CACHE_ostream::close() {
5250
return false;
5351
}
5452

55-
my_off_t IO_CACHE_ostream::tell() {
56-
DBUG_ASSERT(my_b_inited(&m_io_cache));
57-
return my_b_tell(&m_io_cache);
58-
}
59-
6053
bool IO_CACHE_ostream::seek(my_off_t offset) {
6154
DBUG_ASSERT(my_b_inited(&m_io_cache));
6255
return reinit_io_cache(&m_io_cache, WRITE_CACHE, offset, false, true);
6356
}
6457

6558
bool IO_CACHE_ostream::write(const unsigned char *buffer, my_off_t length) {
6659
DBUG_ASSERT(my_b_inited(&m_io_cache));
60+
DBUG_EXECUTE_IF("simulate_ostream_write_failure", return true;);
6761
return my_b_safe_write(&m_io_cache, buffer, length);
6862
}
6963

sql/basic_ostream.h

-5
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ class IO_CACHE_ostream : public Truncatable_ostream {
9999
*/
100100
bool close();
101101

102-
/**
103-
Returns the write position of the file.
104-
*/
105-
my_off_t tell();
106-
107102
bool write(const unsigned char *buffer, my_off_t length) override;
108103
bool seek(my_off_t offset) override;
109104
bool truncate(my_off_t offset) override;

0 commit comments

Comments
 (0)