@@ -129,9 +129,6 @@ const char **spd_mysqld_unix_port;
129129uint *spd_mysqld_port;
130130bool volatile *spd_abort_loop;
131131Time_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;
135132extern long spider_conn_mutex_id;
136133handlerton *spider_hton_ptr;
137134SPIDER_DBTON spider_dbton[SPIDER_DBTON_SIZE];
@@ -7053,30 +7050,6 @@ handler* spider_create_handler(
70537050 MEM_ROOT *mem_root
70547051) {
70557052 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
70807053 DBUG_RETURN (new (mem_root) ha_spider (hton, table));
70817054}
70827055
@@ -7397,6 +7370,50 @@ int spider_panic(
73977370 DBUG_RETURN (0 );
73987371}
73997372
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+
74007417int spider_db_init (
74017418 void *p
74027419) {
@@ -7484,9 +7501,6 @@ int spider_db_init(
74847501 spd_mysqld_port = &mysqld_port;
74857502 spd_abort_loop = &abort_loop;
74867503 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;
74907504
74917505#ifdef HAVE_PSI_INTERFACE
74927506 init_spider_psi_keys ();
@@ -7762,6 +7776,11 @@ int spider_db_init(
77627776 spider_udf_table_mon_list_hash[roop_count].array .size_of_element );
77637777 }
77647778
7779+ if (spider_init_system_tables ())
7780+ {
7781+ goto error_system_table_creation;
7782+ }
7783+
77657784#ifndef WITHOUT_SPIDER_BG_SEARCH
77667785 if (!(spider_table_sts_threads = (SPIDER_THREAD *)
77677786 spider_bulk_malloc (NULL , 256 , MYF (MY_WME | MY_ZEROFILL),
@@ -7772,7 +7791,6 @@ int spider_db_init(
77727791 NullS))
77737792 )
77747793 goto error_alloc_mon_mutxes;
7775- spider_table_sts_threads[0 ].init_command = TRUE ;
77767794
77777795 for (roop_count = 0 ;
77787796 roop_count < (int ) spider_param_table_sts_thread_count ();
@@ -7863,6 +7881,7 @@ int spider_db_init(
78637881error_init_udf_table_mon_cond:
78647882 for (; roop_count >= 0 ; roop_count--)
78657883 pthread_cond_destroy (&spider_udf_table_mon_conds[roop_count]);
7884+ error_system_table_creation:
78667885 roop_count = spider_param_udf_table_mon_mutex_count () - 1 ;
78677886error_init_udf_table_mon_mutex:
78687887 for (; roop_count >= 0 ; roop_count--)
@@ -10478,57 +10497,6 @@ void *spider_table_bg_sts_action(
1047810497 trx->thd = thd;
1047910498 /* init end */
1048010499
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- }
1053210500 if (thd->killed )
1053310501 {
1053410502 thread->killed = TRUE ;
0 commit comments