summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--storage/spider/spd_include.h1
-rw-r--r--storage/spider/spd_init_query.h3
-rw-r--r--storage/spider/spd_table.cc129
3 files changed, 50 insertions, 83 deletions
diff --git a/storage/spider/spd_include.h b/storage/spider/spd_include.h
index 3c5c3754f4e..ce1107838c2 100644
--- a/storage/spider/spd_include.h
+++ b/storage/spider/spd_include.h
@@ -199,7 +199,6 @@ typedef struct st_spider_thread
volatile bool killed;
volatile bool thd_wait;
volatile bool first_free_wait;
- volatile bool init_command;
volatile int error;
pthread_t thread;
pthread_cond_t cond;
diff --git a/storage/spider/spd_init_query.h b/storage/spider/spd_init_query.h
index 5d9e53ada27..1e11e1b70e7 100644
--- a/storage/spider/spd_init_query.h
+++ b/storage/spider/spd_init_query.h
@@ -665,6 +665,5 @@ static LEX_STRING spider_init_queries[] = {
)},
{C_STRING_WITH_LEN(
"drop procedure mysql.spider_plugin_installer"
- )},
- {C_STRING_WITH_LEN("")}
+ )}
};
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 82a6ac41674..793916e0552 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -117,9 +117,6 @@ const char **spd_mysqld_unix_port;
uint *spd_mysqld_port;
bool volatile *spd_abort_loop;
Time_zone *spd_tz_system;
-static int *spd_mysqld_server_started;
-static pthread_mutex_t *spd_LOCK_server_started;
-static pthread_cond_t *spd_COND_server_started;
extern long spider_conn_mutex_id;
handlerton *spider_hton_ptr;
/** All `SPIDER_DBTON`s */
@@ -5912,28 +5909,6 @@ handler* spider_create_handler(
MEM_ROOT *mem_root
) {
DBUG_ENTER("spider_create_handler");
- SPIDER_THREAD *thread = &spider_table_sts_threads[0];
- if (unlikely(thread->init_command))
- {
- THD *thd = current_thd;
- pthread_cond_t *cond = thd->mysys_var->current_cond;
- pthread_mutex_t *mutex = thd->mysys_var->current_mutex;
- /* wait for finishing init_command */
- pthread_mutex_lock(&thread->mutex);
- if (unlikely(thread->init_command))
- {
- thd->mysys_var->current_cond = &thread->sync_cond;
- thd->mysys_var->current_mutex = &thread->mutex;
- pthread_cond_wait(&thread->sync_cond, &thread->mutex);
- }
- pthread_mutex_unlock(&thread->mutex);
- thd->mysys_var->current_cond = cond;
- thd->mysys_var->current_mutex = mutex;
- if (thd->killed)
- {
- DBUG_RETURN(NULL);
- }
- }
DBUG_RETURN(new (mem_root) ha_spider(hton, table));
}
@@ -6205,6 +6180,49 @@ static void spider_update_optimizer_costs(OPTIMIZER_COSTS *costs)
costs->row_copy_cost= 0.00006087;
}
+/*
+ Create or fix the system tables. See spd_init_query.h for the details.
+*/
+bool spider_init_system_tables()
+{
+ DBUG_ENTER("spider_init_system_tables");
+
+ MYSQL *mysql= mysql_init(NULL);
+ if (!mysql)
+ {
+ DBUG_RETURN(TRUE);
+ }
+
+ if (!mysql_real_connect_local(mysql))
+ {
+ mysql_close(mysql);
+ DBUG_RETURN(TRUE);
+ }
+
+ int size= sizeof(spider_init_queries) / sizeof(spider_init_queries[0]);
+ for (int i= 0; i < size; i++)
+ {
+ if (mysql_real_query(mysql, spider_init_queries[i].str,
+ spider_init_queries[i].length))
+ {
+ fprintf(stderr,
+ "[ERROR] SPIDER plugin initialization failed at '%s' by '%s'\n",
+ spider_init_queries[i].str, mysql_error(mysql));
+
+ mysql_close(mysql);
+ DBUG_RETURN(TRUE);
+ }
+
+ if (MYSQL_RES *res= mysql_store_result(mysql))
+ {
+ mysql_free_result(res);
+ }
+ }
+
+ mysql_close(mysql);
+
+ DBUG_RETURN(FALSE);
+}
int spider_db_init(
void *p
@@ -6280,9 +6298,6 @@ int spider_db_init(
spd_mysqld_port = &mysqld_port;
spd_abort_loop = &abort_loop;
spd_tz_system = my_tz_SYSTEM;
- spd_mysqld_server_started = &mysqld_server_started;
- spd_LOCK_server_started = &LOCK_server_started;
- spd_COND_server_started = &COND_server_started;
#ifdef HAVE_PSI_INTERFACE
init_spider_psi_keys();
@@ -6460,6 +6475,11 @@ int spider_db_init(
spider_udf_table_mon_list_hash[roop_count].array.size_of_element);
}
+ if (spider_init_system_tables())
+ {
+ goto error_system_table_creation;
+ }
+
if (!(spider_table_sts_threads = (SPIDER_THREAD *)
spider_bulk_malloc(NULL, 256, MYF(MY_WME | MY_ZEROFILL),
&spider_table_sts_threads, (uint) (sizeof(SPIDER_THREAD) *
@@ -6469,7 +6489,6 @@ int spider_db_init(
NullS))
)
goto error_alloc_mon_mutxes;
- spider_table_sts_threads[0].init_command = TRUE;
for (roop_count = 0;
roop_count < (int) spider_param_table_sts_thread_count();
@@ -6541,6 +6560,7 @@ error_init_udf_table_mon_list_hash:
error_init_udf_table_mon_cond:
for (; roop_count >= 0; roop_count--)
pthread_cond_destroy(&spider_udf_table_mon_conds[roop_count]);
+error_system_table_creation:
roop_count= spider_udf_table_mon_mutex_count - 1;
error_init_udf_table_mon_mutex:
for (; roop_count >= 0; roop_count--)
@@ -8605,7 +8625,6 @@ void spider_free_sts_threads(
) {
bool thread_killed;
DBUG_ENTER("spider_free_sts_threads");
- spider_thread->init_command = FALSE;
pthread_mutex_lock(&spider_thread->mutex);
thread_killed = spider_thread->killed;
spider_thread->killed = TRUE;
@@ -8737,56 +8756,6 @@ void *spider_table_bg_sts_action(
trx->thd = thd;
/* init end */
- if (thread->init_command)
- {
- uint i = 0;
- tmp_disable_binlog(thd);
- thd->security_ctx->skip_grants();
- thd->client_capabilities |= CLIENT_MULTI_RESULTS;
- if (!(*spd_mysqld_server_started) && !thd->killed && !thread->killed)
- {
- pthread_mutex_lock(spd_LOCK_server_started);
- thd->mysys_var->current_cond = spd_COND_server_started;
- thd->mysys_var->current_mutex = spd_LOCK_server_started;
- if (!(*spd_mysqld_server_started) && !thd->killed && !thread->killed &&
- thread->init_command)
- {
- do
- {
- struct timespec abstime;
- set_timespec_nsec(abstime, 1000);
- error_num = pthread_cond_timedwait(spd_COND_server_started,
- spd_LOCK_server_started, &abstime);
- } while (
- (error_num == ETIMEDOUT || error_num == ETIME) &&
- !(*spd_mysqld_server_started) && !thd->killed && !thread->killed &&
- thread->init_command
- );
- }
- pthread_mutex_unlock(spd_LOCK_server_started);
- thd->mysys_var->current_cond = &thread->cond;
- thd->mysys_var->current_mutex = &thread->mutex;
- }
- while (spider_init_queries[i].length && !thd->killed && !thread->killed &&
- thread->init_command)
- {
- dispatch_command(COM_QUERY, thd, spider_init_queries[i].str,
- (uint) spider_init_queries[i].length);
- if (unlikely(thd->is_error()))
- {
- fprintf(stderr, "[ERROR] %s\n", spider_stmt_da_message(thd));
- thd->clear_error();
- break;
- }
- ++i;
- }
- thd->mysys_var->current_cond = &thread->cond;
- thd->mysys_var->current_mutex = &thread->mutex;
- thd->client_capabilities -= CLIENT_MULTI_RESULTS;
- reenable_binlog(thd);
- thread->init_command = FALSE;
- pthread_cond_broadcast(&thread->sync_cond);
- }
if (thd->killed)
{
thread->killed = TRUE;