diff options
Diffstat (limited to 'sql/log.cc')
-rw-r--r-- | sql/log.cc | 98 |
1 files changed, 91 insertions, 7 deletions
diff --git a/sql/log.cc b/sql/log.cc index 2a755144d44..65497a3e065 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -29,9 +29,6 @@ #include <my_dir.h> #include <stdarg.h> #include <m_ctype.h> // For test_if_number -#include <assert.h> - -#define files_charset_info my_charset_latin1 MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log; extern I_List<i_string> binlog_do_db, binlog_ignore_db; @@ -102,8 +99,15 @@ MYSQL_LOG::MYSQL_LOG() MYSQL_LOG::~MYSQL_LOG() { + cleanup(); +} + +void MYSQL_LOG::cleanup() +{ if (inited) { + close(1); + inited= 0; (void) pthread_mutex_destroy(&LOCK_log); (void) pthread_mutex_destroy(&LOCK_index); (void) pthread_cond_destroy(&update_cond); @@ -202,7 +206,9 @@ bool MYSQL_LOG::open(const char *log_name, enum_log_type log_type_arg, case LOG_NORMAL: { char *end; -#ifdef __NT__ +#ifdef EMBEDDED_LIBRARY + sprintf(buff, "%s, Version: %s, embedded library\n", my_progname, server_version); +#elif __NT__ sprintf(buff, "%s, Version: %s, started with:\nTCP Port: %d, Named Pipe: %s\n", my_progname, server_version, mysql_port, mysql_unix_port); #else sprintf(buff, "%s, Version: %s, started with:\nTcp port: %d Unix socket: %s\n", my_progname,server_version,mysql_port,mysql_unix_port); @@ -612,6 +618,8 @@ err: LOG_INFO_IO Got IO error while reading file */ +#ifdef HAVE_REPLICATION + int MYSQL_LOG::purge_first_log(struct st_relay_log_info* rli) { int error; @@ -814,6 +822,8 @@ err: } +#endif /* HAVE_REPLICATION */ + /* Create a new log file name @@ -1123,6 +1133,7 @@ bool MYSQL_LOG::write(Log_event* event_info) #else IO_CACHE *file = &log_file; #endif +#ifdef HAVE_REPLICATION if ((thd && !(thd->options & OPTION_BIN_LOG) && (thd->master_access & SUPER_ACL)) || (local_db && !db_ok(local_db, binlog_do_db, binlog_ignore_db))) @@ -1131,6 +1142,7 @@ bool MYSQL_LOG::write(Log_event* event_info) DBUG_PRINT("error",("!db_ok")); DBUG_RETURN(0); } +#endif /* HAVE_REPLICATION */ error=1; /* @@ -1142,7 +1154,7 @@ bool MYSQL_LOG::write(Log_event* event_info) if (thd->last_insert_id_used) { Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT, - thd->last_insert_id); + thd->current_insert_id); e.set_log_pos(this); if (thd->server_id) e.server_id = thd->server_id; @@ -1165,6 +1177,23 @@ bool MYSQL_LOG::write(Log_event* event_info) if (e.write(file)) goto err; } + if (thd->user_var_events.elements) + { + for (uint i= 0; i < thd->user_var_events.elements; i++) + { + BINLOG_USER_VAR_EVENT *user_var_event; + get_dynamic(&thd->user_var_events,(gptr) &user_var_event, i); + User_var_log_event e(thd, user_var_event->user_var_event->name.str, + user_var_event->user_var_event->name.length, + user_var_event->value, + user_var_event->length, + user_var_event->type, + user_var_event->charset_number); + e.set_log_pos(this); + if (e.write(file)) + goto err; + } + } if (thd->variables.convert_set) { char buf[256], *p; @@ -1512,6 +1541,10 @@ void MYSQL_LOG:: wait_for_update(THD* thd) at once after close, in which case we don't want to close the index file. We only write a 'stop' event to the log if exiting is set + + NOTES + One can do an open on the object at once after doing a close. + The internal structures are not freed until cleanup() is called */ void MYSQL_LOG::close(bool exiting) @@ -1520,6 +1553,7 @@ void MYSQL_LOG::close(bool exiting) DBUG_PRINT("enter",("exiting: %d", (int) exiting)); if (is_open()) { +#ifdef HAVE_REPLICATION if (log_type == LOG_BIN && !no_auto_events && exiting) { Stop_log_event s; @@ -1527,6 +1561,7 @@ void MYSQL_LOG::close(bool exiting) s.write(&log_file); signal_update(); } +#endif /* HAVE_REPLICATION */ end_io_cache(&log_file); if (my_close(log_file.file,MYF(0)) < 0 && ! write_error) { @@ -1584,8 +1619,8 @@ static bool test_if_number(register const char *str, while (*str++ == ' ') ; if (*--str == '-' || *str == '+') str++; - while (my_isdigit(files_charset_info,*str) || (allow_wildcards && - (*str == wild_many || *str == wild_one))) + while (my_isdigit(files_charset_info,*str) || + (allow_wildcards && (*str == wild_many || *str == wild_one))) { flag=1; str++; @@ -1650,3 +1685,52 @@ void sql_perror(const char *message) perror(message); #endif } + +bool flush_error_log() +{ + bool result=0; + if (opt_error_log) + { + char err_renamed[FN_REFLEN], *end; + end= strmake(err_renamed,log_error_file,FN_REFLEN-4); + strmov(end, "-old"); +#ifdef __WIN__ + char err_temp[FN_REFLEN+4]; + /* + On Windows is necessary a temporary file for to rename + the current error file. + */ + strmov(strmov(err_temp, err_renamed),"-tmp"); + (void) my_delete(err_temp, MYF(0)); + if (freopen(err_temp,"a+",stdout)) + { + freopen(err_temp,"a+",stderr); + (void) my_delete(err_renamed, MYF(0)); + my_rename(log_error_file,err_renamed,MYF(0)); + if (freopen(log_error_file,"a+",stdout)) + freopen(log_error_file,"a+",stderr); + int fd, bytes; + char buf[IO_SIZE]; + if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0) + { + while ((bytes = (int) my_read(fd, (byte*) buf, IO_SIZE, MYF(0))) > 0) + my_fwrite(stderr, (byte*) buf, (uint) strlen(buf),MYF(0)); + my_close(fd, MYF(0)); + } + (void) my_delete(err_temp, MYF(0)); + } + else + result= 1; +#else + my_rename(log_error_file,err_renamed,MYF(0)); + if (freopen(log_error_file,"a+",stdout)) + freopen(log_error_file,"a+",stderr); + else + result= 1; +#endif + } + return result; +} + + + |