diff --git a/sql/log.cc b/sql/log.cc index d189f1f1fe3..69957c5c97c 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -157,7 +157,7 @@ void MYSQL_LOG::close_index() } void MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, - const char *new_name) + const char *new_name, bool null_created) { MY_STAT tmp_stat; char buff[512]; @@ -230,8 +230,10 @@ void MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, if ((do_magic && my_b_write(&log_file, (byte*) BINLOG_MAGIC, 4)) || open_index(O_APPEND | O_RDWR | O_CREAT)) goto err; - Start_log_event s; bool error; + Start_log_event s; + if (null_created) + s.created= 0; s.write(&log_file); flush_io_cache(&log_file); pthread_mutex_lock(&LOCK_index); @@ -548,7 +550,15 @@ void MYSQL_LOG::new_file(bool inside_mutex) strmov(new_name, old_name); // Reopen old file name name=0; close(); - open(old_name, log_type, new_name); + /* + new_file() is only used for rotation (in FLUSH LOGS or because size > + max_binlog_size). + If this is a binary log, the Start_log_event at the beginning of + the new file should have created=0 (to distinguish with the Start_log_event + written at server startup, which should trigger temp tables deletion on + >=4.0.14 slaves). + */ + open(old_name, log_type, new_name, 1); my_free(old_name,MYF(0)); last_time=query_start=0; write_error=0; diff --git a/sql/log_event.h b/sql/log_event.h index 68696442490..bb1c9260e21 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -327,6 +327,15 @@ extern char server_version[SERVER_VERSION_LENGTH]; class Start_log_event: public Log_event { public: + /* + If this event is at the start of the first binary log since server startup + 'created' should be the timestamp when the event (and the binary log) was + created. + In the other case (i.e. this event is at the start of a binary log created + by FLUSH LOGS or automatic rotation), 'created' should be 0. + This "trick" is used by MySQL >=4.0.14 slaves to know if they must drop the + stale temporary tables or not. + */ time_t created; uint16 binlog_version; char server_version[50]; diff --git a/sql/sql_class.h b/sql/sql_class.h index d9497907926..8abf87c4cda 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -73,7 +73,7 @@ public: void set_index_file_name(const char* index_file_name = 0); void init(enum_log_type log_type_arg); void open(const char *log_name,enum_log_type log_type, - const char *new_name=0); + const char *new_name=0, bool null_created= 0); void new_file(bool inside_mutex = 0); bool open_index(int options); void close_index();