diff options
author | unknown <monty@donna.mysql.com> | 2000-12-07 14:08:48 +0200 |
---|---|---|
committer | unknown <monty@donna.mysql.com> | 2000-12-07 14:08:48 +0200 |
commit | 29907fc5a4e0982e4bd287355bf79ab6e429795a (patch) | |
tree | 8a5c9d678d477bb2c3fa95057c9299dcf9560aab /sql/log.cc | |
parent | e5c585861e6bf411fd64a18d3a08dbacf039d21a (diff) | |
download | mariadb-git-29907fc5a4e0982e4bd287355bf79ab6e429795a.tar.gz |
Only write full transactions to binary log
A lot of new functions for BDB tables
Fix for DROP DATABASE on windows
Default server_id variables
Docs/manual.texi:
Update of BDB info + Changes
configure.in:
Added test of readlink
include/mysqld_error.h:
Added new error message
sql/ha_berkeley.cc:
Added storing of status, CHECK, ANALYZE and OPTIMIZE TABLE
sql/ha_berkeley.h:
Added storing of status, CHECK, ANALYZE and OPTIMIZE TABLE
sql/handler.cc:
Only write full transactions to binary log
sql/hostname.cc:
cleanup
sql/log.cc:
Only write full transactions to binary log
sql/log_event.h:
Only write full transactions to binary log
sql/mf_iocache.cc:
Changes to be able to use IO_CACHE to save statements in a transaction
sql/mysql_priv.h:
New variables
sql/mysqld.cc:
Only write full transactions to binary log
Added default values for server_id
Lots of new bdb options
sql/share/czech/errmsg.sys:
Added new error message
sql/share/czech/errmsg.txt:
Added new error message
sql/share/danish/errmsg.sys:
Added new error message
sql/share/danish/errmsg.txt:
Added new error message
sql/share/dutch/errmsg.sys:
Added new error message
sql/share/dutch/errmsg.txt:
Added new error message
sql/share/english/errmsg.sys:
Added new error message
sql/share/english/errmsg.txt:
Added new error message
sql/share/estonian/errmsg.sys:
Added new error message
sql/share/estonian/errmsg.txt:
Added new error message
sql/share/french/errmsg.sys:
Added new error message
sql/share/french/errmsg.txt:
Added new error message
sql/share/german/errmsg.sys:
Added new error message
sql/share/german/errmsg.txt:
Added new error message
sql/share/greek/errmsg.sys:
Added new error message
sql/share/greek/errmsg.txt:
Added new error message
sql/share/hungarian/errmsg.sys:
Added new error message
sql/share/hungarian/errmsg.txt:
Added new error message
sql/share/italian/errmsg.sys:
Added new error message
sql/share/italian/errmsg.txt:
Added new error message
sql/share/japanese/errmsg.sys:
Added new error message
sql/share/japanese/errmsg.txt:
Added new error message
sql/share/korean/errmsg.sys:
Added new error message
sql/share/korean/errmsg.txt:
Added new error message
sql/share/norwegian-ny/errmsg.txt:
Added new error message
sql/share/norwegian/errmsg.txt:
Added new error message
sql/share/polish/errmsg.sys:
Added new error message
sql/share/polish/errmsg.txt:
Added new error message
sql/share/portuguese/errmsg.sys:
Added new error message
sql/share/portuguese/errmsg.txt:
Added new error message
sql/share/romanian/errmsg.txt:
Added new error message
sql/share/russian/errmsg.sys:
Added new error message
sql/share/russian/errmsg.txt:
Added new error message
sql/share/slovak/errmsg.sys:
Added new error message
sql/share/slovak/errmsg.txt:
Added new error message
sql/share/spanish/errmsg.sys:
Added new error message
sql/share/spanish/errmsg.txt:
Added new error message
sql/share/swedish/errmsg.OLD:
Added new error message
sql/share/swedish/errmsg.sys:
Added new error message
sql/share/swedish/errmsg.txt:
Added new error message
sql/sql_base.cc:
cleanup
sql/sql_class.cc:
Only write full transactions to binary log
sql/sql_class.h:
Added error handling of failed writes to logs
sql/sql_db.cc:
Fix for DROP DATABASE on windows
sql/sql_delete.cc:
Only write full transactions to binary log
sql/sql_insert.cc:
Only write full transactions to binary log
sql/sql_load.cc:
Only write full transactions to binary log
sql/sql_parse.cc:
End transaction at DROP, RENAME, CREATE and TRUNCATE
sql/sql_table.cc:
Fixes for ALTER TABLE on BDB tables for windows
sql/sql_update.cc:
Only write full transactions to binary log
sql/sql_yacc.yy:
AGAINST is not anymore a reserved word
support-files/my-huge.cnf.sh:
Changed to use binary log
support-files/my-large.cnf.sh:
Changed to use binary log
support-files/my-medium.cnf.sh:
Changed to use binary log
support-files/my-small.cnf.sh:
Changed to use binary log
Diffstat (limited to 'sql/log.cc')
-rw-r--r-- | sql/log.cc | 240 |
1 files changed, 152 insertions, 88 deletions
diff --git a/sql/log.cc b/sql/log.cc index 2dda594ea59..1c377ebc3a5 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -16,6 +16,7 @@ /* logging of commands */ +/* TODO: Abort logging when we get an error in reading or writing log files */ #include "mysql_priv.h" #include "sql_acl.h" @@ -523,14 +524,12 @@ void MYSQL_LOG::new_file() } -void MYSQL_LOG::write(THD *thd,enum enum_server_command command, +bool MYSQL_LOG::write(THD *thd,enum enum_server_command command, const char *format,...) { if (is_open() && (what_to_log & (1L << (uint) command))) { - va_list args; - va_start(args,format); - char buff[32]; + int error=0; VOID(pthread_mutex_lock(&LOCK_log)); /* Test if someone closed after the is_open test */ @@ -538,14 +537,17 @@ void MYSQL_LOG::write(THD *thd,enum enum_server_command command, { time_t skr; ulong id; - int error=0; + va_list args; + va_start(args,format); + char buff[32]; + if (thd) { // Normal thread if ((thd->options & OPTION_LOG_OFF) && (thd->master_access & PROCESS_ACL)) { VOID(pthread_mutex_unlock(&LOCK_log)); - return; // No logging + return 0; // No logging } id=thd->thread_id; if (thd->user_time || !(skr=thd->query_start())) @@ -593,115 +595,184 @@ void MYSQL_LOG::write(THD *thd,enum enum_server_command command, write_error=1; sql_print_error(ER(ER_ERROR_ON_WRITE),name,error); } + va_end(args); + VOID(pthread_mutex_unlock(&LOCK_log)); } - va_end(args); VOID(pthread_mutex_unlock(&LOCK_log)); + return error != 0; } + return 0; } /* Write to binary log in a format to be used for replication */ -void MYSQL_LOG::write(Query_log_event* event_info) +bool MYSQL_LOG::write(Query_log_event* event_info) { + /* In most cases this is only called if 'is_open()' is true */ + bool error=1; + VOID(pthread_mutex_lock(&LOCK_log)); if (is_open()) { - VOID(pthread_mutex_lock(&LOCK_log)); - if (is_open()) + THD *thd=event_info->thd; + IO_CACHE *file = (event_info->cache_stmt ? &thd->transaction.trans_log : + &log_file); + if ((!(thd->options & OPTION_BIN_LOG) && + thd->master_access & PROCESS_ACL) || + !db_ok(event_info->db, binlog_do_db, binlog_ignore_db)) { - THD *thd=event_info->thd; - if ((!(thd->options & OPTION_BIN_LOG) && - thd->master_access & PROCESS_ACL) || - !db_ok(event_info->db, binlog_do_db, binlog_ignore_db)) - { - VOID(pthread_mutex_unlock(&LOCK_log)); - return; - } + VOID(pthread_mutex_unlock(&LOCK_log)); + return 0; + } - if (thd->last_insert_id_used) - { - Intvar_log_event e((uchar)LAST_INSERT_ID_EVENT, thd->last_insert_id); - if (e.write(&log_file)) - { - sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); - goto err; - } - } - if (thd->insert_id_used) - { - Intvar_log_event e((uchar)INSERT_ID_EVENT, thd->last_insert_id); - if (e.write(&log_file)) - { - sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); - goto err; - } - } - if (thd->convert_set) + if (thd->last_insert_id_used) + { + Intvar_log_event e((uchar)LAST_INSERT_ID_EVENT, thd->last_insert_id); + if (e.write(file)) + goto err; + } + if (thd->insert_id_used) + { + Intvar_log_event e((uchar)INSERT_ID_EVENT, thd->last_insert_id); + if (e.write(file)) + goto err; + } + if (thd->convert_set) + { + char buf[1024] = "SET CHARACTER SET "; + char* p = strend(buf); + p = strmov(p, thd->convert_set->name); + int save_query_length = thd->query_length; + // just in case somebody wants it later + thd->query_length = (uint)(p - buf); + Query_log_event e(thd, buf); + if (e.write(file)) + goto err; + thd->query_length = save_query_length; // clean up + } + if (event_info->write(file) || + file == &log_file && flush_io_cache(file)) + goto err; + error=0; + +err: + if (error) + { + if (my_errno == EFBIG) + my_error(ER_TRANS_CACHE_FULL, MYF(0)); + else + my_error(ER_ERROR_ON_WRITE, MYF(0), name, errno); + write_error=1; + } + if (file == &log_file) + VOID(pthread_cond_broadcast(&COND_binlog_update)); + } + else + error=0; + VOID(pthread_mutex_unlock(&LOCK_log)); + return error; +} + +/* + Write a cached log entry to the binary log + We only come here if there is something in the cache. + 'cache' needs to be reinitialized after this functions returns. +*/ + +bool MYSQL_LOG::write(IO_CACHE *cache) +{ + VOID(pthread_mutex_lock(&LOCK_log)); + bool error=1; + if (is_open()) + { + uint length; + my_off_t start_pos=my_b_tell(&log_file); + + if (reinit_io_cache(cache, WRITE_CACHE, 0, 0, 0)) + { + if (!write_error) + sql_print_error(ER(ER_ERROR_ON_WRITE), cache->file_name, errno); + goto err; + } + while ((length=my_b_fill(cache))) + { + if (my_b_write(&log_file, cache->rc_pos, length)) { - char buf[1024] = "SET CHARACTER SET "; - char* p = strend(buf); - p = strmov(p, thd->convert_set->name); - int save_query_length = thd->query_length; - // just in case somebody wants it later - thd->query_length = (uint)(p - buf); - Query_log_event e(thd, buf); - if (e.write(&log_file)) - { + if (!write_error) sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); - goto err; - } - thd->query_length = save_query_length; // clean up + goto err; } - if (event_info->write(&log_file) || flush_io_cache(&log_file)) - { + cache->rc_pos=cache->rc_end; // Mark buffer used up + } + if (flush_io_cache(&log_file)) + { + if (!write_error) sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); - } - err: - VOID(pthread_cond_broadcast(&COND_binlog_update)); + goto err; + } + if (cache->error) // Error on read + { + if (!write_error) + sql_print_error(ER(ER_ERROR_ON_READ), cache->file_name, errno); + goto err; } - VOID(pthread_mutex_unlock(&LOCK_log)); } + error=0; + +err: + if (error) + write_error=1; + else + VOID(pthread_cond_broadcast(&COND_binlog_update)); + + VOID(pthread_mutex_unlock(&LOCK_log)); + return error; } -void MYSQL_LOG::write(Load_log_event* event_info) + +bool MYSQL_LOG::write(Load_log_event* event_info) { + bool error=0; + VOID(pthread_mutex_lock(&LOCK_log)); if (is_open()) { - VOID(pthread_mutex_lock(&LOCK_log)); - if (is_open()) + THD *thd=event_info->thd; + if ((thd->options & OPTION_BIN_LOG) || + !(thd->master_access & PROCESS_ACL)) { - THD *thd=event_info->thd; - if ((thd->options & OPTION_BIN_LOG) || - !(thd->master_access & PROCESS_ACL)) + if (event_info->write(&log_file) || flush_io_cache(&log_file)) { - if (event_info->write(&log_file) || flush_io_cache(&log_file)) + if (!write_error) sql_print_error(ER(ER_ERROR_ON_WRITE), name, errno); - VOID(pthread_cond_broadcast(&COND_binlog_update)); + error=write_error=1; } + VOID(pthread_cond_broadcast(&COND_binlog_update)); } - VOID(pthread_mutex_unlock(&LOCK_log)); } + VOID(pthread_mutex_unlock(&LOCK_log)); + return error; } /* Write update log in a format suitable for incremental backup */ -void MYSQL_LOG::write(THD *thd,const char *query, uint query_length, +bool MYSQL_LOG::write(THD *thd,const char *query, uint query_length, time_t query_start) { + bool error=0; if (is_open()) { time_t current_time; VOID(pthread_mutex_lock(&LOCK_log)); if (is_open()) { // Safety agains reopen - int error=0; + int tmp_errno=0; char buff[80],*end; end=buff; if (!(thd->options & OPTION_UPDATE_LOG) && (thd->master_access & PROCESS_ACL)) { VOID(pthread_mutex_unlock(&LOCK_log)); - return; + return 0; } if ((specialflag & SPECIAL_LONG_LOG_FORMAT) || query_start) { @@ -722,14 +793,14 @@ void MYSQL_LOG::write(THD *thd,const char *query, uint query_length, start->tm_min, start->tm_sec); if (my_b_write(&log_file, (byte*) buff,24)) - error=errno; + tmp_errno=errno; } if (my_b_printf(&log_file, "# User@Host: %s[%s] @ %s [%s]\n", thd->priv_user, thd->user, thd->host ? thd->host : "", thd->ip ? thd->ip : "") == (uint) -1) - error=errno; + tmp_errno=errno; } if (query_start) { @@ -739,12 +810,12 @@ void MYSQL_LOG::write(THD *thd,const char *query, uint query_length, (ulong) (current_time - query_start), (ulong) (thd->time_after_lock - query_start), (ulong) thd->sent_row_count) == (uint) -1) - error=errno; + tmp_errno=errno; } if (thd->db && strcmp(thd->db,db)) { // Database changed if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1) - error=errno; + tmp_errno=errno; strmov(db,thd->db); } if (thd->last_insert_id_used) @@ -777,7 +848,7 @@ void MYSQL_LOG::write(THD *thd,const char *query, uint query_length, *end=0; if (my_b_write(&log_file, (byte*) "SET ",4) || my_b_write(&log_file, (byte*) buff+1,(uint) (end-buff)-1)) - error=errno; + tmp_errno=errno; } if (!query) { @@ -787,29 +858,22 @@ void MYSQL_LOG::write(THD *thd,const char *query, uint query_length, if (my_b_write(&log_file, (byte*) query,query_length) || my_b_write(&log_file, (byte*) ";\n",2) || flush_io_cache(&log_file)) - error=errno; - if (error && ! write_error) + tmp_errno=errno; + if (tmp_errno) { - write_error=1; - sql_print_error(ER(ER_ERROR_ON_WRITE),name,error); + error=1; + if (! write_error) + { + write_error=1; + sql_print_error(ER(ER_ERROR_ON_WRITE),name,error); + } } } VOID(pthread_mutex_unlock(&LOCK_log)); } + return error; } -#ifdef TO_BE_REMOVED -void MYSQL_LOG::flush() -{ - if (is_open()) - if (flush_io_cache(log_file) && ! write_error) - { - write_error=1; - sql_print_error(ER(ER_ERROR_ON_WRITE),name,errno); - } -} -#endif - void MYSQL_LOG::close(bool exiting) { // One can't set log_type here! |