Loading mysql-test/r/csv.result +2 −2 Original line number Diff line number Diff line Loading @@ -4944,10 +4944,10 @@ val UPDATE bug13894 SET val=6 WHERE val=10; SELECT * FROM bug13894; val 5 11 6 6 5 11 DROP TABLE bug13894; DROP TABLE IF EXISTS bug14672; CREATE TABLE bug14672 (c1 integer) engine = CSV; Loading sql/ha_ndbcluster_binlog.cc +2 −2 Original line number Diff line number Diff line Loading @@ -453,7 +453,7 @@ static void ndbcluster_binlog_wait(THD *thd) } /* Called from MYSQL_LOG::reset_logs in log.cc when binlog is emptied Called from MYSQL_BIN_LOG::reset_logs in log.cc when binlog is emptied */ static int ndbcluster_reset_logs(THD *thd) { Loading @@ -477,7 +477,7 @@ static int ndbcluster_reset_logs(THD *thd) } /* Called from MYSQL_LOG::purge_logs in log.cc when the binlog "file" Called from MYSQL_BIN_LOG::purge_logs in log.cc when the binlog "file" is removed */ Loading sql/log.cc +610 −446 File changed.Preview size limit exceeded, changes collapsed. Show changes sql/log.h +81 −52 Original line number Diff line number Diff line Loading @@ -147,33 +147,85 @@ typedef struct st_log_info class Log_event; class Rows_log_event; enum enum_log_type { LOG_CLOSED, LOG_TO_BE_OPENED, LOG_NORMAL, LOG_NEW, LOG_BIN}; enum enum_log_type { LOG_UNKNOWN, LOG_NORMAL, LOG_BIN }; enum enum_log_state { LOG_OPENED, LOG_CLOSED, LOG_TO_BE_OPENED }; /* TODO split MYSQL_LOG into base MYSQL_LOG and MYSQL_QUERY_LOG, MYSQL_SLOW_LOG, MYSQL_BIN_LOG most of the code from MYSQL_LOG should be in the MYSQL_BIN_LOG only (TC_LOG included) TODO use mmap instead of IO_CACHE for binlog (mmap+fsync is two times faster than write+fsync) */ class MYSQL_LOG: public TC_LOG class MYSQL_LOG { public: MYSQL_LOG(); void init_pthread_objects(); void cleanup(); bool open(const char *log_name, enum_log_type log_type, const char *new_name, enum cache_type io_cache_type_arg); void init(enum_log_type log_type_arg, enum cache_type io_cache_type_arg); void close(uint exiting); inline bool is_open() { return log_state != LOG_CLOSED; } const char *generate_name(const char *log_name, const char *suffix, bool strip_ext, char *buff); int generate_new_name(char *new_name, const char *log_name); protected: /* LOCK_log is inited by init_pthread_objects() */ pthread_mutex_t LOCK_log; char *name; char log_file_name[FN_REFLEN]; char time_buff[20], db[NAME_LEN + 1]; bool write_error, inited; IO_CACHE log_file; enum_log_type log_type; volatile enum_log_state log_state; enum cache_type io_cache_type; friend class Log_event; }; class MYSQL_QUERY_LOG: public MYSQL_LOG { public: MYSQL_QUERY_LOG() : last_time(0) {} void reopen_file(); bool write(time_t event_time, const char *user_host, uint user_host_len, int thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len); bool write(THD *thd, time_t current_time, time_t query_start_arg, const char *user_host, uint user_host_len, longlong query_time, longlong lock_time, bool is_command, const char *sql_text, uint sql_text_len); bool open_slow_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE); } bool open_query_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE); } private: time_t last_time; }; class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG { private: /* LOCK_log and LOCK_index are inited by init_pthread_objects() */ pthread_mutex_t LOCK_log, LOCK_index; pthread_mutex_t LOCK_index; pthread_mutex_t LOCK_prep_xids; pthread_cond_t COND_prep_xids; pthread_cond_t update_cond; ulonglong bytes_written; time_t last_time,query_start; IO_CACHE log_file; IO_CACHE index_file; char *name; char time_buff[20],db[NAME_LEN+1]; char log_file_name[FN_REFLEN],index_file_name[FN_REFLEN]; char index_file_name[FN_REFLEN]; /* The max size before rotation (usable only if log_type == LOG_BIN: binary logs and relay logs). Loading @@ -186,13 +238,10 @@ class MYSQL_LOG: public TC_LOG */ ulong max_size; ulong prepared_xids; /* for tc log - number of xids to remember */ volatile enum_log_type log_type; enum cache_type io_cache_type; // current file sequence number for load data infile binary logging uint file_id; uint open_count; // For replication int readers_count; bool write_error, inited; bool need_start_event; /* no_auto_events means we don't want any of these automatic events : Loading @@ -202,13 +251,21 @@ class MYSQL_LOG: public TC_LOG In 5.0 it's 0 for relay logs too! */ bool no_auto_events; friend class Log_event; ulonglong m_table_map_version; int write_to_file(IO_CACHE *cache); /* This is used to start writing to a new log file. The difference from new_file() is locking. new_file_without_locking() does not acquire LOCK_log. */ void new_file_without_locking(); void new_file_impl(bool need_lock); public: MYSQL_LOG::generate_name; MYSQL_LOG::is_open; /* These describe the log's format. This is used only for relay logs. _for_exec is used by the SQL thread, _for_queue by the I/O thread. It's Loading @@ -220,9 +277,9 @@ class MYSQL_LOG: public TC_LOG Format_description_log_event *description_event_for_exec, *description_event_for_queue; MYSQL_LOG(); MYSQL_BIN_LOG(); /* note that there's no destructor ~MYSQL_LOG() ! note that there's no destructor ~MYSQL_BIN_LOG() ! The reason is that we don't want it to be automatically called on exit() - but only during the correct shutdown process */ Loading Loading @@ -264,9 +321,7 @@ class MYSQL_LOG: public TC_LOG void signal_update(); void wait_for_update(THD* thd, bool master_or_slave); void set_need_start_event() { need_start_event = 1; } void init(enum_log_type log_type_arg, enum cache_type io_cache_type_arg, bool no_auto_events_arg, ulong max_size); void init(bool no_auto_events_arg, ulong max_size); void init_pthread_objects(); void cleanup(); bool open(const char *log_name, Loading @@ -275,35 +330,10 @@ class MYSQL_LOG: public TC_LOG enum cache_type io_cache_type_arg, bool no_auto_events_arg, ulong max_size, bool null_created); const char *generate_name(const char *log_name, const char *suffix, bool strip_ext, char *buff); /* simplified open_xxx wrappers for the gigantic open above */ bool open_query_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE, 0, 0, 0); } bool open_slow_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE, 0, 0, 0); } bool open_index_file(const char *index_file_name_arg, const char *log_name); void new_file(bool need_lock); /* log a command to the old-fashioned general log */ bool write(time_t event_time, const char *user_host, uint user_host_len, int thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len); /* log a query to the old-fashioned slow query log */ bool write(THD *thd, time_t current_time, time_t query_start_arg, const char *user_host, uint user_host_len, longlong query_time, longlong lock_time, bool is_command, const char *sql_text, uint sql_text_len); /* Use this to start writing a new log file */ void new_file(); bool write(Log_event* event_info); // binary log write bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event); Loading @@ -319,7 +349,6 @@ class MYSQL_LOG: public TC_LOG bool appendv(const char* buf,uint len,...); bool append(Log_event* ev); int generate_new_name(char *new_name,const char *old_name); void make_log_name(char* buf, const char* log_ident); bool is_active(const char* log_file_name); int update_log_index(LOG_INFO* linfo, bool need_update_threads); Loading @@ -339,7 +368,6 @@ class MYSQL_LOG: public TC_LOG int find_next_log(LOG_INFO* linfo, bool need_mutex); int get_current_log(LOG_INFO* linfo); uint next_file_id(); inline bool is_open() { return log_type != LOG_CLOSED; } inline char* get_index_fname() { return index_file_name;} inline char* get_log_fname() { return log_file_name; } inline char* get_name() { return name; } Loading Loading @@ -416,7 +444,8 @@ class Log_to_csv_event_handler: public Log_event_handler class Log_to_file_event_handler: public Log_event_handler { MYSQL_LOG mysql_log, mysql_slow_log; MYSQL_QUERY_LOG mysql_log; MYSQL_QUERY_LOG mysql_slow_log; bool is_initialized; public: Log_to_file_event_handler(): is_initialized(FALSE) Loading sql/log_event.h +1 −1 Original line number Diff line number Diff line Loading @@ -470,7 +470,7 @@ enum Int_event_type #ifndef MYSQL_CLIENT class String; class MYSQL_LOG; class MYSQL_BIN_LOG; class THD; #endif Loading Loading
mysql-test/r/csv.result +2 −2 Original line number Diff line number Diff line Loading @@ -4944,10 +4944,10 @@ val UPDATE bug13894 SET val=6 WHERE val=10; SELECT * FROM bug13894; val 5 11 6 6 5 11 DROP TABLE bug13894; DROP TABLE IF EXISTS bug14672; CREATE TABLE bug14672 (c1 integer) engine = CSV; Loading
sql/ha_ndbcluster_binlog.cc +2 −2 Original line number Diff line number Diff line Loading @@ -453,7 +453,7 @@ static void ndbcluster_binlog_wait(THD *thd) } /* Called from MYSQL_LOG::reset_logs in log.cc when binlog is emptied Called from MYSQL_BIN_LOG::reset_logs in log.cc when binlog is emptied */ static int ndbcluster_reset_logs(THD *thd) { Loading @@ -477,7 +477,7 @@ static int ndbcluster_reset_logs(THD *thd) } /* Called from MYSQL_LOG::purge_logs in log.cc when the binlog "file" Called from MYSQL_BIN_LOG::purge_logs in log.cc when the binlog "file" is removed */ Loading
sql/log.h +81 −52 Original line number Diff line number Diff line Loading @@ -147,33 +147,85 @@ typedef struct st_log_info class Log_event; class Rows_log_event; enum enum_log_type { LOG_CLOSED, LOG_TO_BE_OPENED, LOG_NORMAL, LOG_NEW, LOG_BIN}; enum enum_log_type { LOG_UNKNOWN, LOG_NORMAL, LOG_BIN }; enum enum_log_state { LOG_OPENED, LOG_CLOSED, LOG_TO_BE_OPENED }; /* TODO split MYSQL_LOG into base MYSQL_LOG and MYSQL_QUERY_LOG, MYSQL_SLOW_LOG, MYSQL_BIN_LOG most of the code from MYSQL_LOG should be in the MYSQL_BIN_LOG only (TC_LOG included) TODO use mmap instead of IO_CACHE for binlog (mmap+fsync is two times faster than write+fsync) */ class MYSQL_LOG: public TC_LOG class MYSQL_LOG { public: MYSQL_LOG(); void init_pthread_objects(); void cleanup(); bool open(const char *log_name, enum_log_type log_type, const char *new_name, enum cache_type io_cache_type_arg); void init(enum_log_type log_type_arg, enum cache_type io_cache_type_arg); void close(uint exiting); inline bool is_open() { return log_state != LOG_CLOSED; } const char *generate_name(const char *log_name, const char *suffix, bool strip_ext, char *buff); int generate_new_name(char *new_name, const char *log_name); protected: /* LOCK_log is inited by init_pthread_objects() */ pthread_mutex_t LOCK_log; char *name; char log_file_name[FN_REFLEN]; char time_buff[20], db[NAME_LEN + 1]; bool write_error, inited; IO_CACHE log_file; enum_log_type log_type; volatile enum_log_state log_state; enum cache_type io_cache_type; friend class Log_event; }; class MYSQL_QUERY_LOG: public MYSQL_LOG { public: MYSQL_QUERY_LOG() : last_time(0) {} void reopen_file(); bool write(time_t event_time, const char *user_host, uint user_host_len, int thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len); bool write(THD *thd, time_t current_time, time_t query_start_arg, const char *user_host, uint user_host_len, longlong query_time, longlong lock_time, bool is_command, const char *sql_text, uint sql_text_len); bool open_slow_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE); } bool open_query_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE); } private: time_t last_time; }; class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG { private: /* LOCK_log and LOCK_index are inited by init_pthread_objects() */ pthread_mutex_t LOCK_log, LOCK_index; pthread_mutex_t LOCK_index; pthread_mutex_t LOCK_prep_xids; pthread_cond_t COND_prep_xids; pthread_cond_t update_cond; ulonglong bytes_written; time_t last_time,query_start; IO_CACHE log_file; IO_CACHE index_file; char *name; char time_buff[20],db[NAME_LEN+1]; char log_file_name[FN_REFLEN],index_file_name[FN_REFLEN]; char index_file_name[FN_REFLEN]; /* The max size before rotation (usable only if log_type == LOG_BIN: binary logs and relay logs). Loading @@ -186,13 +238,10 @@ class MYSQL_LOG: public TC_LOG */ ulong max_size; ulong prepared_xids; /* for tc log - number of xids to remember */ volatile enum_log_type log_type; enum cache_type io_cache_type; // current file sequence number for load data infile binary logging uint file_id; uint open_count; // For replication int readers_count; bool write_error, inited; bool need_start_event; /* no_auto_events means we don't want any of these automatic events : Loading @@ -202,13 +251,21 @@ class MYSQL_LOG: public TC_LOG In 5.0 it's 0 for relay logs too! */ bool no_auto_events; friend class Log_event; ulonglong m_table_map_version; int write_to_file(IO_CACHE *cache); /* This is used to start writing to a new log file. The difference from new_file() is locking. new_file_without_locking() does not acquire LOCK_log. */ void new_file_without_locking(); void new_file_impl(bool need_lock); public: MYSQL_LOG::generate_name; MYSQL_LOG::is_open; /* These describe the log's format. This is used only for relay logs. _for_exec is used by the SQL thread, _for_queue by the I/O thread. It's Loading @@ -220,9 +277,9 @@ class MYSQL_LOG: public TC_LOG Format_description_log_event *description_event_for_exec, *description_event_for_queue; MYSQL_LOG(); MYSQL_BIN_LOG(); /* note that there's no destructor ~MYSQL_LOG() ! note that there's no destructor ~MYSQL_BIN_LOG() ! The reason is that we don't want it to be automatically called on exit() - but only during the correct shutdown process */ Loading Loading @@ -264,9 +321,7 @@ class MYSQL_LOG: public TC_LOG void signal_update(); void wait_for_update(THD* thd, bool master_or_slave); void set_need_start_event() { need_start_event = 1; } void init(enum_log_type log_type_arg, enum cache_type io_cache_type_arg, bool no_auto_events_arg, ulong max_size); void init(bool no_auto_events_arg, ulong max_size); void init_pthread_objects(); void cleanup(); bool open(const char *log_name, Loading @@ -275,35 +330,10 @@ class MYSQL_LOG: public TC_LOG enum cache_type io_cache_type_arg, bool no_auto_events_arg, ulong max_size, bool null_created); const char *generate_name(const char *log_name, const char *suffix, bool strip_ext, char *buff); /* simplified open_xxx wrappers for the gigantic open above */ bool open_query_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, ".log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE, 0, 0, 0); } bool open_slow_log(const char *log_name) { char buf[FN_REFLEN]; return open(generate_name(log_name, "-slow.log", 0, buf), LOG_NORMAL, 0, WRITE_CACHE, 0, 0, 0); } bool open_index_file(const char *index_file_name_arg, const char *log_name); void new_file(bool need_lock); /* log a command to the old-fashioned general log */ bool write(time_t event_time, const char *user_host, uint user_host_len, int thread_id, const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len); /* log a query to the old-fashioned slow query log */ bool write(THD *thd, time_t current_time, time_t query_start_arg, const char *user_host, uint user_host_len, longlong query_time, longlong lock_time, bool is_command, const char *sql_text, uint sql_text_len); /* Use this to start writing a new log file */ void new_file(); bool write(Log_event* event_info); // binary log write bool write(THD *thd, IO_CACHE *cache, Log_event *commit_event); Loading @@ -319,7 +349,6 @@ class MYSQL_LOG: public TC_LOG bool appendv(const char* buf,uint len,...); bool append(Log_event* ev); int generate_new_name(char *new_name,const char *old_name); void make_log_name(char* buf, const char* log_ident); bool is_active(const char* log_file_name); int update_log_index(LOG_INFO* linfo, bool need_update_threads); Loading @@ -339,7 +368,6 @@ class MYSQL_LOG: public TC_LOG int find_next_log(LOG_INFO* linfo, bool need_mutex); int get_current_log(LOG_INFO* linfo); uint next_file_id(); inline bool is_open() { return log_type != LOG_CLOSED; } inline char* get_index_fname() { return index_file_name;} inline char* get_log_fname() { return log_file_name; } inline char* get_name() { return name; } Loading Loading @@ -416,7 +444,8 @@ class Log_to_csv_event_handler: public Log_event_handler class Log_to_file_event_handler: public Log_event_handler { MYSQL_LOG mysql_log, mysql_slow_log; MYSQL_QUERY_LOG mysql_log; MYSQL_QUERY_LOG mysql_slow_log; bool is_initialized; public: Log_to_file_event_handler(): is_initialized(FALSE) Loading
sql/log_event.h +1 −1 Original line number Diff line number Diff line Loading @@ -470,7 +470,7 @@ enum Int_event_type #ifndef MYSQL_CLIENT class String; class MYSQL_LOG; class MYSQL_BIN_LOG; class THD; #endif Loading