Commit b9cf26f7 authored by Jacob Mathew's avatar Jacob Mathew

MDEV-12900: spider tests failed in buildbot with valgrind

The failures with valgrind occur as a result of Spider sometimes using the
wrong transaction for operations in background threads that send requests to
the data nodes.  The use of the wrong transaction caused the networking to the
data nodes to use the wrong thread in some cases.  Valgrind eventually
detects this when such a thread is destroyed before it is used to disconnect
from the data node by that wrong transaction when it is freed.

I have fixed the problem by correcting the transaction used in each of these
cases.

Author:
  Jacob Mathew.

Reviewer:
  Kentoku Shiba.

Merged:
  Commit 4d576d9d on branch bb-10.3-MDEV-12900
parents ff1af15f 4d576d9d
......@@ -86,9 +86,6 @@ extern PSI_thread_key spd_key_thd_bg_crd;
extern PSI_thread_key spd_key_thd_bg_mon;
#endif
#endif
extern pthread_mutex_t spider_global_trx_mutex;
extern SPIDER_TRX *spider_global_trx;
#endif
HASH spider_open_connections;
......@@ -2994,9 +2991,6 @@ void *spider_bg_sts_action(
DBUG_RETURN(NULL);
}
share->bg_sts_thd = thd;
/*
spider.trx = spider_global_trx;
*/
spider.trx = trx;
spider.share = share;
spider.conns = conns;
......@@ -3105,13 +3099,11 @@ void *spider_bg_sts_action(
{
if (!conns[spider.search_link_idx])
{
pthread_mutex_lock(&spider_global_trx_mutex);
spider_get_conn(share, spider.search_link_idx,
share->conn_keys[spider.search_link_idx],
spider_global_trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
&error_num);
conns[spider.search_link_idx]->error_mode = 0;
pthread_mutex_unlock(&spider_global_trx_mutex);
/*
if (
error_num &&
......@@ -3120,7 +3112,7 @@ void *spider_bg_sts_action(
) {
lex_start(thd);
error_num = spider_ping_table_mon_from_table(
spider_global_trx,
trx,
thd,
share,
spider.search_link_idx,
......@@ -3142,7 +3134,6 @@ void *spider_bg_sts_action(
}
if (spider.search_link_idx != -1 && conns[spider.search_link_idx])
{
DBUG_ASSERT(!conns[spider.search_link_idx]->thd);
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (spider_get_sts(share, spider.search_link_idx,
share->bg_sts_try_time, &spider,
......@@ -3163,7 +3154,7 @@ void *spider_bg_sts_action(
) {
lex_start(thd);
error_num = spider_ping_table_mon_from_table(
spider_global_trx,
trx,
thd,
share,
spider.search_link_idx,
......@@ -3369,9 +3360,6 @@ void *spider_bg_crd_action(
table.s = share->table_share;
table.field = share->table_share->field;
table.key_info = share->table_share->key_info;
/*
spider.trx = spider_global_trx;
*/
spider.trx = trx;
spider.change_table_ptr(&table, share->table_share);
spider.share = share;
......@@ -3481,13 +3469,11 @@ void *spider_bg_crd_action(
{
if (!conns[spider.search_link_idx])
{
pthread_mutex_lock(&spider_global_trx_mutex);
spider_get_conn(share, spider.search_link_idx,
share->conn_keys[spider.search_link_idx],
spider_global_trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
trx, &spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
&error_num);
conns[spider.search_link_idx]->error_mode = 0;
pthread_mutex_unlock(&spider_global_trx_mutex);
/*
if (
error_num &&
......@@ -3496,7 +3482,7 @@ void *spider_bg_crd_action(
) {
lex_start(thd);
error_num = spider_ping_table_mon_from_table(
spider_global_trx,
trx,
thd,
share,
spider.search_link_idx,
......@@ -3518,7 +3504,6 @@ void *spider_bg_crd_action(
}
if (spider.search_link_idx != -1 && conns[spider.search_link_idx])
{
DBUG_ASSERT(!conns[spider.search_link_idx]->thd);
#ifdef WITH_PARTITION_STORAGE_ENGINE
if (spider_get_crd(share, spider.search_link_idx,
share->bg_crd_try_time, &spider, &table,
......@@ -3539,7 +3524,7 @@ void *spider_bg_crd_action(
) {
lex_start(thd);
error_num = spider_ping_table_mon_from_table(
spider_global_trx,
trx,
thd,
share,
spider.search_link_idx,
......@@ -3902,7 +3887,7 @@ void *spider_bg_mon_action(
{
lex_start(thd);
error_num = spider_ping_table_mon_from_table(
spider_global_trx,
trx,
thd,
share,
link_idx,
......
......@@ -54,11 +54,6 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status;
extern PSI_mutex_key spd_key_mutex_mon_table_cache;
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
extern pthread_mutex_t spider_global_trx_mutex;
extern SPIDER_TRX *spider_global_trx;
#endif
HASH *spider_udf_table_mon_list_hash;
uint spider_udf_table_mon_list_hash_id;
const char *spider_udf_table_mon_list_hash_func_name;
......@@ -134,7 +129,6 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
)
#endif
{
DBUG_ASSERT(trx != spider_global_trx);
if (
table_mon_list &&
table_mon_list->mon_table_cache_version != mon_table_cache_version
......@@ -659,29 +653,17 @@ SPIDER_CONN *spider_get_ping_table_tgt_conn(
) {
SPIDER_CONN *conn;
DBUG_ENTER("spider_get_ping_table_tgt_conn");
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (trx == spider_global_trx)
pthread_mutex_lock(&spider_global_trx_mutex);
#endif
if (
!(conn = spider_get_conn(
share, 0, share->conn_keys[0], trx, NULL, FALSE, FALSE,
SPIDER_CONN_KIND_MYSQL, error_num))
) {
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (trx == spider_global_trx)
pthread_mutex_unlock(&spider_global_trx_mutex);
#endif
my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0),
share->server_names[0]);
*error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE;
goto error;
}
#ifndef DBUG_OFF
if (trx == spider_global_trx)
{
DBUG_ASSERT(!conn->thd);
}
DBUG_PRINT("info",("spider conn->thd=%p", conn->thd));
if (conn->thd)
{
......@@ -689,10 +671,6 @@ SPIDER_CONN *spider_get_ping_table_tgt_conn(
}
#endif
conn->error_mode = 0;
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (trx == spider_global_trx)
pthread_mutex_unlock(&spider_global_trx_mutex);
#endif
DBUG_RETURN(conn);
error:
......
......@@ -151,9 +151,6 @@ PSI_mutex_key spd_key_mutex_conn;
PSI_mutex_key spd_key_mutex_hs_r_conn;
PSI_mutex_key spd_key_mutex_hs_w_conn;
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
PSI_mutex_key spd_key_mutex_global_trx;
#endif
PSI_mutex_key spd_key_mutex_open_conn;
PSI_mutex_key spd_key_mutex_allocated_thds;
PSI_mutex_key spd_key_mutex_mon_table_cache;
......@@ -203,9 +200,6 @@ static PSI_mutex_info all_spider_mutexes[]=
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
{ &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_hs_w_conn, "hs_w_conn", PSI_FLAG_GLOBAL},
#endif
#ifndef WITHOUT_SPIDER_BG_SEARCH
{ &spd_key_mutex_global_trx, "global_trx", PSI_FLAG_GLOBAL},
#endif
{ &spd_key_mutex_open_conn, "open_conn", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_allocated_thds, "allocated_thds", PSI_FLAG_GLOBAL},
......@@ -386,9 +380,6 @@ pthread_mutex_t spider_allocated_thds_mutex;
#ifndef WITHOUT_SPIDER_BG_SEARCH
pthread_attr_t spider_pt_attr;
pthread_mutex_t spider_global_trx_mutex;
SPIDER_TRX *spider_global_trx;
#endif
extern pthread_mutex_t spider_mem_calc_mutex;
......@@ -6621,10 +6612,6 @@ int spider_db_done(
do_delete_thd = TRUE;
}
#ifndef WITHOUT_SPIDER_BG_SEARCH
spider_free_trx(spider_global_trx, TRUE);
#endif
for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--)
{
if (spider_dbton[roop_count].deinit)
......@@ -6807,9 +6794,6 @@ int spider_db_done(
pthread_mutex_destroy(&spider_mon_table_cache_mutex);
pthread_mutex_destroy(&spider_allocated_thds_mutex);
pthread_mutex_destroy(&spider_open_conn_mutex);
#ifndef WITHOUT_SPIDER_BG_SEARCH
pthread_mutex_destroy(&spider_global_trx_mutex);
#endif
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
pthread_mutex_destroy(&spider_hs_w_conn_mutex);
pthread_mutex_destroy(&spider_hs_r_conn_mutex);
......@@ -7085,18 +7069,6 @@ int spider_db_init(
error_num = HA_ERR_OUT_OF_MEM;
goto error_conn_mutex_init;
}
#ifndef WITHOUT_SPIDER_BG_SEARCH
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&spider_global_trx_mutex, MY_MUTEX_INIT_FAST))
#else
if (mysql_mutex_init(spd_key_mutex_global_trx,
&spider_global_trx_mutex, MY_MUTEX_INIT_FAST))
#endif
{
error_num = HA_ERR_OUT_OF_MEM;
goto error_global_trx_mutex_init;
}
#endif
#if MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST))
#else
......@@ -7399,16 +7371,9 @@ int spider_db_init(
}
}
#ifndef WITHOUT_SPIDER_BG_SEARCH
if (!(spider_global_trx = spider_get_trx(NULL, FALSE, &error_num)))
goto error;
#endif
DBUG_RETURN(0);
#ifndef WITHOUT_SPIDER_BG_SEARCH
error:
roop_count = SPIDER_DBTON_SIZE;
error_init_dbton:
for (roop_count--; roop_count >= 0; roop_count--)
{
......@@ -7525,10 +7490,6 @@ int spider_db_init(
#endif
pthread_mutex_destroy(&spider_open_conn_mutex);
error_open_conn_mutex_init:
#ifndef WITHOUT_SPIDER_BG_SEARCH
pthread_mutex_destroy(&spider_global_trx_mutex);
error_global_trx_mutex_init:
#endif
pthread_mutex_destroy(&spider_conn_mutex);
error_conn_mutex_init:
pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);
......@@ -10165,7 +10126,7 @@ void *spider_table_bg_crd_action(
{
spider_get_conn(share, spider->search_link_idx,
share->conn_keys[spider->search_link_idx],
spider_global_trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
trx, spider, FALSE, FALSE, SPIDER_CONN_KIND_MYSQL,
&error_num);
if (conns[spider->search_link_idx])
{
......
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