List:Commits« Previous MessageNext Message »
From:Alfranio Correia Date:September 30 2009 9:41pm
Subject:bzr commit into mysql-5.1-rep+2 branch (alfranio.correia:3124)
Bug#43075
View as plain text  
#At file:///home/acorreia/workspace.sun/repository.mysql/bzrwork/backport/mysql-5.1-rep%2B2/ based on revid:luis.soares@stripped

 3124 Alfranio Correia	2009-09-30
      BUG#43075 rpl.rpl_sync fails sporadically on pushbuild
      
      NOTE: Backporting the patch to next-mr.
            
      The slave was crashing while failing to execute the init_slave() function.
            
      The issue stems from two different reasons:
            
      1 - A failure while allocating the master info structure generated a
          segfault due to a NULL pointer.
            
      2 - A failure while recovering generated a segfault due to a non-initialized
          relay log file. In other words, the mi->init and rli->init were both set to true
          before executing the recovery process thus creating an inconsistent state as the
          relay log file was not initialized.
            
      To circumvent such problems, we refactored the recovery process which is now executed
      while initializing the relay log. It is ensured that the master info structure is
      created before accessing it and any error is propagated thus avoiding to set mi->init
      and rli->init to true when for instance the relay log is not initialized or the relay
      info is not flushed.
            
      The changes related to the refactory are described below:
            
      1 - Removed call to init_recovery from init_slave.
            
      2 - Changed the signature of the function init_recovery.
            
      3 - Removed flushes. They are called while initializing the relay log and master
          info.
            
      4 - Made sure that if the relay info is not flushed the mi-init and rli-init are not
          set to true.
            
      In this patch, we also replaced the exit(1) in the fault injection by DBUG_ABORT()
      to make it compliant with the code guidelines.

    modified:
      sql/rpl_mi.cc
      sql/rpl_rli.cc
      sql/slave.cc
      sql/slave.h
=== modified file 'sql/rpl_mi.cc'
--- a/sql/rpl_mi.cc	2009-09-29 14:40:52 +0000
+++ b/sql/rpl_mi.cc	2009-09-30 21:41:05 +0000
@@ -310,6 +310,7 @@ file '%s')", fname);
     goto err;
 
   mi->inited = 1;
+  mi->rli.is_relay_log_recovery= FALSE;
   // 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, 1))))

=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc	2009-09-29 14:40:52 +0000
+++ b/sql/rpl_rli.cc	2009-09-30 21:41:05 +0000
@@ -259,8 +259,10 @@ Failed to open the existing relay log in
     rli->group_relay_log_pos= rli->event_relay_log_pos= relay_log_pos;
     rli->group_master_log_pos= master_log_pos;
 
-    if (!rli->is_relay_log_recovery &&
-        init_relay_log_pos(rli,
+    if (rli->is_relay_log_recovery && init_recovery(rli->mi, &msg))
+      goto err;
+
+    if (init_relay_log_pos(rli,
                            rli->group_relay_log_name,
                            rli->group_relay_log_pos,
                            0 /* no data lock*/,
@@ -275,7 +277,6 @@ Failed to open the existing relay log in
   }
 
 #ifndef DBUG_OFF
-  if (!rli->is_relay_log_recovery)
   {
     char llbuf1[22], llbuf2[22];
     DBUG_PRINT("info", ("my_b_tell(rli->cur_log)=%s rli->event_relay_log_pos=%s",
@@ -292,7 +293,10 @@ Failed to open the existing relay log in
   */
   reinit_io_cache(&rli->info_file, WRITE_CACHE,0L,0,1);
   if ((error= flush_relay_log_info(rli)))
-    sql_print_error("Failed to flush relay log info file");
+  {
+    msg= "Failed to flush relay log info file";
+    goto err;
+  }
   if (count_relay_log_space(rli))
   {
     msg="Error counting relay log space";

=== modified file 'sql/slave.cc'
--- a/sql/slave.cc	2009-09-29 14:40:52 +0000
+++ b/sql/slave.cc	2009-09-30 21:41:05 +0000
@@ -129,7 +129,6 @@ static bool wait_for_relay_log_space(Rel
 static inline bool io_slave_killed(THD* thd,Master_info* mi);
 static inline bool sql_slave_killed(THD* thd,Relay_log_info* rli);
 static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type);
-static int init_recovery(Master_info* mi);
 static void print_slave_skip_errors(void);
 static int safe_connect(THD* thd, MYSQL* mysql, Master_info* mi);
 static int safe_reconnect(THD* thd, MYSQL* mysql, Master_info* mi,
@@ -264,12 +263,6 @@ int init_slave()
     goto err;
   }
 
-  if (active_mi->rli.is_relay_log_recovery && init_recovery(active_mi))
-  {
-    error= 1;
-    goto err;
-  }
-
   if (server_id && !master_host && active_mi->host[0])
     master_host= active_mi->host;
 
@@ -291,7 +284,6 @@ int init_slave()
   }
 
 err:
-  active_mi->rli.is_relay_log_recovery= FALSE;
   pthread_mutex_unlock(&LOCK_active_mi);
   DBUG_RETURN(error);
 }
@@ -323,9 +315,8 @@ err:
   
    If there is an error, it returns (1), otherwise returns (0).
  */
-static int init_recovery(Master_info* mi)
+int init_recovery(Master_info* mi, const char** errmsg)
 {
-  const char *errmsg= 0;
   DBUG_ENTER("init_recovery");
  
   Relay_log_info *rli= &mi->rli;
@@ -345,26 +336,8 @@ static int init_recovery(Master_info* mi
             sizeof(mi->rli.event_relay_log_name)-1);
  
     rli->group_relay_log_pos= rli->event_relay_log_pos= BIN_LOG_HEADER_SIZE;
- 
-    if (init_relay_log_pos(rli,
-                           rli->group_relay_log_name,
-                           rli->group_relay_log_pos,
-                           0 /*no data lock*/,
-                            &errmsg, 0))
-      DBUG_RETURN(1);
- 
-    if (flush_master_info(mi, 0))
-    {
-      sql_print_error("Failed to flush master info file");
-      DBUG_RETURN(1);
-    }
-    if (flush_relay_log_info(rli))
-    {
-       sql_print_error("Failed to flush relay info file");
-       DBUG_RETURN(1);
-    }
   }
- 
+
   DBUG_RETURN(0);
 }
  

=== modified file 'sql/slave.h'
--- a/sql/slave.h	2009-07-06 08:02:14 +0000
+++ b/sql/slave.h	2009-09-30 21:41:05 +0000
@@ -134,6 +134,7 @@ extern ulonglong relay_log_space_limit;
 #define SLAVE_FORCE_ALL 4
 
 int init_slave();
+int init_recovery(Master_info* mi, const char** errmsg);
 void init_slave_skip_errors(const char* arg);
 bool flush_relay_log_info(Relay_log_info* rli);
 int register_slave_on_master(MYSQL* mysql);


Attachment: [text/bzr-bundle]
Thread
bzr commit into mysql-5.1-rep+2 branch (alfranio.correia:3124)Bug#43075Alfranio Correia30 Sep