From c4d69f17753f375e8cfd18c33de291cdf13504f9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 11 Aug 2011 11:38:52 +0200 Subject: MWL#234: Support for marking binlog events to not be replicated, and for telling slaves not to replicate events with such mark --- sql/sql_repl.cc | 77 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 32 deletions(-) (limited to 'sql/sql_repl.cc') diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 5038d02abca..8de2ce5fcf1 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -337,6 +337,41 @@ Increase max_allowed_packet on master"; } +/* + Helper function for mysql_binlog_send() to write an event down the slave + connection. + + Returns NULL on success, error message string on error. +*/ +static const char * +send_event_to_slave(THD *thd, NET *net, String* const packet) +{ + thd_proc_info(thd, "Sending binlog event to slave"); + + /* + Skip events with the @@do_not_replicate flag set, if slave requested + skipping of such events. + */ + if (thd->options & OPTION_DO_NOT_REPLICATE) + { + uint16 flags= uint2korr(&((*packet)[FLAGS_OFFSET+1])); + if (flags & LOG_EVENT_DO_NOT_REPLICATE_F) + return NULL; + } + + if (my_net_write(net, (uchar*) packet->ptr(), packet->length())) + return "Failed on my_net_write()"; + + DBUG_PRINT("info", ("log event code %d", (*packet)[LOG_EVENT_OFFSET+1] )); + if ((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT) + { + if (send_file(thd)) + return "failed in send_file()"; + } + + return NULL; /* Success */ +} + /* TODO: Clean up loop to only have one call to send_file() */ @@ -349,9 +384,9 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, char search_file_name[FN_REFLEN], *name; IO_CACHE log; File file = -1; - String* packet = &thd->packet; + String* const packet = &thd->packet; int error; - const char *errmsg = "Unknown error"; + const char *errmsg = "Unknown error", *tmp_msg; NET* net = &thd->net; pthread_mutex_t *log_lock; bool binlog_can_be_corrupted= FALSE; @@ -588,9 +623,9 @@ impossible position"; else if ((*packet)[EVENT_TYPE_OFFSET+1] == STOP_EVENT) binlog_can_be_corrupted= FALSE; - if (my_net_write(net, (uchar*) packet->ptr(), packet->length())) + if ((tmp_msg= send_event_to_slave(thd, net, packet))) { - errmsg = "Failed on my_net_write()"; + errmsg = tmp_msg; my_errno= ER_UNKNOWN_ERROR; goto err; } @@ -603,17 +638,6 @@ impossible position"; } }); - DBUG_PRINT("info", ("log event code %d", - (*packet)[LOG_EVENT_OFFSET+1] )); - if ((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT) - { - if (send_file(thd)) - { - errmsg = "failed in send_file()"; - my_errno= ER_UNKNOWN_ERROR; - goto err; - } - } packet->set("\0", 1, &my_charset_bin); } @@ -713,23 +737,12 @@ impossible position"; if (read_packet) { - thd_proc_info(thd, "Sending binlog event to slave"); - if (my_net_write(net, (uchar*) packet->ptr(), packet->length()) ) - { - errmsg = "Failed on my_net_write()"; - my_errno= ER_UNKNOWN_ERROR; - goto err; - } - - if ((*packet)[LOG_EVENT_OFFSET+1] == LOAD_EVENT) - { - if (send_file(thd)) - { - errmsg = "failed in send_file()"; - my_errno= ER_UNKNOWN_ERROR; - goto err; - } - } + if ((tmp_msg= send_event_to_slave(thd, net, packet))) + { + errmsg = tmp_msg; + my_errno= ER_UNKNOWN_ERROR; + goto err; + } packet->set("\0", 1, &my_charset_bin); /* No need to net_flush because we will get to flush later when -- cgit v1.2.1 From b1a13cb15a2cca5dece24c860f64b5ee012ed199 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 12 Aug 2011 13:18:34 +0200 Subject: MWL#234: After-review fixes, including better names for the new system variables. --- sql/sql_repl.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'sql/sql_repl.cc') diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 8de2ce5fcf1..8c2e6e82cd4 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -349,13 +349,17 @@ send_event_to_slave(THD *thd, NET *net, String* const packet) thd_proc_info(thd, "Sending binlog event to slave"); /* - Skip events with the @@do_not_replicate flag set, if slave requested + Skip events with the @@skip_replication flag set, if slave requested skipping of such events. */ - if (thd->options & OPTION_DO_NOT_REPLICATE) + if (thd->options & OPTION_SKIP_REPLICATION) { + /* + The first byte of the packet is a '\0' to distinguish it from an error + packet. So the actual event starts at offset +1. + */ uint16 flags= uint2korr(&((*packet)[FLAGS_OFFSET+1])); - if (flags & LOG_EVENT_DO_NOT_REPLICATE_F) + if (flags & LOG_EVENT_SKIP_REPLICATION_F) return NULL; } -- cgit v1.2.1