Skip to content

Commit

Permalink
MDEV-30727 Check spider_hton_ptr in spider udfs
Browse files Browse the repository at this point in the history
We have to #undef my_error and find it from udfs when spider is not
installed.
  • Loading branch information
mariadb-YuchenPei committed Apr 29, 2024
1 parent bda8d4f commit 267dd5a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
24 changes: 24 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/r/mdev_30727.result
Original file line number Diff line number Diff line change
@@ -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 changes: 30 additions & 0 deletions storage/spider/mysql-test/spider/bugfix/t/mdev_30727.test
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions storage/spider/spd_copy_tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions storage/spider/spd_direct_sql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
Expand Down

0 comments on commit 267dd5a

Please sign in to comment.