diff options
author | unknown <petr@mysql.com> | 2006-05-05 10:45:58 +0400 |
---|---|---|
committer | unknown <petr@mysql.com> | 2006-05-05 10:45:58 +0400 |
commit | 0f5d9df3de15d3588d2b35923536ec5dd2a0e754 (patch) | |
tree | c388200837e23985854de7a23be71ad14804ceda /sql/log.h | |
parent | 6c40054624c906aa385ff114eef030bb87da5777 (diff) | |
download | mariadb-git-0f5d9df3de15d3588d2b35923536ec5dd2a0e754.tar.gz |
WL#3153 "Split logs". Recommit with post-review fixes
sql/ha_ndbcluster_binlog.cc:
use MYSQL_BIN_LOG instead of MYSQL_LOG
sql/log.cc:
Split MYSQL_LOG into base MYSQL_LOG and
MYSQL_GENERAL_LOG, MYSQL_SLOW_LOG, MYSQL_BIN_LOG
sql/log.h:
Split MYSQL_LOG into base MYSQL_LOG and
MYSQL_GENERAL_LOG, MYSQL_SLOW_LOG, MYSQL_BIN_LOG
sql/log_event.h:
use MYSQL_BIN_LOG instead of MYSQL_LOG
sql/mysql_priv.h:
use MYSQL_BIN_LOG instead of MYSQL_LOG
sql/mysqld.cc:
fix appropriate comments: use MYSQL_BIN_LOG instead of MYSQL_LOG
sql/rpl_injector.cc:
use MYSQL_BIN_LOG instead of MYSQL_LOG
sql/rpl_injector.h:
use MYSQL_BIN_LOG instead of MYSQL_LOG
sql/rpl_rli.h:
use MYSQL_BIN_LOG instead of MYSQL_LOG
sql/slave.cc:
Fix appropriate comments: use MYSQL_BIN_LOG instead of MYSQL_LOG.
Fix usage of new_file(): now we don't need to pass locking-related
info to the function.
sql/slave.h:
Use MYSQL_BIN_LOG instead of MYSQL_LOG in appropriate comments
Diffstat (limited to 'sql/log.h')
-rw-r--r-- | sql/log.h | 135 |
1 files changed, 84 insertions, 51 deletions
diff --git a/sql/log.h b/sql/log.h index 03d5466e549..589932dcac0 100644 --- a/sql/log.h +++ b/sql/log.h @@ -147,33 +147,89 @@ 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_CLOSED, LOG_TO_BE_OPENED, LOG_NORMAL, LOG_BIN}; /* - 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(); + void reopen_file(); + 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_type != 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; + volatile enum_log_type log_type; + enum cache_type io_cache_type; + time_t last_time; + + friend class Log_event; +}; + +class MYSQL_GENERAL_LOG: public MYSQL_LOG +{ +public: + MYSQL_GENERAL_LOG() {} /* get rid of gcc warning */ + 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 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); + } +}; + +class MYSQL_SLOW_LOG: public MYSQL_LOG +{ +public: + MYSQL_SLOW_LOG() {} /* get rid of gcc warning */ + 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); + } +}; + +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). @@ -186,13 +242,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 : @@ -202,13 +255,20 @@ 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; /* 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 @@ -220,9 +280,9 @@ public: 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 */ @@ -264,9 +324,7 @@ public: 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, @@ -275,35 +333,10 @@ public: 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); @@ -319,7 +352,6 @@ public: 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); @@ -416,7 +448,8 @@ public: class Log_to_file_event_handler: public Log_event_handler { - MYSQL_LOG mysql_log, mysql_slow_log; + MYSQL_GENERAL_LOG mysql_log; + MYSQL_SLOW_LOG mysql_slow_log; bool is_initialized; public: Log_to_file_event_handler(): is_initialized(FALSE) |