I'm also trying to investigate what is needed for auto-repair.
1. Auto-repair doesn't work for mysql.proc table.
I run a CREATE PROCEDURE ... , and kill the server right after ha_myisam::write_row(). If I restart the server and attempt to use mysql.proc again, I get:
mysql> create procedure p4() begin select now(); end //
ERROR 145 (HY000): Table './mysql/proc' is marked as crashed and should be repaired
2. Auto-repair does work for regular tables.
mysql> insert into t21 values (2);
|
ERROR 2013 (HY000): Lost connection to MySQL server during query
|
^^ -- I intentionally kill the server
|
|
mysql> select * from t21;
|
ERROR 2006 (HY000): MySQL server has gone away
|
No connection. Trying to reconnect...
|
Connection id: 3
|
Current database: test
|
|
+------+
|
| a |
|
+------+
|
| 1 |
|
| 2 |
|
+------+
|
2 rows in set, 7 warnings (18 min 49.03 sec)
|
|
mysql> show warnings\G
|
Message: Table './test/t21' is marked as crashed and should be repaired
|
Message: Table 't21' is marked as crashed and should be repaired
|
Message: 1 client is using or hasn't closed the table properly
|
Message: Size of datafile is: 14 Should be: 7
|
Message: Record-count is not ok; is 2 Should be: 1
|
Message: Found 2 key parts. Should be: 1
|
Message: Number of rows changed from 1 to 2
|
7 rows in set (0.00 sec)
|
Code-wise, auto-repair happens in open_table() and open_tables(). In open_table, there is this code:
else if (share->crashed)
|
(void) ot_ctx->request_backoff_action(Open_table_context::OT_REPAIR,
|
table_list);
|
and open_tables() has:
error= open_and_process_table(thd, thd->lex, tables, counter,
|
flags, prelocking_strategy,
|
has_prelocking_list, &ot_ctx,
|
&new_frm_mem);
|
|
if (error)
|
{
|
if (ot_ctx.can_recover_from_failed_open())
|
Hint from Monty: check out the code in sp.cc:
if (table->file->ha_write_row(table->record[0]))
ret= SP_WRITE_ROW_FAILED;
/* Make change permanent and avoid 'table is marked as crashed' errors */
table->file->extra(HA_EXTRA_FLUSH);
Note the HA_EXTRA_FLUSH call. We will need to add it to EITS tables.