So… in removing the FRM file in Drizzle, I found a bit of a nugget on how drop table works (currently in the MySQL server and now “did” in Drizzle).
If you DROP TABLE t1; this is what happens
- open the .frm file
- read first 10bytes (oh, and if you get EIO there, in a SELECT * FROM INFORMATION_SCHEMA.TABLES you’ll get “Error” instead of “Base Table”)
- if (header[0] != (unsigned char) 254 || header[1] != 1 ||
(header[2] != FRM_VER && header[2] != FRM_VER+1 &&
(header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
return true;
Which means that you probably (well, should have) set your enum legacy_db_type to DB_TYPE_UNKNOWN in the caller of bool mysql_frm_type(Session *, char *path, enum legacy_db_type *dbt) otherwise you end up in some form of pain. - Else, *dbt= (enum legacy_db_type) (uint) *(header + 3);
return true;Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â // Is probably a .frm table
I do like the “probably”.
Oh, and on a “storage engine api” front, some places seem to expect handler::delete_table(const char* name) to return ENOENT on table not existing. In reality however:
- int ha_heap::delete_table(const char *name)
{
-Â int error= heap_delete_table(name);
-Â return error == ENOENT ? 0 : error;
+Â return heap_delete_table(name);
} - InnoDB (note the behaviour of returning DB_TABLE_NOT_FOUND… which isn’t ENOENT)
err = DB_TABLE_NOT_FOUND;
ut_print_timestamp(stderr);fputs(“Â InnoDB: Error: table “, stderr);
ut_print_name(stderr, trx, TRUE, name);
fputs(” does not exist in the InnoDB internaln”
“InnoDB: data dictionary though MySQL is”
” trying to drop it.n”
“InnoDB: Have you copied the .frm file”
” of the table to then”
“InnoDB: MySQL database directory”
” from another database?n”
“InnoDB: You can look for further help fromn”
“InnoDB: http://dev.mysql.com/doc/refman/5.1/en/”
“innodb-troubleshooting.htmln”,
stderr); - and MyISAM would generate the error message itself, but that’s fixed with:
-Â if (my_delete_with_symlink(from, MYF(MY_WME)))
+Â if (my_delete_with_symlink(from, 0))
return(my_errno);
and just to add to the fun, elsewhere in the code, a access(2) call on the frm file name is used to determine if the table exists or not.
The road to removing the FRM has all sorts of these weird-ass things along it. Kinda nice to be able to replace this with something better (and, hopefully – good).
But let me sum up with sql_table.cc:
“This code is wrong and will be removed, please do not copy.”
We have had a few cases where a crash between creation/deletion of the FRM file and the call to get the storage engine to create/delete the table leaves a server stuck. Somewhat annoying and nice to know that Drizzle can fix it.
you could probably hack in a few calls (to unlink or drop table) to innodb and get most of the way there (albeit in a hackish way)…. I’ve yet to look at how innodb data dictionary is implemented… but if it’s transactional along with other tables.. you could put FRMs straight in there and use table discovery to get back to a known state.
(or wait for Drizzle of course)
Pingback: MySQL opening .frm even when table is in table definition cache - MySQL Performance Blog