diff --git a/mysql-test/main/delayed.result b/mysql-test/main/delayed.result index d10f4ae22cf..26a1fc670f4 100644 --- a/mysql-test/main/delayed.result +++ b/mysql-test/main/delayed.result @@ -500,7 +500,8 @@ call mtr.add_suppression("Checking table"); insert delayed into t1 values (2,2); Warnings: 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); flush tables t1; select * from t1; diff --git a/mysql-test/main/myisam.result b/mysql-test/main/myisam.result index 4864ef0bb13..bef8790e141 100644 --- a/mysql-test/main/myisam.result +++ b/mysql-test/main/myisam.result @@ -2545,7 +2545,7 @@ INSERT INTO t1 VALUES ('0'),('0'),('0'),('0'),('0'),('0'),('0'); Warnings: 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; INSERT INTO t1 VALUES('1'); SELECT * FROM t1, t1 AS a1 WHERE t1.a=1 AND a1.a=1; diff --git a/mysql-test/main/myisam_recover.result b/mysql-test/main/myisam_recover.result index 92df67b42d1..3a2c424c8b2 100644 --- a/mysql-test/main/myisam_recover.result +++ b/mysql-test/main/myisam_recover.result @@ -87,7 +87,7 @@ a 6 Warnings: 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 # @@ -139,7 +139,7 @@ a 4 Warnings: 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; ALTER TABLE t2 ADD val INT; connection default; diff --git a/mysql-test/main/repair.result b/mysql-test/main/repair.result index 75d7525ee71..18a7cf509c4 100644 --- a/mysql-test/main/repair.result +++ b/mysql-test/main/repair.result @@ -78,7 +78,7 @@ INSERT INTO t1 VALUES ('0'),('0'),('0'),('0'),('0'),('0'),('0'); Warnings: 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; REPAIR TABLE t1; Table Op Msg_type Msg_text diff --git a/mysql-test/suite/maria/maria-recover.result b/mysql-test/suite/maria/maria-recover.result index 4d0b4317afe..8a33307b2b0 100644 --- a/mysql-test/suite/maria/maria-recover.result +++ b/mysql-test/suite/maria/maria-recover.result @@ -27,7 +27,7 @@ ThursdayMorningsMarket ThursdayMorningsMarketb Warnings: 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 select * from t_corrupted2; a diff --git a/mysql-test/suite/parts/r/partition_recover_myisam.result b/mysql-test/suite/parts/r/partition_recover_myisam.result index 4b9e3f5c283..151ff802a82 100644 --- a/mysql-test/suite/parts/r/partition_recover_myisam.result +++ b/mysql-test/suite/parts/r/partition_recover_myisam.result @@ -18,10 +18,10 @@ a 11 Warnings: 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 datafile is: 77 Should be: 7 -Error 1034 Number of rows changed from 1 to 11 +Warning 1034 Size of datafile is: 77 Should be: 7 +Warning 1034 Number of rows changed from 1 to 11 DROP TABLE t1_will_crash; CREATE TABLE t1_will_crash (a INT, KEY (a)) ENGINE=MyISAM @@ -47,8 +47,8 @@ a 11 Warnings: 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 datafile is: 28 Should be: 7 -Error 1034 Number of rows changed from 1 to 4 +Warning 1034 Size of datafile is: 28 Should be: 7 +Warning 1034 Number of rows changed from 1 to 4 DROP TABLE t1_will_crash; diff --git a/sql/log.cc b/sql/log.cc index 93f034543a5..86137ad3543 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1162,6 +1162,10 @@ bool LOGGER::error_log_print(enum loglevel level, const char *format, { bool error= FALSE; 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 */ for (current_handler= error_log_handler_list ; *current_handler ;) diff --git a/sql/sql_class.h b/sql/sql_class.h index 8dc9dde2b18..64ce52049d0 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3123,6 +3123,9 @@ public: it returned an error on master, and this is OK on the slave. */ 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. Used so that if another transaction needs to wait for a row lock held by diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 49bee1889bd..147147f0191 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7593,8 +7593,14 @@ void THD::reset_for_next_command(bool do_clear_error) DBUG_ASSERT(!in_sub_stmt); if (likely(do_clear_error)) + { 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; /* We also assign stmt_lex in lex_start(), but during bootstrap this diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index e9e65f42905..aa9f18966c4 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -387,6 +387,10 @@ static void init_aria_psi_keys(void) #define init_aria_psi_keys() /* no-op */ #endif /* HAVE_PSI_INTERFACE */ +const char *MA_CHECK_INFO= "info"; +const char *MA_CHECK_WARNING= "warning"; +const char *MA_CHECK_ERROR= "error"; + /***************************************************************************** ** MARIA tables *****************************************************************************/ @@ -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 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()) { - sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); + _ma_check_print(param, msg_type, msgbuf); return; } if (param->testflag & (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) - sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); + _ma_check_print(param, msg_type, msgbuf); return; } 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, sql_print_error("Failed on my_net_write, writing to stderr instead: %s.%s: %s\n", param->db_name, param->table_name, msgbuf); 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; } @@ -879,7 +902,7 @@ void _ma_check_print_error(HA_CHECK *param, const char *fmt, ...) if (param->testflag & T_SUPPRESS_ERR_HANDLING) DBUG_VOID_RETURN; 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); DBUG_VOID_RETURN; } @@ -890,7 +913,7 @@ void _ma_check_print_info(HA_CHECK *param, const char *fmt, ...) va_list args; DBUG_ENTER("_ma_check_print_info"); 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); DBUG_VOID_RETURN; } @@ -903,7 +926,7 @@ void _ma_check_print_warning(HA_CHECK *param, const char *fmt, ...) param->warning_printed= 1; param->out_flag |= O_DATA_LOST; 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); DBUG_VOID_RETURN; } @@ -1390,6 +1413,16 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) mysql_mutex_unlock(&share->intern_lock); info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | 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) diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 557daf616c2..9ab7d156251 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -96,6 +96,10 @@ static MYSQL_THDVAR_ENUM(stats_method, PLUGIN_VAR_RQCMDARG, "and NULLS_IGNORED", NULL, NULL, 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 /** 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, 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 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()) { - sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); + mi_check_print(param, msg_type, msgbuf); return; } if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_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) - sql_print_error("%s.%s: %s", param->db_name, param->table_name, msgbuf); + mi_check_print(param, msg_type, msgbuf); return; } 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, sql_print_error("Failed on my_net_write, writing to stderr instead: %s\n", msgbuf); 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) mysql_mutex_unlock(¶m->print_msg_mutex); @@ -592,7 +615,7 @@ void mi_check_print_error(HA_CHECK *param, const char *fmt,...) return; va_list args; 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); } @@ -600,7 +623,7 @@ void mi_check_print_info(HA_CHECK *param, const char *fmt,...) { va_list args; 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; va_end(args); } @@ -611,7 +634,7 @@ void mi_check_print_warning(HA_CHECK *param, const char *fmt,...) param->out_flag|= O_DATA_LOST; va_list args; 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); } @@ -1036,6 +1059,15 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) mysql_mutex_unlock(&share->intern_lock); info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | 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)