Bug #74277 MySQL may not call SE delete_table method with dynamic plugins
Submitted: 8 Oct 2014 15:19 Modified: 17 Aug 2015 14:21
Reporter: Morgan Tocker Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Storage Engine API Severity:S3 (Non-critical)
Version:5.6.21 OS:Any
Assigned to: CPU Architecture:Any

[8 Oct 2014 15:19] Morgan Tocker
Description:
Via: https://github.com/Tokutek/tokudb-engine/wiki/Dynamic-plugins

Dynamic plugins do not work in MySQL. For example, when a table is dropped, MySQL will not inform the storage engine if the dynamic plugin number assigned to a storage engine changes. Here is how to reproduce the problem.

How to repeat:
Step 1. Hack the example storage engine to create a file for each table and to unlink the file when the table is deleted.

$ diff ha_example.cc ~/Downloads/mysql-5.6.21/storage/example
836,839d835
<   int r = ::unlink(name);
<   if (r == -1)
<       r = errno;
<   assert(r == 0);
913,915d908
<   int fd = ::creat(name, 0777);
<   assert(fd != -1);
<   ::close(fd);

Step 2. Startup MySQL and install the example storage engine.

Step 3. Create a table s.

create table test.s (id int) engine=example;

There should be a file s.frm and a file s in the test directory.

Step 4. Drop table s. All of the files in the test directory are removed.

Step 5. Create another table t.

create table test.t (id int) engine=example;

There should be a file t.frm and a file t in the test directory.

Step 6. Shutdown MySQL

Step 7. Change the plugin number in the t.frm file from 42 to 43. 42 is the plugin number that is stored in byte 3 of the frm file. This can happen if the sequence of dynamic plugins that are installed changes.

$ hexdump -C t.frm
00000000  fe 01 09 2a 03 00 00 10  01 00 00 30 00 00 10 00  |...*.......0....|
00000010  05 00 00 00 00 00 00 00  00 00 00 02 08 00 08 00  |................|
00000020  00 05 00 00 00 00 08 00  00 00 00 00 00 00 00 10  |................|
00000030  00 00 00 bd c5 00 00 1b  00 00 00 00 00 00 00 00  |................|
00000040  2f 2f 00 00 20 00 00 00  00 00 00 00 00 00 00 00  |//.. ...........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001000  00 00 00 00 02 00 ff 00  00 00 00 00 00 00 00 00  |................|
00001010  ff 00 00 00 00 00 00 07  00 45 58 41 4d 50 4c 45  |.........EXAMPLE|

Step 8. Start MySQL

Step 9. Drop table t.

Problem: MySQL does not call the example storage engine's delete_tablehandler method, so the files managed by the example storage engine are NOT cleaned up.

Suggested fix:
MySQL must call the example storage engine's delete_table handler method.
[28 Oct 2014 11:28] MySQL Verification Team
Hello Morgan,

Thank you for the bug report and test case.

Thanks,
Umesh
[28 Oct 2014 11:28] MySQL Verification Team
test results

Attachment: 74277.txt (text/plain), 5.40 KiB.

[17 Aug 2015 14:21] Paul DuBois
Noted in 5.8.0 changelog.

For dynamic storage engine plugins, DROP TABLE, TRUNCATE TABLE, and
RENAME TABLE did not work due to incorrectly determining the engine
from the .frm file.