mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16:29 +00:00
Merge remote-tracking branch 'tbrs/master' into heroku
Grab the configuration struct changes. It was expeditious to un-do some of my by-hand line-wrapping that avoids 80 character limit, though. Conflicts: config.c config.h repmgr.c repmgr.h repmgrd.c
This commit is contained in:
36
repmgrd.c
36
repmgrd.c
@@ -32,11 +32,8 @@
|
||||
|
||||
#include "libpq/pqsignal.h"
|
||||
|
||||
char myClusterName[MAXLEN];
|
||||
|
||||
/* Local info */
|
||||
int myLocalMode = STANDBY_MODE;
|
||||
int myLocalId = -1;
|
||||
PGconn *myLocalConn = NULL;
|
||||
|
||||
/* Primary info */
|
||||
@@ -51,6 +48,8 @@ const char *progname;
|
||||
char *config_file = NULL;
|
||||
bool verbose = false;
|
||||
|
||||
// should initialize with {0} to be ANSI complaint ? but this raises error with gcc -Wall
|
||||
repmgr_config config = {};
|
||||
|
||||
static void help(const char *progname);
|
||||
static void checkClusterConfiguration(void);
|
||||
@@ -96,7 +95,6 @@ main(int argc, char **argv)
|
||||
int optindex;
|
||||
int c;
|
||||
|
||||
char conninfo[MAXLEN];
|
||||
char standby_version[MAXVERSIONSTR];
|
||||
|
||||
progname = get_progname(argv[0]);
|
||||
@@ -146,15 +144,15 @@ main(int argc, char **argv)
|
||||
/*
|
||||
* Read the configuration file: repmgr.conf
|
||||
*/
|
||||
parse_config(config_file, myClusterName, &myLocalId, conninfo);
|
||||
if (myLocalId == -1)
|
||||
parse_config(config_file, &config);
|
||||
if (config.node == -1)
|
||||
{
|
||||
fprintf(stderr, "Node information is missing. "
|
||||
"Check the configuration file.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
myLocalConn = establishDBConnection(conninfo, true);
|
||||
myLocalConn = establishDBConnection(config.conninfo, true);
|
||||
|
||||
/* should be v9 or better */
|
||||
pg_version(myLocalConn, standby_version);
|
||||
@@ -173,21 +171,21 @@ main(int argc, char **argv)
|
||||
myLocalMode = is_standby(myLocalConn) ? STANDBY_MODE : PRIMARY_MODE;
|
||||
if (myLocalMode == PRIMARY_MODE)
|
||||
{
|
||||
primaryId = myLocalId;
|
||||
strcpy(primaryConninfo, conninfo);
|
||||
primaryId = config.node;
|
||||
strcpy(primaryConninfo, config.conninfo);
|
||||
primaryConn = myLocalConn;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* I need the id of the primary as well as a connection to it */
|
||||
primaryConn = getMasterConnection(myLocalConn, myLocalId,
|
||||
myClusterName, &primaryId, NULL);
|
||||
primaryConn = getMasterConnection(myLocalConn, config.node, config.cluster_name, &primaryId);
|
||||
|
||||
if (primaryConn == NULL)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
checkClusterConfiguration();
|
||||
checkNodeConfiguration(conninfo);
|
||||
checkNodeConfiguration(config.conninfo);
|
||||
if (myLocalMode == STANDBY_MODE)
|
||||
{
|
||||
MonitorCheck();
|
||||
@@ -251,8 +249,8 @@ MonitorExecute(void)
|
||||
for (connection_retries = 0; connection_retries < 6;
|
||||
connection_retries++)
|
||||
{
|
||||
primaryConn = getMasterConnection(myLocalConn, myLocalId,
|
||||
myClusterName, &primaryId, NULL);
|
||||
primaryConn = getMasterConnection(myLocalConn, config.node, config.cluster_name, &primaryId);
|
||||
|
||||
if (PQstatus(primaryConn) == CONNECTION_OK)
|
||||
{
|
||||
/* Connected, we can continue the process so break the loop */
|
||||
@@ -336,8 +334,8 @@ MonitorExecute(void)
|
||||
"INSERT INTO repmgr_%s.repl_monitor "
|
||||
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
||||
" '%s', '%s', "
|
||||
" %lld, %lld)", myClusterName,
|
||||
primaryId, myLocalId, monitor_standby_timestamp,
|
||||
" %lld, %lld)", config.cluster_name,
|
||||
primaryId, config.node, monitor_standby_timestamp,
|
||||
last_wal_primary_location,
|
||||
last_wal_standby_received,
|
||||
(lsn_primary - lsn_standby_received),
|
||||
@@ -360,7 +358,7 @@ checkClusterConfiguration(void)
|
||||
|
||||
sqlquery_snprintf(sqlquery, "SELECT oid FROM pg_class "
|
||||
" WHERE oid = 'repmgr_%s.repl_nodes'::regclass",
|
||||
myClusterName);
|
||||
config.cluster_name);
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
@@ -398,7 +396,7 @@ checkNodeConfiguration(char *conninfo)
|
||||
/* Check if we have my node information in repl_nodes */
|
||||
sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
||||
" WHERE id = %d AND cluster = '%s' ",
|
||||
myClusterName, myLocalId, myClusterName);
|
||||
config.cluster_name, config.node, config.cluster_name);
|
||||
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
@@ -421,7 +419,7 @@ checkNodeConfiguration(char *conninfo)
|
||||
/* Adding the node */
|
||||
sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
|
||||
"VALUES (%d, '%s', '%s')",
|
||||
myClusterName, myLocalId, myClusterName, conninfo);
|
||||
config.cluster_name, config.node, config.cluster_name, conninfo);
|
||||
|
||||
if (!PQexec(primaryConn, sqlquery))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user