1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-27 05:41:41 +03:00

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 4d576d9 on branch bb-10.3-MDEV-12900
This commit is contained in:
Jacob Mathew
2018-05-21 18:16:03 -07:00
parent 31584c8bb8
commit afe5a51c2d
3 changed files with 7 additions and 83 deletions

View File

@@ -67,9 +67,6 @@ extern PSI_thread_key spd_key_thd_bg_crd;
extern PSI_thread_key spd_key_thd_bg_mon; extern PSI_thread_key spd_key_thd_bg_mon;
#endif #endif
#endif #endif
extern pthread_mutex_t spider_global_trx_mutex;
extern SPIDER_TRX *spider_global_trx;
#endif #endif
HASH spider_open_connections; HASH spider_open_connections;
@@ -2799,9 +2796,6 @@ void *spider_bg_sts_action(
DBUG_RETURN(NULL); DBUG_RETURN(NULL);
} }
share->bg_sts_thd = thd; share->bg_sts_thd = thd;
/*
spider.trx = spider_global_trx;
*/
spider.trx = trx; spider.trx = trx;
spider.share = share; spider.share = share;
spider.conns = conns; spider.conns = conns;
@@ -2914,13 +2908,11 @@ void *spider_bg_sts_action(
{ {
if (!conns[spider.search_link_idx]) if (!conns[spider.search_link_idx])
{ {
pthread_mutex_lock(&spider_global_trx_mutex);
spider_get_conn(share, spider.search_link_idx, spider_get_conn(share, spider.search_link_idx,
share->conn_keys[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); &error_num);
conns[spider.search_link_idx]->error_mode = 0; conns[spider.search_link_idx]->error_mode = 0;
pthread_mutex_unlock(&spider_global_trx_mutex);
/* /*
if ( if (
error_num && error_num &&
@@ -2929,7 +2921,7 @@ void *spider_bg_sts_action(
) { ) {
lex_start(thd); lex_start(thd);
error_num = spider_ping_table_mon_from_table( error_num = spider_ping_table_mon_from_table(
spider_global_trx, trx,
thd, thd,
share, share,
(uint32) share->monitoring_sid[spider.search_link_idx], (uint32) share->monitoring_sid[spider.search_link_idx],
@@ -2950,7 +2942,6 @@ void *spider_bg_sts_action(
} }
if (spider.search_link_idx != -1 && conns[spider.search_link_idx]) if (spider.search_link_idx != -1 && conns[spider.search_link_idx])
{ {
DBUG_ASSERT(!conns[spider.search_link_idx]->thd);
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
if (spider_get_sts(share, spider.search_link_idx, if (spider_get_sts(share, spider.search_link_idx,
share->bg_sts_try_time, &spider, share->bg_sts_try_time, &spider,
@@ -2971,7 +2962,7 @@ void *spider_bg_sts_action(
) { ) {
lex_start(thd); lex_start(thd);
error_num = spider_ping_table_mon_from_table( error_num = spider_ping_table_mon_from_table(
spider_global_trx, trx,
thd, thd,
share, share,
(uint32) share->monitoring_sid[spider.search_link_idx], (uint32) share->monitoring_sid[spider.search_link_idx],
@@ -3181,9 +3172,6 @@ void *spider_bg_crd_action(
table.s = share->table_share; table.s = share->table_share;
table.field = share->table_share->field; table.field = share->table_share->field;
table.key_info = share->table_share->key_info; table.key_info = share->table_share->key_info;
/*
spider.trx = spider_global_trx;
*/
spider.trx = trx; spider.trx = trx;
spider.change_table_ptr(&table, share->table_share); spider.change_table_ptr(&table, share->table_share);
spider.share = share; spider.share = share;
@@ -3297,13 +3285,11 @@ void *spider_bg_crd_action(
{ {
if (!conns[spider.search_link_idx]) if (!conns[spider.search_link_idx])
{ {
pthread_mutex_lock(&spider_global_trx_mutex);
spider_get_conn(share, spider.search_link_idx, spider_get_conn(share, spider.search_link_idx,
share->conn_keys[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); &error_num);
conns[spider.search_link_idx]->error_mode = 0; conns[spider.search_link_idx]->error_mode = 0;
pthread_mutex_unlock(&spider_global_trx_mutex);
/* /*
if ( if (
error_num && error_num &&
@@ -3312,7 +3298,7 @@ void *spider_bg_crd_action(
) { ) {
lex_start(thd); lex_start(thd);
error_num = spider_ping_table_mon_from_table( error_num = spider_ping_table_mon_from_table(
spider_global_trx, trx,
thd, thd,
share, share,
(uint32) share->monitoring_sid[spider.search_link_idx], (uint32) share->monitoring_sid[spider.search_link_idx],
@@ -3333,7 +3319,6 @@ void *spider_bg_crd_action(
} }
if (spider.search_link_idx != -1 && conns[spider.search_link_idx]) if (spider.search_link_idx != -1 && conns[spider.search_link_idx])
{ {
DBUG_ASSERT(!conns[spider.search_link_idx]->thd);
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
if (spider_get_crd(share, spider.search_link_idx, if (spider_get_crd(share, spider.search_link_idx,
share->bg_crd_try_time, &spider, &table, share->bg_crd_try_time, &spider, &table,
@@ -3354,7 +3339,7 @@ void *spider_bg_crd_action(
) { ) {
lex_start(thd); lex_start(thd);
error_num = spider_ping_table_mon_from_table( error_num = spider_ping_table_mon_from_table(
spider_global_trx, trx,
thd, thd,
share, share,
(uint32) share->monitoring_sid[spider.search_link_idx], (uint32) share->monitoring_sid[spider.search_link_idx],
@@ -3703,7 +3688,7 @@ void *spider_bg_mon_action(
{ {
lex_start(thd); lex_start(thd);
error_num = spider_ping_table_mon_from_table( error_num = spider_ping_table_mon_from_table(
spider_global_trx, trx,
thd, thd,
share, share,
(uint32) share->monitoring_sid[link_idx], (uint32) share->monitoring_sid[link_idx],

View File

@@ -52,11 +52,6 @@ extern PSI_mutex_key spd_key_mutex_mon_list_update_status;
extern PSI_mutex_key spd_key_mutex_mon_table_cache; extern PSI_mutex_key spd_key_mutex_mon_table_cache;
#endif #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; HASH *spider_udf_table_mon_list_hash;
uint spider_udf_table_mon_list_hash_id; uint spider_udf_table_mon_list_hash_id;
const char *spider_udf_table_mon_list_hash_func_name; const char *spider_udf_table_mon_list_hash_func_name;
@@ -130,7 +125,6 @@ SPIDER_TABLE_MON_LIST *spider_get_ping_table_mon_list(
) )
#endif #endif
{ {
DBUG_ASSERT(trx != spider_global_trx);
if ( if (
table_mon_list && table_mon_list &&
table_mon_list->mon_table_cache_version != mon_table_cache_version table_mon_list->mon_table_cache_version != mon_table_cache_version
@@ -608,29 +602,17 @@ SPIDER_CONN *spider_get_ping_table_tgt_conn(
) { ) {
SPIDER_CONN *conn; SPIDER_CONN *conn;
DBUG_ENTER("spider_get_ping_table_tgt_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 ( if (
!(conn = spider_get_conn( !(conn = spider_get_conn(
share, 0, share->conn_keys[0], trx, NULL, FALSE, FALSE, share, 0, share->conn_keys[0], trx, NULL, FALSE, FALSE,
SPIDER_CONN_KIND_MYSQL, error_num)) 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), my_error(ER_CONNECT_TO_FOREIGN_DATA_SOURCE, MYF(0),
share->server_names[0]); share->server_names[0]);
*error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE; *error_num = ER_CONNECT_TO_FOREIGN_DATA_SOURCE;
goto error; goto error;
} }
#ifndef DBUG_OFF #ifndef DBUG_OFF
if (trx == spider_global_trx)
{
DBUG_ASSERT(!conn->thd);
}
DBUG_PRINT("info",("spider conn->thd=%p", conn->thd)); DBUG_PRINT("info",("spider conn->thd=%p", conn->thd));
if (conn->thd) if (conn->thd)
{ {
@@ -638,10 +620,6 @@ SPIDER_CONN *spider_get_ping_table_tgt_conn(
} }
#endif #endif
conn->error_mode = 0; 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); DBUG_RETURN(conn);
error: error:

View File

@@ -97,9 +97,6 @@ PSI_mutex_key spd_key_mutex_conn;
PSI_mutex_key spd_key_mutex_hs_r_conn; PSI_mutex_key spd_key_mutex_hs_r_conn;
PSI_mutex_key spd_key_mutex_hs_w_conn; PSI_mutex_key spd_key_mutex_hs_w_conn;
#endif #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_open_conn;
PSI_mutex_key spd_key_mutex_allocated_thds; PSI_mutex_key spd_key_mutex_allocated_thds;
PSI_mutex_key spd_key_mutex_mon_table_cache; PSI_mutex_key spd_key_mutex_mon_table_cache;
@@ -143,9 +140,6 @@ static PSI_mutex_info all_spider_mutexes[]=
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
{ &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL}, { &spd_key_mutex_hs_r_conn, "hs_r_conn", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_hs_w_conn, "hs_w_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 #endif
{ &spd_key_mutex_open_conn, "open_conn", PSI_FLAG_GLOBAL}, { &spd_key_mutex_open_conn, "open_conn", PSI_FLAG_GLOBAL},
{ &spd_key_mutex_allocated_thds, "allocated_thds", PSI_FLAG_GLOBAL}, { &spd_key_mutex_allocated_thds, "allocated_thds", PSI_FLAG_GLOBAL},
@@ -300,9 +294,6 @@ pthread_mutex_t spider_allocated_thds_mutex;
#ifndef WITHOUT_SPIDER_BG_SEARCH #ifndef WITHOUT_SPIDER_BG_SEARCH
pthread_attr_t spider_pt_attr; pthread_attr_t spider_pt_attr;
pthread_mutex_t spider_global_trx_mutex;
SPIDER_TRX *spider_global_trx;
#endif #endif
extern pthread_mutex_t spider_mem_calc_mutex; extern pthread_mutex_t spider_mem_calc_mutex;
@@ -6096,10 +6087,6 @@ int spider_db_done(
do_delete_thd = TRUE; 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--) for (roop_count = SPIDER_DBTON_SIZE - 1; roop_count >= 0; roop_count--)
{ {
if (spider_dbton[roop_count].deinit) if (spider_dbton[roop_count].deinit)
@@ -6267,9 +6254,6 @@ int spider_db_done(
pthread_mutex_destroy(&spider_mon_table_cache_mutex); pthread_mutex_destroy(&spider_mon_table_cache_mutex);
pthread_mutex_destroy(&spider_allocated_thds_mutex); pthread_mutex_destroy(&spider_allocated_thds_mutex);
pthread_mutex_destroy(&spider_open_conn_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) #if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
pthread_mutex_destroy(&spider_hs_w_conn_mutex); pthread_mutex_destroy(&spider_hs_w_conn_mutex);
pthread_mutex_destroy(&spider_hs_r_conn_mutex); pthread_mutex_destroy(&spider_hs_r_conn_mutex);
@@ -6513,18 +6497,6 @@ int spider_db_init(
error_num = HA_ERR_OUT_OF_MEM; error_num = HA_ERR_OUT_OF_MEM;
goto error_conn_mutex_init; 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 MYSQL_VERSION_ID < 50500
if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST)) if (pthread_mutex_init(&spider_open_conn_mutex, MY_MUTEX_INIT_FAST))
#else #else
@@ -6789,16 +6761,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); DBUG_RETURN(0);
#ifndef WITHOUT_SPIDER_BG_SEARCH #ifndef WITHOUT_SPIDER_BG_SEARCH
error:
roop_count = SPIDER_DBTON_SIZE;
error_init_dbton: error_init_dbton:
for (roop_count--; roop_count >= 0; roop_count--) for (roop_count--; roop_count >= 0; roop_count--)
{ {
@@ -6900,10 +6865,6 @@ error_hs_r_conn_mutex_init:
#endif #endif
pthread_mutex_destroy(&spider_open_conn_mutex); pthread_mutex_destroy(&spider_open_conn_mutex);
error_open_conn_mutex_init: 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); pthread_mutex_destroy(&spider_conn_mutex);
error_conn_mutex_init: error_conn_mutex_init:
pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex); pthread_mutex_destroy(&spider_lgtm_tblhnd_share_mutex);