Commit 51e0c518 authored by unknown's avatar unknown

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
parent 485fbfb6
......@@ -428,7 +428,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)
{
......@@ -452,7 +452,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
*/
......
This diff is collapsed.
......@@ -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 @@ 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
*/
......@@ -264,9 +324,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,
......@@ -275,35 +333,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);
......@@ -319,7 +352,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);
......@@ -416,7 +448,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_GENERAL_LOG mysql_log;
MYSQL_SLOW_LOG mysql_slow_log;
bool is_initialized;
public:
Log_to_file_event_handler(): is_initialized(FALSE)
......
......@@ -470,7 +470,7 @@ enum Int_event_type
#ifndef MYSQL_CLIENT
class String;
class MYSQL_LOG;
class MYSQL_BIN_LOG;
class THD;
#endif
......
......@@ -1525,7 +1525,7 @@ extern char *default_tz_name;
extern my_bool opt_large_pages;
extern uint opt_large_page_size;
extern MYSQL_LOG mysql_bin_log;
extern MYSQL_BIN_LOG mysql_bin_log;
extern LOGGER logger;
extern TABLE_LIST general_log, slow_log;
extern FILE *bootstrap_file;
......
......@@ -2610,10 +2610,10 @@ static int init_common_variables(const char *conf_file_name, int argc,
global_system_variables.time_zone= my_tz_SYSTEM;
/*
Init mutexes for the global MYSQL_LOG objects.
Init mutexes for the global MYSQL_BIN_LOG objects.
As safe_mutex depends on what MY_INIT() does, we can't init the mutexes of
global MYSQL_LOGs in their constructors, because then they would be inited
before MY_INIT(). So we do it here.
global MYSQL_BIN_LOGs in their constructors, because then they would be
inited before MY_INIT(). So we do it here.
*/
mysql_bin_log.init_pthread_objects();
......
......@@ -25,7 +25,7 @@
/* inline since it's called below */
inline
injector::transaction::transaction(MYSQL_LOG *log, THD *thd)
injector::transaction::transaction(MYSQL_BIN_LOG *log, THD *thd)
: m_state(START_STATE), m_thd(thd)
{
/*
......
......@@ -26,7 +26,7 @@
/* Forward declarations */
class handler;
class MYSQL_LOG;
class MYSQL_BIN_LOG;
class st_table;
typedef st_table TABLE;
......@@ -219,7 +219,7 @@ class injector
private:
/* Only the injector may construct these object */
transaction(MYSQL_LOG *, THD *);
transaction(MYSQL_BIN_LOG *, THD *);
void swap(transaction& o) {
/* std::swap(m_start_pos, o.m_start_pos); */
......
......@@ -69,7 +69,7 @@ typedef struct st_relay_log_info
Protected with internal locks.
Must get data_lock when resetting the logs.
*/
MYSQL_LOG relay_log;
MYSQL_BIN_LOG relay_log;
LOG_INFO linfo;
IO_CACHE cache_buf,*cur_log;
......
......@@ -4570,7 +4570,7 @@ static Log_event* next_event(RELAY_LOG_INFO* rli)
When the relay log is created when the I/O thread starts, easy: the
master will send the description event and we will queue it.
But if the relay log is created by new_file(): then the solution is:
MYSQL_LOG::open() will write the buffered description event.
MYSQL_BIN_LOG::open() will write the buffered description event.
*/
if ((ev=Log_event::read_log_event(cur_log,0,
rli->relay_log.description_event_for_exec)))
......@@ -4832,7 +4832,8 @@ event(errno: %d cur_log->error: %d)",
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).
Returns nothing as we cannot catch any error (MYSQL_BIN_LOG::new_file()
is void).
*/
void rotate_relay_log(MASTER_INFO* mi)
......@@ -4854,7 +4855,7 @@ void rotate_relay_log(MASTER_INFO* mi)
}
/* If the relay log is closed, new_file() will do nothing. */
rli->relay_log.new_file(1);
rli->relay_log.new_file();
/*
We harvest now, because otherwise BIN_LOG_HEADER_SIZE will not immediately
......
......@@ -73,7 +73,7 @@
run_lock protects all information about the run state: slave_running, and the
existence of the I/O thread (to stop/start it, you need this mutex).
data_lock protects some moving members of the struct: counters (log name,
position) and relay log (MYSQL_LOG object).
position) and relay log (MYSQL_BIN_LOG object).
In RELAY_LOG_INFO: run_lock, data_lock
see MASTER_INFO
......@@ -81,7 +81,7 @@
Order of acquisition: if you want to have LOCK_active_mi and a run_lock, you
must acquire LOCK_active_mi first.
In MYSQL_LOG: LOCK_log, LOCK_index of the binlog and the relay log
In MYSQL_BIN_LOG: LOCK_log, LOCK_index of the binlog and the relay log
LOCK_log: when you write to it. LOCK_index: when you create/delete a binlog
(so that you have to update the .index file).
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment