mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
Make repmgrd survive to the failover
To do this it needs to reconnect to the new master
This commit is contained in:
33
repmgrd.c
33
repmgrd.c
@@ -81,6 +81,8 @@ bool verbose = false;
|
|||||||
bool monitoring_history = false;
|
bool monitoring_history = false;
|
||||||
char repmgr_schema[MAXLEN];
|
char repmgr_schema[MAXLEN];
|
||||||
|
|
||||||
|
bool failover_done = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* should initialize with {0} to be ANSI complaint ? but this raises
|
* should initialize with {0} to be ANSI complaint ? but this raises
|
||||||
* error with gcc -Wall
|
* error with gcc -Wall
|
||||||
@@ -203,6 +205,16 @@ main(int argc, char **argv)
|
|||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MAIN LOOP
|
||||||
|
* This loops cicles once per failover and at startup
|
||||||
|
* Requisites:
|
||||||
|
* - myLocalConn needs to be already setted with an active connection
|
||||||
|
* - no master connection
|
||||||
|
*/
|
||||||
|
do
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Set my server mode, establish a connection to primary
|
* Set my server mode, establish a connection to primary
|
||||||
* and start monitor
|
* and start monitor
|
||||||
@@ -233,13 +245,15 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
log_info(_("%s Starting continuous primary connection check\n"), progname);
|
log_info(_("%s Starting continuous primary connection check\n"), progname);
|
||||||
|
|
||||||
/* Check that primary is still alive, and standbies are sending info */
|
/* Check that primary is still alive, and standbies are sending info */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Every SLEEP_MONITOR seconds, do master checks
|
* Every SLEEP_MONITOR seconds, do master checks
|
||||||
* XXX
|
* XXX
|
||||||
* Check that standbies are sending info
|
* Check that standbies are sending info
|
||||||
*/
|
*/
|
||||||
for (;;)
|
do
|
||||||
{
|
{
|
||||||
if (CheckPrimaryConnection())
|
if (CheckPrimaryConnection())
|
||||||
{
|
{
|
||||||
@@ -254,7 +268,7 @@ main(int argc, char **argv)
|
|||||||
/* XXX
|
/* XXX
|
||||||
* May we do something more verbose ?
|
* May we do something more verbose ?
|
||||||
*/
|
*/
|
||||||
exit (1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (got_SIGHUP)
|
if (got_SIGHUP)
|
||||||
@@ -269,7 +283,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
got_SIGHUP = false;
|
got_SIGHUP = false;
|
||||||
}
|
}
|
||||||
}
|
} while (!failover_done);
|
||||||
break;
|
break;
|
||||||
case WITNESS_MODE:
|
case WITNESS_MODE:
|
||||||
case STANDBY_MODE:
|
case STANDBY_MODE:
|
||||||
@@ -307,7 +321,7 @@ main(int argc, char **argv)
|
|||||||
log_info(_("%s Starting continuous standby node monitoring\n"), progname);
|
log_info(_("%s Starting continuous standby node monitoring\n"), progname);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;)
|
do
|
||||||
{
|
{
|
||||||
if (myLocalMode == WITNESS_MODE)
|
if (myLocalMode == WITNESS_MODE)
|
||||||
WitnessMonitor();
|
WitnessMonitor();
|
||||||
@@ -326,12 +340,16 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
got_SIGHUP = false;
|
got_SIGHUP = false;
|
||||||
}
|
}
|
||||||
}
|
} while (!failover_done);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_err(_("%s: Unrecognized mode for node %d\n"), progname, local_options.node);
|
log_err(_("%s: Unrecognized mode for node %d\n"), progname, local_options.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
failover_done = false;
|
||||||
|
|
||||||
|
} while (true);
|
||||||
|
|
||||||
/* Prevent a double-free */
|
/* Prevent a double-free */
|
||||||
if (primaryConn == myLocalConn)
|
if (primaryConn == myLocalConn)
|
||||||
myLocalConn = NULL;
|
myLocalConn = NULL;
|
||||||
@@ -481,6 +499,7 @@ StandbyMonitor(void)
|
|||||||
* a new primaryConn
|
* a new primaryConn
|
||||||
*/
|
*/
|
||||||
do_failover();
|
do_failover();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,6 +920,9 @@ do_failover(void)
|
|||||||
exit(ERR_FAILOVER_FAIL);
|
exit(ERR_FAILOVER_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* to force it to re-calculate mode and master node */
|
||||||
|
failover_done = true;
|
||||||
|
|
||||||
/* and reconnect to the local database */
|
/* and reconnect to the local database */
|
||||||
myLocalConn = establishDBConnection(local_options.conninfo, true);
|
myLocalConn = establishDBConnection(local_options.conninfo, true);
|
||||||
}
|
}
|
||||||
@@ -1089,6 +1111,7 @@ static void
|
|||||||
handle_sigint(SIGNAL_ARGS)
|
handle_sigint(SIGNAL_ARGS)
|
||||||
{
|
{
|
||||||
CloseConnections();
|
CloseConnections();
|
||||||
|
logger_shutdown();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user