Skip to content

Commit b84d335

Browse files
MDEV-33538 make auxiliary spider plugins init depend on actual spider
The two I_S plugins SPIDER_ALLOC_MEM and SPIDER_WRAPPER_PROTOCOL only makes sense if the main SPIDER plugin is installed. Further, SPIDER_ALLOC_MEM requires a mutex that requires SPIDER init to fill the table. We also update the spider init query to override --transaction_read_only=on so that it does not affect the spider init. Also fixed error handling in spider_db_init() so that failure in spider table init does not result in memory leak
1 parent 20f60fe commit b84d335

12 files changed

+66
-13
lines changed

sql/handler.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,6 @@ int ha_initialize_handlerton(st_plugin_int *plugin)
641641
hton->slot= HA_SLOT_UNDEF;
642642
/* Historical Requirement */
643643
plugin->data= hton; // shortcut for the future
644-
/* [remove after merge] notes on merge conflict (MDEV-31400):
645-
10.6-10.11: 13ba00ff4933cfc1712676f323587504e453d1b5
646-
11.0-11.2: 42f8be10f18163c4025710cf6a212e82bddb2f62
647-
The 10.11->11.0 conflict is trivial, but the reference commit also
648-
contains different non-conflict changes needs to be applied to 11.0
649-
(and beyond).
650-
*/
651644
if (plugin->plugin->init && (ret= plugin->plugin->init(hton)))
652645
goto err;
653646

sql/sql_show.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9942,6 +9942,7 @@ ST_SCHEMA_TABLE schema_tables[]=
99429942
int initialize_schema_table(st_plugin_int *plugin)
99439943
{
99449944
ST_SCHEMA_TABLE *schema_table;
9945+
int err;
99459946
DBUG_ENTER("initialize_schema_table");
99469947

99479948
if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(key_memory_ST_SCHEMA_TABLE,
@@ -9958,12 +9959,15 @@ int initialize_schema_table(st_plugin_int *plugin)
99589959
/* Make the name available to the init() function. */
99599960
schema_table->table_name= plugin->name.str;
99609961

9961-
if (plugin->plugin->init(schema_table))
9962+
if ((err= plugin->plugin->init(schema_table)))
99629963
{
9963-
sql_print_error("Plugin '%s' init function returned error.",
9964-
plugin->name.str);
9964+
if (err != HA_ERR_RETRY_INIT)
9965+
sql_print_error("Plugin '%s' init function returned error.",
9966+
plugin->name.str);
99659967
plugin->data= NULL;
99669968
my_free(schema_table);
9969+
if (err == HA_ERR_RETRY_INIT)
9970+
DBUG_RETURN(err);
99679971
DBUG_RETURN(1);
99689972
}
99699973

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
show create table information_schema.SPIDER_ALLOC_MEM;
2+
Table Create Table
3+
SPIDER_ALLOC_MEM CREATE TEMPORARY TABLE `SPIDER_ALLOC_MEM` (
4+
`ID` int(10) unsigned NOT NULL,
5+
`FUNC_NAME` varchar(64),
6+
`FILE_NAME` varchar(64),
7+
`LINE_NO` int(10) unsigned,
8+
`TOTAL_ALLOC_MEM` bigint(20) unsigned,
9+
`CURRENT_ALLOC_MEM` bigint(20),
10+
`ALLOC_MEM_COUNT` bigint(20) unsigned,
11+
`FREE_MEM_COUNT` bigint(20) unsigned
12+
) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
call mtr.add_suppression("\\[ERROR\\] SPIDER plugin initialization failed");
2+
call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER' registration as a STORAGE ENGINE failed.");
3+
call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_WRAPPER_PROTOCOLS' registration as a INFORMATION SCHEMA failed.");
4+
call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_ALLOC_MEM' registration as a INFORMATION SCHEMA failed.");
5+
create table mysql.spider_tables (c int);
6+
# restart: --plugin-load-add=ha_spider
7+
SELECT * FROM information_schema.SPIDER_ALLOC_MEM;
8+
ERROR 42S02: Unknown table 'SPIDER_ALLOC_MEM' in information_schema

storage/spider/mysql-test/spider/bugfix/r/plugin_load_add_all.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
#
44
select * from mysql.plugin;
55
name dl
6+
select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = "information_schema" and TABLE_NAME like "SPIDER_%";
7+
TABLE_NAME
8+
SPIDER_ALLOC_MEM
9+
SPIDER_WRAPPER_PROTOCOLS
610
create table t (c int) Engine=SPIDER;
711
drop table t;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--plugin-load-add=ha_spider
2+
--transaction-read-only=on
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# we check that information_schema.SPIDER_ALLOC_MEM exists
2+
show create table information_schema.SPIDER_ALLOC_MEM;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
call mtr.add_suppression("\\[ERROR\\] SPIDER plugin initialization failed");
2+
call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER' registration as a STORAGE ENGINE failed.");
3+
call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_WRAPPER_PROTOCOLS' registration as a INFORMATION SCHEMA failed.");
4+
call mtr.add_suppression(".*\\[ERROR\\] Plugin 'SPIDER_ALLOC_MEM' registration as a INFORMATION SCHEMA failed.");
5+
# We create a table with identical name of the spider system table, to
6+
# fail the spider init query ([ERROR] SPIDER plugin initialization
7+
# failed at 'alter table mysql.spider_tables add column if not exists
8+
# link_id int not null default 0 after table_name, drop primary key,
9+
# add primary key (db_name, table_name, link_id), algorithm=copy,
10+
# lock=shared;' by 'Unknown column 'table_name' in 'spider_tables'')
11+
# This will cause the init of spider_alloc_mem to fail because it
12+
# depends on the main spider plugin.
13+
create table mysql.spider_tables (c int);
14+
--let $restart_parameters= --plugin-load-add=ha_spider
15+
--source include/restart_mysqld.inc
16+
--error ER_UNKNOWN_TABLE
17+
SELECT * FROM information_schema.SPIDER_ALLOC_MEM;

storage/spider/mysql-test/spider/bugfix/t/plugin_load_add_all.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
--echo #
44
# A simple test that tests plugin-load-add=ha_spider
55
select * from mysql.plugin;
6+
select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = "information_schema" and TABLE_NAME like "SPIDER_%";
67
create table t (c int) Engine=SPIDER;
78
drop table t;

storage/spider/spd_i_s.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,10 @@ static int spider_i_s_alloc_mem_init(
129129
void *p
130130
) {
131131
ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *) p;
132+
const LEX_CSTRING spider_name={STRING_WITH_LEN("SPIDER")};
132133
DBUG_ENTER("spider_i_s_alloc_mem_init");
134+
if (!plugin_is_ready(&spider_name, MYSQL_STORAGE_ENGINE_PLUGIN))
135+
DBUG_RETURN(HA_ERR_RETRY_INIT);
133136
schema->fields_info = Show::spider_i_s_alloc_mem_fields_info;
134137
schema->fill_table = spider_i_s_alloc_mem_fill_table;
135138
schema->idx_field1 = 0;
@@ -249,7 +252,10 @@ static int spider_i_s_wrapper_protocols_init(
249252
void *p
250253
) {
251254
ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *) p;
255+
const LEX_CSTRING spider_name={STRING_WITH_LEN("SPIDER")};
252256
DBUG_ENTER("spider_i_s_wrapper_protocols_init");
257+
if (!plugin_is_ready(&spider_name, MYSQL_STORAGE_ENGINE_PLUGIN))
258+
DBUG_RETURN(HA_ERR_RETRY_INIT);
253259
schema->fields_info = Show::spider_i_s_wrapper_protocols_fields_info;
254260
schema->fill_table = spider_i_s_wrapper_protocols_fill_table;
255261
schema->idx_field1 = 0;

0 commit comments

Comments
 (0)