Skip to content

Commit

Permalink
MDEV-15712: If remote server used by Spider table is unavailable, som…
Browse files Browse the repository at this point in the history
…e operations hang for a long time

When an attempt to connect to the remote server fails, Spider retries to
connect to the remote server 1000 times or until the connection attempt
succeeds.  This is perceived as a hang if the remote server remains
unavailable.

I have introduced changes in Spider's table status handler to fix this problem.

Author:
  Jacob Mathew.

Reviewer:
  Kentoku Shiba.

Merged From:
  Branch bb-10.3-MDEV-15712.
  • Loading branch information
Jacob Mathew committed May 1, 2018
2 parents 68cbabb + 6ee6933 commit bf92784
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion storage/spider/spd_db_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ int spider_db_connect(
conn->net_write_timeout = spider_param_net_write_timeout(thd,
share->net_write_timeouts[link_idx]);
connect_retry_interval = spider_param_connect_retry_interval(thd);
connect_retry_count = spider_param_connect_retry_count(thd);
if (conn->disable_connect_retry)
connect_retry_count = 0;
else
connect_retry_count = spider_param_connect_retry_count(thd);
} else {
conn->connect_timeout = spider_param_connect_timeout(NULL,
share->connect_timeouts[link_idx]);
Expand Down
21 changes: 20 additions & 1 deletion storage/spider/spd_db_mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11139,13 +11139,15 @@ int spider_mysql_handler::show_table_status(
ulonglong auto_increment_value = 0;
DBUG_ENTER("spider_mysql_handler::show_table_status");
DBUG_PRINT("info",("spider sts_mode=%d", sts_mode));

if (sts_mode == 1)
{
pthread_mutex_lock(&conn->mta_conn_mutex);
SPIDER_SET_FILE_POS(&conn->mta_conn_mutex_file_pos);
conn->need_mon = &spider->need_mons[link_idx];
conn->mta_conn_mutex_lock_already = TRUE;
conn->mta_conn_mutex_unlock_later = TRUE;
conn->disable_connect_retry = TRUE;
spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd,
share);
if (
Expand All @@ -11167,6 +11169,7 @@ int spider_mysql_handler::show_table_status(
/* retry */
if ((error_num = spider_db_ping(spider, conn, link_idx)))
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11175,6 +11178,7 @@ int spider_mysql_handler::show_table_status(
}
if ((error_num = spider_db_set_names(spider, conn, link_idx)))
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11190,11 +11194,13 @@ int spider_mysql_handler::show_table_status(
-1,
&spider->need_mons[link_idx])
) {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
DBUG_RETURN(spider_db_errorno(conn));
}
} else {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11210,6 +11216,7 @@ int spider_mysql_handler::show_table_status(
request_key.next = NULL;
if (spider_param_dry_access())
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11218,11 +11225,13 @@ int spider_mysql_handler::show_table_status(
}
if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num)))
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
if (error_num || (error_num = spider_db_errorno(conn)))
DBUG_RETURN(error_num);
else {
else
{
my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM,
ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0),
mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(),
Expand All @@ -11231,6 +11240,7 @@ int spider_mysql_handler::show_table_status(
DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM);
}
}
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand Down Expand Up @@ -11278,6 +11288,7 @@ int spider_mysql_handler::show_table_status(
conn->need_mon = &spider->need_mons[link_idx];
conn->mta_conn_mutex_lock_already = TRUE;
conn->mta_conn_mutex_unlock_later = TRUE;
conn->disable_connect_retry = TRUE;
spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd,
share);
if (
Expand All @@ -11299,6 +11310,7 @@ int spider_mysql_handler::show_table_status(
/* retry */
if ((error_num = spider_db_ping(spider, conn, link_idx)))
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11307,6 +11319,7 @@ int spider_mysql_handler::show_table_status(
}
if ((error_num = spider_db_set_names(spider, conn, link_idx)))
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11322,11 +11335,13 @@ int spider_mysql_handler::show_table_status(
-1,
&spider->need_mons[link_idx])
) {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
DBUG_RETURN(spider_db_errorno(conn));
}
} else {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11342,6 +11357,7 @@ int spider_mysql_handler::show_table_status(
request_key.next = NULL;
if (spider_param_dry_access())
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand All @@ -11350,13 +11366,15 @@ int spider_mysql_handler::show_table_status(
}
if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num)))
{
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
if (error_num || (error_num = spider_db_errorno(conn)))
DBUG_RETURN(error_num);
else
DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE);
}
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
Expand Down Expand Up @@ -11413,6 +11431,7 @@ int spider_mysql_handler::show_table_status(
DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value));
}

DBUG_RETURN(0);
}

Expand Down
3 changes: 3 additions & 0 deletions storage/spider/spd_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ typedef struct st_spider_conn
st_spider_conn *bulk_access_next;
#endif

bool disable_connect_retry; /* TRUE if it is unnecessary to
retry to connect after a
connection error */
bool connect_error_with_message;
char connect_error_msg[MYSQL_ERRMSG_SIZE];
int connect_error;
Expand Down

0 comments on commit bf92784

Please sign in to comment.