mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 04:22:27 +01:00
Add support for specifyihng the number of reconnec retries oin the command line
This commit is contained in:
parent
3f56853fcf
commit
9d1c19c7b0
1 changed files with 19 additions and 14 deletions
|
@ -87,14 +87,6 @@
|
|||
#endif
|
||||
#define MAX_SERVER_ARGS 64
|
||||
|
||||
/*
|
||||
Sometimes in a test the client starts before
|
||||
the server - to solve the problem, we try again
|
||||
after some sleep if connection fails the first
|
||||
time
|
||||
*/
|
||||
#define CON_RETRY_SLEEP 2
|
||||
#define MAX_CON_TRIES 5
|
||||
|
||||
#define SLAVE_POLL_INTERVAL 300000 /* 0.3 of a sec */
|
||||
#define DEFAULT_DELIMITER ";"
|
||||
|
@ -108,7 +100,7 @@ enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
|
|||
OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT, OPT_SKIP_SAFEMALLOC,
|
||||
OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, OPT_SSL_CA, OPT_SSL_CAPATH,
|
||||
OPT_SSL_CIPHER,OPT_PS_PROTOCOL,OPT_SP_PROTOCOL,OPT_CURSOR_PROTOCOL,
|
||||
OPT_VIEW_PROTOCOL, OPT_SSL_VERIFY_SERVER_CERT};
|
||||
OPT_VIEW_PROTOCOL, OPT_SSL_VERIFY_SERVER_CERT, OPT_MAX_CONNECT_RETRIES};
|
||||
|
||||
/* ************************************************************************ */
|
||||
/*
|
||||
|
@ -157,6 +149,7 @@ static int record = 0, opt_sleep=0;
|
|||
static char *db = 0, *pass=0;
|
||||
const char *user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./";
|
||||
static int port = 0;
|
||||
static int opt_max_connect_retries;
|
||||
static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0;
|
||||
static my_bool tty_password= 0;
|
||||
static my_bool ps_protocol= 0, ps_protocol_enabled= 0;
|
||||
|
@ -2125,9 +2118,16 @@ void init_manager()
|
|||
db, port, sock
|
||||
|
||||
NOTE
|
||||
This function will try to connect to the given server MAX_CON_TRIES
|
||||
times and sleep CON_RETRY_SLEEP seconds between attempts before
|
||||
finally giving up. This helps in situation when the client starts
|
||||
|
||||
Sometimes in a test the client starts before
|
||||
the server - to solve the problem, we try again
|
||||
after some sleep if connection fails the first
|
||||
time
|
||||
|
||||
This function will try to connect to the given server
|
||||
"opt_max_connect_retries" times and sleep "connection_retry_sleep"
|
||||
seconds between attempts before finally giving up.
|
||||
This helps in situation when the client starts
|
||||
before the server (which happens sometimes).
|
||||
It will ignore any errors during these retries. One should use
|
||||
connect_n_handle_errors() if he expects a connection error and wants
|
||||
|
@ -2142,8 +2142,9 @@ int safe_connect(MYSQL* mysql, const char *host, const char *user,
|
|||
{
|
||||
int con_error= 1;
|
||||
my_bool reconnect= 1;
|
||||
static int connection_retry_sleep= 2; /* Seconds */
|
||||
int i;
|
||||
for (i= 0; i < MAX_CON_TRIES; ++i)
|
||||
for (i= 0; i < opt_max_connect_retries; i++)
|
||||
{
|
||||
if (mysql_real_connect(mysql, host,user, pass, db, port, sock,
|
||||
CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS))
|
||||
|
@ -2151,7 +2152,7 @@ int safe_connect(MYSQL* mysql, const char *host, const char *user,
|
|||
con_error= 0;
|
||||
break;
|
||||
}
|
||||
sleep(CON_RETRY_SLEEP);
|
||||
sleep(connection_retry_sleep);
|
||||
}
|
||||
/*
|
||||
TODO: change this to 0 in future versions, but the 'kill' test relies on
|
||||
|
@ -2887,6 +2888,10 @@ static struct my_option my_long_options[] =
|
|||
{"compress", 'C', "Use the compressed server/client protocol.",
|
||||
(gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
|
||||
0, 0, 0},
|
||||
{"max-connect-retries", OPT_MAX_CONNECT_RETRIES,
|
||||
"Max number of connection attempts when connecting to server",
|
||||
(gptr*) &opt_max_connect_retries, (gptr*) &opt_max_connect_retries, 0,
|
||||
GET_INT, REQUIRED_ARG, 5, 1, 10, 0, 0, 0},
|
||||
{"cursor-protocol", OPT_CURSOR_PROTOCOL, "Use cursors for prepared statements.",
|
||||
(gptr*) &cursor_protocol, (gptr*) &cursor_protocol, 0,
|
||||
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
||||
|
|
Loading…
Reference in a new issue