summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <guilhem@mysql.com>2003-07-06 17:59:54 +0200
committerunknown <guilhem@mysql.com>2003-07-06 17:59:54 +0200
commitc22f493a4f4f0d864eb1440a5c9aaf247f446817 (patch)
tree68a7f6c662f44a6131f23d21d858dd0527d408c2
parent1c88eeadd353ad80468e3bfc1635baee29d0d45a (diff)
downloadmariadb-git-c22f493a4f4f0d864eb1440a5c9aaf247f446817.tar.gz
WL#912 (more user control on relay logs):
FLUSH LOGS now rotates relay logs, and a new variable max_relay_log_size. Plus a very small bit of code cleaning. libmysqld/lib_sql.cc: open_log has no default arguments anymore. mysql-test/r/rpl_flush_log_loop.result: result update now that FLUSH LOGS rotates relay logs. mysql-test/r/rpl_log.result: result update now that FLUSH LOGS rotates relay logs. mysql-test/r/rpl_rotate_logs.result: result update now that max_binlog_size is 4096. mysql-test/t/rpl_rotate_logs-master.opt: now max_binlog_size must be a multiple of 4096 (see change in mysqld.cc) sql/log.cc: Got rid of default arguments of various MYSQL_LOG methods (the default arguments made code reading uneasy). Set max_size in ::init(). New function set_max_size() to set max_size of a MYSQL_LOG on-the-fly. More DBUG info. sql/mysql_priv.h: no defaults in open_log(). New variables max_relay_log_size. sql/mysqld.cc: New variable and option max_relay_log_size. max_binlog_size and max_relay_log_size are multiples of IO_SIZE. No more default arguments for log functions. sql/set_var.cc: New variable max_relay_log_size. If it is 0, then max_binlog_size will apply to relay logs. When one of these variables is changed, fix_max_%log_size is called to update max_size of the binary and/or relay logs. sql/slave.cc: New function rotate_relay_log(). sql/slave.h: New function rotate_relay_log(). sql/sql_class.h: New member max_size of MYSQL_LOG (for automatic rotation). New method set_max_size() for setting on-the-fly. sql/sql_parse.cc: Flush the relay log in FLUSH LOGS.
-rw-r--r--libmysqld/lib_sql.cc8
-rw-r--r--mysql-test/r/rpl_flush_log_loop.result2
-rw-r--r--mysql-test/r/rpl_log.result2
-rw-r--r--mysql-test/r/rpl_max_relay_size.result61
-rw-r--r--mysql-test/r/rpl_rotate_logs.result6
-rw-r--r--mysql-test/t/rpl_max_relay_size.test81
-rw-r--r--mysql-test/t/rpl_rotate_logs-master.opt2
-rw-r--r--sql/log.cc72
-rw-r--r--sql/mysql_priv.h7
-rw-r--r--sql/mysqld.cc30
-rw-r--r--sql/set_var.cc30
-rw-r--r--sql/slave.cc52
-rw-r--r--sql/slave.h1
-rw-r--r--sql/sql_class.h18
-rw-r--r--sql/sql_parse.cc8
15 files changed, 335 insertions, 45 deletions
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 7682d60d991..eddb326f6c4 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -511,17 +511,17 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
/* Setup log files */
if (opt_log)
open_log(&mysql_log, glob_hostname, opt_logname, ".log", NullS,
- LOG_NORMAL);
+ LOG_NORMAL, 0, 0, 0);
if (opt_update_log)
{
open_log(&mysql_update_log, glob_hostname, opt_update_logname, "",
- NullS, LOG_NEW);
+ NullS, LOG_NEW, 0, 0, 0);
using_update_log=1;
}
if (opt_slow_log)
open_log(&mysql_slow_log, glob_hostname, opt_slow_logname, "-slow.log",
- NullS, LOG_NORMAL);
+ NullS, LOG_NORMAL, 0, 0, 0);
if (ha_init())
{
sql_print_error("Can't init databases");
@@ -586,7 +586,7 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups)
opt_bin_logname=my_strdup(tmp,MYF(MY_WME));
}
open_log(&mysql_bin_log, glob_hostname, opt_bin_logname, "-bin",
- opt_binlog_index_name, LOG_BIN);
+ opt_binlog_index_name, LOG_BIN, 0, 0, max_binlog_size);
using_update_log=1;
}
diff --git a/mysql-test/r/rpl_flush_log_loop.result b/mysql-test/r/rpl_flush_log_loop.result
index da2930f30c3..3273ce43a17 100644
--- a/mysql-test/r/rpl_flush_log_loop.result
+++ b/mysql-test/r/rpl_flush_log_loop.result
@@ -14,4 +14,4 @@ slave start;
flush logs;
show slave status;
Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
-127.0.0.1 root SLAVE_PORT 60 slave-bin.001 79 relay-log.001 119 slave-bin.001 Yes Yes 0 0 79 119
+127.0.0.1 root SLAVE_PORT 60 slave-bin.001 79 relay-log.002 119 slave-bin.001 Yes Yes 0 0 79 119
diff --git a/mysql-test/r/rpl_log.result b/mysql-test/r/rpl_log.result
index 616ad319880..640e6f02103 100644
--- a/mysql-test/r/rpl_log.result
+++ b/mysql-test/r/rpl_log.result
@@ -93,6 +93,6 @@ slave-bin.002 62 Query 1 168 use test; insert into t1 values (1)
slave-bin.002 122 Query 1 228 use test; drop table t1
show slave status;
Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
-127.0.0.1 root MASTER_PORT 1 master-bin.002 276 slave-relay-bin.002 1563 master-bin.002 Yes Yes 0 0 276 1563
+127.0.0.1 root MASTER_PORT 1 master-bin.002 276 slave-relay-bin.003 211 master-bin.002 Yes Yes 0 0 276 211
show binlog events in 'slave-bin.005' from 4;
Error when executing command SHOW BINLOG EVENTS: Could not find target log
diff --git a/mysql-test/r/rpl_max_relay_size.result b/mysql-test/r/rpl_max_relay_size.result
new file mode 100644
index 00000000000..5c5a9d622e5
--- /dev/null
+++ b/mysql-test/r/rpl_max_relay_size.result
@@ -0,0 +1,61 @@
+slave stop;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+slave start;
+stop slave;
+create table t1 (a int);
+drop table t1;
+reset slave;
+set global max_binlog_size=8192;
+set global max_relay_log_size=8192-1;
+select @@global.max_relay_log_size;
+@@global.max_relay_log_size
+4096
+start slave;
+show slave status;
+Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
+127.0.0.1 root 9306 1 master-bin.001 50477 slave-relay-bin.014 1221 master-bin.001 Yes Yes 0 0 50477 1221
+stop slave;
+reset slave;
+set global max_relay_log_size=(5*4096);
+select @@global.max_relay_log_size;
+@@global.max_relay_log_size
+20480
+start slave;
+show slave status;
+Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
+127.0.0.1 root 9306 1 master-bin.001 50477 slave-relay-bin.004 9457 master-bin.001 Yes Yes 0 0 50477 9457
+stop slave;
+reset slave;
+set global max_relay_log_size=0;
+select @@global.max_relay_log_size;
+@@global.max_relay_log_size
+0
+start slave;
+show slave status;
+Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
+127.0.0.1 root 9306 1 master-bin.001 50477 slave-relay-bin.008 1283 master-bin.001 Yes Yes 0 0 50477 1283
+stop slave;
+reset slave;
+flush logs;
+show slave status;
+Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
+127.0.0.1 root 9306 1 4 slave-relay-bin.001 4 No No 0 0 0 4
+reset slave;
+start slave;
+flush logs;
+create table t1 (a int);
+show slave status;
+Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
+127.0.0.1 root 9306 1 master-bin.001 50535 slave-relay-bin.009 62 master-bin.001 Yes Yes 0 0 50535 62
+flush logs;
+drop table t1;
+show slave status;
+Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
+127.0.0.1 root 9306 1 master-bin.001 50583 slave-relay-bin.010 52 master-bin.001 Yes Yes 0 0 50583 52
+flush logs;
+show master status;
+File Position Binlog_do_db Binlog_ignore_db
+master-bin.002 4
diff --git a/mysql-test/r/rpl_rotate_logs.result b/mysql-test/r/rpl_rotate_logs.result
index f49006e8e05..07490744d81 100644
--- a/mysql-test/r/rpl_rotate_logs.result
+++ b/mysql-test/r/rpl_rotate_logs.result
@@ -65,17 +65,15 @@ show master logs;
Log_name
master-bin.003
master-bin.004
-master-bin.005
-master-bin.006
show master status;
File Position Binlog_do_db Binlog_ignore_db
-master-bin.006 838
+master-bin.004 2886
select * from t4;
a
testing temporary tables part 2
show slave status;
Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
-127.0.0.1 root MASTER_PORT 60 master-bin.006 838 slave-relay-bin.001 8034 master-bin.006 Yes Yes 0 0 838 8034
+127.0.0.1 root MASTER_PORT 60 master-bin.004 2886 slave-relay-bin.001 7870 master-bin.004 Yes Yes 0 0 2886 7870
lock tables t3 read;
select count(*) from t3 where n >= 4;
count(*)
diff --git a/mysql-test/t/rpl_max_relay_size.test b/mysql-test/t/rpl_max_relay_size.test
new file mode 100644
index 00000000000..4befe4024fc
--- /dev/null
+++ b/mysql-test/t/rpl_max_relay_size.test
@@ -0,0 +1,81 @@
+# Test of options max_binlog_size and max_relay_log_size and
+# how they act (if max_relay_log_size == 0, use max_binlog_size
+# for relay logs too).
+# Test of manual relay log rotation with FLUSH LOGS.
+
+source include/master-slave.inc;
+connection slave;
+stop slave;
+connection master;
+# Generate a big enough master's binlog to cause relay log rotations
+create table t1 (a int);
+let $1=800;
+disable_query_log;
+begin;
+while ($1)
+{
+# eval means expand $ expressions
+ eval insert into t1 values( $1 );
+ dec $1;
+}
+enable_query_log;
+drop table t1;
+save_master_pos;
+connection slave;
+reset slave;
+set global max_binlog_size=8192;
+set global max_relay_log_size=8192-1; # mapped to 4096
+select @@global.max_relay_log_size;
+start slave;
+sync_with_master;
+show slave status;
+stop slave;
+reset slave;
+set global max_relay_log_size=(5*4096);
+select @@global.max_relay_log_size;
+start slave;
+sync_with_master;
+show slave status;
+stop slave;
+reset slave;
+set global max_relay_log_size=0;
+select @@global.max_relay_log_size;
+start slave;
+sync_with_master;
+show slave status;
+
+# Tests below are mainly to ensure that we have not coded with wrong assumptions
+
+stop slave;
+reset slave;
+# test of relay log rotation when the slave is stopped
+# (to make sure it does not crash).
+flush logs;
+show slave status;
+
+reset slave;
+start slave;
+sync_with_master;
+# test of relay log rotation when the slave is started
+flush logs;
+# We have now easy way to be sure that the SQL thread has now deleted the
+# log we just closed. But a trick to achieve this is do an update on the master.
+connection master;
+create table t1 (a int);
+save_master_pos;
+connection slave;
+sync_with_master;
+show slave status;
+# one more rotation, to be sure Relay_log_space is correctly updated
+flush logs;
+connection master;
+drop table t1;
+save_master_pos;
+connection slave;
+sync_with_master;
+show slave status;
+
+connection master;
+# test that the absence of relay logs does not make a master crash
+flush logs;
+show master status;
diff --git a/mysql-test/t/rpl_rotate_logs-master.opt b/mysql-test/t/rpl_rotate_logs-master.opt
index f27601e0d7d..ad2c6a647b5 100644
--- a/mysql-test/t/rpl_rotate_logs-master.opt
+++ b/mysql-test/t/rpl_rotate_logs-master.opt
@@ -1 +1 @@
--O max_binlog_size=2048
+-O max_binlog_size=4096
diff --git a/sql/log.cc b/sql/log.cc
index 99bc6ee32b4..ef7cdd0dbd5 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -133,11 +133,15 @@ int MYSQL_LOG::generate_new_name(char *new_name, const char *log_name)
void MYSQL_LOG::init(enum_log_type log_type_arg,
enum cache_type io_cache_type_arg,
- bool no_auto_events_arg)
+ bool no_auto_events_arg,
+ ulong max_size_arg)
{
+ DBUG_ENTER("MYSQL_LOG::init");
log_type = log_type_arg;
io_cache_type = io_cache_type_arg;
no_auto_events = no_auto_events_arg;
+ max_size=max_size_arg;
+ DBUG_PRINT("info",("log_type=%d max_size=%lu", log_type, max_size));
if (!inited)
{
inited= 1;
@@ -145,6 +149,7 @@ void MYSQL_LOG::init(enum_log_type log_type_arg,
(void) pthread_mutex_init(&LOCK_index, MY_MUTEX_INIT_SLOW);
(void) pthread_cond_init(&update_cond, 0);
}
+ DBUG_VOID_RETURN;
}
@@ -165,7 +170,8 @@ void MYSQL_LOG::init(enum_log_type log_type_arg,
bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
const char *new_name, const char *index_file_name_arg,
enum cache_type io_cache_type_arg,
- bool no_auto_events_arg)
+ bool no_auto_events_arg,
+ ulong max_size)
{
char buff[512];
File file= -1, index_file_nr= -1;
@@ -178,7 +184,7 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg,
if (!inited && log_type_arg == LOG_BIN && *fn_ext(log_name))
no_rotate = 1;
- init(log_type_arg,io_cache_type_arg,no_auto_events_arg);
+ init(log_type_arg,io_cache_type_arg,no_auto_events_arg,max_size);
if (!(name=my_strdup(log_name,MYF(MY_WME))))
goto err;
@@ -577,7 +583,7 @@ bool MYSQL_LOG::reset_logs(THD* thd)
if (!thd->slave_thread)
need_start_event=1;
open(save_name, save_log_type, 0, index_file_name,
- io_cache_type, no_auto_events);
+ io_cache_type, no_auto_events, max_size);
my_free((gptr) save_name, MYF(0));
err:
@@ -802,8 +808,12 @@ void MYSQL_LOG::new_file(bool need_lock)
char new_name[FN_REFLEN], *new_name_ptr, *old_name;
enum_log_type save_log_type;
+ DBUG_ENTER("MYSQL_LOG::new_file");
if (!is_open())
- return; // Should never happen
+ {
+ DBUG_PRINT("info",("log is closed"));
+ DBUG_VOID_RETURN;
+ }
if (need_lock)
{
@@ -865,8 +875,16 @@ void MYSQL_LOG::new_file(bool need_lock)
save_log_type=log_type;
name=0; // Don't free name
close();
+/*
+ if (save_log_type == LOG_BIN)
+ {
+ printf("after close, before open; I wait for 20 seconds\n");
+ sleep(20);
+ printf("sleep finished, opening\n");
+ }
+*/
open(old_name, save_log_type, new_name_ptr, index_file_name, io_cache_type,
- no_auto_events);
+ no_auto_events, max_size);
my_free(old_name,MYF(0));
end:
@@ -875,6 +893,7 @@ end:
pthread_mutex_unlock(&LOCK_index);
pthread_mutex_unlock(&LOCK_log);
}
+ DBUG_VOID_RETURN;
}
@@ -882,7 +901,8 @@ bool MYSQL_LOG::append(Log_event* ev)
{
bool error = 0;
pthread_mutex_lock(&LOCK_log);
-
+ DBUG_ENTER("MYSQL_LOG::append");
+
DBUG_ASSERT(log_file.type == SEQ_READ_APPEND);
/*
Log_event::write() is smart enough to use my_b_write() or
@@ -894,7 +914,8 @@ bool MYSQL_LOG::append(Log_event* ev)
goto err;
}
bytes_written += ev->get_event_len();
- if ((uint) my_b_append_tell(&log_file) > max_binlog_size)
+ DBUG_PRINT("info",("max_size=%lu",max_size));
+ if ((uint) my_b_append_tell(&log_file) > max_size)
{
pthread_mutex_lock(&LOCK_index);
new_file(0);
@@ -904,13 +925,14 @@ bool MYSQL_LOG::append(Log_event* ev)
err:
pthread_mutex_unlock(&LOCK_log);
signal_update(); // Safe as we don't call close
- return error;
+ DBUG_RETURN(error);
}
bool MYSQL_LOG::appendv(const char* buf, uint len,...)
{
bool error= 0;
+ DBUG_ENTER("MYSQL_LOG::appendv");
va_list(args);
va_start(args,len);
@@ -926,8 +948,8 @@ bool MYSQL_LOG::appendv(const char* buf, uint len,...)
}
bytes_written += len;
} while ((buf=va_arg(args,const char*)) && (len=va_arg(args,uint)));
-
- if ((uint) my_b_append_tell(&log_file) > max_binlog_size)
+ DBUG_PRINT("info",("max_size=%lu",max_size));
+ if ((uint) my_b_append_tell(&log_file) > max_size)
{
pthread_mutex_lock(&LOCK_index);
new_file(0);
@@ -938,7 +960,7 @@ err:
pthread_mutex_unlock(&LOCK_log);
if (!error)
signal_update();
- return error;
+ DBUG_RETURN(error);
}
@@ -1188,8 +1210,9 @@ bool MYSQL_LOG::write(Log_event* event_info)
called_handler_commit=1;
}
}
- /* we wrote to the real log, check automatic rotation */
- should_rotate= (my_b_tell(file) >= (my_off_t) max_binlog_size);
+ /* We wrote to the real log, check automatic rotation; */
+ DBUG_PRINT("info",("max_size=%lu",max_size));
+ should_rotate= (my_b_tell(file) >= (my_off_t) max_size);
}
error=0;
@@ -1319,7 +1342,8 @@ bool MYSQL_LOG::write(THD *thd, IO_CACHE *cache)
log_file.pos_in_file)))
goto err;
signal_update();
- if (my_b_tell(&log_file) >= (my_off_t) max_binlog_size)
+ DBUG_PRINT("info",("max_size=%lu",max_size));
+ if (my_b_tell(&log_file) >= (my_off_t) max_size)
{
pthread_mutex_lock(&LOCK_index);
new_file(0); // inside mutex
@@ -1563,6 +1587,24 @@ void MYSQL_LOG::close(bool exiting)
DBUG_VOID_RETURN;
}
+void MYSQL_LOG::set_max_size(ulong max_size_arg)
+{
+ /*
+ We need to take locks, otherwise this may happen:
+ new_file() is called, calls open(old_max_size), then before open() starts,
+ set_max_size() sets max_size to max_size_arg, then open() starts and
+ uses the old_max_size argument, so max_size_arg has been overwritten and
+ it's like if the SET command was never run.
+ */
+ if (is_open())
+ {
+ pthread_mutex_lock(&LOCK_log);
+ pthread_mutex_lock(&LOCK_index);
+ max_size= max_size_arg;
+ pthread_mutex_unlock(&LOCK_index);
+ pthread_mutex_unlock(&LOCK_log);
+ }
+}
/*
Check if a string is a valid number
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 702db98748a..723df948e1d 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -606,8 +606,8 @@ bool fn_format_relative_to_data_home(my_string to, const char *name,
bool open_log(MYSQL_LOG *log, const char *hostname,
const char *opt_name, const char *extension,
const char *index_file_name,
- enum_log_type type, bool read_append = 0,
- bool no_auto_events = 0);
+ enum_log_type type, bool read_append,
+ bool no_auto_events, ulong max_size);
/* mysqld.cc */
void clear_error_message(THD *thd);
@@ -654,7 +654,8 @@ extern ulong max_insert_delayed_threads, max_user_connections;
extern ulong long_query_count, what_to_log,flush_time,opt_sql_mode;
extern ulong query_buff_size, thread_stack,thread_stack_min;
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
-extern ulong max_binlog_size, rpl_recovery_rank, thread_cache_size;
+extern ulong max_binlog_size, max_relay_log_size;
+extern ulong rpl_recovery_rank, thread_cache_size;
extern ulong com_stat[(uint) SQLCOM_END], com_other, back_log;
extern ulong specialflag, current_pid;
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 4f6f55bce0b..c45b3184f16 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -354,7 +354,7 @@ ulong table_cache_size,
query_buff_size,
slow_launch_time = 2L,
slave_open_temp_tables=0,
- open_files_limit=0, max_binlog_size;
+ open_files_limit=0, max_binlog_size, max_relay_log_size;
ulong com_stat[(uint) SQLCOM_END], com_other;
ulong slave_net_timeout;
ulong thread_cache_size=0, binlog_cache_size=0, max_binlog_cache_size=0;
@@ -1950,7 +1950,7 @@ bool open_log(MYSQL_LOG *log, const char *hostname,
const char *opt_name, const char *extension,
const char *index_file_name,
enum_log_type type, bool read_append,
- bool no_auto_events)
+ bool no_auto_events, ulong max_size)
{
char tmp[FN_REFLEN];
if (!opt_name || !opt_name[0])
@@ -1976,7 +1976,7 @@ bool open_log(MYSQL_LOG *log, const char *hostname,
}
return log->open(opt_name, type, 0, index_file_name,
(read_append) ? SEQ_READ_APPEND : WRITE_CACHE,
- no_auto_events);
+ no_auto_events, max_size);
}
@@ -2196,17 +2196,17 @@ int main(int argc, char **argv)
/* Setup log files */
if (opt_log)
open_log(&mysql_log, glob_hostname, opt_logname, ".log", NullS,
- LOG_NORMAL);
+ LOG_NORMAL, 0, 0, 0);
if (opt_update_log)
{
open_log(&mysql_update_log, glob_hostname, opt_update_logname, "",
- NullS, LOG_NEW);
+ NullS, LOG_NEW, 0, 0, 0);
using_update_log=1;
}
if (opt_slow_log)
open_log(&mysql_slow_log, glob_hostname, opt_slow_logname, "-slow.log",
- NullS, LOG_NORMAL);
+ NullS, LOG_NORMAL, 0, 0, 0);
if (opt_error_log)
{
@@ -2321,7 +2321,7 @@ The server will not act as a slave.");
if (opt_bin_log)
{
open_log(&mysql_bin_log, glob_hostname, opt_bin_logname, "-bin",
- opt_binlog_index_name,LOG_BIN);
+ opt_binlog_index_name, LOG_BIN, 0, 0, max_binlog_size);
using_update_log=1;
}
else if (opt_log_slave_updates)
@@ -3156,8 +3156,8 @@ enum options {
OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE,
OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS,
OPT_MAX_DELAYED_THREADS, OPT_MAX_HEP_TABLE_SIZE,
- OPT_MAX_JOIN_SIZE, OPT_MAX_SORT_LENGTH, OPT_MAX_SEEKS_FOR_KEY,
- OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS,
+ OPT_MAX_JOIN_SIZE, OPT_MAX_RELAY_LOG_SIZE, OPT_MAX_SORT_LENGTH,
+ OPT_MAX_SEEKS_FOR_KEY, OPT_MAX_TMP_TABLES, OPT_MAX_USER_CONNECTIONS,
OPT_MAX_WRITE_LOCK_COUNT, OPT_BULK_INSERT_BUFFER_SIZE,
OPT_MYISAM_BLOCK_SIZE, OPT_MYISAM_MAX_EXTRA_SORT_FILE_SIZE,
OPT_MYISAM_MAX_SORT_FILE_SIZE, OPT_MYISAM_SORT_BUFFER_SIZE,
@@ -3809,9 +3809,11 @@ replicating a LOAD DATA INFILE command",
(gptr*) &max_binlog_cache_size, (gptr*) &max_binlog_cache_size, 0,
GET_ULONG, REQUIRED_ARG, ~0L, IO_SIZE, ~0L, 0, IO_SIZE, 0},
{"max_binlog_size", OPT_MAX_BINLOG_SIZE,
- "Binary log will be rotated automatically when the size crosses the limit.",
+ "Binary log will be rotated automatically when the size exceeds this \
+value. Will also apply to relay logs if max_relay_log_size is 0. \
+The minimum value for this variable is 4096.",
(gptr*) &max_binlog_size, (gptr*) &max_binlog_size, 0, GET_ULONG,
- REQUIRED_ARG, 1024*1024L*1024L, 1024, 1024*1024L*1024L, 0, 1, 0},
+ REQUIRED_ARG, 1024*1024L*1024L, IO_SIZE, 1024*1024L*1024L, 0, IO_SIZE, 0},
{"max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1,
@@ -3834,6 +3836,12 @@ replicating a LOAD DATA INFILE command",
(gptr*) &global_system_variables.max_join_size,
(gptr*) &max_system_variables.max_join_size, 0, GET_HA_ROWS, REQUIRED_ARG,
~0L, 1, ~0L, 0, 1, 0},
+ {"max_relay_log_size", OPT_MAX_RELAY_LOG_SIZE,
+ "If non-zero: relay log will be rotated automatically when the size exceeds \
+this value; if zero (the default): when the size exceeds max_binlog_size. \
+0 expected, the minimum value for this variable is 4096.",
+ (gptr*) &max_relay_log_size, (gptr*) &max_relay_log_size, 0, GET_ULONG,
+ REQUIRED_ARG, 0L, 0L, 1024*1024L*1024L, 0, IO_SIZE, 0},
{ "max_seeks_for_key", OPT_MAX_SEEKS_FOR_KEY,
"Limit assumed max number of seeks when looking up rows based on a key",
(gptr*) &global_system_variables.max_seeks_for_key,
diff --git a/sql/set_var.cc b/sql/set_var.cc
index b66c410c6d5..b3238d1c0ec 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -84,6 +84,8 @@ static void fix_query_cache_size(THD *thd, enum_var_type type);
static void fix_key_buffer_size(THD *thd, enum_var_type type);
static void fix_myisam_max_extra_sort_file_size(THD *thd, enum_var_type type);
static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type);
+static void fix_max_binlog_size(THD *thd, enum_var_type type);
+static void fix_max_relay_log_size(THD *thd, enum_var_type type);
/*
Variable definition list
@@ -142,7 +144,8 @@ sys_var_thd_ulong sys_max_allowed_packet("max_allowed_packet",
sys_var_long_ptr sys_max_binlog_cache_size("max_binlog_cache_size",
&max_binlog_cache_size);
sys_var_long_ptr sys_max_binlog_size("max_binlog_size",
- &max_binlog_size);
+ &max_binlog_size,
+ fix_max_binlog_size);
sys_var_long_ptr sys_max_connections("max_connections",
&max_connections);
sys_var_long_ptr sys_max_connect_errors("max_connect_errors",
@@ -161,6 +164,9 @@ sys_var_thd_ha_rows sys_sql_max_join_size("sql_max_join_size",
&SV::max_join_size,
fix_max_join_size);
#endif
+sys_var_long_ptr sys_max_relay_log_size("max_relay_log_size",
+ &max_relay_log_size,
+ fix_max_relay_log_size);
sys_var_thd_ulong sys_max_sort_length("max_sort_length",
&SV::max_sort_length);
sys_var_long_ptr sys_max_user_connections("max_user_connections",
@@ -350,6 +356,7 @@ sys_var *sys_variables[]=
&sys_max_delayed_threads,
&sys_max_heap_table_size,
&sys_max_join_size,
+ &sys_max_relay_log_size,
&sys_max_seeks_for_key,
&sys_max_sort_length,
&sys_max_tmp_tables,
@@ -495,6 +502,7 @@ struct show_var_st init_vars[]= {
{sys_max_delayed_threads.name,(char*) &sys_max_delayed_threads, SHOW_SYS},
{sys_max_heap_table_size.name,(char*) &sys_max_heap_table_size, SHOW_SYS},
{sys_max_join_size.name, (char*) &sys_max_join_size, SHOW_SYS},
+ {sys_max_relay_log_size.name, (char*) &sys_max_relay_log_size, SHOW_SYS},
{sys_max_seeks_for_key.name, (char*) &sys_max_seeks_for_key, SHOW_SYS},
{sys_max_sort_length.name, (char*) &sys_max_sort_length, SHOW_SYS},
{sys_max_user_connections.name,(char*) &sys_max_user_connections, SHOW_SYS},
@@ -697,6 +705,26 @@ void fix_delay_key_write(THD *thd, enum_var_type type)
}
}
+void fix_max_binlog_size(THD *thd, enum_var_type type)
+{
+ DBUG_ENTER("fix_max_binlog_size");
+ DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu",
+ max_binlog_size, max_relay_log_size));
+ mysql_bin_log.set_max_size(max_binlog_size);
+ if (!max_relay_log_size)
+ active_mi->rli.relay_log.set_max_size(max_binlog_size);
+ DBUG_VOID_RETURN;
+}
+
+void fix_max_relay_log_size(THD *thd, enum_var_type type)
+{
+ DBUG_ENTER("fix_max_relay_log_size");
+ DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu",
+ max_binlog_size, max_relay_log_size));
+ active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
+ max_relay_log_size: max_binlog_size);
+ DBUG_VOID_RETURN;
+}
bool sys_var_long_ptr::update(THD *thd, set_var *var)
{
diff --git a/sql/slave.cc b/sql/slave.cc
index aa9dd14b1c7..f004ed538b0 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -1235,7 +1235,17 @@ int init_relay_log_info(RELAY_LOG_INFO* rli, const char* info_fname)
if (open_log(&rli->relay_log, glob_hostname, opt_relay_logname,
"-relay-bin", opt_relaylog_index_name,
LOG_BIN, 1 /* read_append cache */,
- 1 /* no auto events */))
+ 1 /* no auto events */,
+ /*
+ For the maximum size, we choose max_relay_log_size if it is
+ non-zero, max_binlog_size otherwise. If later the user does SET
+ GLOBAL on one of these variables, fix_max_binlog_size and
+ fix_max_relay_log_size will reconsider the choice (for example
+ if the user changes max_relay_log_size to zero, we have to
+ switch to using max_binlog_size for the relay log) and update
+ rli->relay_log.max_size (and mysql_bin_log.max_size).
+ */
+ max_relay_log_size ? max_relay_log_size : max_binlog_size))
{
sql_print_error("Failed in open_log() called from init_relay_log_info()");
DBUG_RETURN(1);
@@ -3421,6 +3431,46 @@ err:
DBUG_RETURN(0);
}
+/*
+ Rotate a relay log (this is used only by FLUSH LOGS; the automatic rotation
+ because of size is simpler because when we do it we already have all relevant
+ locks; here we don't, so this function is mainly taking locks).
+ Returns nothing as we cannot catch any error (MYSQL_LOG::new_file() is void).
+*/
+
+void rotate_relay_log(MASTER_INFO* mi)
+{
+ DBUG_ENTER("rotate_relay_log");
+ RELAY_LOG_INFO* rli= &mi->rli;
+ /* If this server is not a slave (or RESET SLAVE has just been run) */
+ if (!rli->inited)
+ {
+ DBUG_PRINT("info", ("rli->inited=0"));
+ DBUG_VOID_RETURN;
+ }
+ lock_slave_threads(mi);
+ pthread_mutex_lock(&rli->data_lock);
+ /* If the relay log is closed, new_file() will do nothing. */
+ rli->relay_log.new_file(1);
+ /*
+ We harvest now, because otherwise BIN_LOG_HEADER_SIZE will not immediately
+ be counted, so imagine a succession of FLUSH LOGS and assume the slave
+ threads are started:
+ relay_log_space decreases by the size of the deleted relay log, but does not
+ increase, so flush-after-flush we may become negative, which is wrong.
+ Even if this will be corrected as soon as a query is replicated on the slave
+ (because the I/O thread will then call harvest_bytes_written() which will
+ harvest all these BIN_LOG_HEADER_SIZE we forgot), it may give strange output
+ in SHOW SLAVE STATUS meanwhile. So we harvest now.
+ If the log is closed, then this will just harvest the last writes, probably
+ 0 as they probably have been harvested.
+ */
+ rli->relay_log.harvest_bytes_written(&rli->log_space_total);
+ pthread_mutex_unlock(&rli->data_lock);
+ unlock_slave_threads(mi);
+ DBUG_VOID_RETURN;
+}
+
#ifdef __GNUC__
template class I_List_iterator<i_string>;
diff --git a/sql/slave.h b/sql/slave.h
index 6a73c86d304..aedb21757f8 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -403,6 +403,7 @@ int init_relay_log_pos(RELAY_LOG_INFO* rli,const char* log,ulonglong pos,
int purge_relay_logs(RELAY_LOG_INFO* rli, THD *thd, bool just_reset,
const char** errmsg);
+void rotate_relay_log(MASTER_INFO* mi);
extern "C" pthread_handler_decl(handle_slave_io,arg);
extern "C" pthread_handler_decl(handle_slave_sql,arg);
diff --git a/sql/sql_class.h b/sql/sql_class.h
index d1b2ef82ccb..71b943b5d26 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -84,6 +84,17 @@ class MYSQL_LOG {
bool no_rotate;
bool need_start_event;
bool no_auto_events; // for relay binlog
+ /*
+ The max size before rotation (usable only if log_type == LOG_BIN: binary
+ logs and relay logs).
+ For a binlog, max_size should be max_binlog_size.
+ For a relay log, it should be max_relay_log_size if this is non-zero,
+ max_binlog_size otherwise.
+ max_size is set in init(), and dynamically changed (when one does SET
+ GLOBAL MAX_BINLOG_SIZE|MAX_RELAY_LOG_SIZE) by fix_max_binlog_size and
+ fix_max_relay_log_size).
+ */
+ ulong max_size;
friend class Log_event;
public:
@@ -105,17 +116,18 @@ public:
bytes_written=0;
DBUG_VOID_RETURN;
}
+ void set_max_size(ulong max_size_arg);
void signal_update() { pthread_cond_broadcast(&update_cond);}
void wait_for_update(THD* thd);
void set_need_start_event() { need_start_event = 1; }
void init(enum_log_type log_type_arg,
- enum cache_type io_cache_type_arg = WRITE_CACHE,
- bool no_auto_events_arg = 0);
+ enum cache_type io_cache_type_arg,
+ bool no_auto_events_arg, ulong max_size);
void cleanup();
bool open(const char *log_name,enum_log_type log_type,
const char *new_name, const char *index_file_name_arg,
enum cache_type io_cache_type_arg,
- bool no_auto_events_arg);
+ bool no_auto_events_arg, ulong max_size);
void new_file(bool need_lock= 1);
bool write(THD *thd, enum enum_server_command command,
const char *format,...);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c5b08c6121a..b8ac230f828 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3571,10 +3571,18 @@ bool reload_acl_and_cache(THD *thd, ulong options, TABLE_LIST *tables)
}
if (options & REFRESH_LOG)
{
+ /*
+ Flush the normal query log, the update log, the binary log, the slow query
+ log, and the relay log (if it exists).
+ */
mysql_log.new_file(1);
mysql_update_log.new_file(1);
mysql_bin_log.new_file(1);
mysql_slow_log.new_file(1);
+ LOCK_ACTIVE_MI;
+ rotate_relay_log(active_mi);
+ UNLOCK_ACTIVE_MI;
+
if (ha_flush_logs())
result=1;
if (flush_error_log())