Commit bf92784d authored by Jacob Mathew's avatar Jacob Mathew

MDEV-15712: If remote server used by Spider table is unavailable, some...

MDEV-15712: If remote server used by Spider table is unavailable, some 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.
parents 68cbabbf 6ee6933a
...@@ -121,7 +121,10 @@ int spider_db_connect( ...@@ -121,7 +121,10 @@ int spider_db_connect(
conn->net_write_timeout = spider_param_net_write_timeout(thd, conn->net_write_timeout = spider_param_net_write_timeout(thd,
share->net_write_timeouts[link_idx]); share->net_write_timeouts[link_idx]);
connect_retry_interval = spider_param_connect_retry_interval(thd); 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 { } else {
conn->connect_timeout = spider_param_connect_timeout(NULL, conn->connect_timeout = spider_param_connect_timeout(NULL,
share->connect_timeouts[link_idx]); share->connect_timeouts[link_idx]);
......
...@@ -11139,6 +11139,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11139,6 +11139,7 @@ int spider_mysql_handler::show_table_status(
ulonglong auto_increment_value = 0; ulonglong auto_increment_value = 0;
DBUG_ENTER("spider_mysql_handler::show_table_status"); DBUG_ENTER("spider_mysql_handler::show_table_status");
DBUG_PRINT("info",("spider sts_mode=%d", sts_mode)); DBUG_PRINT("info",("spider sts_mode=%d", sts_mode));
if (sts_mode == 1) if (sts_mode == 1)
{ {
pthread_mutex_lock(&conn->mta_conn_mutex); pthread_mutex_lock(&conn->mta_conn_mutex);
...@@ -11146,6 +11147,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11146,6 +11147,7 @@ int spider_mysql_handler::show_table_status(
conn->need_mon = &spider->need_mons[link_idx]; conn->need_mon = &spider->need_mons[link_idx];
conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_lock_already = TRUE;
conn->mta_conn_mutex_unlock_later = 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, spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd,
share); share);
if ( if (
...@@ -11167,6 +11169,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11167,6 +11169,7 @@ int spider_mysql_handler::show_table_status(
/* retry */ /* retry */
if ((error_num = spider_db_ping(spider, conn, link_idx))) 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_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11175,6 +11178,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11175,6 +11178,7 @@ int spider_mysql_handler::show_table_status(
} }
if ((error_num = spider_db_set_names(spider, conn, link_idx))) 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_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11190,11 +11194,13 @@ int spider_mysql_handler::show_table_status( ...@@ -11190,11 +11194,13 @@ int spider_mysql_handler::show_table_status(
-1, -1,
&spider->need_mons[link_idx]) &spider->need_mons[link_idx])
) { ) {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
DBUG_RETURN(spider_db_errorno(conn)); DBUG_RETURN(spider_db_errorno(conn));
} }
} else { } else {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11210,6 +11216,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11210,6 +11216,7 @@ int spider_mysql_handler::show_table_status(
request_key.next = NULL; request_key.next = NULL;
if (spider_param_dry_access()) if (spider_param_dry_access())
{ {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11218,11 +11225,13 @@ int spider_mysql_handler::show_table_status( ...@@ -11218,11 +11225,13 @@ int spider_mysql_handler::show_table_status(
} }
if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) 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_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
if (error_num || (error_num = spider_db_errorno(conn))) if (error_num || (error_num = spider_db_errorno(conn)))
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
else { else
{
my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM, my_printf_error(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM,
ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0), ER_SPIDER_REMOTE_TABLE_NOT_FOUND_STR, MYF(0),
mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(), mysql_share->db_names_str[spider->conn_link_idx[link_idx]].ptr(),
...@@ -11231,6 +11240,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11231,6 +11240,7 @@ int spider_mysql_handler::show_table_status(
DBUG_RETURN(ER_SPIDER_REMOTE_TABLE_NOT_FOUND_NUM); 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_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11278,6 +11288,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11278,6 +11288,7 @@ int spider_mysql_handler::show_table_status(
conn->need_mon = &spider->need_mons[link_idx]; conn->need_mon = &spider->need_mons[link_idx];
conn->mta_conn_mutex_lock_already = TRUE; conn->mta_conn_mutex_lock_already = TRUE;
conn->mta_conn_mutex_unlock_later = 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, spider_conn_set_timeout_from_share(conn, link_idx, spider->trx->thd,
share); share);
if ( if (
...@@ -11299,6 +11310,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11299,6 +11310,7 @@ int spider_mysql_handler::show_table_status(
/* retry */ /* retry */
if ((error_num = spider_db_ping(spider, conn, link_idx))) 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_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11307,6 +11319,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11307,6 +11319,7 @@ int spider_mysql_handler::show_table_status(
} }
if ((error_num = spider_db_set_names(spider, conn, link_idx))) 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_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11322,11 +11335,13 @@ int spider_mysql_handler::show_table_status( ...@@ -11322,11 +11335,13 @@ int spider_mysql_handler::show_table_status(
-1, -1,
&spider->need_mons[link_idx]) &spider->need_mons[link_idx])
) { ) {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
DBUG_RETURN(spider_db_errorno(conn)); DBUG_RETURN(spider_db_errorno(conn));
} }
} else { } else {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11342,6 +11357,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11342,6 +11357,7 @@ int spider_mysql_handler::show_table_status(
request_key.next = NULL; request_key.next = NULL;
if (spider_param_dry_access()) if (spider_param_dry_access())
{ {
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11350,6 +11366,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11350,6 +11366,7 @@ int spider_mysql_handler::show_table_status(
} }
if (!(res = conn->db_conn->store_result(NULL, &request_key, &error_num))) 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_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
if (error_num || (error_num = spider_db_errorno(conn))) if (error_num || (error_num = spider_db_errorno(conn)))
...@@ -11357,6 +11374,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11357,6 +11374,7 @@ int spider_mysql_handler::show_table_status(
else else
DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE); DBUG_RETURN(ER_QUERY_ON_FOREIGN_DATA_SOURCE);
} }
conn->disable_connect_retry = FALSE;
conn->mta_conn_mutex_lock_already = FALSE; conn->mta_conn_mutex_lock_already = FALSE;
conn->mta_conn_mutex_unlock_later = FALSE; conn->mta_conn_mutex_unlock_later = FALSE;
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos); SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
...@@ -11413,6 +11431,7 @@ int spider_mysql_handler::show_table_status( ...@@ -11413,6 +11431,7 @@ int spider_mysql_handler::show_table_status(
DBUG_PRINT("info",("spider auto_increment_value=%llu", DBUG_PRINT("info",("spider auto_increment_value=%llu",
share->lgtm_tblhnd_share->auto_increment_value)); share->lgtm_tblhnd_share->auto_increment_value));
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -526,6 +526,9 @@ typedef struct st_spider_conn ...@@ -526,6 +526,9 @@ typedef struct st_spider_conn
st_spider_conn *bulk_access_next; st_spider_conn *bulk_access_next;
#endif #endif
bool disable_connect_retry; /* TRUE if it is unnecessary to
retry to connect after a
connection error */
bool connect_error_with_message; bool connect_error_with_message;
char connect_error_msg[MYSQL_ERRMSG_SIZE]; char connect_error_msg[MYSQL_ERRMSG_SIZE];
int connect_error; int connect_error;
......
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