From 544781ad888c388cff6e4d7917585f1173df19f8 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Dec 2007 10:13:54 +0200 Subject: Bug #31359 change_master sets group_master_log_pos twice, ignores future_group_master_log_p There was a redundant assignement. However, that's the only artifact. Wrt to future_group_master_log_position, there is no issue. The counter is supposed to be set at Log_event::exec_event(). It's used only by Innodb for recovery purposes. sql/sql_repl.cc: removing a redundant line which arrived with the revision 1.102.1.7. --- sql/sql_repl.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'sql') diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 903d254db8f..90eea8d322f 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1229,9 +1229,6 @@ bool change_master(THD* thd, MASTER_INFO* mi) DBUG_RETURN(TRUE); } } - mi->rli.group_master_log_pos = mi->master_log_pos; - DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - /* Coordinates in rli were spoilt by the 'if (need_relay_log_purge)' block, so restore them to good values. If we left them to ''/0, that would work; @@ -1243,6 +1240,7 @@ bool change_master(THD* thd, MASTER_INFO* mi) That's why we always save good coords in rli. */ mi->rli.group_master_log_pos= mi->master_log_pos; + DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); strmake(mi->rli.group_master_log_name,mi->master_log_name, sizeof(mi->rli.group_master_log_name)-1); -- cgit v1.2.1 From 40d89c44ea03dcd3ad069bb59883272fc0a52b19 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Dec 2007 22:34:43 +0200 Subject: BUG#30435 loading large LOAD DATA INFILE breaks slave with read_buffer_size set on master BUG#33413 show binlog events fails if binlog has event size of close to max_allowed_packet The size of Append_block replication event was determined solely by read_buffer_size whereas the rest of replication code deals with max_allowed_packet. When the former parameter was set to larger than the latter there were two artifacts: the master could not read events from binlog; show master events did not show. Fixed with - fragmenting the used io-cached buffer into pieces each size of less than max_allowed_packet (bug#30435) - incrementing show-binlog-events handling thread's max_allowed_packet with the max estimated for the replication header size include/my_sys.h: accessor-macros added in order not to mess with the io cache's implementation details in code that merely exploits the io-cache. sql/sql_repl.cc: BUG#33413: incrementing thd->variables.max_allowed_packet with the max estimation for the replication header size (from bug#19402); refactoring log_loaded_block() to fragment the io_cache buffer in case read_buffer_size > max_allowed_packet. mysql-test/r/rpl_loaddata_map.result: New BitKeeper file ``mysql-test/r/rpl_loaddata_map.result'' mysql-test/t/rpl_loaddata_map-master.opt: specific options to trigger BUG#30435, BUG#33413 situations mysql-test/t/rpl_loaddata_map-slave.opt: max_allowed_packet to be compatible with the master's version. mysql-test/t/rpl_loaddata_map.test: regression tests for two bugs. --- sql/sql_repl.cc | 69 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'sql') diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 903d254db8f..c1ba33ce27d 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1355,6 +1355,11 @@ bool mysql_show_binlog_events(THD* thd) if ((file=open_binlog(&log, linfo.log_file_name, &errmsg)) < 0) goto err; + /* + to account binlog event header size + */ + thd->variables.max_allowed_packet += MAX_LOG_EVENT_HEADER; + pthread_mutex_lock(log_lock); /* @@ -1365,7 +1370,6 @@ bool mysql_show_binlog_events(THD* thd) This code will fail on a mixed relay log (one which has Format_desc then Rotate then Format_desc). */ - ev = Log_event::read_log_event(&log,(pthread_mutex_t*)0,description_event); if (ev) { @@ -1556,37 +1560,52 @@ err: DBUG_RETURN(TRUE); } - +/** + Load data's io cache specific hook to be executed + before a chunk of data is being read into the cache's buffer + The fuction instantianates and writes into the binlog + replication events along LOAD DATA processing. + + @param file pointer to io-cache + @return 0 +*/ int log_loaded_block(IO_CACHE* file) { + DBUG_ENTER("log_loaded_block"); LOAD_FILE_INFO *lf_info; - uint block_len ; - - /* file->request_pos contains position where we started last read */ - char* buffer = (char*) file->request_pos; - if (!(block_len = (char*) file->read_end - (char*) buffer)) - return 0; - lf_info = (LOAD_FILE_INFO*) file->arg; + uint block_len; + /* buffer contains position where we started last read */ + char* buffer= my_b_get_buffer_start(file); + uint max_event_size= current_thd->variables.max_allowed_packet; + lf_info= (LOAD_FILE_INFO*) file->arg; if (lf_info->last_pos_in_file != HA_POS_ERROR && - lf_info->last_pos_in_file >= file->pos_in_file) + lf_info->last_pos_in_file >= my_b_get_pos_in_file(file)) return 0; - lf_info->last_pos_in_file = file->pos_in_file; - if (lf_info->wrote_create_file) - { - Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer, - block_len, lf_info->log_delayed); - mysql_bin_log.write(&a); - } - else + + for (block_len= my_b_get_bytes_in_buffer(file); block_len > 0; + buffer += min(block_len, max_event_size), + block_len -= min(block_len, max_event_size)) { - Begin_load_query_log_event b(lf_info->thd, lf_info->thd->db, - buffer, block_len, - lf_info->log_delayed); - mysql_bin_log.write(&b); - lf_info->wrote_create_file = 1; - DBUG_SYNC_POINT("debug_lock.created_file_event",10); + lf_info->last_pos_in_file= my_b_get_pos_in_file(file); + if (lf_info->wrote_create_file) + { + Append_block_log_event a(lf_info->thd, lf_info->thd->db, buffer, + min(block_len, max_event_size), + lf_info->log_delayed); + mysql_bin_log.write(&a); + } + else + { + Begin_load_query_log_event b(lf_info->thd, lf_info->thd->db, + buffer, + min(block_len, max_event_size), + lf_info->log_delayed); + mysql_bin_log.write(&b); + lf_info->wrote_create_file= 1; + DBUG_SYNC_POINT("debug_lock.created_file_event",10); + } } - return 0; + DBUG_RETURN(0); } #endif /* HAVE_REPLICATION */ -- cgit v1.2.1 From 7e555be488181ca12bb533d847a704c68f3adfb0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 6 Jan 2008 20:16:28 +0800 Subject: Replace one overlooked return with DBUG_RETURN in function log_loaded_block --- sql/sql_repl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql') diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 7787a0980fd..f2312afa878 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1578,7 +1578,7 @@ int log_loaded_block(IO_CACHE* file) lf_info= (LOAD_FILE_INFO*) file->arg; if (lf_info->last_pos_in_file != HA_POS_ERROR && lf_info->last_pos_in_file >= my_b_get_pos_in_file(file)) - return 0; + DBUG_RETURN(0); for (block_len= my_b_get_bytes_in_buffer(file); block_len > 0; buffer += min(block_len, max_event_size), -- cgit v1.2.1 From 3a6e84a2b36d6bf49bedc6f0e4f97b79220456d2 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Jan 2008 16:39:44 +0100 Subject: BUG#27779: Slave cannot read old rows log events. Problem: Replication fails when master is mysql-5.1-wl2325-5.0-drop6 and slave is mysql-5.1-new-rpl. The reason is that, in mysql-5.1-wl2325-5.0-drop6, the event type id's were different than in mysql-5.1-new-rpl. Fix (in mysql-5.1-new-rpl): (1) detect that the server that generated the events uses the old format, by checking the server version of the format_description_log_event This patch recognizes mysql-5.1-wl2325-5.0-drop6p13-alpha, mysql-5.1-wl2325-5.0-drop6, mysql-5.1-wl2325-5.0, mysql-5.1-wl2325-no-dd. (2) if the generating server is old, map old event types to new event types using a permutation array. I've also added a test case which reads binlogs for four different versions. mysql-test/suite/binlog/std_data/binlog_old_version_5_1-telco.000001: BitKeeper file /home/sven/bk/b27779-old_row_events/5.1-new-rpl/mysql-test/suite/binlog/std_data/binlog_old_version_5_1-telco.000001 mysql-test/suite/binlog/std_data/binlog_old_version_5_1-wl2325_row.000001: BitKeeper file /home/sven/bk/b27779-old_row_events/5.1-new-rpl/mysql-test/suite/binlog/std_data/binlog_old_version_5_1-wl2325_row.000001 mysql-test/suite/binlog/std_data/binlog_old_version_5_1-wl2325_stm.000001: BitKeeper file /home/sven/bk/b27779-old_row_events/5.1-new-rpl/mysql-test/suite/binlog/std_data/binlog_old_version_5_1-wl2325_stm.000001 mysql-test/suite/binlog/std_data/binlog_old_version_5_1_17.000001: BitKeeper file /home/sven/bk/b27779-old_row_events/5.1-new-rpl/mysql-test/suite/binlog/std_data/binlog_old_version_5_1_17.000001 mysql-test/suite/binlog/std_data/binlog_old_version_5_1_23.000001: BitKeeper file /home/sven/bk/b27779-old_row_events/5.1-new-rpl/mysql-test/suite/binlog/std_data/binlog_old_version_5_1_23.000001 sql/log_event.cc: Added code to read events generated by mysql-5.1-wl2325-5.0-drop6p13-alpha, mysql-5.1-wl2325-5.0-drop6, mysql-5.1-wl2325-5.0, mysql-5.1-wl2325-no-dd. More precisely, the event type id's had different numbers in those versions. To fix, we add a permutation array which maps old_id to new_id when the format_description_log_event indicates that the originating server is of the old type. We also need to permute the post_header_len array accordingly. sql/log_event.h: sql/log_event.h@1.169, 2008-01-09 11:34:37+01:00, sven@riska.(none) +5 -1 Added declaration needed in log_event.cc. Also, the destructor of Format_description_log_event is sometimes called when post_header_len is null, so we must pass the MY_ALLOW_ZERO_PTR flag to my_free. mysql-test/suite/binlog/r/binlog_old_versions.result: Result file for new test. mysql-test/suite/binlog/t/binlog_old_versions.test: New test case that loads binlogs from several old versions. --- sql/log_event.cc | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- sql/log_event.h | 6 +++- 2 files changed, 89 insertions(+), 3 deletions(-) (limited to 'sql') diff --git a/sql/log_event.cc b/sql/log_event.cc index 31c14bbd81d..45478020a36 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1071,6 +1071,29 @@ Log_event* Log_event::read_log_event(const char* buf, uint event_len, } else { + /* + In some previuos versions (see comment in + Format_description_log_event::Format_description_log_event(char*,...)), + event types were assigned different id numbers than in the + present version. In order to replicate from such versions to the + present version, we must map those event type id's to our event + type id's. The mapping is done with the event_type_permutation + array, which was set up when the Format_description_log_event + was read. + */ + if (description_event->event_type_permutation) + { + IF_DBUG({ + int new_event_type= + description_event->event_type_permutation[event_type]; + DBUG_PRINT("info", + ("converting event type %d to %d (%s)", + event_type, new_event_type, + get_type_str((Log_event_type)new_event_type))); + }); + event_type= description_event->event_type_permutation[event_type]; + } + switch(event_type) { case QUERY_EVENT: ev = new Query_log_event(buf, event_len, description_event, QUERY_EVENT); @@ -2771,7 +2794,7 @@ int Start_log_event_v3::do_apply_event(Relay_log_info const *rli) Format_description_log_event:: Format_description_log_event(uint8 binlog_ver, const char* server_ver) - :Start_log_event_v3() + :Start_log_event_v3(), event_type_permutation(0) { binlog_version= binlog_ver; switch (binlog_ver) { @@ -2896,7 +2919,7 @@ Format_description_log_event(const char* buf, const Format_description_log_event* description_event) - :Start_log_event_v3(buf, description_event) + :Start_log_event_v3(buf, description_event), event_type_permutation(0) { DBUG_ENTER("Format_description_log_event::Format_description_log_event(char*,...)"); buf+= LOG_EVENT_MINIMAL_HEADER_LEN; @@ -2911,6 +2934,65 @@ Format_description_log_event(const char* buf, number_of_event_types* sizeof(*post_header_len), MYF(0)); calc_server_version_split(); + + /* + In some previous versions, the events were given other event type + id numbers than in the present version. When replicating from such + a version, we therefore set up an array that maps those id numbers + to the id numbers of the present server. + + If post_header_len is null, it means malloc failed, and is_valid + will fail, so there is no need to do anything. + + The trees which have wrong event id's are: + mysql-5.1-wl2325-5.0-drop6p13-alpha, mysql-5.1-wl2325-5.0-drop6, + mysql-5.1-wl2325-5.0, mysql-5.1-wl2325-no-dd (`grep -C2 + BEGIN_LOAD_QUERY_EVENT /home/bk/ * /sql/log_event.h`). The + corresponding version (`grep mysql, configure.in` in those trees) + strings are 5.2.2-a_drop6p13-alpha, 5.2.2-a_drop6p13c, + 5.1.5-a_drop5p20, 5.1.2-a_drop5p5. + */ + if (post_header_len && + (strncmp(server_version, "5.1.2-a_drop5", 13) == 0 || + strncmp(server_version, "5.1.5-a_drop5", 13) == 0 || + strncmp(server_version, "5.2.2-a_drop6", 13) == 0)) + { + if (number_of_event_types != 22) + { + DBUG_PRINT("info", (" number_of_event_types=%d", + number_of_event_types)); + /* this makes is_valid() return false. */ + my_free(post_header_len, MYF(MY_ALLOW_ZERO_PTR)); + post_header_len= NULL; + DBUG_VOID_RETURN; + } + static const uint8 perm[23]= + { + UNKNOWN_EVENT, START_EVENT_V3, QUERY_EVENT, STOP_EVENT, ROTATE_EVENT, + INTVAR_EVENT, LOAD_EVENT, SLAVE_EVENT, CREATE_FILE_EVENT, + APPEND_BLOCK_EVENT, EXEC_LOAD_EVENT, DELETE_FILE_EVENT, + NEW_LOAD_EVENT, + RAND_EVENT, USER_VAR_EVENT, + FORMAT_DESCRIPTION_EVENT, + TABLE_MAP_EVENT, + PRE_GA_WRITE_ROWS_EVENT, + PRE_GA_UPDATE_ROWS_EVENT, + PRE_GA_DELETE_ROWS_EVENT, + XID_EVENT, + BEGIN_LOAD_QUERY_EVENT, + EXECUTE_LOAD_QUERY_EVENT, + }; + event_type_permutation= perm; + /* + Since we use (permuted) event id's to index the post_header_len + array, we need to permute the post_header_len array too. + */ + uint8 post_header_len_temp[23]; + for (int i= 1; i < 23; i++) + post_header_len_temp[perm[i] - 1]= post_header_len[i - 1]; + for (int i= 0; i < 22; i++) + post_header_len[i] = post_header_len_temp[i]; + } DBUG_VOID_RETURN; } diff --git a/sql/log_event.h b/sql/log_event.h index 4a75f330203..31c1ab7173a 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -2106,12 +2106,16 @@ public: /* The list of post-headers' lengthes */ uint8 *post_header_len; uchar server_version_split[3]; + const uint8 *event_type_permutation; Format_description_log_event(uint8 binlog_ver, const char* server_ver=0); Format_description_log_event(const char* buf, uint event_len, const Format_description_log_event *description_event); - ~Format_description_log_event() { my_free((uchar*)post_header_len, MYF(0)); } + ~Format_description_log_event() + { + my_free((uchar*)post_header_len, MYF(MY_ALLOW_ZERO_PTR)); + } Log_event_type get_type_code() { return FORMAT_DESCRIPTION_EVENT;} #ifndef MYSQL_CLIENT bool write(IO_CACHE* file); -- cgit v1.2.1 From d2b4d051ea9b40ab8f3950270fa2d0777f3108bc Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 25 Jan 2008 15:02:26 +0800 Subject: BUG#33862 completely failed DROP USER statement gets replicated The problem is when create/rename/drop users, the statement was logged regardless of error, even if no data has been changed, the statement was logged. After this patch, create/rename/drop users don't write the binlog if the statement makes no changes, if the statement does make any changes, log the statement with possible error code. This patch is based on the patch for BUG#29749, which is not pushed sql/sql_acl.cc: when create/rename/drop users, don't write the binlog if the statement make no changes mysql-test/r/rpl_user.result: New BitKeeper file ``mysql-test/r/rpl_user.result'' mysql-test/t/rpl_user.test: New BitKeeper file ``mysql-test/t/rpl_user.test'' --- sql/sql_acl.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'sql') diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 1850821a287..a5140d6f7d0 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -5333,6 +5333,7 @@ bool mysql_create_user(THD *thd, List &list) LEX_USER *user_name, *tmp_user_name; List_iterator user_list(list); TABLE_LIST tables[GRANT_TABLES]; + bool some_users_created= FALSE; DBUG_ENTER("mysql_create_user"); /* CREATE USER may be skipped on replication client. */ @@ -5361,6 +5362,7 @@ bool mysql_create_user(THD *thd, List &list) continue; } + some_users_created= TRUE; sql_mode= thd->variables.sql_mode; if (replace_user_table(thd, tables[0].table, *user_name, 0, 0, 1, 0)) { @@ -5371,7 +5373,10 @@ bool mysql_create_user(THD *thd, List &list) VOID(pthread_mutex_unlock(&acl_cache->lock)); - if (mysql_bin_log.is_open()) + if (result) + my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe()); + + if (some_users_created && mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE); mysql_bin_log.write(&qinfo); @@ -5379,8 +5384,6 @@ bool mysql_create_user(THD *thd, List &list) rw_unlock(&LOCK_grant); close_thread_tables(thd); - if (result) - my_error(ER_CANNOT_USER, MYF(0), "CREATE USER", wrong_users.c_ptr_safe()); DBUG_RETURN(result); } @@ -5405,6 +5408,7 @@ bool mysql_drop_user(THD *thd, List &list) LEX_USER *user_name, *tmp_user_name; List_iterator user_list(list); TABLE_LIST tables[GRANT_TABLES]; + bool some_users_deleted= FALSE; DBUG_ENTER("mysql_drop_user"); /* DROP USER may be skipped on replication client. */ @@ -5426,7 +5430,9 @@ bool mysql_drop_user(THD *thd, List &list) { append_user(&wrong_users, user_name); result= TRUE; + continue; } + some_users_deleted= TRUE; } /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */ @@ -5440,7 +5446,7 @@ bool mysql_drop_user(THD *thd, List &list) DBUG_PRINT("info", ("thd->net.last_errno: %d", thd->net.last_errno)); DBUG_PRINT("info", ("thd->net.last_error: %s", thd->net.last_error)); - if (mysql_bin_log.is_open()) + if (some_users_deleted && mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE); mysql_bin_log.write(&qinfo); @@ -5473,6 +5479,7 @@ bool mysql_rename_user(THD *thd, List &list) LEX_USER *user_to, *tmp_user_to; List_iterator user_list(list); TABLE_LIST tables[GRANT_TABLES]; + bool some_users_renamed= FALSE; DBUG_ENTER("mysql_rename_user"); /* RENAME USER may be skipped on replication client. */ @@ -5506,7 +5513,9 @@ bool mysql_rename_user(THD *thd, List &list) { append_user(&wrong_users, user_from); result= TRUE; + continue; } + some_users_renamed= TRUE; } /* Rebuild 'acl_check_hosts' since 'acl_users' has been modified */ @@ -5514,7 +5523,10 @@ bool mysql_rename_user(THD *thd, List &list) VOID(pthread_mutex_unlock(&acl_cache->lock)); - if (mysql_bin_log.is_open()) + if (result) + my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe()); + + if (some_users_renamed && mysql_bin_log.is_open()) { Query_log_event qinfo(thd, thd->query, thd->query_length, 0, FALSE); mysql_bin_log.write(&qinfo); @@ -5522,8 +5534,6 @@ bool mysql_rename_user(THD *thd, List &list) rw_unlock(&LOCK_grant); close_thread_tables(thd); - if (result) - my_error(ER_CANNOT_USER, MYF(0), "RENAME USER", wrong_users.c_ptr_safe()); DBUG_RETURN(result); } -- cgit v1.2.1 From 5a039fa28bd9660c2f939452c4f0af732cbecfc3 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 29 Jan 2008 11:56:48 +0800 Subject: BUG#26489 Corruption in relay logs Here is the scenario that causes the failure.(by Mats) 1. The to-be corrupt log event (let's call it X), is split into two packets B and C on the network level (net_write_buff()). The parts are X = (x',x''). The part x' ends up in packet B and part x'' ends up in packet C. Prior to the corrupt event X, the event Y has been written successfully, but has been split into two packets as well, which we call (y',y''). 2. The master sends packet A = (y'',x') to the slave, increases the packet sequence number, the slave receives the packet, but fails to reply before the master gets a timeout. 3. Since the master got a timeout, it reports failure, and aborts sending the binary log by exiting mysql_binlog_send(). However, it leaves the buffer intact, still holding y'' (but not x', since the write_pos is not increased). 4. After exiting mysql_binlog_send(), the master does a disconnection of the client thread, which involves sending an error message e to the client (i.e., the slave). 5. In this case, net_write_buff() is used again, but this time the old contents of the packet is used so that the new packet is D = (y'',e). Note that this will use a new packet sequence number, since the packet number was increased in step 2. 6. The slave receives the tail y'' of the Y log event, concatenates this with x' (which it already received), and writes the event (x',y'') it to the relay log since it hasn't noticed anything is amiss. 7. It then tries to read more bytes, which is either e (if the length given for X just happened to match the length given for Y, or just plain garbage because the slave is out of sync with what is actually sent. 8. After a while, the SQL thread tries to execute the event (x',y''), which is very likely to be just nonsense. The problem can be fixed by not resetting net->error after the call of mysql_binlog_send, so the error message will not be sent and the connection will be closed. sql/sql_parse.cc: Do not reset net->error, if net->error == 2, we should not try to use the connection again --- sql/sql_parse.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'sql') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 16a64c48cdd..a3547787e86 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1999,7 +1999,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd, unregister_slave(thd,1,1); /* fake COM_QUIT -- if we get here, the thread needs to terminate */ error = TRUE; - net->error = 0; break; } #endif -- cgit v1.2.1