Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
3.4.1, 3.3.11
-
None
-
Linux
Description
When using a connection string with multiple hosts, to achieve failover, and reconnections happens, either by calling mariadb_reconnect(), using MYSQL_OPT_RECONNECT or the reconnect=1 connection string option, reconnection will only tried on the host that was connected to in the connection string, even though there are more hosts to choose from. This is non-intuitive and is also not the way Connector/J works.
The following code should, when srv1 fails, report an error and then reconnect to srv2, but instead it keeps reporting errors on connecting to srv1:
#include <stdio.h>
|
#include <stdlib.h>
|
#include <mysql.h>
|
|
int main(int argc, char *argv[]) |
{
|
MYSQL *pMariaDB;
|
MYSQL_RES *pRes;
|
MYSQL_ROW row;
|
my_bool bTrue = 1;
|
|
pMariaDB = mysql_init(NULL);
|
mysql_optionsv(pMariaDB, MYSQL_OPT_RECONNECT, &bTrue);
|
if(mysql_real_connect(pMariaDB, "host=srv1,srv2;user=appuser;" |
"password=apppwd;database=appdb;ssl_verify_server_cert=0;reconnect=1", |
NULL, NULL, NULL, 0, NULL, CLIENT_INTERACTIVE) == NULL)
|
{
|
fprintf(stderr, "Error connecting to MariaDB:\n%s\n", mysql_error(pMariaDB)); |
return 1; |
}
|
|
for(;; sleep(1)) |
{
|
if(mysql_query(pMariaDB, "SELECT NOW()") != 0) |
fprintf(stderr, "Error in query MariaDB:\n%s\n", mysql_error(pMariaDB)); |
else |
{
|
if((pRes = mysql_store_result(pMariaDB)) == NULL) |
{
|
fprintf(stderr, "Error in store_result MariaDB:\n%s\n", |
mysql_error(pMariaDB));
|
continue; |
}
|
|
while((row = mysql_fetch_row(pRes)) != NULL) |
printf("Now: %s\n", row[0]); |
mysql_free_result(pRes);
|
}
|
}
|
|
mysql_close(pMariaDB);
|
return 0; |
}
|