Commit 1c0d5ad2 authored by guilhem@mysql.com's avatar guilhem@mysql.com

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).
parent 30541b32
...@@ -894,7 +894,7 @@ int load_master_data(THD* thd) ...@@ -894,7 +894,7 @@ int load_master_data(THD* thd)
if (active_mi->master_log_pos < BIN_LOG_HEADER_SIZE) if (active_mi->master_log_pos < BIN_LOG_HEADER_SIZE)
active_mi->master_log_pos = BIN_LOG_HEADER_SIZE; active_mi->master_log_pos = BIN_LOG_HEADER_SIZE;
active_mi->rli.pending = 0; active_mi->rli.pending = 0;
flush_master_info(active_mi); flush_master_info(active_mi, 0);
} }
mc_mysql_free_result(master_status_res); mc_mysql_free_result(master_status_res);
} }
......
...@@ -1657,7 +1657,7 @@ file '%s')", fname); ...@@ -1657,7 +1657,7 @@ file '%s')", fname);
mi->inited = 1; mi->inited = 1;
// now change cache READ -> WRITE - must do this before flush_master_info // now change cache READ -> WRITE - must do this before flush_master_info
reinit_io_cache(&mi->file, WRITE_CACHE,0L,0,1); 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"); sql_print_error("Failed to flush master info file");
pthread_mutex_unlock(&mi->data_lock); pthread_mutex_unlock(&mi->data_lock);
DBUG_RETURN(error); DBUG_RETURN(error);
...@@ -1784,13 +1784,15 @@ int show_master_info(THD* thd, MASTER_INFO* mi) ...@@ -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; IO_CACHE* file = &mi->file;
char lbuf[22]; char lbuf[22];
DBUG_ENTER("flush_master_info"); DBUG_ENTER("flush_master_info");
DBUG_PRINT("enter",("master_pos: %ld", (long) mi->master_log_pos)); 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_seek(file, 0L);
my_b_printf(file, "%s\n%s\n%s\n%s\n%s\n%d\n%d\n", 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), mi->master_log_name, llstr(mi->master_log_pos, lbuf),
...@@ -2542,7 +2544,7 @@ reconnect done to recover from failed read"); ...@@ -2542,7 +2544,7 @@ reconnect done to recover from failed read");
sql_print_error("Slave I/O thread could not queue event from master"); sql_print_error("Slave I/O thread could not queue event from master");
goto err; goto err;
} }
flush_master_info(mi); flush_master_info(mi, 1);
/* /*
See if the relay logs take too much space. See if the relay logs take too much space.
We don't lock mi->rli.log_space_lock here; this dirty read saves time We don't lock mi->rli.log_space_lock here; this dirty read saves time
......
...@@ -361,7 +361,7 @@ typedef struct st_table_rule_ent ...@@ -361,7 +361,7 @@ typedef struct st_table_rule_ent
int init_slave(); int init_slave();
void init_slave_skip_errors(const char* arg); 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); bool flush_relay_log_info(RELAY_LOG_INFO* rli);
int register_slave_on_master(MYSQL* mysql); int register_slave_on_master(MYSQL* mysql);
int terminate_slave_threads(MASTER_INFO* mi, int thread_mask, int terminate_slave_threads(MASTER_INFO* mi, int thread_mask,
......
...@@ -958,7 +958,7 @@ int change_master(THD* thd, MASTER_INFO* mi) ...@@ -958,7 +958,7 @@ int change_master(THD* thd, MASTER_INFO* mi)
sizeof(mi->master_log_name)-1); sizeof(mi->master_log_name)-1);
} }
flush_master_info(mi); flush_master_info(mi, 0);
if (need_relay_log_purge) if (need_relay_log_purge)
{ {
mi->rli.skip_log_purge= 0; mi->rli.skip_log_purge= 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment