mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
Reformat all source code using astyle
astyle --style=ansi --indent=tab
This commit is contained in:
82
check_dir.c
82
check_dir.c
@@ -43,45 +43,45 @@ static int mkdir_p(char *path, mode_t omode);
|
||||
int
|
||||
check_dir(char *dir)
|
||||
{
|
||||
DIR *chkdir;
|
||||
struct dirent *file;
|
||||
int result = 1;
|
||||
DIR *chkdir;
|
||||
struct dirent *file;
|
||||
int result = 1;
|
||||
|
||||
errno = 0;
|
||||
errno = 0;
|
||||
|
||||
chkdir = opendir(dir);
|
||||
chkdir = opendir(dir);
|
||||
|
||||
if (!chkdir)
|
||||
return (errno == ENOENT) ? 0 : -1;
|
||||
if (!chkdir)
|
||||
return (errno == ENOENT) ? 0 : -1;
|
||||
|
||||
while ((file = readdir(chkdir)) != NULL)
|
||||
{
|
||||
if (strcmp(".", file->d_name) == 0 ||
|
||||
strcmp("..", file->d_name) == 0)
|
||||
{
|
||||
/* skip this and parent directory */
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 2; /* not empty */
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ((file = readdir(chkdir)) != NULL)
|
||||
{
|
||||
if (strcmp(".", file->d_name) == 0 ||
|
||||
strcmp("..", file->d_name) == 0)
|
||||
{
|
||||
/* skip this and parent directory */
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 2; /* not empty */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
|
||||
* released version
|
||||
*/
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
errno = 0;
|
||||
/*
|
||||
* This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but not in
|
||||
* released version
|
||||
*/
|
||||
if (GetLastError() == ERROR_NO_MORE_FILES)
|
||||
errno = 0;
|
||||
#endif
|
||||
|
||||
closedir(chkdir);
|
||||
closedir(chkdir);
|
||||
|
||||
if (errno != 0)
|
||||
return -1; /* some kind of I/O error? */
|
||||
if (errno != 0)
|
||||
return -1; /* some kind of I/O error? */
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -93,13 +93,13 @@ check_dir(char *dir)
|
||||
bool
|
||||
create_directory(char *dir)
|
||||
{
|
||||
if (mkdir_p(dir, 0700) == 0)
|
||||
return true;
|
||||
if (mkdir_p(dir, 0700) == 0)
|
||||
return true;
|
||||
|
||||
fprintf(stderr, _("Could not create directory \"%s\": %s\n"),
|
||||
dir, strerror(errno));
|
||||
fprintf(stderr, _("Could not create directory \"%s\": %s\n"),
|
||||
dir, strerror(errno));
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -126,10 +126,10 @@ mkdir_p(char *path, mode_t omode)
|
||||
{
|
||||
struct stat sb;
|
||||
mode_t numask,
|
||||
oumask;
|
||||
oumask;
|
||||
int first,
|
||||
last,
|
||||
retval;
|
||||
last,
|
||||
retval;
|
||||
char *p;
|
||||
|
||||
p = path;
|
||||
@@ -148,8 +148,8 @@ mkdir_p(char *path, mode_t omode)
|
||||
return 1;
|
||||
}
|
||||
else if (p[1] == ':' &&
|
||||
((p[0] >= 'a' && p[0] <= 'z') ||
|
||||
(p[0] >= 'A' && p[0] <= 'Z')))
|
||||
((p[0] >= 'a' && p[0] <= 'z') ||
|
||||
(p[0] >= 'A' && p[0] <= 'Z')))
|
||||
{
|
||||
/* local drive */
|
||||
p += 2;
|
||||
@@ -224,5 +224,5 @@ is_pg_dir(char *dir)
|
||||
|
||||
sprintf(path, "%s/PG_VERSION", dir);
|
||||
|
||||
return (stat(path, &sb) == 0) ? true : false;
|
||||
return (stat(path, &sb) == 0) ? true : false;
|
||||
}
|
||||
|
||||
28
config.c
28
config.c
@@ -55,28 +55,28 @@ parse_config(const char *config_file, char *cluster_name, int *node, char *conni
|
||||
}
|
||||
|
||||
|
||||
/* Close file */
|
||||
fclose (fp);
|
||||
/* Close file */
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
char *
|
||||
trim (char *s)
|
||||
{
|
||||
/* Initialize start, end pointers */
|
||||
char *s1 = s, *s2 = &s[strlen (s) - 1];
|
||||
/* Initialize start, end pointers */
|
||||
char *s1 = s, *s2 = &s[strlen (s) - 1];
|
||||
|
||||
/* Trim and delimit right side */
|
||||
while ( (isspace (*s2)) && (s2 >= s1) )
|
||||
--s2;
|
||||
*(s2+1) = '\0';
|
||||
/* Trim and delimit right side */
|
||||
while ( (isspace (*s2)) && (s2 >= s1) )
|
||||
--s2;
|
||||
*(s2+1) = '\0';
|
||||
|
||||
/* Trim left side */
|
||||
while ( (isspace (*s1)) && (s1 < s2) )
|
||||
++s1;
|
||||
/* Trim left side */
|
||||
while ( (isspace (*s1)) && (s1 < s2) )
|
||||
++s1;
|
||||
|
||||
/* Copy finished string */
|
||||
strcpy (s, s1);
|
||||
return s;
|
||||
/* Copy finished string */
|
||||
strcpy (s, s1);
|
||||
return s;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
100
dbutils.c
100
dbutils.c
@@ -32,7 +32,7 @@ establishDBConnection(const char *conninfo, const bool exit_on_error)
|
||||
if ((PQstatus(conn) != CONNECTION_OK))
|
||||
{
|
||||
fprintf(stderr, "Connection to database failed: %s",
|
||||
PQerrorMessage(conn));
|
||||
PQerrorMessage(conn));
|
||||
if (exit_on_error)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -82,18 +82,18 @@ pg_version(PGconn *conn, char* major_version)
|
||||
int major_version1;
|
||||
char *major_version2;
|
||||
|
||||
res = PQexec(conn, "WITH pg_version(ver) AS (SELECT split_part(version(), ' ', 2)) "
|
||||
"SELECT split_part(ver, '.', 1), split_part(ver, '.', 2) FROM pg_version");
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
res = PQexec(conn, "WITH pg_version(ver) AS (SELECT split_part(version(), ' ', 2)) "
|
||||
"SELECT split_part(ver, '.', 1), split_part(ver, '.', 2) FROM pg_version");
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
||||
PQclear(res);
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
}
|
||||
major_version1 = atoi(PQgetvalue(res, 0, 0));
|
||||
major_version2 = PQgetvalue(res, 0, 1);
|
||||
PQclear(res);
|
||||
}
|
||||
major_version1 = atoi(PQgetvalue(res, 0, 0));
|
||||
major_version2 = PQgetvalue(res, 0, 1);
|
||||
PQclear(res);
|
||||
|
||||
if (major_version1 >= 9)
|
||||
{
|
||||
@@ -114,21 +114,21 @@ guc_setted(PGconn *conn, const char *parameter, const char *op, const char *valu
|
||||
char sqlquery[MAXQUERY];
|
||||
|
||||
sprintf(sqlquery, "SELECT true FROM pg_settings "
|
||||
" WHERE name = '%s' AND setting %s '%s'",
|
||||
parameter, op, value);
|
||||
" WHERE name = '%s' AND setting %s '%s'",
|
||||
parameter, op, value);
|
||||
|
||||
res = PQexec(conn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
res = PQexec(conn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
||||
PQclear(res);
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (PQntuples(res) == 0)
|
||||
{
|
||||
PQclear(res);
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
PQclear(res);
|
||||
|
||||
@@ -144,17 +144,17 @@ get_cluster_size(PGconn *conn)
|
||||
char sqlquery[MAXQUERY];
|
||||
|
||||
sprintf(sqlquery, "SELECT pg_size_pretty(SUM(pg_database_size(oid))::bigint) "
|
||||
" FROM pg_database ");
|
||||
" FROM pg_database ");
|
||||
|
||||
res = PQexec(conn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
res = PQexec(conn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
||||
PQclear(res);
|
||||
PQclear(res);
|
||||
PQfinish(conn);
|
||||
exit(1);
|
||||
}
|
||||
size = PQgetvalue(res, 0, 0);
|
||||
}
|
||||
size = PQgetvalue(res, 0, 0);
|
||||
PQclear(res);
|
||||
return size;
|
||||
}
|
||||
@@ -167,28 +167,28 @@ PGconn *
|
||||
getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
||||
{
|
||||
PGconn *master_conn = NULL;
|
||||
PGresult *res1;
|
||||
PGresult *res2;
|
||||
PGresult *res1;
|
||||
PGresult *res2;
|
||||
char sqlquery[MAXQUERY];
|
||||
char master_conninfo[MAXCONNINFO];
|
||||
int i;
|
||||
|
||||
/* find all nodes belonging to this cluster */
|
||||
sprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
||||
" WHERE cluster = '%s' and id <> %d",
|
||||
cluster, cluster, id);
|
||||
" WHERE cluster = '%s' and id <> %d",
|
||||
cluster, cluster, id);
|
||||
|
||||
res1 = PQexec(standby_conn, sqlquery);
|
||||
if (PQresultStatus(res1) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "Can't get nodes info: %s\n", PQerrorMessage(standby_conn));
|
||||
PQclear(res1);
|
||||
res1 = PQexec(standby_conn, sqlquery);
|
||||
if (PQresultStatus(res1) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "Can't get nodes info: %s\n", PQerrorMessage(standby_conn));
|
||||
PQclear(res1);
|
||||
PQfinish(standby_conn);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < PQntuples(res1); i++)
|
||||
{
|
||||
{
|
||||
/* initialize with the values of the current node being processed */
|
||||
*master_id = atoi(PQgetvalue(res1, i, 0));
|
||||
strncpy(master_conninfo, PQgetvalue(res1, i, 2), MAXCONNINFO);
|
||||
@@ -198,17 +198,17 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
||||
|
||||
/*
|
||||
* I can't use the is_standby() function here because on error that
|
||||
* function closes the connection i pass and exit, but i still need to close
|
||||
* function closes the connection i pass and exit, but i still need to close
|
||||
* standby_conn
|
||||
*/
|
||||
res2 = PQexec(master_conn, "SELECT pg_is_in_recovery()");
|
||||
if (PQresultStatus(res2) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "Can't get recovery state from this node: %s\n", PQerrorMessage(master_conn));
|
||||
PQclear(res2);
|
||||
res2 = PQexec(master_conn, "SELECT pg_is_in_recovery()");
|
||||
if (PQresultStatus(res2) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "Can't get recovery state from this node: %s\n", PQerrorMessage(master_conn));
|
||||
PQclear(res2);
|
||||
PQfinish(master_conn);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* if false, this is the master */
|
||||
if (strcmp(PQgetvalue(res2, 0, 0), "f") == 0)
|
||||
@@ -224,16 +224,16 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
||||
PQfinish(master_conn);
|
||||
*master_id = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If we finish this loop without finding a master then
|
||||
* we doesn't have the info or the master has failed (or we
|
||||
* reached max_connections or superuser_reserved_connections,
|
||||
* anything else i'm missing?),
|
||||
* we doesn't have the info or the master has failed (or we
|
||||
* reached max_connections or superuser_reserved_connections,
|
||||
* anything else i'm missing?),
|
||||
* Probably we will need to check the error to know if we need
|
||||
* to start failover procedure or just fix some situation on the
|
||||
* standby.
|
||||
*/
|
||||
* to start failover procedure or just fix some situation on the
|
||||
* standby.
|
||||
*/
|
||||
PQclear(res1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
221
repmgrd.c
221
repmgrd.c
@@ -84,7 +84,8 @@ static void setup_cancel_handler(void);
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
static struct option long_options[] = {
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"config", required_argument, NULL, 'f'},
|
||||
{"verbose", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0}
|
||||
@@ -93,7 +94,7 @@ main(int argc, char **argv)
|
||||
int optindex;
|
||||
int c;
|
||||
|
||||
char conninfo[MAXLEN];
|
||||
char conninfo[MAXLEN];
|
||||
char standby_version[MAXVERSIONSTR];
|
||||
|
||||
progname = get_progname(argv[0]);
|
||||
@@ -117,15 +118,15 @@ main(int argc, char **argv)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'f':
|
||||
config_file = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
||||
exit(1);
|
||||
case 'f':
|
||||
config_file = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,16 +140,16 @@ main(int argc, char **argv)
|
||||
|
||||
/*
|
||||
* Read the configuration file: repmgr.conf
|
||||
*/
|
||||
*/
|
||||
parse_config(config_file, myClusterName, &myLocalId, conninfo);
|
||||
if (myLocalId == -1)
|
||||
{
|
||||
fprintf(stderr, "Node information is missing. "
|
||||
"Check the configuration file.\n");
|
||||
"Check the configuration file.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
myLocalConn = establishDBConnection(conninfo, true);
|
||||
myLocalConn = establishDBConnection(conninfo, true);
|
||||
|
||||
/* should be v9 or better */
|
||||
pg_version(myLocalConn, standby_version);
|
||||
@@ -159,10 +160,10 @@ main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set my server mode, establish a connection to primary
|
||||
/*
|
||||
* Set my server mode, establish a connection to primary
|
||||
* and start monitor
|
||||
*/
|
||||
*/
|
||||
myLocalMode = is_standby(myLocalConn) ? STANDBY_MODE : PRIMARY_MODE;
|
||||
if (myLocalMode == PRIMARY_MODE)
|
||||
{
|
||||
@@ -185,10 +186,10 @@ main(int argc, char **argv)
|
||||
MonitorCheck();
|
||||
}
|
||||
|
||||
/* close the connection to the database and cleanup */
|
||||
CloseConnections();
|
||||
/* close the connection to the database and cleanup */
|
||||
CloseConnections();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +201,7 @@ main(int argc, char **argv)
|
||||
static void
|
||||
MonitorExecute(void)
|
||||
{
|
||||
PGresult *res;
|
||||
PGresult *res;
|
||||
char monitor_standby_timestamp[MAXLEN];
|
||||
char last_wal_primary_location[MAXLEN];
|
||||
char last_wal_standby_received[MAXLEN];
|
||||
@@ -263,7 +264,7 @@ MonitorExecute(void)
|
||||
if (!is_standby(myLocalConn))
|
||||
{
|
||||
fprintf(stderr, "\n%s: seems like we have been promoted, so exit from monitoring...\n",
|
||||
progname);
|
||||
progname);
|
||||
CloseConnections();
|
||||
exit(1);
|
||||
}
|
||||
@@ -271,43 +272,43 @@ MonitorExecute(void)
|
||||
/*
|
||||
* first check if there is a command being executed,
|
||||
* and if that is the case, cancel the query so i can
|
||||
* insert the current record
|
||||
*/
|
||||
* insert the current record
|
||||
*/
|
||||
if (PQisBusy(primaryConn) == 1)
|
||||
CancelQuery();
|
||||
|
||||
/* Get local xlog info */
|
||||
sprintf(sqlquery,
|
||||
"SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), "
|
||||
"pg_last_xlog_replay_location()");
|
||||
sprintf(sqlquery,
|
||||
"SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), "
|
||||
"pg_last_xlog_replay_location()");
|
||||
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(myLocalConn));
|
||||
PQclear(res);
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(myLocalConn));
|
||||
PQclear(res);
|
||||
/* if there is any error just let it be and retry in next loop */
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(monitor_standby_timestamp, PQgetvalue(res, 0, 0));
|
||||
strcpy(last_wal_standby_received , PQgetvalue(res, 0, 1));
|
||||
strcpy(last_wal_standby_applied , PQgetvalue(res, 0, 2));
|
||||
PQclear(res);
|
||||
strcpy(monitor_standby_timestamp, PQgetvalue(res, 0, 0));
|
||||
strcpy(last_wal_standby_received , PQgetvalue(res, 0, 1));
|
||||
strcpy(last_wal_standby_applied , PQgetvalue(res, 0, 2));
|
||||
PQclear(res);
|
||||
|
||||
/* Get primary xlog info */
|
||||
sprintf(sqlquery, "SELECT pg_current_xlog_location() ");
|
||||
sprintf(sqlquery, "SELECT pg_current_xlog_location() ");
|
||||
|
||||
res = PQexec(primaryConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(primaryConn));
|
||||
PQclear(res);
|
||||
return;
|
||||
}
|
||||
res = PQexec(primaryConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(primaryConn));
|
||||
PQclear(res);
|
||||
return;
|
||||
}
|
||||
|
||||
strcpy(last_wal_primary_location, PQgetvalue(res, 0, 0));
|
||||
PQclear(res);
|
||||
strcpy(last_wal_primary_location, PQgetvalue(res, 0, 0));
|
||||
PQclear(res);
|
||||
|
||||
/* Calculate the lag */
|
||||
lsn_primary = walLocationToBytes(last_wal_primary_location);
|
||||
@@ -318,15 +319,15 @@ MonitorExecute(void)
|
||||
* Build the SQL to execute on primary
|
||||
*/
|
||||
sprintf(sqlquery,
|
||||
"INSERT INTO repmgr_%s.repl_monitor "
|
||||
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
||||
" '%s', '%s', "
|
||||
" %lld, %lld)", myClusterName,
|
||||
primaryId, myLocalId, monitor_standby_timestamp,
|
||||
last_wal_primary_location,
|
||||
last_wal_standby_received,
|
||||
(lsn_primary - lsn_standby_received),
|
||||
(lsn_standby_received - lsn_standby_applied));
|
||||
"INSERT INTO repmgr_%s.repl_monitor "
|
||||
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
||||
" '%s', '%s', "
|
||||
" %lld, %lld)", myClusterName,
|
||||
primaryId, myLocalId, monitor_standby_timestamp,
|
||||
last_wal_primary_location,
|
||||
last_wal_standby_received,
|
||||
(lsn_primary - lsn_standby_received),
|
||||
(lsn_standby_received - lsn_standby_applied));
|
||||
|
||||
/*
|
||||
* Execute the query asynchronously, but don't check for a result. We
|
||||
@@ -334,27 +335,27 @@ MonitorExecute(void)
|
||||
*/
|
||||
if (PQsendQuery(primaryConn, sqlquery) == 0)
|
||||
fprintf(stderr, "Query could not be sent to primary. %s\n",
|
||||
PQerrorMessage(primaryConn));
|
||||
PQerrorMessage(primaryConn));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
checkClusterConfiguration(void)
|
||||
{
|
||||
PGresult *res;
|
||||
PGresult *res;
|
||||
|
||||
sprintf(sqlquery, "SELECT oid FROM pg_class "
|
||||
" WHERE oid = 'repmgr_%s.repl_nodes'::regclass",
|
||||
myClusterName);
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(myLocalConn));
|
||||
PQclear(res);
|
||||
PQfinish(myLocalConn);
|
||||
PQfinish(primaryConn);
|
||||
" WHERE oid = 'repmgr_%s.repl_nodes'::regclass",
|
||||
myClusterName);
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(myLocalConn));
|
||||
PQclear(res);
|
||||
PQfinish(myLocalConn);
|
||||
PQfinish(primaryConn);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If there isn't any results then we have not configured a primary node yet
|
||||
@@ -363,10 +364,10 @@ checkClusterConfiguration(void)
|
||||
*/
|
||||
if (PQntuples(res) == 0)
|
||||
{
|
||||
fprintf(stderr, "The replication cluster is not configured\n");
|
||||
PQclear(res);
|
||||
PQfinish(myLocalConn);
|
||||
PQfinish(primaryConn);
|
||||
fprintf(stderr, "The replication cluster is not configured\n");
|
||||
PQclear(res);
|
||||
PQfinish(myLocalConn);
|
||||
PQfinish(primaryConn);
|
||||
exit(1);
|
||||
}
|
||||
PQclear(res);
|
||||
@@ -376,24 +377,24 @@ checkClusterConfiguration(void)
|
||||
static void
|
||||
checkNodeConfiguration(char *conninfo)
|
||||
{
|
||||
PGresult *res;
|
||||
PGresult *res;
|
||||
|
||||
/*
|
||||
* Check if we have my node information in repl_nodes
|
||||
*/
|
||||
sprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
||||
" WHERE id = %d AND cluster = '%s' ",
|
||||
myClusterName, myLocalId, myClusterName);
|
||||
" WHERE id = %d AND cluster = '%s' ",
|
||||
myClusterName, myLocalId, myClusterName);
|
||||
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(myLocalConn));
|
||||
PQclear(res);
|
||||
PQfinish(myLocalConn);
|
||||
PQfinish(primaryConn);
|
||||
res = PQexec(myLocalConn, sqlquery);
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
fprintf(stderr, "PQexec failed: %s\n", PQerrorMessage(myLocalConn));
|
||||
PQclear(res);
|
||||
PQfinish(myLocalConn);
|
||||
PQfinish(primaryConn);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If there isn't any results then we have not configured this node yet
|
||||
@@ -401,16 +402,16 @@ checkNodeConfiguration(char *conninfo)
|
||||
*/
|
||||
if (PQntuples(res) == 0)
|
||||
{
|
||||
PQclear(res);
|
||||
PQclear(res);
|
||||
/* Adding the node */
|
||||
sprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
|
||||
"VALUES (%d, '%s', '%s')",
|
||||
myClusterName, myLocalId, myClusterName, conninfo);
|
||||
"VALUES (%d, '%s', '%s')",
|
||||
myClusterName, myLocalId, myClusterName, conninfo);
|
||||
|
||||
if (!PQexec(primaryConn, sqlquery))
|
||||
if (!PQexec(primaryConn, sqlquery))
|
||||
{
|
||||
fprintf(stderr, "Cannot insert node details, %s\n",
|
||||
PQerrorMessage(primaryConn));
|
||||
PQerrorMessage(primaryConn));
|
||||
PQfinish(myLocalConn);
|
||||
PQfinish(primaryConn);
|
||||
exit(1);
|
||||
@@ -423,30 +424,30 @@ checkNodeConfiguration(char *conninfo)
|
||||
static unsigned long long int
|
||||
walLocationToBytes(char *wal_location)
|
||||
{
|
||||
unsigned int xlogid;
|
||||
unsigned int xrecoff;
|
||||
unsigned int xlogid;
|
||||
unsigned int xrecoff;
|
||||
|
||||
if (sscanf(wal_location, "%X/%X", &xlogid, &xrecoff) != 2)
|
||||
{
|
||||
fprintf(stderr, "wrong log location format: %s\n", wal_location);
|
||||
return 0;
|
||||
}
|
||||
return ((xlogid * 16 * 1024 * 1024 * 255) + xrecoff);
|
||||
if (sscanf(wal_location, "%X/%X", &xlogid, &xrecoff) != 2)
|
||||
{
|
||||
fprintf(stderr, "wrong log location format: %s\n", wal_location);
|
||||
return 0;
|
||||
}
|
||||
return ((xlogid * 16 * 1024 * 1024 * 255) + xrecoff);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
help(const char *progname)
|
||||
{
|
||||
printf(_("\n%s: Replicator manager daemon \n"), progname);
|
||||
printf(_("Usage:\n"));
|
||||
printf(_(" %s [OPTIONS]\n"), progname);
|
||||
printf(_("\nOptions:\n"));
|
||||
printf(_("\n%s: Replicator manager daemon \n"), progname);
|
||||
printf(_("Usage:\n"));
|
||||
printf(_(" %s [OPTIONS]\n"), progname);
|
||||
printf(_("\nOptions:\n"));
|
||||
printf(_(" --help show this help, then exit\n"));
|
||||
printf(_(" --version output version information, then exit\n"));
|
||||
printf(_(" --verbose output verbose activity information\n"));
|
||||
printf(_(" -f, --config_file=PATH database to connect to\n"));
|
||||
printf(_("\n%s monitors a cluster of servers.\n"), progname);
|
||||
printf(_("\n%s monitors a cluster of servers.\n"), progname);
|
||||
}
|
||||
|
||||
|
||||
@@ -455,13 +456,13 @@ help(const char *progname)
|
||||
static void
|
||||
handle_sigint(SIGNAL_ARGS)
|
||||
{
|
||||
CloseConnections();
|
||||
CloseConnections();
|
||||
}
|
||||
|
||||
static void
|
||||
setup_cancel_handler(void)
|
||||
{
|
||||
pqsignal(SIGINT, handle_sigint);
|
||||
pqsignal(SIGINT, handle_sigint);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -469,13 +470,13 @@ setup_cancel_handler(void)
|
||||
static void
|
||||
CancelQuery(void)
|
||||
{
|
||||
char errbuf[256];
|
||||
PGcancel *pgcancel;
|
||||
char errbuf[256];
|
||||
PGcancel *pgcancel;
|
||||
|
||||
pgcancel = PQgetCancel(primaryConn);
|
||||
pgcancel = PQgetCancel(primaryConn);
|
||||
|
||||
if (!pgcancel || PQcancel(pgcancel, errbuf, 256) == 0)
|
||||
fprintf(stderr, "Can't stop current query: %s", errbuf);
|
||||
if (!pgcancel || PQcancel(pgcancel, errbuf, 256) == 0)
|
||||
fprintf(stderr, "Can't stop current query: %s", errbuf);
|
||||
|
||||
PQfreeCancel(pgcancel);
|
||||
PQfreeCancel(pgcancel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user