-
unknown authored
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.
9438b985