diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-01 18:15:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-01 18:15:00 +0000 |
commit | a2a2e32c02643a0cec111511220227703fda1cd5 (patch) | |
tree | 69cc2b631234c2a8e026b9cd4d72676c61c594df /sql/slave.cc | |
parent | Releasing progress-linux version 1:10.11.8-1~progress7.99u1. (diff) | |
download | mariadb-a2a2e32c02643a0cec111511220227703fda1cd5.tar.xz mariadb-a2a2e32c02643a0cec111511220227703fda1cd5.zip |
Merging upstream version 1:11.4.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sql/slave.cc')
-rw-r--r-- | sql/slave.cc | 598 |
1 files changed, 92 insertions, 506 deletions
diff --git a/sql/slave.cc b/sql/slave.cc index 9ac467cc..48be8cd0 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -36,7 +36,6 @@ #include "rpl_filter.h" #include "repl_failsafe.h" #include "transaction.h" -#include <thr_alarm.h> #include <my_dir.h> #include <sql_common.h> #include <errmsg.h> @@ -159,7 +158,6 @@ failed read" typedef enum { SLAVE_THD_IO, SLAVE_THD_SQL} SLAVE_THD_TYPE; static int process_io_rotate(Master_info* mi, Rotate_log_event* rev); -static int process_io_create_file(Master_info* mi, Create_file_log_event* cev); static bool wait_for_relay_log_space(Relay_log_info* rli); static bool io_slave_killed(Master_info* mi); static bool sql_slave_killed(rpl_group_info *rgi); @@ -1076,24 +1074,11 @@ terminate_slave_thread(THD *thd, mysql_mutex_lock(&thd->LOCK_thd_kill); mysql_mutex_lock(&thd->LOCK_thd_data); -#ifndef DONT_USE_THR_ALARM - /* - Error codes from pthread_kill are: - EINVAL: invalid signal number (can't happen) - ESRCH: thread already killed (can happen, should be ignored) - */ - int err __attribute__((unused))= pthread_kill(thd->real_id, thr_client_alarm); - DBUG_ASSERT(err != EINVAL); -#endif thd->awake_no_mutex(NOT_KILLED); mysql_mutex_unlock(&thd->LOCK_thd_kill); mysql_mutex_unlock(&thd->LOCK_thd_data); - /* - There is a small chance that slave thread might miss the first - alarm. To protect againts it, resend the signal until it reacts - */ struct timespec abstime; set_timespec(abstime,2); error= mysql_cond_timedwait(term_cond, term_lock, &abstime); @@ -1490,20 +1475,6 @@ bool net_request_file(NET* net, const char* fname) (uchar*) "", 0)); } -/* - From other comments and tests in code, it looks like - sometimes Query_log_event and Load_log_event can have db == 0 - (see rewrite_db() above for example) - (cases where this happens are unclear; it may be when the master is 3.23). -*/ - -const char *print_slave_db_safe(const char* db) -{ - DBUG_ENTER("*print_slave_db_safe"); - - DBUG_RETURN((db ? db : "")); -} - #endif /* HAVE_REPLICATION */ bool Sql_cmd_show_slave_status::execute(THD *thd) @@ -1788,6 +1759,8 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) case 0: case 1: case 2: + case 3: + case 4: errmsg= err_buff2; snprintf(err_buff2, sizeof(err_buff2), "Master reported unrecognized MariaDB version: %s", @@ -1795,14 +1768,6 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) err_code= ER_SLAVE_FATAL_ERROR; sprintf(err_buff, ER_DEFAULT(err_code), err_buff2); break; - case 3: - mi->rli.relay_log.description_event_for_queue= new - Format_description_log_event(1, mysql->server_version); - break; - case 4: - mi->rli.relay_log.description_event_for_queue= new - Format_description_log_event(3, mysql->server_version); - break; default: /* Master is MySQL >=5.0. Give a default Format_desc event, so that we can @@ -1813,7 +1778,8 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) master is 3.23, 4.0, etc. */ mi->rli.relay_log.description_event_for_queue= new - Format_description_log_event(4, mysql->server_version); + Format_description_log_event(4, mysql->server_version, + mi->rli.relay_log.relay_log_checksum_alg); break; } } @@ -1872,10 +1838,8 @@ static int get_master_version_and_clock(MYSQL* mysql, Master_info* mi) until it has received a new FD_m. */ - mi->rli.relay_log.description_event_for_queue->checksum_alg= - mi->rli.relay_log.relay_log_checksum_alg; - DBUG_ASSERT(mi->rli.relay_log.description_event_for_queue->checksum_alg != + DBUG_ASSERT(mi->rli.relay_log.description_event_for_queue->used_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF); DBUG_ASSERT(mi->rli.relay_log.relay_log_checksum_alg != BINLOG_CHECKSUM_ALG_UNDEF); @@ -2548,6 +2512,42 @@ after_set_capability: goto err; } } + + query_str.length(0); + if (query_str.append( + STRING_WITH_LEN("SET @slave_gtid_until_before_gtids="), + system_charset_info) || + query_str.append_ulonglong(mi->rli.is_until_before_gtids)) + { + err_code= ER_OUTOFMEMORY; + errmsg= + "The slave I/O thread stops because a fatal out-of-memory error " + "is encountered when it tries to set " + "@slave_gtid_until_before_gtids."; + sprintf(err_buff, "%s Error: Out of memory", errmsg); + goto err; + } + + rc= mysql_real_query(mysql, query_str.ptr(), query_str.length()); + if (unlikely(rc)) + { + err_code= mysql_errno(mysql); + if (is_network_error(err_code)) + { + mi->report(ERROR_LEVEL, err_code, NULL, + "Setting @slave_gtid_until_before_gtids failed with " + "error: %s", mysql_error(mysql)); + goto network_err; + } + else + { + /* Fatal error */ + errmsg= "The slave I/O thread stops because a fatal error is " + "encountered when it tries to set @slave_gtid_until_before_gtids."; + sprintf(err_buff, "%s Error: %s", errmsg, mysql_error(mysql)); + goto err; + } + } } } else @@ -2764,7 +2764,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) { DBUG_PRINT("info",("writing a Rotate event to track down ignored events")); rev->server_id= 0; // don't be ignored by slave SQL thread - if (unlikely(rli->relay_log.append(rev))) + if (unlikely(rli->relay_log.append(rev, rli->relay_log.relay_log_checksum_alg))) mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "failed to write a Rotate event" @@ -2777,7 +2777,7 @@ static void write_ignored_events_info_to_relay_log(THD *thd, Master_info *mi) DBUG_PRINT("info",("writing a Gtid_list event to track down ignored events")); glev->server_id= 0; // don't be ignored by slave SQL thread glev->set_artificial_event(); // Don't mess up Exec_Master_Log_Pos - if (unlikely(rli->relay_log.append(glev))) + if (unlikely(rli->relay_log.append(glev, rli->relay_log.relay_log_checksum_alg))) mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), "failed to write a Gtid_list event to the relay log, " @@ -4949,34 +4949,31 @@ connected: goto connected; } - if (mi->rli.relay_log.description_event_for_queue->binlog_version > 1) + /* + Register ourselves with the master. + */ + THD_STAGE_INFO(thd, stage_registering_slave_on_master); + if (register_slave_on_master(mysql, mi, &suppress_warnings)) { - /* - Register ourselves with the master. - */ - THD_STAGE_INFO(thd, stage_registering_slave_on_master); - if (register_slave_on_master(mysql, mi, &suppress_warnings)) + if (!check_io_slave_killed(mi, "Slave I/O thread killed " + "while registering slave on master")) { - if (!check_io_slave_killed(mi, "Slave I/O thread killed " - "while registering slave on master")) - { - sql_print_error("Slave I/O thread couldn't register on master"); - if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings, - reconnect_messages[SLAVE_RECON_ACT_REG])) - goto err; - } - else + sql_print_error("Slave I/O thread couldn't register on master"); + if (try_to_reconnect(thd, mysql, mi, &retry_count, suppress_warnings, + reconnect_messages[SLAVE_RECON_ACT_REG])) goto err; - goto connected; } - DBUG_EXECUTE_IF("fail_com_register_slave", - { - mi->report(ERROR_LEVEL, ER_SLAVE_MASTER_COM_FAILURE, NULL, - ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_REGISTER_SLAVE", - "Debug Induced Error"); - goto err; - }); + else + goto err; + goto connected; } + DBUG_EXECUTE_IF("fail_com_register_slave", + { + mi->report(ERROR_LEVEL, ER_SLAVE_MASTER_COM_FAILURE, NULL, + ER(ER_SLAVE_MASTER_COM_FAILURE), "COM_REGISTER_SLAVE", + "Debug Induced Error"); + goto err; + }); DBUG_PRINT("info",("Starting reading binary log from master")); thd->set_command(COM_SLAVE_IO); @@ -5998,115 +5995,6 @@ err_during_init: /* - process_io_create_file() -*/ - -static int process_io_create_file(Master_info* mi, Create_file_log_event* cev) -{ - int error = 1; - ulong num_bytes; - bool cev_not_written; - THD *thd = mi->io_thd; - NET *net = &mi->mysql->net; - DBUG_ENTER("process_io_create_file"); - - if (unlikely(!cev->is_valid())) - DBUG_RETURN(1); - - if (!mi->rpl_filter->db_ok(cev->db)) - { - skip_load_data_infile(net); - DBUG_RETURN(0); - } - DBUG_ASSERT(cev->inited_from_old); - thd->file_id = cev->file_id = mi->file_id++; - thd->variables.server_id = cev->server_id; - cev_not_written = 1; - - if (unlikely(net_request_file(net,cev->fname))) - { - sql_print_error("Slave I/O: failed requesting download of '%s'", - cev->fname); - goto err; - } - - /* - This dummy block is so we could instantiate Append_block_log_event - once and then modify it slightly instead of doing it multiple times - in the loop - */ - { - Append_block_log_event aev(thd,0,0,0,0); - - for (;;) - { - if (unlikely((num_bytes=my_net_read(net)) == packet_error)) - { - sql_print_error("Network read error downloading '%s' from master", - cev->fname); - goto err; - } - if (unlikely(!num_bytes)) /* eof */ - { - /* 3.23 master wants it */ - net_write_command(net, 0, (uchar*) "", 0, (uchar*) "", 0); - /* - If we wrote Create_file_log_event, then we need to write - Execute_load_log_event. If we did not write Create_file_log_event, - then this is an empty file and we can just do as if the LOAD DATA - INFILE had not existed, i.e. write nothing. - */ - if (unlikely(cev_not_written)) - break; - Execute_load_log_event xev(thd,0,0); - xev.log_pos = cev->log_pos; - if (unlikely(mi->rli.relay_log.append(&xev))) - { - mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), - "error writing Exec_load event to relay log"); - goto err; - } - mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total); - break; - } - if (unlikely(cev_not_written)) - { - cev->block = net->read_pos; - cev->block_len = num_bytes; - if (unlikely(mi->rli.relay_log.append(cev))) - { - mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), - "error writing Create_file event to relay log"); - goto err; - } - cev_not_written=0; - mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total); - } - else - { - aev.block = net->read_pos; - aev.block_len = num_bytes; - aev.log_pos = cev->log_pos; - if (unlikely(mi->rli.relay_log.append(&aev))) - { - mi->report(ERROR_LEVEL, ER_SLAVE_RELAY_LOG_WRITE_FAILURE, NULL, - ER_THD(thd, ER_SLAVE_RELAY_LOG_WRITE_FAILURE), - "error writing Append_block event to relay log"); - goto err; - } - mi->rli.relay_log.harvest_bytes_written(&mi->rli.log_space_total) ; - } - } - } - error=0; -err: - DBUG_RETURN(error); -} - - -/* Start using a new binary log on the master SYNOPSIS @@ -6150,25 +6038,10 @@ static int process_io_rotate(Master_info *mi, Rotate_log_event *rev) mi->events_till_disconnect++; #endif - /* - If description_event_for_queue is format <4, there is conversion in the - relay log to the slave's format (4). And Rotate can mean upgrade or - nothing. If upgrade, it's to 5.0 or newer, so we will get a Format_desc, so - no need to reset description_event_for_queue now. And if it's nothing (same - master version as before), no need (still using the slave's format). - */ + /* this prevents a redundant FDLE in the relay log */ if (mi->rli.relay_log.description_event_for_queue->binlog_version >= 4) - { - DBUG_ASSERT(mi->rli.relay_log.description_event_for_queue->checksum_alg == - mi->rli.relay_log.relay_log_checksum_alg); - - delete mi->rli.relay_log.description_event_for_queue; - /* start from format 3 (MySQL 4.0) again */ - mi->rli.relay_log.description_event_for_queue= new - Format_description_log_event(3); - mi->rli.relay_log.description_event_for_queue->checksum_alg= - mi->rli.relay_log.relay_log_checksum_alg; - } + mi->rli.relay_log.description_event_for_queue->binlog_version= 3; + /* Rotate the relay log makes binlog format detection easier (at next slave start or mysqlbinlog) @@ -6177,216 +6050,9 @@ static int process_io_rotate(Master_info *mi, Rotate_log_event *rev) } /* - Reads a 3.23 event and converts it to the slave's format. This code was - copied from MySQL 4.0. -*/ -static int queue_binlog_ver_1_event(Master_info *mi, const uchar *buf, - ulong event_len) -{ - const char *errmsg = 0; - ulong inc_pos; - bool ignore_event= 0; - uchar *tmp_buf = 0; - Relay_log_info *rli= &mi->rli; - DBUG_ENTER("queue_binlog_ver_1_event"); - - /* - If we get Load event, we need to pass a non-reusable buffer - to read_log_event, so we do a trick - */ - if ((uchar)buf[EVENT_TYPE_OFFSET] == LOAD_EVENT) - { - if (unlikely(!(tmp_buf= (uchar*) my_malloc(key_memory_binlog_ver_1_event, - event_len+1, MYF(MY_WME))))) - { - mi->report(ERROR_LEVEL, ER_SLAVE_FATAL_ERROR, NULL, - ER(ER_SLAVE_FATAL_ERROR), "Memory allocation failed"); - DBUG_RETURN(1); - } - memcpy(tmp_buf,buf,event_len); - /* - Create_file constructor wants a 0 as last char of buffer, this 0 will - serve as the string-termination char for the file's name (which is at the - end of the buffer) - We must increment event_len, otherwise the event constructor will not see - this end 0, which leads to segfault. - */ - tmp_buf[event_len++]=0; - int4store(tmp_buf+EVENT_LEN_OFFSET, event_len); - buf= tmp_buf; - } - /* - This will transform LOAD_EVENT into CREATE_FILE_EVENT, ask the master to - send the loaded file, and write it to the relay log in the form of - Append_block/Exec_load (the SQL thread needs the data, as that thread is not - connected to the master). - */ - Log_event *ev= - Log_event::read_log_event(buf, event_len, &errmsg, - mi->rli.relay_log.description_event_for_queue, 0); - if (unlikely(!ev)) - { - sql_print_error("Read invalid event from master: '%s',\ - master could be corrupt but a more likely cause of this is a bug", - errmsg); - my_free(tmp_buf); - DBUG_RETURN(1); - } - - mysql_mutex_lock(&mi->data_lock); - ev->log_pos= mi->master_log_pos; /* 3.23 events don't contain log_pos */ - switch (ev->get_type_code()) { - case STOP_EVENT: - ignore_event= 1; - inc_pos= event_len; - break; - case ROTATE_EVENT: - if (unlikely(process_io_rotate(mi,(Rotate_log_event*)ev))) - { - delete ev; - mysql_mutex_unlock(&mi->data_lock); - DBUG_RETURN(1); - } - inc_pos= 0; - break; - case CREATE_FILE_EVENT: - /* - Yes it's possible to have CREATE_FILE_EVENT here, even if we're in - queue_old_event() which is for 3.23 events which don't comprise - CREATE_FILE_EVENT. This is because read_log_event() above has just - transformed LOAD_EVENT into CREATE_FILE_EVENT. - */ - { - /* We come here when and only when tmp_buf != 0 */ - DBUG_ASSERT(tmp_buf != 0); - inc_pos=event_len; - ev->log_pos+= inc_pos; - int error = process_io_create_file(mi,(Create_file_log_event*)ev); - delete ev; - mi->master_log_pos += inc_pos; - DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - mysql_mutex_unlock(&mi->data_lock); - my_free(tmp_buf); - DBUG_RETURN(error); - } - default: - inc_pos= event_len; - break; - } - if (likely(!ignore_event)) - { - if (ev->log_pos) - /* - Don't do it for fake Rotate events (see comment in - Log_event::Log_event(const char* buf...) in log_event.cc). - */ - ev->log_pos+= event_len; /* make log_pos be the pos of the end of the event */ - if (unlikely(rli->relay_log.append(ev))) - { - delete ev; - mysql_mutex_unlock(&mi->data_lock); - DBUG_RETURN(1); - } - rli->relay_log.harvest_bytes_written(&rli->log_space_total); - } - delete ev; - mi->master_log_pos+= inc_pos; - DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - mysql_mutex_unlock(&mi->data_lock); - DBUG_RETURN(0); -} - -/* - Reads a 4.0 event and converts it to the slave's format. This code was copied - from queue_binlog_ver_1_event(), with some affordable simplifications. -*/ -static int queue_binlog_ver_3_event(Master_info *mi, const uchar *buf, - ulong event_len) -{ - const char *errmsg = 0; - ulong inc_pos; - char *tmp_buf = 0; - Relay_log_info *rli= &mi->rli; - DBUG_ENTER("queue_binlog_ver_3_event"); - - /* read_log_event() will adjust log_pos to be end_log_pos */ - Log_event *ev= - Log_event::read_log_event(buf, event_len, &errmsg, - mi->rli.relay_log.description_event_for_queue, 0); - if (unlikely(!ev)) - { - sql_print_error("Read invalid event from master: '%s',\ - master could be corrupt but a more likely cause of this is a bug", - errmsg); - my_free(tmp_buf); - DBUG_RETURN(1); - } - mysql_mutex_lock(&mi->data_lock); - switch (ev->get_type_code()) { - case STOP_EVENT: - goto err; - case ROTATE_EVENT: - if (unlikely(process_io_rotate(mi,(Rotate_log_event*)ev))) - { - delete ev; - mysql_mutex_unlock(&mi->data_lock); - DBUG_RETURN(1); - } - inc_pos= 0; - break; - default: - inc_pos= event_len; - break; - } - - if (unlikely(rli->relay_log.append(ev))) - { - delete ev; - mysql_mutex_unlock(&mi->data_lock); - DBUG_RETURN(1); - } - rli->relay_log.harvest_bytes_written(&rli->log_space_total); - delete ev; - mi->master_log_pos+= inc_pos; -err: - DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) mi->master_log_pos)); - mysql_mutex_unlock(&mi->data_lock); - DBUG_RETURN(0); -} - -/* - queue_old_event() - - Writes a 3.23 or 4.0 event to the relay log, after converting it to the 5.0 - (exactly, slave's) format. To do the conversion, we create a 5.0 event from - the 3.23/4.0 bytes, then write this event to the relay log. - - TODO: - Test this code before release - it has to be tested on a separate - setup with 3.23 master or 4.0 master -*/ - -static int queue_old_event(Master_info *mi, const uchar *buf, ulong event_len) -{ - DBUG_ENTER("queue_old_event"); - - switch (mi->rli.relay_log.description_event_for_queue->binlog_version) { - case 1: - DBUG_RETURN(queue_binlog_ver_1_event(mi,buf,event_len)); - case 3: - DBUG_RETURN(queue_binlog_ver_3_event(mi,buf,event_len)); - default: /* unsupported format; eg version 2 */ - DBUG_PRINT("info",("unsupported binlog format %d in queue_old_event()", - mi->rli.relay_log.description_event_for_queue->binlog_version)); - DBUG_RETURN(1); - } -} - -/* queue_event() - If the event is 3.23/4.0, passes it to queue_old_event() which will convert - it. Otherwise, writes a 5.0 (or newer) event to the relay log. Then there is + Writes a 5.0 (or newer) event to the relay log. Then there is no format conversion, it's pure read/write of bytes. So a 5.0.0 slave's relay log can contain events in the slave's format or in any >=5.0.0 format. @@ -6417,7 +6083,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) Show-up of FD:s affects checksum_alg at once because that changes FD_queue. */ - enum enum_binlog_checksum_alg checksum_alg= + enum_binlog_checksum_alg checksum_alg= mi->checksum_alg_before_fd != BINLOG_CHECKSUM_ALG_UNDEF ? mi->checksum_alg_before_fd : mi->rli.relay_log.relay_log_checksum_alg; @@ -6441,7 +6107,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) { // checksum behaviour is similar to the pre-checksum FD handling mi->checksum_alg_before_fd= BINLOG_CHECKSUM_ALG_UNDEF; - mi->rli.relay_log.description_event_for_queue->checksum_alg= + mi->rli.relay_log.description_event_for_queue->used_checksum_alg= mi->rli.relay_log.relay_log_checksum_alg= checksum_alg= BINLOG_CHECKSUM_ALG_OFF; } @@ -6474,10 +6140,6 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) } DBUG_ASSERT(((uchar) buf[FLAGS_OFFSET] & LOG_EVENT_ACCEPT_OWN_F) == 0); - if (mi->rli.relay_log.description_event_for_queue->binlog_version<4 && - buf[EVENT_TYPE_OFFSET] != FORMAT_DESCRIPTION_EVENT /* a way to escape */) - DBUG_RETURN(queue_old_event(mi,buf,event_len)); - #ifdef ENABLED_DEBUG_SYNC /* A (+d,dbug.rows_events_to_delay_relay_logging)-test is supposed to @@ -6570,8 +6232,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) We detect this case by noticing a change of server_id and in this case likewise rollback the partially received event group. */ - Format_description_log_event fdle(4); - fdle.checksum_alg= checksum_alg; + Format_description_log_event fdle(4, NULL, checksum_alg); /* Possible crash is flagged in being created FD' common header @@ -6603,7 +6264,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) rev.new_log_ident); } mysql_mutex_lock(log_lock); - if (likely(!rli->relay_log.write_event(&fdle) && + if (likely(!rli->relay_log.write_event(&fdle, checksum_alg) && !rli->relay_log.flush_and_sync(NULL))) { rli->relay_log.harvest_bytes_written(&rli->log_space_total); @@ -6652,7 +6313,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) event_len - BINLOG_CHECKSUM_LEN); int4store(&rot_buf[event_len - BINLOG_CHECKSUM_LEN], rot_crc); DBUG_ASSERT(event_len == uint4korr(&rot_buf[EVENT_LEN_OFFSET])); - DBUG_ASSERT(mi->rli.relay_log.description_event_for_queue->checksum_alg == + DBUG_ASSERT(mi->rli.relay_log.description_event_for_queue->used_checksum_alg == mi->rli.relay_log.relay_log_checksum_alg); /* the first one */ DBUG_ASSERT(mi->checksum_alg_before_fd != BINLOG_CHECKSUM_ALG_UNDEF); @@ -6672,7 +6333,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) int4store(&rot_buf[EVENT_LEN_OFFSET], uint4korr(&rot_buf[EVENT_LEN_OFFSET]) - BINLOG_CHECKSUM_LEN); DBUG_ASSERT(event_len == uint4korr(&rot_buf[EVENT_LEN_OFFSET])); - DBUG_ASSERT(mi->rli.relay_log.description_event_for_queue->checksum_alg == + DBUG_ASSERT(mi->rli.relay_log.description_event_for_queue->used_checksum_alg == mi->rli.relay_log.relay_log_checksum_alg); /* the first one */ DBUG_ASSERT(mi->checksum_alg_before_fd != BINLOG_CHECKSUM_ALG_UNDEF); @@ -6712,11 +6373,11 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) tmp->copy_crypto_data(mi->rli.relay_log.description_event_for_queue); delete mi->rli.relay_log.description_event_for_queue; mi->rli.relay_log.description_event_for_queue= tmp; - if (tmp->checksum_alg == BINLOG_CHECKSUM_ALG_UNDEF) - tmp->checksum_alg= BINLOG_CHECKSUM_ALG_OFF; + if (tmp->used_checksum_alg == BINLOG_CHECKSUM_ALG_UNDEF) + tmp->used_checksum_alg= BINLOG_CHECKSUM_ALG_OFF; /* installing new value of checksum Alg for relay log */ - mi->rli.relay_log.relay_log_checksum_alg= tmp->checksum_alg; + mi->rli.relay_log.relay_log_checksum_alg= tmp->used_checksum_alg; /* Do not queue any format description event that we receive after a @@ -6741,7 +6402,7 @@ static int queue_event(Master_info* mi, const uchar *buf, ulong event_len) */ inc_pos= uint4korr(buf+LOG_POS_OFFSET) ? event_len : 0; DBUG_PRINT("info",("binlog format is now %d", - mi->rli.relay_log.description_event_for_queue->binlog_version)); + mi->rli.relay_log.description_event_for_queue->binlog_version)); } break; @@ -7281,7 +6942,8 @@ dbug_gtid_accept: rli->relay_log.description_event_for_queue->created= 0; rli->relay_log.description_event_for_queue->set_artificial_event(); if (rli->relay_log.append_no_lock - (rli->relay_log.description_event_for_queue)) + (rli->relay_log.description_event_for_queue, + rli->relay_log.relay_log_checksum_alg)) error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE; else rli->relay_log.harvest_bytes_written(&rli->log_space_total); @@ -7294,7 +6956,8 @@ dbug_gtid_accept: */ Rotate_log_event fake_rev(mi->master_log_name, 0, mi->master_log_pos, 0); fake_rev.server_id= mi->master_id; - if (rli->relay_log.append_no_lock(&fake_rev)) + if (rli->relay_log.append_no_lock(&fake_rev, + rli->relay_log.relay_log_checksum_alg)) error= ER_SLAVE_RELAY_LOG_WRITE_FAILURE; else rli->relay_log.harvest_bytes_written(&rli->log_space_total); @@ -7567,28 +7230,23 @@ static int connect_to_master(THD* thd, MYSQL* mysql, Master_info* mi, if (opt_slave_compressed_protocol) client_flag|= CLIENT_COMPRESS; /* We will use compression */ - mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout); - mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout); - mysql_options(mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, - (char*) &my_true); + mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &slave_net_timeout); + mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, &slave_net_timeout); + mysql_options(mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, &my_true); #ifdef HAVE_OPENSSL if (mi->ssl) { - mysql_ssl_set(mysql, - mi->ssl_key[0]?mi->ssl_key:0, - mi->ssl_cert[0]?mi->ssl_cert:0, - mi->ssl_ca[0]?mi->ssl_ca:0, - mi->ssl_capath[0]?mi->ssl_capath:0, - mi->ssl_cipher[0]?mi->ssl_cipher:0); - mysql_options(mysql, MYSQL_OPT_SSL_CRL, - mi->ssl_crl[0] ? mi->ssl_crl : 0); - mysql_options(mysql, MYSQL_OPT_SSL_CRLPATH, - mi->ssl_crlpath[0] ? mi->ssl_crlpath : 0); + mysql_ssl_set(mysql, mi->ssl_key, mi->ssl_cert, mi->ssl_ca, mi->ssl_capath, + mi->ssl_cipher); + mysql_options(mysql, MYSQL_OPT_SSL_CRL, mi->ssl_crl); + mysql_options(mysql, MYSQL_OPT_SSL_CRLPATH, mi->ssl_crlpath); mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &mi->ssl_verify_server_cert); } + else #endif + mysql->options.use_ssl= 0; /* If server's default charset is not supported (like utf16, utf32) as client @@ -7698,78 +7356,6 @@ static int safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi, } -#ifdef NOT_USED -MYSQL *rpl_connect_master(MYSQL *mysql) -{ - Master_info *mi= my_pthread_getspecific_ptr(Master_info*, RPL_MASTER_INFO); - bool allocated= false; - my_bool my_true= 1; - THD *thd; - - if (!mi) - { - sql_print_error("'rpl_connect_master' must be called in slave I/O thread context."); - return NULL; - } - thd= mi->io_thd; - if (!mysql) - { - if(!(mysql= mysql_init(NULL))) - { - sql_print_error("rpl_connect_master: failed in mysql_init()"); - return NULL; - } - allocated= true; - } - - /* - XXX: copied from connect_to_master, this function should not - change the slave status, so we cannot use connect_to_master - directly - - TODO: make this part a seperate function to eliminate duplication - */ - mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char *) &slave_net_timeout); - mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (char *) &slave_net_timeout); - mysql_options(mysql, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY, - (char*) &my_true); - -#ifdef HAVE_OPENSSL - if (mi->ssl) - { - mysql_ssl_set(mysql, - mi->ssl_key[0]?mi->ssl_key:0, - mi->ssl_cert[0]?mi->ssl_cert:0, - mi->ssl_ca[0]?mi->ssl_ca:0, - mi->ssl_capath[0]?mi->ssl_capath:0, - mi->ssl_cipher[0]?mi->ssl_cipher:0); - mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, - &mi->ssl_verify_server_cert); - } -#endif - - mysql_options(mysql, MYSQL_SET_CHARSET_NAME, - default_charset_info->cs_name.str); - - if (mi->user == NULL - || mi->user[0] == 0 - || io_slave_killed( mi) - || !mysql_real_connect(mysql, mi->host, mi->user, mi->password, 0, - mi->port, 0, 0)) - { - if (!io_slave_killed( mi)) - sql_print_error("rpl_connect_master: error connecting to master: %s (server_error: %d)", - mysql_error(mysql), mysql_errno(mysql)); - - if (allocated) - mysql_close(mysql); // this will free the object - return NULL; - } - return mysql; -} -#endif - - /* Called when we notice that the current "hot" log got rotated under our feet. */ @@ -7781,8 +7367,8 @@ static IO_CACHE *reopen_relay_log(Relay_log_info *rli, const char **errmsg) DBUG_ASSERT(rli->cur_log_fd == -1); IO_CACHE *cur_log = rli->cur_log=&rli->cache_buf; - if ((rli->cur_log_fd=open_binlog(cur_log,rli->event_relay_log_name, - errmsg)) <0) + rli->cur_log_fd= open_binlog(cur_log,rli->event_relay_log_name, errmsg); + if (rli->cur_log_fd <0) DBUG_RETURN(0); /* We want to start exactly where we was before: |