mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-28 09:26: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;
|
||||
char repmgr_schema[MAXLEN];
|
||||
|
||||
bool failover_done = false;
|
||||
|
||||
/*
|
||||
* should initialize with {0} to be ANSI complaint ? but this raises
|
||||
* error with gcc -Wall
|
||||
@@ -203,6 +205,16 @@ main(int argc, char **argv)
|
||||
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
|
||||
* and start monitor
|
||||
@@ -233,13 +245,15 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
log_info(_("%s Starting continuous primary connection check\n"), progname);
|
||||
|
||||
/* Check that primary is still alive, and standbies are sending info */
|
||||
|
||||
/*
|
||||
* Every SLEEP_MONITOR seconds, do master checks
|
||||
* XXX
|
||||
* Check that standbies are sending info
|
||||
*/
|
||||
for (;;)
|
||||
do
|
||||
{
|
||||
if (CheckPrimaryConnection())
|
||||
{
|
||||
@@ -254,7 +268,7 @@ main(int argc, char **argv)
|
||||
/* XXX
|
||||
* May we do something more verbose ?
|
||||
*/
|
||||
exit (1);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (got_SIGHUP)
|
||||
@@ -269,7 +283,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
got_SIGHUP = false;
|
||||
}
|
||||
}
|
||||
} while (!failover_done);
|
||||
break;
|
||||
case WITNESS_MODE:
|
||||
case STANDBY_MODE:
|
||||
@@ -307,7 +321,7 @@ main(int argc, char **argv)
|
||||
log_info(_("%s Starting continuous standby node monitoring\n"), progname);
|
||||
}
|
||||
|
||||
for (;;)
|
||||
do
|
||||
{
|
||||
if (myLocalMode == WITNESS_MODE)
|
||||
WitnessMonitor();
|
||||
@@ -326,12 +340,16 @@ main(int argc, char **argv)
|
||||
}
|
||||
got_SIGHUP = false;
|
||||
}
|
||||
}
|
||||
} while (!failover_done);
|
||||
break;
|
||||
default:
|
||||
log_err(_("%s: Unrecognized mode for node %d\n"), progname, local_options.node);
|
||||
}
|
||||
|
||||
failover_done = false;
|
||||
|
||||
} while (true);
|
||||
|
||||
/* Prevent a double-free */
|
||||
if (primaryConn == myLocalConn)
|
||||
myLocalConn = NULL;
|
||||
@@ -481,6 +499,7 @@ StandbyMonitor(void)
|
||||
* a new primaryConn
|
||||
*/
|
||||
do_failover();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -901,6 +920,9 @@ do_failover(void)
|
||||
exit(ERR_FAILOVER_FAIL);
|
||||
}
|
||||
|
||||
/* to force it to re-calculate mode and master node */
|
||||
failover_done = true;
|
||||
|
||||
/* and reconnect to the local database */
|
||||
myLocalConn = establishDBConnection(local_options.conninfo, true);
|
||||
}
|
||||
@@ -1089,6 +1111,7 @@ static void
|
||||
handle_sigint(SIGNAL_ARGS)
|
||||
{
|
||||
CloseConnections();
|
||||
logger_shutdown();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user