Commit 267dd5a9 authored by Yuchen Pei's avatar Yuchen Pei

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.
parent bda8d4fd
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
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
......@@ -1154,12 +1154,20 @@ long long spider_copy_tables_body(
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");
......
......@@ -1789,6 +1789,9 @@ long long spider_direct_sql_body(
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");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment