static bool CheckPrimaryConnection(void) { int connection_retries; /* * Check if the master is still available * if after NUM_RETRY * SLEEP_RETRY seconds of retries * we cannot reconnect * return false */ for (connection_retries = 0; connection_retries < NUM_RETRY; connection_retries++) { if (!is_pgup(primaryConn)) { log_warning(_("%s: Connection to master has been lost, trying to recover... %i seconds before failover decision\n"), progname, (SLEEP_RETRY*(NUM_RETRY-connection_retries))); /* wait SLEEP_RETRY seconds between retries */ sleep(SLEEP_RETRY); } else { log_info(_("%s: Connection to master has been restored.\n"), progname); break; } } if (!is_pgup(primaryConn)) { log_err(_("%s: We couldn't reconnect for long enough, exiting...\n"), progname); /* XXX Anything else to do here? */ return false; } return true; }
static bool check_connection(PGconn *conn, const char *type) { int connection_retries; /* * Check if the master is still available if after * local_options.reconnect_attempts * local_options.reconnect_intvl * seconds of retries we cannot reconnect return false */ for (connection_retries = 0; connection_retries < local_options.reconnect_attempts; connection_retries++) { if (!is_pgup(conn, local_options.master_response_timeout)) { log_warning(_("%s: Connection to %s has been lost, trying to recover... %i seconds before failover decision\n"), progname, type, (local_options.reconnect_intvl * (local_options.reconnect_attempts - connection_retries))); /* wait local_options.reconnect_intvl seconds between retries */ sleep(local_options.reconnect_intvl); } else { if (connection_retries > 0) { log_info(_("%s: Connection to %s has been restored.\n"), progname, type); } return true; } } if (!is_pgup(conn, local_options.master_response_timeout)) { log_err(_("%s: We couldn't reconnect for long enough, exiting...\n"), progname); /* XXX Anything else to do here? */ return false; } return true; }