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:
@ -92,6 +92,27 @@ int Mariadb_nodes::connect()
|
|||||||
return res;
|
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()
|
void Mariadb_nodes::close_connections()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
@ -397,7 +418,7 @@ int Mariadb_nodes::start_replication()
|
|||||||
create_users(i);
|
create_users(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect();
|
robust_connect(10);
|
||||||
|
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
{
|
{
|
||||||
@ -523,7 +544,7 @@ int Galera_nodes::start_galera()
|
|||||||
a.join();
|
a.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
local_result += connect();
|
local_result += robust_connect(5) ? 0 : 1;
|
||||||
local_result += execute_query(nodes[0], "%s", create_repl_user);
|
local_result += execute_query(nodes[0], "%s", create_repl_user);
|
||||||
|
|
||||||
close_connections();
|
close_connections();
|
||||||
|
@ -153,6 +153,13 @@ public:
|
|||||||
int connect(int i);
|
int connect(int i);
|
||||||
int connect();
|
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()
|
* @brief Close connections opened by connect()
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user