mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-23 07:06:30 +00:00
Merge remote branch 'gbartolini/gabriele-2010-12' into heroku
Conflicts: config.c dbutils.c dbutils.h repmgrd.c Signed-off-by: Dan Farina <drfarina@acm.org>
This commit is contained in:
31
config.c
31
config.c
@@ -11,11 +11,15 @@
|
||||
|
||||
#include "strutil.h"
|
||||
|
||||
|
||||
void
|
||||
parse_config(const char *config_file, char *cluster_name, int *node,
|
||||
char *conninfo)
|
||||
{
|
||||
char *s, buff[1024];
|
||||
char *s, buff[MAXLINELENGTH];
|
||||
char name[MAXLEN];
|
||||
char value[MAXLEN];
|
||||
|
||||
FILE *fp = fopen (config_file, "r");
|
||||
|
||||
if (fp == NULL)
|
||||
@@ -24,9 +28,6 @@ parse_config(const char *config_file, char *cluster_name, int *node,
|
||||
/* Read next line */
|
||||
while ((s = fgets (buff, sizeof buff, fp)) != NULL)
|
||||
{
|
||||
char name[MAXLEN];
|
||||
char value[MAXLEN];
|
||||
|
||||
/* Skip blank lines and comments */
|
||||
if (buff[0] == '\n' || buff[0] == '#')
|
||||
continue;
|
||||
@@ -36,16 +37,16 @@ parse_config(const char *config_file, char *cluster_name, int *node,
|
||||
|
||||
/* Copy into correct entry in parameters struct */
|
||||
if (strcmp(name, "cluster") == 0)
|
||||
strncpy(cluster_name, value, MAXLEN);
|
||||
strncpy (cluster_name, value, MAXLEN);
|
||||
else if (strcmp(name, "node") == 0)
|
||||
*node = atoi(value);
|
||||
else if (strcmp(name, "conninfo") == 0)
|
||||
strncpy(conninfo, value, MAXLEN);
|
||||
strncpy (conninfo, value, MAXLEN);
|
||||
else
|
||||
printf("WARNING: %s/%s: Unknown name/value pair!\n",
|
||||
name, value);
|
||||
printf ("WARNING: %s/%s: Unknown name/value pair!\n", name, value);
|
||||
}
|
||||
|
||||
|
||||
/* Close file */
|
||||
fclose (fp);
|
||||
}
|
||||
@@ -58,12 +59,12 @@ trim (char *s)
|
||||
|
||||
/* Trim and delimit right side */
|
||||
while ( (isspace (*s2)) && (s2 >= s1) )
|
||||
s2--;
|
||||
--s2;
|
||||
*(s2+1) = '\0';
|
||||
|
||||
/* Trim left side */
|
||||
while ( (isspace (*s1)) && (s1 < s2) )
|
||||
s1++;
|
||||
++s1;
|
||||
|
||||
/* Copy finished string */
|
||||
strcpy (s, s1);
|
||||
@@ -73,14 +74,13 @@ trim (char *s)
|
||||
void
|
||||
parse_line(char *buff, char *name, char *value)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
/*
|
||||
* first we find the name of the parameter
|
||||
*/
|
||||
j = 0;
|
||||
for (i = 0; i < MAXLEN; i++)
|
||||
for ( ; i < MAXLEN; ++i)
|
||||
{
|
||||
if (buff[i] != '=')
|
||||
name[j++] = buff[i];
|
||||
@@ -89,12 +89,11 @@ parse_line(char *buff, char *name, char *value)
|
||||
}
|
||||
name[j] = '\0';
|
||||
|
||||
i++;
|
||||
/*
|
||||
* Now the value
|
||||
*/
|
||||
j = 0;
|
||||
for ( ; i < MAXLEN; i++)
|
||||
for ( ++i ; i < MAXLEN; ++i)
|
||||
if (buff[i] == '\'')
|
||||
continue;
|
||||
else if (buff[i] != '\n')
|
||||
|
||||
28
dbutils.c
28
dbutils.c
@@ -9,21 +9,21 @@
|
||||
*/
|
||||
|
||||
#include "repmgr.h"
|
||||
|
||||
#include "strutil.h"
|
||||
|
||||
PGconn *
|
||||
establishDBConnection(const char *conninfo, const bool exit_on_error)
|
||||
{
|
||||
PGconn *conn;
|
||||
|
||||
/* Make a connection to the database */
|
||||
conn = PQconnectdb(conninfo);
|
||||
PGconn *conn = PQconnectdb(conninfo);
|
||||
|
||||
/* Check to see that the backend connection was successfully made */
|
||||
if ((PQstatus(conn) != CONNECTION_OK))
|
||||
{
|
||||
fprintf(stderr, "Connection to database failed: %s",
|
||||
PQerrorMessage(conn));
|
||||
|
||||
if (exit_on_error)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -35,7 +35,6 @@ establishDBConnection(const char *conninfo, const bool exit_on_error)
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool
|
||||
is_standby(PGconn *conn)
|
||||
{
|
||||
@@ -67,12 +66,9 @@ is_standby(PGconn *conn)
|
||||
* if 8 or inferior returns an empty string
|
||||
*/
|
||||
char *
|
||||
pg_version(PGconn *conn)
|
||||
pg_version(PGconn *conn, char* major_version)
|
||||
{
|
||||
PGresult *res;
|
||||
|
||||
const size_t major_version_sz = 10;
|
||||
char *major_version;
|
||||
PGresult *res;
|
||||
|
||||
int major_version1;
|
||||
char *major_version2;
|
||||
@@ -94,13 +90,11 @@ pg_version(PGconn *conn)
|
||||
major_version1 = atoi(PQgetvalue(res, 0, 0));
|
||||
major_version2 = PQgetvalue(res, 0, 1);
|
||||
|
||||
major_version = malloc(major_version_sz);
|
||||
|
||||
if (major_version1 >= 9)
|
||||
{
|
||||
/* form a major version string */
|
||||
xsnprintf(major_version, major_version_sz, "%d.%s",
|
||||
major_version1, major_version2);
|
||||
xsnprintf(major_version, MAXVERSIONSTR, "%d.%s", major_version1,
|
||||
major_version2);
|
||||
}
|
||||
else
|
||||
strcpy(major_version, "");
|
||||
@@ -145,8 +139,8 @@ const char *
|
||||
get_cluster_size(PGconn *conn)
|
||||
{
|
||||
PGresult *res;
|
||||
const char *size;
|
||||
char sqlquery[QUERY_STR_LEN];
|
||||
const char *size;
|
||||
char sqlquery[QUERY_STR_LEN];
|
||||
|
||||
sqlquery_snprintf(
|
||||
sqlquery,
|
||||
@@ -178,7 +172,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
||||
PGresult *res1;
|
||||
PGresult *res2;
|
||||
char sqlquery[QUERY_STR_LEN];
|
||||
char master_conninfo[8192];
|
||||
char master_conninfo[MAXCONNINFO];
|
||||
int i;
|
||||
|
||||
/* find all nodes belonging to this cluster */
|
||||
@@ -200,7 +194,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
||||
{
|
||||
/* initialize with the values of the current node being processed */
|
||||
*master_id = atoi(PQgetvalue(res1, i, 0));
|
||||
strcpy(master_conninfo, PQgetvalue(res1, i, 2));
|
||||
strncpy(master_conninfo, PQgetvalue(res1, i, 2), MAXCONNINFO);
|
||||
master_conn = establishDBConnection(master_conninfo, false);
|
||||
|
||||
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
PGconn *establishDBConnection(const char *conninfo, const bool exit_on_error);
|
||||
bool is_standby(PGconn *conn);
|
||||
char *pg_version(PGconn *conn);
|
||||
char *pg_version(PGconn *conn, char* major_version);
|
||||
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
|
||||
const char *value);
|
||||
const char *get_cluster_size(PGconn *conn);
|
||||
|
||||
28
repmgr.c
28
repmgr.c
@@ -299,7 +299,7 @@ do_master_register(void)
|
||||
char conninfo[MAXLEN];
|
||||
|
||||
bool schema_exists = false;
|
||||
const char *master_version = NULL;
|
||||
char master_version[MAXVERSIONSTR];
|
||||
|
||||
/*
|
||||
* Read the configuration file: repmgr.conf
|
||||
@@ -315,7 +315,7 @@ do_master_register(void)
|
||||
conn = establishDBConnection(conninfo, true);
|
||||
|
||||
/* master should be v9 or better */
|
||||
master_version = pg_version(conn);
|
||||
pg_version(conn, master_version);
|
||||
if (strcmp(master_version, "") == 0)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -484,8 +484,8 @@ do_standby_register(void)
|
||||
int myLocalId = -1;
|
||||
char conninfo[MAXLEN];
|
||||
|
||||
const char *master_version = NULL;
|
||||
const char *standby_version = NULL;
|
||||
char master_version[MAXVERSIONSTR];
|
||||
char standby_version[MAXVERSIONSTR];
|
||||
|
||||
/*
|
||||
* Read the configuration file: repmgr.conf
|
||||
@@ -501,7 +501,7 @@ do_standby_register(void)
|
||||
conn = establishDBConnection(conninfo, true);
|
||||
|
||||
/* should be v9 or better */
|
||||
standby_version = pg_version(conn);
|
||||
pg_version(conn, standby_version);
|
||||
if (strcmp(standby_version, "") == 0)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -548,7 +548,7 @@ do_standby_register(void)
|
||||
return;
|
||||
|
||||
/* master should be v9 or better */
|
||||
master_version = pg_version(master_conn);
|
||||
pg_version(master_conn, master_version);
|
||||
if (strcmp(master_version, "") == 0)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -626,7 +626,7 @@ do_standby_clone(void)
|
||||
const char *first_wal_segment = NULL;
|
||||
const char *last_wal_segment = NULL;
|
||||
|
||||
const char *master_version = NULL;
|
||||
char master_version[MAXVERSIONSTR];
|
||||
|
||||
/* if dest_dir hasn't been provided, initialize to current directory */
|
||||
if (dest_dir == NULL)
|
||||
@@ -709,7 +709,7 @@ do_standby_clone(void)
|
||||
}
|
||||
|
||||
/* primary should be v9 or better */
|
||||
master_version = pg_version(conn);
|
||||
pg_version(conn, master_version);
|
||||
if (strcmp(master_version, "") == 0)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -1028,7 +1028,7 @@ do_standby_promote(void)
|
||||
char recovery_file_path[MAXLEN];
|
||||
char recovery_done_path[MAXLEN];
|
||||
|
||||
const char *standby_version = NULL;
|
||||
char standby_version[MAXVERSIONSTR];
|
||||
|
||||
/*
|
||||
* Read the configuration file: repmgr.conf
|
||||
@@ -1045,7 +1045,7 @@ do_standby_promote(void)
|
||||
conn = establishDBConnection(conninfo, true);
|
||||
|
||||
/* we need v9 or better */
|
||||
standby_version = pg_version(conn);
|
||||
pg_version(conn, standby_version);
|
||||
if (strcmp(standby_version, "") == 0)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -1140,8 +1140,8 @@ do_standby_follow(void)
|
||||
int r;
|
||||
char data_dir[MAXLEN];
|
||||
|
||||
const char *master_version = NULL;
|
||||
const char *standby_version = NULL;
|
||||
char master_version[MAXVERSIONSTR];
|
||||
char standby_version[MAXVERSIONSTR];
|
||||
|
||||
/* Read the configuration file: repmgr.conf */
|
||||
parse_config(config_file, myClusterName, &myLocalId, conninfo);
|
||||
@@ -1163,7 +1163,7 @@ do_standby_follow(void)
|
||||
}
|
||||
|
||||
/* should be v9 or better */
|
||||
standby_version = pg_version(conn);
|
||||
pg_version(conn, standby_version);
|
||||
if (strcmp(standby_version, "") == 0)
|
||||
{
|
||||
PQfinish(conn);
|
||||
@@ -1191,7 +1191,7 @@ do_standby_follow(void)
|
||||
}
|
||||
|
||||
/* should be v9 or better */
|
||||
master_version = pg_version(master_conn);
|
||||
pg_version(master_conn, master_version);
|
||||
if (strcmp(master_version, "") == 0)
|
||||
{
|
||||
PQfinish(conn);
|
||||
|
||||
@@ -84,7 +84,7 @@ main(int argc, char **argv)
|
||||
int c;
|
||||
|
||||
char conninfo[MAXLEN];
|
||||
const char *standby_version = NULL;
|
||||
char standby_version[MAXVERSIONSTR];
|
||||
|
||||
progname = get_progname(argv[0]);
|
||||
|
||||
@@ -144,7 +144,7 @@ main(int argc, char **argv)
|
||||
myLocalConn = establishDBConnection(conninfo, true);
|
||||
|
||||
/* should be v9 or better */
|
||||
standby_version = pg_version(myLocalConn);
|
||||
pg_version(myLocalConn, standby_version);
|
||||
if (strcmp(standby_version, "") == 0)
|
||||
{
|
||||
PQfinish(myLocalConn);
|
||||
|
||||
@@ -8,8 +8,11 @@
|
||||
#ifndef _STRUTIL_H_
|
||||
#define _STRUTIL_H_
|
||||
|
||||
#define QUERY_STR_LEN 8192
|
||||
#define MAXLEN 1024
|
||||
#define QUERY_STR_LEN 8192
|
||||
#define MAXLEN 1024
|
||||
#define MAXLINELENGTH 4096
|
||||
#define MAXVERSIONSTR 16
|
||||
#define MAXCONNINFO 1024
|
||||
|
||||
|
||||
extern int xsnprintf(char *str, size_t size, const char *format, ...);
|
||||
|
||||
Reference in New Issue
Block a user