Skip to content

Commit d23ad36

Browse files
Revert "MDEV-27233 Server hangs when using --init-file which loads Spider and creates a Spider table"
This reverts commit c160a11.
1 parent 1ebfa2a commit d23ad36

File tree

9 files changed

+214
-64
lines changed

9 files changed

+214
-64
lines changed

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

storage/spider/mysql-test/spider/bugfix/t/mdev_27233.opt

Lines changed: 0 additions & 1 deletion
This file was deleted.

storage/spider/mysql-test/spider/bugfix/t/mdev_27233.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
This file was deleted.

storage/spider/mysql-test/spider/include/deinit_spider.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if (`SELECT IF($PLUGIN_VERSION = 3, 1, 0)`)
2020
if ($HAS_REWRITE)
2121
{
2222
DROP FUNCTION spider_flush_rewrite_cache;
23+
UNINSTALL PLUGIN spider_rewrite;
2324
DROP TABLE IF EXISTS mysql.spider_rewrite_tables;
2425
DROP TABLE IF EXISTS mysql.spider_rewrite_table_tables;
2526
DROP TABLE IF EXISTS mysql.spider_rewrite_table_partitions;
@@ -32,7 +33,9 @@ DROP FUNCTION spider_copy_tables;
3233
DROP FUNCTION spider_ping_table;
3334
DROP FUNCTION spider_bg_direct_sql;
3435
DROP FUNCTION spider_direct_sql;
35-
UNINSTALL SONAME "ha_spider.so";
36+
UNINSTALL PLUGIN spider_wrapper_protocols;
37+
UNINSTALL PLUGIN spider_alloc_mem;
38+
UNINSTALL PLUGIN spider;
3639
DROP TABLE IF EXISTS mysql.spider_xa;
3740
DROP TABLE IF EXISTS mysql.spider_xa_member;
3841
DROP TABLE IF EXISTS mysql.spider_xa_failed_log;

storage/spider/mysql-test/spider/include/init_spider.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let $VERSION_COMPILE_OS_WIN=
22
`SELECT IF(@@version_compile_os like 'Win%', 1, 0)`;
33
if ($VERSION_COMPILE_OS_WIN)
44
{
5-
INSTALL SONAME 'ha_spider.dll';
5+
INSTALL PLUGIN spider SONAME 'ha_spider.dll';
66
if ($MASTER_1_MYPORT)
77
{
88
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (
@@ -76,7 +76,7 @@ if ($VERSION_COMPILE_OS_WIN)
7676
}
7777
if (!$VERSION_COMPILE_OS_WIN)
7878
{
79-
INSTALL SONAME 'ha_spider.so';
79+
INSTALL PLUGIN spider SONAME 'ha_spider.so';
8080
if ($MASTER_1_MYSOCK)
8181
{
8282
eval CREATE SERVER s_1 FOREIGN DATA WRAPPER mysql OPTIONS (

storage/spider/spd_include.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ typedef struct st_spider_thread
324324
volatile bool killed;
325325
volatile bool thd_wait;
326326
volatile bool first_free_wait;
327+
volatile bool init_command;
327328
volatile int error;
328329
pthread_t thread;
329330
pthread_cond_t cond;

storage/spider/spd_init_query.h

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,82 @@ static LEX_STRING spider_init_queries[] = {
662662
"create procedure mysql.spider_plugin_installer()"
663663
"begin"
664664
" set @win_plugin := IF(@@version_compile_os like 'Win%', 1, 0);"
665+
/*
666+
Install spider plugin
667+
*/
668+
/*
669+
" set @have_spider_i_s_plugin := 0;"
670+
" select @have_spider_i_s_plugin := 1 from INFORMATION_SCHEMA.plugins"
671+
" where PLUGIN_NAME = 'SPIDER';"
672+
" set @have_spider_plugin := 0;"
673+
" select @have_spider_plugin := 1 from mysql.plugin"
674+
" where name = 'spider';"
675+
" if @have_spider_i_s_plugin = 0 then"
676+
" if @have_spider_plugin = 1 then"
677+
" / *"
678+
" spider plugin is present in mysql.plugin but not in"
679+
" information_schema.plugins. Remove spider plugin entry"
680+
" in mysql.plugin first."
681+
" * /"
682+
" delete from mysql.plugin where name = 'spider';"
683+
" end if;"
684+
" if @win_plugin = 0 then "
685+
" install plugin spider soname 'ha_spider.so';"
686+
" else"
687+
" install plugin spider soname 'ha_spider.dll';"
688+
" end if;"
689+
" end if;"
690+
*/
691+
/*
692+
Install spider_alloc_mem plugin
693+
*/
694+
" set @have_spider_i_s_alloc_mem_plugin := 0;"
695+
" select @have_spider_i_s_alloc_mem_plugin := 1"
696+
" from INFORMATION_SCHEMA.plugins"
697+
" where PLUGIN_NAME = 'SPIDER_ALLOC_MEM';"
698+
" set @have_spider_alloc_mem_plugin := 0;"
699+
" select @have_spider_alloc_mem_plugin := 1 from mysql.plugin"
700+
" where name = 'spider_alloc_mem';"
701+
" if @have_spider_i_s_alloc_mem_plugin = 0 then"
702+
" if @have_spider_alloc_mem_plugin = 1 then"
703+
" /*"
704+
" spider_alloc_mem plugin is present in mysql.plugin but not in"
705+
" information_schema.plugins. Remove spider_alloc_mem plugin entry"
706+
" in mysql.plugin first."
707+
" */"
708+
" delete from mysql.plugin where name = 'spider_alloc_mem';"
709+
" end if;"
710+
" if @win_plugin = 0 then "
711+
" install plugin spider_alloc_mem soname 'ha_spider.so';"
712+
" else"
713+
" install plugin spider_alloc_mem soname 'ha_spider.dll';"
714+
" end if;"
715+
" end if;"
716+
/*
717+
Install spider_wrapper_protocols plugin
718+
*/
719+
" set @have_spider_i_s_wrapper_protocols_plugin := 0;"
720+
" select @have_spider_i_s_wrapper_protocols_plugin := 1"
721+
" from INFORMATION_SCHEMA.plugins"
722+
" where PLUGIN_NAME = 'SPIDER_WRAPPER_PROTOCOLS';"
723+
" set @have_spider_wrapper_protocols_plugin := 0;"
724+
" select @have_spider_wrapper_protocols_plugin := 1 from mysql.plugin"
725+
" where name = 'spider_wrapper_protocols';"
726+
" if @have_spider_i_s_wrapper_protocols_plugin = 0 then"
727+
" if @have_spider_wrapper_protocols_plugin = 1 then"
728+
" /*"
729+
" spider_wrapper_protocols plugin is present in mysql.plugin but not in"
730+
" information_schema.plugins. Remove spider_wrapper_protocols plugin entry"
731+
" in mysql.plugin first."
732+
" */"
733+
" delete from mysql.plugin where name = 'spider_wrapper_protocols';"
734+
" end if;"
735+
" if @win_plugin = 0 then "
736+
" install plugin spider_wrapper_protocols soname 'ha_spider.so';"
737+
" else"
738+
" install plugin spider_wrapper_protocols soname 'ha_spider.dll';"
739+
" end if;"
740+
" end if;"
665741
" set @have_spider_direct_sql_udf := 0;"
666742
" select @have_spider_direct_sql_udf := 1 from mysql.func"
667743
" where name = 'spider_direct_sql';"
@@ -722,12 +798,60 @@ static LEX_STRING spider_init_queries[] = {
722798
" soname 'ha_spider.dll';"
723799
" end if;"
724800
" end if;"
801+
" if @server_name = 'MariaDB' and"
802+
" ("
803+
" @server_major_version > 10 or"
804+
" ("
805+
" @server_major_version = 10 and"
806+
" @server_minor_version >= 8"
807+
" )"
808+
" )"
809+
" then"
810+
/*
811+
Install spider_rewrite plugin
812+
*/
813+
" set @have_spider_i_s_rewrite_plugin := 0;"
814+
" select @have_spider_i_s_rewrite_plugin := 1"
815+
" from INFORMATION_SCHEMA.plugins"
816+
" where PLUGIN_NAME = 'SPIDER_REWRITE';"
817+
" set @have_spider_rewrite_plugin := 0;"
818+
" select @have_spider_rewrite_plugin := 1 from mysql.plugin"
819+
" where name = 'spider_rewrite';"
820+
" if @have_spider_i_s_rewrite_plugin = 0 then"
821+
" if @have_spider_rewrite_plugin = 1 then"
822+
" /*"
823+
" spider_rewrite plugin is present in mysql.plugin but not in"
824+
" information_schema.plugins. Remove spider_rewrite plugin entry"
825+
" in mysql.plugin first."
826+
" */"
827+
" delete from mysql.plugin where name = 'spider_rewrite';"
828+
" end if;"
829+
" if @win_plugin = 0 then "
830+
" install plugin spider_rewrite soname 'ha_spider.so';"
831+
" else"
832+
" install plugin spider_rewrite soname 'ha_spider.dll';"
833+
" end if;"
834+
" end if;"
835+
" set @have_spider_flush_rewrite_cache_udf := 0;"
836+
" select @have_spider_flush_rewrite_cache_udf := 1 from mysql.func"
837+
" where name = 'spider_flush_rewrite_cache';"
838+
" if @have_spider_flush_rewrite_cache_udf = 0 then"
839+
" if @win_plugin = 0 then "
840+
" create function spider_flush_rewrite_cache returns int"
841+
" soname 'ha_spider.so';"
842+
" else"
843+
" create function spider_flush_rewrite_cache returns int"
844+
" soname 'ha_spider.dll';"
845+
" end if;"
846+
" end if;"
847+
" end if;"
725848
"end;"
726849
)},
727850
{C_STRING_WITH_LEN(
728851
"call mysql.spider_plugin_installer"
729852
)},
730853
{C_STRING_WITH_LEN(
731854
"drop procedure mysql.spider_plugin_installer"
732-
)}
855+
)},
856+
{C_STRING_WITH_LEN("")}
733857
};

storage/spider/spd_table.cc

Lines changed: 82 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ const char **spd_mysqld_unix_port;
129129
uint *spd_mysqld_port;
130130
bool volatile *spd_abort_loop;
131131
Time_zone *spd_tz_system;
132+
static int *spd_mysqld_server_started;
133+
static pthread_mutex_t *spd_LOCK_server_started;
134+
static pthread_cond_t *spd_COND_server_started;
132135
extern long spider_conn_mutex_id;
133136
handlerton *spider_hton_ptr;
134137
SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
@@ -7050,6 +7053,30 @@ handler* spider_create_handler(
70507053
MEM_ROOT *mem_root
70517054
) {
70527055
DBUG_ENTER("spider_create_handler");
7056+
#ifndef WITHOUT_SPIDER_BG_SEARCH
7057+
SPIDER_THREAD *thread = &spider_table_sts_threads[0];
7058+
if (unlikely(thread->init_command))
7059+
{
7060+
THD *thd = current_thd;
7061+
pthread_cond_t *cond = thd->mysys_var->current_cond;
7062+
pthread_mutex_t *mutex = thd->mysys_var->current_mutex;
7063+
/* wait for finishing init_command */
7064+
pthread_mutex_lock(&thread->mutex);
7065+
if (unlikely(thread->init_command))
7066+
{
7067+
thd->mysys_var->current_cond = &thread->sync_cond;
7068+
thd->mysys_var->current_mutex = &thread->mutex;
7069+
pthread_cond_wait(&thread->sync_cond, &thread->mutex);
7070+
}
7071+
pthread_mutex_unlock(&thread->mutex);
7072+
thd->mysys_var->current_cond = cond;
7073+
thd->mysys_var->current_mutex = mutex;
7074+
if (thd->killed)
7075+
{
7076+
DBUG_RETURN(NULL);
7077+
}
7078+
}
7079+
#endif
70537080
DBUG_RETURN(new (mem_root) ha_spider(hton, table));
70547081
}
70557082

@@ -7370,50 +7397,6 @@ int spider_panic(
73707397
DBUG_RETURN(0);
73717398
}
73727399

7373-
/*
7374-
Create or fix the system tables. See spd_init_query.h for the details.
7375-
*/
7376-
bool spider_init_system_tables()
7377-
{
7378-
DBUG_ENTER("spider_init_system_tables");
7379-
7380-
MYSQL *mysql= mysql_init(NULL);
7381-
if (!mysql)
7382-
{
7383-
DBUG_RETURN(TRUE);
7384-
}
7385-
7386-
if (!mysql_real_connect_local(mysql))
7387-
{
7388-
mysql_close(mysql);
7389-
DBUG_RETURN(TRUE);
7390-
}
7391-
7392-
int size= sizeof(spider_init_queries) / sizeof(spider_init_queries[0]);
7393-
for (int i= 0; i < size; i++)
7394-
{
7395-
if (mysql_real_query(mysql, spider_init_queries[i].str,
7396-
spider_init_queries[i].length))
7397-
{
7398-
fprintf(stderr,
7399-
"[ERROR] SPIDER plugin initialization failed at '%s' by '%s'\n",
7400-
spider_init_queries[i].str, mysql_error(mysql));
7401-
7402-
mysql_close(mysql);
7403-
DBUG_RETURN(TRUE);
7404-
}
7405-
7406-
if (MYSQL_RES *res= mysql_store_result(mysql))
7407-
{
7408-
mysql_free_result(res);
7409-
}
7410-
}
7411-
7412-
mysql_close(mysql);
7413-
7414-
DBUG_RETURN(FALSE);
7415-
}
7416-
74177400
int spider_db_init(
74187401
void *p
74197402
) {
@@ -7501,6 +7484,9 @@ int spider_db_init(
75017484
spd_mysqld_port = &mysqld_port;
75027485
spd_abort_loop = &abort_loop;
75037486
spd_tz_system = my_tz_SYSTEM;
7487+
spd_mysqld_server_started = &mysqld_server_started;
7488+
spd_LOCK_server_started = &LOCK_server_started;
7489+
spd_COND_server_started = &COND_server_started;
75047490

75057491
#ifdef HAVE_PSI_INTERFACE
75067492
init_spider_psi_keys();
@@ -7776,11 +7762,6 @@ int spider_db_init(
77767762
spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
77777763
}
77787764

7779-
if (spider_init_system_tables())
7780-
{
7781-
goto error_system_table_creation;
7782-
}
7783-
77847765
#ifndef WITHOUT_SPIDER_BG_SEARCH
77857766
if (!(spider_table_sts_threads = (SPIDER_THREAD *)
77867767
spider_bulk_malloc(NULL, 256, MYF(MY_WME | MY_ZEROFILL),
@@ -7791,6 +7772,7 @@ int spider_db_init(
77917772
NullS))
77927773
)
77937774
goto error_alloc_mon_mutxes;
7775+
spider_table_sts_threads[0].init_command = TRUE;
77947776

77957777
for (roop_count = 0;
77967778
roop_count < (int) spider_param_table_sts_thread_count();
@@ -7881,7 +7863,6 @@ int spider_db_init(
78817863
error_init_udf_table_mon_cond:
78827864
for (; roop_count >= 0; roop_count--)
78837865
pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
7884-
error_system_table_creation:
78857866
roop_count = spider_param_udf_table_mon_mutex_count() - 1;
78867867
error_init_udf_table_mon_mutex:
78877868
for (; roop_count >= 0; roop_count--)
@@ -10497,6 +10478,57 @@ void *spider_table_bg_sts_action(
1049710478
trx->thd = thd;
1049810479
/* init end */
1049910480

10481+
if (thread->init_command)
10482+
{
10483+
uint i = 0;
10484+
tmp_disable_binlog(thd);
10485+
thd->security_ctx->skip_grants();
10486+
thd->client_capabilities |= CLIENT_MULTI_RESULTS;
10487+
if (!(*spd_mysqld_server_started) && !thd->killed)
10488+
{
10489+
pthread_mutex_lock(spd_LOCK_server_started);
10490+
thd->mysys_var->current_cond = spd_COND_server_started;
10491+
thd->mysys_var->current_mutex = spd_LOCK_server_started;
10492+
if (!(*spd_mysqld_server_started) && !thd->killed)
10493+
{
10494+
do
10495+
{
10496+
struct timespec abstime;
10497+
set_timespec_nsec(abstime, 1000);
10498+
error_num = pthread_cond_timedwait(spd_COND_server_started,
10499+
spd_LOCK_server_started, &abstime);
10500+
} while (
10501+
(error_num == ETIMEDOUT || error_num == ETIME) &&
10502+
!(*spd_mysqld_server_started) && !thd->killed && !thread->killed
10503+
);
10504+
}
10505+
pthread_mutex_unlock(spd_LOCK_server_started);
10506+
thd->mysys_var->current_cond = &thread->cond;
10507+
thd->mysys_var->current_mutex = &thread->mutex;
10508+
}
10509+
while (spider_init_queries[i].length && !thd->killed && !thread->killed)
10510+
{
10511+
dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
10512+
(uint) spider_init_queries[i].length);
10513+
if (unlikely(thd->is_error()))
10514+
{
10515+
fprintf(stderr, "[ERROR] %s\n", spider_stmt_da_message(thd));
10516+
thd->clear_error();
10517+
break;
10518+
}
10519+
++i;
10520+
}
10521+
thd->mysys_var->current_cond = &thread->cond;
10522+
thd->mysys_var->current_mutex = &thread->mutex;
10523+
thd->client_capabilities -= CLIENT_MULTI_RESULTS;
10524+
reenable_binlog(thd);
10525+
thread->init_command = FALSE;
10526+
pthread_cond_broadcast(&thread->sync_cond);
10527+
}
10528+
if (thd->killed)
10529+
{
10530+
thread->killed = TRUE;
10531+
}
1050010532
if (thd->killed)
1050110533
{
1050210534
thread->killed = TRUE;

0 commit comments

Comments
 (0)