Bug #39051 UNISTALL PLUGIN defers uninstall after SELECT on any plugin table
Submitted: 26 Aug 2008 16:30 Modified: 27 Aug 2008 8:50
Reporter: Inaam Rana Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1, 6.0 BZR OS:Any
Assigned to: CPU Architecture:Any

[26 Aug 2008 16:30] Inaam Rana
Description:
If we do any select on installed plugin, a consequent uninstall will get deferred with a warning:

+--------------+
| version() |
+--------------+
| 5.1.28-debug |
+--------------+
1 row in set (0.00 sec)

mysql> use test;
Database changed
mysql> show plugins;
+------------+--------+----------------+---------+---------+
| Name | Status | Type | Library | License |
+------------+--------+----------------+---------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
+------------+--------+----------------+---------+---------+
5 rows in set (0.00 sec)

mysql> INSTALL PLUGIN INNODB SONAME 'ha_innodb.so';
Query OK, 0 rows affected (1.48 sec)

mysql> show plugins;
+------------+--------+----------------+--------------+---------+
| Name | Status | Type | Library | License |
+------------+--------+----------------+--------------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | ha_innodb.so | GPL |
+------------+--------+----------------+--------------+---------+
6 rows in set (0.00 sec)

mysql> create table t1 (id int primary key) engine=innodb;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from t1;
Empty set (0.00 sec)

mysql> uninstall plugin innodb;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------+
| Warning | 0 | Plugin is busy and will be uninstalled on shutdown |
+---------+------+----------------------------------------------------+
1 row in set (0.01 sec)

How to repeat:
See above

Suggested fix:
The warning 'Plugin is busy...' comes from sql_plugin.cc

1718 if (plugin->ref_count)
1719 push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 0,
1720 "Plugin is busy and will be uninstalled on shutdown");
1721 else
1722 reap_needed= true;
1723 reap_plugins();

The ref_count is non-zero because a SELECT results in incrementing it thrice but decrementing it twice. I cannot fathom the need for incrementing ref_count multiple times for the same select but this asymmetry of increment/decrement is causing the delay in uninstall.

The increments to ref_count happen in open_binary_frm() in table.cc.
[26 Aug 2008 17:46] Sveta Smirnova
Thank you for the report.

Verified as described: issue FLUSH TABLES before UNINSTALL.

Test case:

$cat plugin_bug39053.test
--source include/have_example_plugin.inc

show plugins;

INSTALL PLUGIN example SONAME 'ha_example.so';

show plugins;

CREATE TABLE t1(a int) ENGINE=EXAMPLE;
select * from t1;

uninstall plugin example;

$cat plugin_bug39053-master.opt
$EXAMPLE_PLUGIN_OPT
[27 Aug 2008 8:50] Sergei Golubchik
Expected behavior. A plugin cannot be unloaded because it's used by an open table,  that is, it cannot be unloaded as long as there is at least one InnoDB table.

And there is one open InnoDB table in your case, namely, in the table cache. FLUSH TABLES empties the table cache.