Commit 21a8aaa2 authored by sasha@mysql.sashanet.com's avatar sasha@mysql.sashanet.com
Browse files

fixed race condition in automatic binlog rotation

remove extension from binary log if the user specifies one to avoid
    non-rotatable logs
fixed possible use of unitialized IO_CACHE in debug mode
parent b6273bfc
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -511,16 +511,18 @@ bool MYSQL_LOG::is_active(const char* log_file_name)
  return inited && !strcmp(log_file_name, this->log_file_name);
}

void MYSQL_LOG::new_file()
void MYSQL_LOG::new_file(bool inside_mutex)
{
  // only rotate open logs that are marked non-rotatable
  // (binlog with constant name are non-rotatable)
  if (is_open() && ! no_rotate)
  {
    char new_name[FN_REFLEN], *old_name=name;
    if (!inside_mutex)
      VOID(pthread_mutex_lock(&LOCK_log));
    if (generate_new_name(new_name, name))
    {
      if (!inside_mutex)
        VOID(pthread_mutex_unlock(&LOCK_log));
      return;					// Something went wrong
    }
@@ -540,6 +542,7 @@ void MYSQL_LOG::new_file()
    my_free(old_name,MYF(0));
    last_time=query_start=0;
    write_error=0;
    if (!inside_mutex)
      VOID(pthread_mutex_unlock(&LOCK_log));
  }
}
@@ -695,9 +698,9 @@ bool MYSQL_LOG::write(Query_log_event* event_info)
    if (file == &log_file)
      VOID(pthread_cond_broadcast(&COND_binlog_update));
  }
  VOID(pthread_mutex_unlock(&LOCK_log));
  if (should_rotate)
    new_file();
    new_file(1); // inside mutex
  VOID(pthread_mutex_unlock(&LOCK_log));
  return error;
}

@@ -782,11 +785,13 @@ bool MYSQL_LOG::write(Load_log_event* event_info)
	VOID(pthread_cond_broadcast(&COND_binlog_update));
      }
    }
    
    if(should_rotate)
      new_file(1); // inside mutex
    
    VOID(pthread_mutex_unlock(&LOCK_log));
  }

  if(should_rotate)
    new_file();
  
  return error;
}
+7 −0
Original line number Diff line number Diff line
@@ -1477,6 +1477,13 @@ static void open_log(MYSQL_LOG *log, const char *hostname,
    strmov(strcend(tmp,'.'),extension);
    opt_name=tmp;
  }
  // get rid of extention if the log is binary to avoid problems
  if (type == LOG_BIN)
  {
    char* p = strrchr(opt_name, FN_EXTCHAR);
    if (p)
      *p = 0;
  }
  log->open(opt_name,type);
}

+5 −0
Original line number Diff line number Diff line
@@ -189,6 +189,11 @@ static void free_string_array(DYNAMIC_ARRAY *a)

void end_slave()
{
  pthread_mutex_lock(&LOCK_slave);
  while (slave_running)
    pthread_cond_wait(&COND_slave_stopped, &LOCK_slave);
  pthread_mutex_unlock(&LOCK_slave);
  
  end_master_info(&glob_mi);
  if(do_table_inited)
    hash_free(&replicate_do_table);
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ class MYSQL_LOG {
  void init(enum_log_type log_type_arg);
  void open(const char *log_name,enum_log_type log_type,
	    const char *new_name=0);
  void new_file(void);
  void new_file(bool inside_mutex = 0);
  bool open_index(int options);
  void close_index();
  bool write(THD *thd, enum enum_server_command command,const char *format,...);
+1 −1
Original line number Diff line number Diff line
@@ -274,6 +274,7 @@ void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags)
  int left_events = max_binlog_dump_events;
#endif  
  DBUG_ENTER("mysql_binlog_send");
  bzero((char*) &log,sizeof(log));

#ifndef DBUG_OFF
  if (opt_sporadic_binlog_dump_fail && (binlog_dump_count++ % 2))
@@ -283,7 +284,6 @@ void mysql_binlog_send(THD* thd, char* log_ident, ulong pos, ushort flags)
  }
#endif  

  bzero((char*) &log,sizeof(log));

  if(!mysql_bin_log.is_open())
  {