summaryrefslogtreecommitdiff
path: root/sql/sql_table.cc
diff options
context:
space:
mode:
authorpetr/cps@mysql.com/owlet. <>2006-08-03 21:28:15 +0400
committerpetr/cps@mysql.com/owlet. <>2006-08-03 21:28:15 +0400
commitbe2ce2614ba6a6840c4d57dae5e75bc1826424d1 (patch)
treecb952c4fb976588566dd3442e145ab59847f7c7c /sql/sql_table.cc
parenta68400dd9850f20827f3becfd29d52a2601c4c07 (diff)
downloadmariadb-git-be2ce2614ba6a6840c4d57dae5e75bc1826424d1.tar.gz
Fix Bug #18559 "log tables cannot change engine, and
gets deadlocked when dropping w/ log on" Log tables rely on concurrent insert machinery to add data. This means that log tables are always opened and locked by special (artificial) logger threads. Because of this, the thread which tries to drop a log table starts to wait for the table to be unlocked. Which will happen only if the log table is disabled. Alike situation happens if one tries to alter a log table. However in addition to the problem above, alter table calls check_if_locking_is_allowed() routine for the engine. The routine does not allow alter for the log tables. So, alter doesn't start waiting forever for logs to be disabled, but returns with an error. Another problem is that not all engines could be used for the log tables. That's because they need concurrent insert. In this patch we: (1) Explicitly disallow to drop/alter a log table if it is currently used by the logger. (2) Update MyISAM to support log tables (3) Allow to drop log tables/alter log tables if log is disabled At the same time we (4) Disallow to alter log tables to unsupported engine (after this patch CSV and MyISAM are alowed) Recommit with review fixes.
Diffstat (limited to 'sql/sql_table.cc')
-rw-r--r--sql/sql_table.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index ccddefab421..c0c88039051 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -1537,6 +1537,18 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
table->db_type= NULL;
if ((share= get_cached_table_share(table->db, table->table_name)))
table->db_type= share->db_type;
+
+ /* Disable drop of enabled log tables */
+ if (share && share->log_table &&
+ ((!my_strcasecmp(system_charset_info, table->table_name,
+ "general_log") && opt_log &&
+ logger.is_general_log_table_enabled()) ||
+ (!my_strcasecmp(system_charset_info, table->table_name, "slow_log")
+ && opt_slow_log && logger.is_slow_log_table_enabled())))
+ {
+ my_error(ER_CANT_DROP_LOG_TABLE, MYF(0));
+ DBUG_RETURN(1);
+ }
}
if (lock_table_names(thd, tables))
@@ -4991,6 +5003,42 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
LINT_INIT(index_add_buffer);
LINT_INIT(index_drop_buffer);
+ if (table_list && table_list->db &&
+ !my_strcasecmp(system_charset_info, table_list->db, "mysql") &&
+ table_list->table_name)
+ {
+ enum enum_table_kind { NOT_LOG_TABLE= 1, GENERAL_LOG, SLOW_LOG }
+ table_kind= NOT_LOG_TABLE;
+
+ if (!my_strcasecmp(system_charset_info, table_list->table_name,
+ "general_log"))
+ table_kind= GENERAL_LOG;
+ else
+ if (!my_strcasecmp(system_charset_info, table_list->table_name,
+ "slow_log"))
+ table_kind= SLOW_LOG;
+
+ /* Disable alter of enabled log tables */
+ if ((table_kind == GENERAL_LOG && opt_log &&
+ logger.is_general_log_table_enabled()) ||
+ (table_kind == SLOW_LOG && opt_slow_log &&
+ logger.is_slow_log_table_enabled()))
+ {
+ my_error(ER_CANT_ALTER_LOG_TABLE, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
+
+ /* Disable alter of log tables to unsupported engine */
+ if ((table_kind == GENERAL_LOG || table_kind == SLOW_LOG) &&
+ (lex_create_info->used_fields & HA_CREATE_USED_ENGINE) &&
+ !(lex_create_info->db_type->db_type == DB_TYPE_MYISAM ||
+ lex_create_info->db_type->db_type == DB_TYPE_CSV_DB))
+ {
+ my_error(ER_BAD_LOG_ENGINE, MYF(0));
+ DBUG_RETURN(TRUE);
+ }
+ }
+
thd->proc_info="init";
if (!(create_info= copy_create_info(lex_create_info)))
{