From c6d91e00bbd103e46d806b1b9aad1963f4cfe18c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 10 Mar 2004 16:56:28 +0100 Subject: [PATCH] Backporting parts of ChangeSet 1.1620.12.1 and ChangeSet 1.1625.2.1 from 4.1. This makes the slave I/O thread flush the relay log after every event, which provides additional safety in case of brutal crash (reduces chances to lose a part of the relay log). sql/repl_failsafe.cc: update for new prototype sql/slave.cc: The slave I/O thread now flushes the relay log after writing every event to it, like we already do in 4.1. sql/slave.h: new prototype sql/sql_repl.cc: update for new prototype --- sql/repl_failsafe.cc | 2 +- sql/slave.cc | 8 +++++--- sql/slave.h | 2 +- sql/sql_repl.cc | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 6599516044a..56789a01bf4 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -894,7 +894,7 @@ int load_master_data(THD* thd) if (active_mi->master_log_pos < BIN_LOG_HEADER_SIZE) active_mi->master_log_pos = BIN_LOG_HEADER_SIZE; active_mi->rli.pending = 0; - flush_master_info(active_mi); + flush_master_info(active_mi, 0); } mc_mysql_free_result(master_status_res); } diff --git a/sql/slave.cc b/sql/slave.cc index b497880aaa3..84f4ff4f3e0 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1657,7 +1657,7 @@ file '%s')", fname); mi->inited = 1; // now change cache READ -> WRITE - must do this before flush_master_info reinit_io_cache(&mi->file, WRITE_CACHE,0L,0,1); - if ((error=test(flush_master_info(mi)))) + if ((error= test(flush_master_info(mi, 1)))) sql_print_error("Failed to flush master info file"); pthread_mutex_unlock(&mi->data_lock); DBUG_RETURN(error); @@ -1784,13 +1784,15 @@ int show_master_info(THD* thd, MASTER_INFO* mi) } -bool flush_master_info(MASTER_INFO* mi) +bool flush_master_info(MASTER_INFO* mi, bool flush_relay_log_cache) { IO_CACHE* file = &mi->file; char lbuf[22]; DBUG_ENTER("flush_master_info"); DBUG_PRINT("enter",("master_pos: %ld", (long) mi->master_log_pos)); + if (flush_relay_log_cache) /* Comments for this are in MySQL 4.1 */ + flush_io_cache(mi->rli.relay_log.get_log_file()); my_b_seek(file, 0L); my_b_printf(file, "%s\n%s\n%s\n%s\n%s\n%d\n%d\n", mi->master_log_name, llstr(mi->master_log_pos, lbuf), @@ -2542,7 +2544,7 @@ reconnect done to recover from failed read"); sql_print_error("Slave I/O thread could not queue event from master"); goto err; } - flush_master_info(mi); + flush_master_info(mi, 1); /* See if the relay logs take too much space. We don't lock mi->rli.log_space_lock here; this dirty read saves time diff --git a/sql/slave.h b/sql/slave.h index 8331e722a51..9877582d094 100644 --- a/sql/slave.h +++ b/sql/slave.h @@ -361,7 +361,7 @@ typedef struct st_table_rule_ent int init_slave(); void init_slave_skip_errors(const char* arg); -bool flush_master_info(MASTER_INFO* mi); +bool flush_master_info(MASTER_INFO* mi, bool flush_relay_log_cache); bool flush_relay_log_info(RELAY_LOG_INFO* rli); int register_slave_on_master(MYSQL* mysql); int terminate_slave_threads(MASTER_INFO* mi, int thread_mask, diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index 7c56670935b..cff36eaa388 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -958,7 +958,7 @@ int change_master(THD* thd, MASTER_INFO* mi) sizeof(mi->master_log_name)-1); } - flush_master_info(mi); + flush_master_info(mi, 0); if (need_relay_log_purge) { mi->rli.skip_log_purge= 0;