MXS-1367: Add timeouts for retried queries

The total timeout for the retrying of interrupted queries can now be
configured with the `query_retry_timeout` parameter. It controls the total
timeout in seconds that the query can take.

The actual connection, read and write timeouts of the connector aren't a
good configuration value to use for abstracted queries as the time that it
takes to execute a query can be composed of both connections, reads and
writes. This is caused by the usage of MYSQL_OPT_RECONNECT that hides the
fact that the connector reconnects to the server when a query is
attempted.
This commit is contained in:
Markus Mäkelä
2017-10-03 11:12:45 +03:00
parent 67ef7bd058
commit 9280f1a5d7
6 changed files with 38 additions and 7 deletions

View File

@ -197,10 +197,12 @@ static bool is_connection_error(int errcode)
int mxs_mysql_query(MYSQL* conn, const char* query)
{
MXS_CONFIG* cnf = config_get_global_options();
time_t start = time(NULL);
int rc = mysql_query(conn, query);
for (int n = 0; rc != 0 && n < cnf->query_retries &&
is_connection_error(mysql_errno(conn)); n++)
is_connection_error(mysql_errno(conn)) &&
time(NULL) - start < cnf->query_retry_timeout; n++)
{
rc = mysql_query(conn, query);
}