Commit 8cc53ade authored by Monty's avatar Monty

MDEV-17068 mysql system table is marked as crashed and should be repaired...

MDEV-17068 mysql system table is marked as crashed and should be repaired after the server crashes or is killed

- Changed ERROR to WARNING for MyISAM/Aria message
  that are warnings in the check utilities.
  This affects for example "client is using or
  hasn't closed the table properly".
- Print "Table is fixed" if check succeded in
  fixing the table.
parent f451fd8c
...@@ -500,7 +500,8 @@ call mtr.add_suppression("Checking table"); ...@@ -500,7 +500,8 @@ call mtr.add_suppression("Checking table");
insert delayed into t1 values (2,2); insert delayed into t1 values (2,2);
Warnings: Warnings:
Error 145 Table './test/t1' is marked as crashed and should be repaired Error 145 Table './test/t1' is marked as crashed and should be repaired
Error 1034 1 client is using or hasn't closed the table properly Warning 1034 1 client is using or hasn't closed the table properly
Note 1034 Table is fixed
insert delayed into t1 values (3,3); insert delayed into t1 values (3,3);
flush tables t1; flush tables t1;
select * from t1; select * from t1;
......
...@@ -2545,7 +2545,7 @@ INSERT INTO t1 VALUES ...@@ -2545,7 +2545,7 @@ INSERT INTO t1 VALUES
('0'),('0'),('0'),('0'),('0'),('0'),('0'); ('0'),('0'),('0'),('0'),('0'),('0'),('0');
Warnings: Warnings:
Error 1034 myisam_sort_buffer_size is too small. X Error 1034 myisam_sort_buffer_size is too small. X
Error 1034 Number of rows changed from 0 to 157 Warning 1034 Number of rows changed from 0 to 157
SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size; SET myisam_sort_buffer_size=@@global.myisam_sort_buffer_size;
INSERT INTO t1 VALUES('1'); INSERT INTO t1 VALUES('1');
SELECT * FROM t1, t1 AS a1 WHERE t1.a=1 AND a1.a=1; SELECT * FROM t1, t1 AS a1 WHERE t1.a=1 AND a1.a=1;
......
...@@ -87,7 +87,7 @@ a ...@@ -87,7 +87,7 @@ a
6 6
Warnings: Warnings:
Error 145 Table 't1' is marked as crashed and should be repaired Error 145 Table 't1' is marked as crashed and should be repaired
Error 1034 Number of rows changed from 3 to 6 Warning 1034 Number of rows changed from 3 to 6
# #
# Cleanup # Cleanup
# #
...@@ -139,7 +139,7 @@ a ...@@ -139,7 +139,7 @@ a
4 4
Warnings: Warnings:
Error 145 Table 't1' is marked as crashed and should be repaired Error 145 Table 't1' is marked as crashed and should be repaired
Error 1034 Number of rows changed from 1 to 2 Warning 1034 Number of rows changed from 1 to 2
connect con2, localhost, root; connect con2, localhost, root;
ALTER TABLE t2 ADD val INT; ALTER TABLE t2 ADD val INT;
connection default; connection default;
......
...@@ -78,7 +78,7 @@ INSERT INTO t1 VALUES ...@@ -78,7 +78,7 @@ INSERT INTO t1 VALUES
('0'),('0'),('0'),('0'),('0'),('0'),('0'); ('0'),('0'),('0'),('0'),('0'),('0'),('0');
Warnings: Warnings:
Error 1034 myisam_sort_buffer_size is too small. X Error 1034 myisam_sort_buffer_size is too small. X
Error 1034 Number of rows changed from 0 to 157 Warning 1034 Number of rows changed from 0 to 157
SET myisam_repair_threads=2; SET myisam_repair_threads=2;
REPAIR TABLE t1; REPAIR TABLE t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
......
...@@ -27,7 +27,7 @@ ThursdayMorningsMarket ...@@ -27,7 +27,7 @@ ThursdayMorningsMarket
ThursdayMorningsMarketb ThursdayMorningsMarketb
Warnings: Warnings:
Error 145 t_corrupted2' is marked as crashed and should be repaired Error 145 t_corrupted2' is marked as crashed and should be repaired
Error 1034 1 client is using or hasn't closed the table properly Warning 1034 1 client is using or hasn't closed the table properly
Error 1034 Wrong base information on indexpage at page: 1 Error 1034 Wrong base information on indexpage at page: 1
select * from t_corrupted2; select * from t_corrupted2;
a a
......
...@@ -18,10 +18,10 @@ a ...@@ -18,10 +18,10 @@ a
11 11
Warnings: Warnings:
Error 145 Table 't1_will_crash' is marked as crashed and should be repaired Error 145 Table 't1_will_crash' is marked as crashed and should be repaired
Error 1034 1 client is using or hasn't closed the table properly Warning 1034 1 client is using or hasn't closed the table properly
Error 1034 Size of indexfile is: 1024 Should be: 2048 Error 1034 Size of indexfile is: 1024 Should be: 2048
Error 1034 Size of datafile is: 77 Should be: 7 Warning 1034 Size of datafile is: 77 Should be: 7
Error 1034 Number of rows changed from 1 to 11 Warning 1034 Number of rows changed from 1 to 11
DROP TABLE t1_will_crash; DROP TABLE t1_will_crash;
CREATE TABLE t1_will_crash (a INT, KEY (a)) CREATE TABLE t1_will_crash (a INT, KEY (a))
ENGINE=MyISAM ENGINE=MyISAM
...@@ -47,8 +47,8 @@ a ...@@ -47,8 +47,8 @@ a
11 11
Warnings: Warnings:
Error 145 Table 't1_will_crash#P#p1' is marked as crashed and should be repaired Error 145 Table 't1_will_crash#P#p1' is marked as crashed and should be repaired
Error 1034 1 client is using or hasn't closed the table properly Warning 1034 1 client is using or hasn't closed the table properly
Error 1034 Size of indexfile is: 1024 Should be: 2048 Error 1034 Size of indexfile is: 1024 Should be: 2048
Error 1034 Size of datafile is: 28 Should be: 7 Warning 1034 Size of datafile is: 28 Should be: 7
Error 1034 Number of rows changed from 1 to 4 Warning 1034 Number of rows changed from 1 to 4
DROP TABLE t1_will_crash; DROP TABLE t1_will_crash;
...@@ -1162,6 +1162,10 @@ bool LOGGER::error_log_print(enum loglevel level, const char *format, ...@@ -1162,6 +1162,10 @@ bool LOGGER::error_log_print(enum loglevel level, const char *format,
{ {
bool error= FALSE; bool error= FALSE;
Log_event_handler **current_handler; Log_event_handler **current_handler;
THD *thd= current_thd;
if (likely(thd))
thd->error_printed_to_log= 1;
/* currently we don't need locking here as there is no error_log table */ /* currently we don't need locking here as there is no error_log table */
for (current_handler= error_log_handler_list ; *current_handler ;) for (current_handler= error_log_handler_list ; *current_handler ;)
......
...@@ -3123,6 +3123,9 @@ class THD :public Statement, ...@@ -3123,6 +3123,9 @@ class THD :public Statement,
it returned an error on master, and this is OK on the slave. it returned an error on master, and this is OK on the slave.
*/ */
bool is_slave_error; bool is_slave_error;
/* True if we have printed something to the error log for this statement */
bool error_printed_to_log;
/* /*
True when a transaction is queued up for binlog group commit. True when a transaction is queued up for binlog group commit.
Used so that if another transaction needs to wait for a row lock held by Used so that if another transaction needs to wait for a row lock held by
......
...@@ -7593,8 +7593,14 @@ void THD::reset_for_next_command(bool do_clear_error) ...@@ -7593,8 +7593,14 @@ void THD::reset_for_next_command(bool do_clear_error)
DBUG_ASSERT(!in_sub_stmt); DBUG_ASSERT(!in_sub_stmt);
if (likely(do_clear_error)) if (likely(do_clear_error))
{
clear_error(1); clear_error(1);
/*
The following variable can't be reset in clear_error() as
clear_error() is called during auto_repair of table
*/
error_printed_to_log= 0;
}
free_list= 0; free_list= 0;
/* /*
We also assign stmt_lex in lex_start(), but during bootstrap this We also assign stmt_lex in lex_start(), but during bootstrap this
......
...@@ -387,6 +387,10 @@ static void init_aria_psi_keys(void) ...@@ -387,6 +387,10 @@ static void init_aria_psi_keys(void)
#define init_aria_psi_keys() /* no-op */ #define init_aria_psi_keys() /* no-op */
#endif /* HAVE_PSI_INTERFACE */ #endif /* HAVE_PSI_INTERFACE */
const char *MA_CHECK_INFO= "info";
const char *MA_CHECK_WARNING= "warning";
const char *MA_CHECK_ERROR= "error";
/***************************************************************************** /*****************************************************************************
** MARIA tables ** MARIA tables
*****************************************************************************/ *****************************************************************************/
...@@ -399,6 +403,20 @@ static handler *maria_create_handler(handlerton *hton, ...@@ -399,6 +403,20 @@ static handler *maria_create_handler(handlerton *hton,
} }
static void _ma_check_print(HA_CHECK *param, const char* msg_type,
const char *msgbuf)
{
if (msg_type == MA_CHECK_INFO)
sql_print_information("%s.%s: %s", param->db_name, param->table_name,
msgbuf);
else if (msg_type == MA_CHECK_WARNING)
sql_print_warning("%s.%s: %s", param->db_name, param->table_name,
msgbuf);
else
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf);
}
// collect errors printed by maria_check routines // collect errors printed by maria_check routines
static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type, static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type,
...@@ -420,16 +438,21 @@ static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type, ...@@ -420,16 +438,21 @@ static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type,
if (!thd->vio_ok()) if (!thd->vio_ok())
{ {
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); _ma_check_print(param, msg_type, msgbuf);
return; return;
} }
if (param->testflag & if (param->testflag &
(T_CREATE_MISSING_KEYS | T_SAFE_REPAIR | T_AUTO_REPAIR)) (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR | T_AUTO_REPAIR))
{ {
my_message(ER_NOT_KEYFILE, msgbuf, MYF(0)); myf flag= 0;
if (msg_type == MA_CHECK_INFO)
flag= ME_NOTE;
else if (msg_type == MA_CHECK_WARNING)
flag= ME_WARNING;
my_message(ER_NOT_KEYFILE, msgbuf, MYF(flag));
if (thd->variables.log_warnings > 2) if (thd->variables.log_warnings > 2)
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); _ma_check_print(param, msg_type, msgbuf);
return; return;
} }
length= (uint) (strxmov(name, param->db_name, ".", param->table_name, length= (uint) (strxmov(name, param->db_name, ".", param->table_name,
...@@ -451,7 +474,7 @@ static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type, ...@@ -451,7 +474,7 @@ static void _ma_check_print_msg(HA_CHECK *param, const char *msg_type,
sql_print_error("Failed on my_net_write, writing to stderr instead: %s.%s: %s\n", sql_print_error("Failed on my_net_write, writing to stderr instead: %s.%s: %s\n",
param->db_name, param->table_name, msgbuf); param->db_name, param->table_name, msgbuf);
else if (thd->variables.log_warnings > 2) else if (thd->variables.log_warnings > 2)
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); _ma_check_print(param, msg_type, msgbuf);
return; return;
} }
...@@ -879,7 +902,7 @@ void _ma_check_print_error(HA_CHECK *param, const char *fmt, ...) ...@@ -879,7 +902,7 @@ void _ma_check_print_error(HA_CHECK *param, const char *fmt, ...)
if (param->testflag & T_SUPPRESS_ERR_HANDLING) if (param->testflag & T_SUPPRESS_ERR_HANDLING)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
va_start(args, fmt); va_start(args, fmt);
_ma_check_print_msg(param, "error", fmt, args); _ma_check_print_msg(param, MA_CHECK_ERROR, fmt, args);
va_end(args); va_end(args);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -890,7 +913,7 @@ void _ma_check_print_info(HA_CHECK *param, const char *fmt, ...) ...@@ -890,7 +913,7 @@ void _ma_check_print_info(HA_CHECK *param, const char *fmt, ...)
va_list args; va_list args;
DBUG_ENTER("_ma_check_print_info"); DBUG_ENTER("_ma_check_print_info");
va_start(args, fmt); va_start(args, fmt);
_ma_check_print_msg(param, "info", fmt, args); _ma_check_print_msg(param, MA_CHECK_INFO, fmt, args);
va_end(args); va_end(args);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -903,7 +926,7 @@ void _ma_check_print_warning(HA_CHECK *param, const char *fmt, ...) ...@@ -903,7 +926,7 @@ void _ma_check_print_warning(HA_CHECK *param, const char *fmt, ...)
param->warning_printed= 1; param->warning_printed= 1;
param->out_flag |= O_DATA_LOST; param->out_flag |= O_DATA_LOST;
va_start(args, fmt); va_start(args, fmt);
_ma_check_print_msg(param, "warning", fmt, args); _ma_check_print_msg(param, MA_CHECK_WARNING, fmt, args);
va_end(args); va_end(args);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -1390,6 +1413,16 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) ...@@ -1390,6 +1413,16 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
mysql_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE |
HA_STATUS_CONST); HA_STATUS_CONST);
/*
Write a 'table is ok' message to error log if table is ok and
we have written to error log that table was getting checked
*/
if (!error && !(table->db_stat & HA_READ_ONLY) &&
!maria_is_crashed(file) && thd->error_printed_to_log &&
(param->warning_printed || param->error_printed ||
param->note_printed))
_ma_check_print_info(param, "Table is fixed");
} }
} }
else if (!maria_is_crashed(file) && !thd->killed) else if (!maria_is_crashed(file) && !thd->killed)
......
...@@ -96,6 +96,10 @@ static MYSQL_THDVAR_ENUM(stats_method, PLUGIN_VAR_RQCMDARG, ...@@ -96,6 +96,10 @@ static MYSQL_THDVAR_ENUM(stats_method, PLUGIN_VAR_RQCMDARG,
"and NULLS_IGNORED", NULL, NULL, "and NULLS_IGNORED", NULL, NULL,
MI_STATS_METHOD_NULLS_NOT_EQUAL, &myisam_stats_method_typelib); MI_STATS_METHOD_NULLS_NOT_EQUAL, &myisam_stats_method_typelib);
const char *MI_CHECK_INFO= "info";
const char *MI_CHECK_WARNING= "warning";
const char *MI_CHECK_ERROR= "error";
#ifndef DBUG_OFF #ifndef DBUG_OFF
/** /**
Causes the thread to wait in a spin lock for a query kill signal. Causes the thread to wait in a spin lock for a query kill signal.
...@@ -130,6 +134,20 @@ static handler *myisam_create_handler(handlerton *hton, ...@@ -130,6 +134,20 @@ static handler *myisam_create_handler(handlerton *hton,
return new (mem_root) ha_myisam(hton, table); return new (mem_root) ha_myisam(hton, table);
} }
static void mi_check_print(HA_CHECK *param, const char* msg_type,
const char *msgbuf)
{
if (msg_type == MI_CHECK_INFO)
sql_print_information("%s.%s: %s", param->db_name, param->table_name,
msgbuf);
else if (msg_type == MI_CHECK_WARNING)
sql_print_warning("%s.%s: %s", param->db_name, param->table_name,
msgbuf);
else
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf);
}
// collect errors printed by mi_check routines // collect errors printed by mi_check routines
static void mi_check_print_msg(HA_CHECK *param, const char* msg_type, static void mi_check_print_msg(HA_CHECK *param, const char* msg_type,
...@@ -151,16 +169,21 @@ static void mi_check_print_msg(HA_CHECK *param, const char* msg_type, ...@@ -151,16 +169,21 @@ static void mi_check_print_msg(HA_CHECK *param, const char* msg_type,
if (!thd->vio_ok()) if (!thd->vio_ok())
{ {
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); mi_check_print(param, msg_type, msgbuf);
return; return;
} }
if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR | if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR |
T_AUTO_REPAIR)) T_AUTO_REPAIR))
{ {
my_message(ER_NOT_KEYFILE, msgbuf, MYF(0)); myf flag= 0;
if (msg_type == MI_CHECK_INFO)
flag= ME_NOTE;
else if (msg_type == MI_CHECK_WARNING)
flag= ME_WARNING;
my_message(ER_NOT_KEYFILE, msgbuf, MYF(flag));
if (thd->variables.log_warnings > 2 && ! thd->log_all_errors) if (thd->variables.log_warnings > 2 && ! thd->log_all_errors)
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); mi_check_print(param, msg_type, msgbuf);
return; return;
} }
length=(uint) (strxmov(name, param->db_name,".",param->table_name,NullS) - length=(uint) (strxmov(name, param->db_name,".",param->table_name,NullS) -
...@@ -185,7 +208,7 @@ static void mi_check_print_msg(HA_CHECK *param, const char* msg_type, ...@@ -185,7 +208,7 @@ static void mi_check_print_msg(HA_CHECK *param, const char* msg_type,
sql_print_error("Failed on my_net_write, writing to stderr instead: %s\n", sql_print_error("Failed on my_net_write, writing to stderr instead: %s\n",
msgbuf); msgbuf);
else if (thd->variables.log_warnings > 2) else if (thd->variables.log_warnings > 2)
sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); mi_check_print(param, msg_type, msgbuf);
if (param->need_print_msg_lock) if (param->need_print_msg_lock)
mysql_mutex_unlock(&param->print_msg_mutex); mysql_mutex_unlock(&param->print_msg_mutex);
...@@ -592,7 +615,7 @@ void mi_check_print_error(HA_CHECK *param, const char *fmt,...) ...@@ -592,7 +615,7 @@ void mi_check_print_error(HA_CHECK *param, const char *fmt,...)
return; return;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
mi_check_print_msg(param, "error", fmt, args); mi_check_print_msg(param, MI_CHECK_ERROR, fmt, args);
va_end(args); va_end(args);
} }
...@@ -600,7 +623,7 @@ void mi_check_print_info(HA_CHECK *param, const char *fmt,...) ...@@ -600,7 +623,7 @@ void mi_check_print_info(HA_CHECK *param, const char *fmt,...)
{ {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
mi_check_print_msg(param, "info", fmt, args); mi_check_print_msg(param, MI_CHECK_INFO, fmt, args);
param->note_printed= 1; param->note_printed= 1;
va_end(args); va_end(args);
} }
...@@ -611,7 +634,7 @@ void mi_check_print_warning(HA_CHECK *param, const char *fmt,...) ...@@ -611,7 +634,7 @@ void mi_check_print_warning(HA_CHECK *param, const char *fmt,...)
param->out_flag|= O_DATA_LOST; param->out_flag|= O_DATA_LOST;
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
mi_check_print_msg(param, "warning", fmt, args); mi_check_print_msg(param, MI_CHECK_WARNING, fmt, args);
va_end(args); va_end(args);
} }
...@@ -1036,6 +1059,15 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -1036,6 +1059,15 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
mysql_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE |
HA_STATUS_CONST); HA_STATUS_CONST);
/*
Write a 'table is ok' message to error log if table is ok and
we have written to error log that table was getting checked
*/
if (!error && !(table->db_stat & HA_READ_ONLY) &&
!mi_is_crashed(file) && thd->error_printed_to_log &&
(param->warning_printed || param->error_printed ||
param->note_printed))
mi_check_print_info(param, "Table is fixed");
} }
} }
else if (!mi_is_crashed(file) && !thd->killed) else if (!mi_is_crashed(file) && !thd->killed)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment