diff options
author | unknown <petr/cps@mysql.com/owlet.local> | 2006-10-13 17:26:46 +0400 |
---|---|---|
committer | unknown <petr/cps@mysql.com/owlet.local> | 2006-10-13 17:26:46 +0400 |
commit | 9438b9851901c48f8e280c2665f9469c2f998c2f (patch) | |
tree | d9ddce943269971a31abcd891f5801ef0afea94f /sql/log.h | |
parent | d57163fcf84d6fc0e8cad5fdbbe5c14274eb694c (diff) | |
download | mariadb-git-9438b9851901c48f8e280c2665f9469c2f998c2f.tar.gz |
Fix for Bug #17544 "Cannot do atomic log rotate",
Bug #21785 "Server crashes after rename of the log table" and
Bug #21966 "Strange warnings on create like/repair of the log
tables"
According to the patch, from now on, one should use RENAME to
perform a log table rotation (this should also be reflected in
the manual).
Here is a sample:
use mysql;
CREATE TABLE IF NOT EXISTS general_log2 LIKE general_log;
RENAME TABLE general_log TO general_log_backup, general_log2 TO general_log;
The rules for Rename of the log tables are following:
IF 1. Log tables are enabled
AND 2. Rename operates on the log table and nothing is being
renamed to the log table.
DO 3. Throw an error message.
ELSE 4. Perform rename.
The very RENAME query will go the the old (backup) table. This is
consistent with the behavoiur we have with binlog ROTATE LOGS
statement.
Other problems, which are solved by the patch are:
1) Now REPAIR of the log table is exclusive operation (as it should be), this
also eliminates lock-related warnings. and
2) CREATE LIKE TABLE now usese usual read lock on the source table rather
then name lock, which is too restrictive. This way we get rid of another
log table-related warning, which occured because of the above fact
(as a side-effect, name lock resulted in a warning).
mysql-test/r/log_tables.result:
update result file
mysql-test/t/log_tables.test:
Add tests for the bugs
sql/handler.cc:
update comment
sql/handler.h:
update function to reflect changes in log tables
locking logic.
sql/lock.cc:
Now we allow locking of the log tables for "privileged" threads
Privileged thread must explicitly close and lock log tables. This
is required for admin operations such as REPAIR.
sql/log.cc:
Changes to the file:
1) Add checks for table schema. It's more important now,
as we allow rename of the log tables. Since we should
check for schema when writing to a log table.
E.g. if one created a table with one-only comlumn and
renamed it to general_log, the server should cope with
it.
2) refactor LOGGER::flush(), so that we can now use the same
machinery as we use in FLUSH LOGS in other statements:
whenever we have to perform a serious operation on the log
tables, we have to
(a) lock logger, which blocks other concurrent statements (such
as selects) (b) close logs. Then perform an
exclusive operation, c) reenable logs and d) unlock logger.
3) Add a function to check if a given table is a log table.
4) Add support for "privileged" thread
5) merge is_[general/slow]_log_table_enabled() into one function.
6) Add new function: reopen _log_tables, which reopens the tables,
which were enabled (after temporary close, required for admin
operation)
sql/log.h:
1) add a new call close_n_lock_tables(). Now we use it instead of
LOGGER::flush() in FLUSH LOGS implementation.
2) add a prototype for the function to check if a given
table is a log table;
3) add privileged table flag to table logger
4) merge is_[general/slow]_log_table_enabled()
into one function.
sql/mysql_priv.h:
move log table defines to log.h
sql/sql_delete.cc:
use new function check_if_log_table() instead of direct strcmp
sql/sql_rename.cc:
Traverse the list of tables in mysql_rename_tables
to make sure that log tables are processed correctly
(that is, according to the rules specified in the
main CS comment)
sql/sql_table.cc:
1) mysql_admin_table() should disable logs if it performs
exclusive admin operation on a log table. This way we
also eliminate warning on REPAIR of the log table.
2) mysql_create_like_table should read-lock the source table
instead getting name lock on it. Name lock is too restrictive
in this case.
sql/share/errmsg.txt:
Add a new error message for rename of the log tables
sql/table.cc:
use new function instead of direct strcmp.
change my_strcasecmp() -> strcmp(), when
comparing system db and table names
storage/csv/ha_tina.cc:
update function to reflect changes in log tables
locking logic.
storage/myisam/ha_myisam.cc:
update function to reflect changes in log tables
locking logic.
Diffstat (limited to 'sql/log.h')
-rw-r--r-- | sql/log.h | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/sql/log.h b/sql/log.h index d598952a853..fd8453649b3 100644 --- a/sql/log.h +++ b/sql/log.h @@ -403,6 +403,9 @@ public: }; +int check_if_log_table(uint db_len, const char *db, uint table_name_len, + const char *table_name, uint check_if_opened); + class Log_to_csv_event_handler: public Log_event_handler { /* @@ -411,6 +414,16 @@ class Log_to_csv_event_handler: public Log_event_handler THD's of the query. The reason is the locking order and duration. */ THD *general_log_thd, *slow_log_thd; + /* + This is for the thread, which called tmp_close_log_tables. The thread + will be allowed to write-lock the log tables (as it explicitly disabled + logging). This is used for such operations as REPAIR, which require + exclusive lock on the log tables. + NOTE: there can be only one priviliged thread, as one should + lock logger with logger.lock() before calling tmp_close_log_tables(). + So no other thread could get privileged status at the same time. + */ + THD *privileged_thread; friend class LOGGER; TABLE_LIST general_log, slow_log; @@ -435,13 +448,20 @@ public: const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs); - bool flush(THD *thd, TABLE_LIST *close_slow_Log, - TABLE_LIST* close_general_log); + void tmp_close_log_tables(THD *thd); void close_log_table(uint log_type, bool lock_in_use); bool reopen_log_table(uint log_type); + THD* get_privileged_thread() + { + return privileged_thread; + } }; +/* type of the log table */ +#define QUERY_LOG_SLOW 1 +#define QUERY_LOG_GENERAL 2 + class Log_to_file_event_handler: public Log_event_handler { MYSQL_QUERY_LOG mysql_log; @@ -497,13 +517,18 @@ public: {} void lock() { (void) pthread_mutex_lock(&LOCK_logger); } void unlock() { (void) pthread_mutex_unlock(&LOCK_logger); } - bool is_general_log_table_enabled() + void tmp_close_log_tables(THD *thd); + bool is_log_table_enabled(uint log_table_type) { - return table_log_handler && table_log_handler->general_log.table != 0; - } - bool is_slow_log_table_enabled() - { - return table_log_handler && table_log_handler->slow_log.table != 0; + switch (log_table_type) { + case QUERY_LOG_SLOW: + return table_log_handler && table_log_handler->slow_log.table != 0; + case QUERY_LOG_GENERAL: + return table_log_handler && table_log_handler->general_log.table != 0; + default: + DBUG_ASSERT(0); + return FALSE; /* make compiler happy */ + } } /* We want to initialize all log mutexes as soon as possible, @@ -541,6 +566,7 @@ public: void close_log_table(uint log_type, bool lock_in_use); bool reopen_log_table(uint log_type); + bool reopen_log_tables(); /* we use this function to setup all enabled log event handlers */ int set_handlers(uint error_log_printer, @@ -563,6 +589,13 @@ public: return file_log_handler->get_mysql_log(); return NULL; } + THD* get_privileged_thread() + { + if (table_log_handler) + return table_log_handler->get_privileged_thread(); + else + return NULL; + } }; enum enum_binlog_format { |