Make node startup more robust

The connection attempts to all nodes are done over a period of time to
cope with slowly starting servers.
This commit is contained in:
Markus Mäkelä
2018-11-16 02:32:22 +02:00
parent 1f8180b8ee
commit d60e97dfa5
2 changed files with 30 additions and 2 deletions

View File

@ -92,6 +92,27 @@ int Mariadb_nodes::connect()
return res;
}
bool Mariadb_nodes::robust_connect(int n)
{
bool rval = false;
for (int i = 0; i < n; i++)
{
if (connect() == 0)
{
// Connected successfully, return immediately
rval = true;
break;
}
// We failed to connect, disconnect and wait for a second before trying again
disconnect();
sleep(1);
}
return rval;
}
void Mariadb_nodes::close_connections()
{
for (int i = 0; i < N; i++)
@ -397,7 +418,7 @@ int Mariadb_nodes::start_replication()
create_users(i);
}
connect();
robust_connect(10);
for (int i = 0; i < N; i++)
{
@ -523,7 +544,7 @@ int Galera_nodes::start_galera()
a.join();
}
local_result += connect();
local_result += robust_connect(5) ? 0 : 1;
local_result += execute_query(nodes[0], "%s", create_repl_user);
close_connections();

View File

@ -153,6 +153,13 @@ public:
int connect(int i);
int connect();
/**
* Repeatedly try to connect with one second sleep in between attempts
*
* @return True on success
*/
bool robust_connect(int n);
/**
* @brief Close connections opened by connect()
*