diff options
author | Kristian Nielsen <knielsen@knielsen-hq.org> | 2015-03-04 13:10:37 +0100 |
---|---|---|
committer | Kristian Nielsen <knielsen@knielsen-hq.org> | 2015-03-04 13:36:29 +0100 |
commit | 78c74dbe30d3a22feec5d069c7424d5a8a86ea4c (patch) | |
tree | 5f5f3f5181c89fc2f4f59b50d30ad6304775e120 /sql | |
parent | ad0d203f2ec9b3c696e6c688fe9314f498efc232 (diff) | |
download | mariadb-git-78c74dbe30d3a22feec5d069c7424d5a8a86ea4c.tar.gz |
MDEV-6403: Temporary tables lost at STOP SLAVE in GTID mode if master has not rotated binlog since restart
The binlog contains specially marked format description events to mark
when a master restart happened (which could have caused temporary
tables to be silently dropped). Such events also cause slave to close
temporary tables.
However, there was a bug that if after this, slave re-connects to the
master in GTID mode, the master can send an old format description
event again. If temporary tables are closed when such event is seen
for the second time, it might drop temporary tables created after that
event, and cause replication failure.
With this patch, the restart flag of the format description event is
cleared by the master when it is sent to the slave in a subsequent
connection, to avoid the errorneous temp table close.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/rpl_gtid.cc | 25 | ||||
-rw-r--r-- | sql/rpl_gtid.h | 1 | ||||
-rw-r--r-- | sql/sql_repl.cc | 25 |
3 files changed, 51 insertions, 0 deletions
diff --git a/sql/rpl_gtid.cc b/sql/rpl_gtid.cc index d4c7b2c3fbf..f17ece298d3 100644 --- a/sql/rpl_gtid.cc +++ b/sql/rpl_gtid.cc @@ -1870,6 +1870,31 @@ slave_connection_state::get_gtid_list(rpl_gtid *gtid_list, uint32 list_size) /* + Check if the GTID position has been reached, for mysql_binlog_send(). + + The position has not been reached if we have anything in the state, unless + it has either the START_ON_EMPTY_DOMAIN flag set (which means it does not + belong to this master at all), or the START_OWN_SLAVE_POS (which means that + we start on an old position from when the server was a slave with + --log-slave-updates=0). +*/ +bool +slave_connection_state::is_pos_reached() +{ + uint32 i; + + for (i= 0; i < hash.records; ++i) + { + entry *e= (entry *)my_hash_element(&hash, i); + if (!(e->flags & (START_OWN_SLAVE_POS|START_ON_EMPTY_DOMAIN))) + return false; + } + + return true; +} + + +/* Execute a MASTER_GTID_WAIT(). The position to wait for is in gtid_str in string form. The timeout in microseconds is in timeout_us, zero means no timeout. diff --git a/sql/rpl_gtid.h b/sql/rpl_gtid.h index 22771833845..997540728a5 100644 --- a/sql/rpl_gtid.h +++ b/sql/rpl_gtid.h @@ -288,6 +288,7 @@ struct slave_connection_state int to_string(String *out_str); int append_to_string(String *out_str); int get_gtid_list(rpl_gtid *gtid_list, uint32 list_size); + bool is_pos_reached(); }; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 68535938484..2b5572609d8 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -2375,6 +2375,31 @@ impossible position"; info.fdev= tmp; (*packet)[FLAGS_OFFSET+ev_offset] &= ~LOG_EVENT_BINLOG_IN_USE_F; + + if (info.using_gtid_state) + { + /* + If this event has the field `created' set, then it will cause the + slave to delete all active temporary tables. This must not happen + if the slave received any later GTIDs in a previous connect, as + those GTIDs might have created new temporary tables that are still + needed. + + So here, we check if the starting GTID position was already + reached before this format description event. If not, we clear the + `created' flag to preserve temporary tables on the slave. (If the + slave connects at a position past this event, it means that it + already received and handled it in a previous connect). + */ + if (!info.gtid_state.is_pos_reached()) + { + int4store((char*) packet->ptr()+LOG_EVENT_MINIMAL_HEADER_LEN+ + ST_CREATED_OFFSET+ev_offset, (ulong) 0); + if (info.current_checksum_alg != BINLOG_CHECKSUM_ALG_OFF && + info.current_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF) + fix_checksum(packet, ev_offset); + } + } } #ifndef DBUG_OFF |