Browse Source

MDEV-30727 Check spider_hton_ptr in spider udfs

We have to #undef my_error and find it from udfs when spider is not
installed.
pull/3116/head
Yuchen Pei 2 years ago
parent
commit
267dd5a993
No known key found for this signature in database GPG Key ID: 3DD1B35105743563
  1. 24
      storage/spider/mysql-test/spider/bugfix/r/mdev_30727.result
  2. 30
      storage/spider/mysql-test/spider/bugfix/t/mdev_30727.test
  3. 8
      storage/spider/spd_copy_tables.cc
  4. 8
      storage/spider/spd_direct_sql.cc

24
storage/spider/mysql-test/spider/bugfix/r/mdev_30727.result

@ -0,0 +1,24 @@
CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.so';
SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
ERROR HY000: Plugin 'SPIDER' is not loaded
CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so';
SELECT spider_bg_direct_sql ('SELECT * FROM s','a','srv "b"');
ERROR HY000: Plugin 'SPIDER' is not loaded
CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.so';
SELECT spider_copy_tables ('t', '0', '0');
ERROR HY000: Plugin 'SPIDER' is not loaded
CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.so';
SELECT spider_flush_table_mon_cache ();
spider_flush_table_mon_cache ()
1
install soname 'ha_spider';
SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
ERROR HY000: The foreign server name you are trying to reference does not exist. Data source error: b
call mtr.add_suppression(".*\\[Error\\] (mysqld|mariadbd): Can't find record in 'spider_tables'");
SELECT spider_copy_tables ('t', '0', '0');
ERROR HY000: Can't find record in 'spider_tables'
SELECT spider_flush_table_mon_cache ();
spider_flush_table_mon_cache ()
1
Warnings:
Warning 1620 Plugin is busy and will be uninstalled on shutdown

30
storage/spider/mysql-test/spider/bugfix/t/mdev_30727.test

@ -0,0 +1,30 @@
CREATE FUNCTION spider_direct_sql RETURNS INT SONAME 'ha_spider.so';
--error ER_PLUGIN_IS_NOT_LOADED
SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
CREATE FUNCTION spider_bg_direct_sql RETURNS INT SONAME 'ha_spider.so';
--error ER_PLUGIN_IS_NOT_LOADED
SELECT spider_bg_direct_sql ('SELECT * FROM s','a','srv "b"');
CREATE FUNCTION spider_copy_tables RETURNS INT SONAME 'ha_spider.so';
--error ER_PLUGIN_IS_NOT_LOADED
SELECT spider_copy_tables ('t', '0', '0');
# spider_flush_table_mon_cache does not require spider init to function
CREATE FUNCTION spider_flush_table_mon_cache RETURNS INT SONAME 'ha_spider.so';
SELECT spider_flush_table_mon_cache ();
# The function functions properly after the plugin is installed
install soname 'ha_spider';
--error ER_FOREIGN_SERVER_DOESNT_EXIST
SELECT spider_direct_sql ('SELECT * FROM s','a','srv "b"');
call mtr.add_suppression(".*\\[Error\\] (mysqld|mariadbd): Can't find record in 'spider_tables'");
--error ER_KEY_NOT_FOUND
SELECT spider_copy_tables ('t', '0', '0');
SELECT spider_flush_table_mon_cache ();
--disable_query_log
--source ../../include/clean_up_spider.inc

8
storage/spider/spd_copy_tables.cc

@ -1154,12 +1154,20 @@ error:
DBUG_RETURN(0);
}
#undef my_error
extern "C" void my_error(unsigned int nr, unsigned long MyFlags, ...);
my_bool spider_copy_tables_init_body(
UDF_INIT *initid,
UDF_ARGS *args,
char *message
) {
DBUG_ENTER("spider_copy_tables_init_body");
if (!spider_hton_ptr)
{
my_error(ER_PLUGIN_IS_NOT_LOADED, MYF(0), "SPIDER");
goto error;
}
if (args->arg_count != 3 && args->arg_count != 4)
{
strcpy(message, "spider_copy_tables() requires 3 or 4 arguments");

8
storage/spider/spd_direct_sql.cc

@ -1789,6 +1789,9 @@ error:
DBUG_RETURN(0);
}
#undef my_error
extern "C" void my_error(unsigned int nr, unsigned long MyFlags, ...);
my_bool spider_direct_sql_init_body(
UDF_INIT *initid,
UDF_ARGS *args,
@ -1797,6 +1800,11 @@ my_bool spider_direct_sql_init_body(
) {
SPIDER_BG_DIRECT_SQL *bg_direct_sql;
DBUG_ENTER("spider_direct_sql_init_body");
if (!spider_hton_ptr)
{
my_error(ER_PLUGIN_IS_NOT_LOADED, MYF(0), "SPIDER");
goto error;
}
if (args->arg_count != 3)
{
strcpy(message, "spider_(bg)_direct_sql() requires 3 arguments");

Loading…
Cancel
Save