Fix a myriad of problems introduced by merging

Signed-off-by: Dan Farina <drfarina@acm.org>
This commit is contained in:
Dan Farina
2011-02-06 18:32:49 -08:00
parent c356f9e97f
commit bfd3aed33b
7 changed files with 79 additions and 59 deletions

View File

@@ -17,14 +17,12 @@
*
*/
#include "config.h"
#include "repmgr.h"
#include "strutil.h"
void
parse_config(const char *config_file, repmgr_config *config)
char *conninfo)
{
char *s, buff[MAXLINELENGTH];
char name[MAXLEN];

View File

@@ -16,6 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
#include "strutil.h"
typedef struct
{
@@ -28,3 +33,5 @@ typedef struct
void parse_config(const char *config_file, repmgr_config *config);
void parse_line(char *buff, char *name, char *value);
char *trim(char *s);
#endif

View File

@@ -341,7 +341,8 @@ do_master_register(void)
}
/* Check if there is a schema for this cluster */
sqlquery_sprintf(sqlquery, "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'", config.cluster_name);
sqlquery_snprintf(sqlquery, "SELECT 1 FROM pg_namespace "
"WHERE nspname = 'repmgr_%s'", config.cluster_name);
res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
@@ -397,8 +398,10 @@ do_master_register(void)
" last_wal_primary_location TEXT NOT NULL, "
" last_wal_standby_location TEXT NOT NULL, "
" replication_lag BIGINT NOT NULL, "
" apply_lag BIGINT NOT NULL) ", config.cluster_name);
myClusterName);
" apply_lag BIGINT NOT NULL) ",
config.cluster_name);
}
if (!PQexec(conn, sqlquery))
{
fprintf(stderr,
@@ -424,15 +427,15 @@ do_master_register(void)
PQfinish(conn);
return;
}
}
else
{
PGconn *master_conn;
int id;
/* Ensure there isn't any other master already registered */
master_conn = getMasterConnection(conn, config.node, config.cluster_name, &id);
NULL);
master_conn = getMasterConnection(conn, config.node,
config.cluster_name, &id, NULL);
if (master_conn != NULL)
{
PQfinish(master_conn);
@@ -459,7 +462,8 @@ do_master_register(void)
sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
"VALUES (%d, '%s', '%s')",
config.cluster_name, config.node, config.cluster_name, config.conninfo);
config.cluster_name, config.node, config.cluster_name,
config.conninfo);
if (!PQexec(conn, sqlquery))
{
@@ -508,9 +512,9 @@ do_standby_register(void)
}
/* Check if there is a schema for this cluster */
sqlquery_snprintf(sqlquery, "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'", config.cluster_name);
"SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'",
myClusterName);
sqlquery_snprintf(sqlquery, "SELECT 1 FROM pg_namespace "
"WHERE nspname = 'repmgr_%s'", config.cluster_name);
res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
@@ -531,8 +535,9 @@ do_standby_register(void)
PQclear(res);
/* check if there is a master in this cluster */
master_conn = getMasterConnection(conn, config.node, config.cluster_name, &master_id);
master_conn = getMasterConnection(conn, config.node, config.cluster_name,
&master_id, NULL);
if (!master_conn)
return;
@@ -1056,7 +1061,8 @@ do_standby_promote(void)
}
/* we also need to check if there isn't any master already */
old_master_conn = getMasterConnection(conn, config.node, config.cluster_name, &old_master_id);
old_master_conn = getMasterConnection(conn, config.node, config.cluster_name,
&old_master_id, NULL);
if (old_master_conn != NULL)
{
@@ -1152,7 +1158,8 @@ do_standby_follow(void)
}
/* we also need to check if there is any master in the cluster */
master_conn = getMasterConnection(conn, config.node, config.cluster_name, &master_id);
master_conn = getMasterConnection(conn, config.node, config.cluster_name,
&master_id, (char *) &master_conninfo);
if (master_conn == NULL)
{
@@ -1366,10 +1373,12 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
char host_string[MAXLEN];
int r;
if (strnlen(config.rsync_options, QUERY_STR_LEN) == 0)
sprintf(options, "--archive --checksum --compress --progress --rsh=ssh");
if (strnlen(config.rsync_options, MAXLEN) == 0)
maxlen_snprintf(
options, "%s",
"--archive --checksum --compress --progress --rsh=ssh");
else
strncpy(options, config.rsync_options, QUERY_STR_LEN);
maxlen_snprintf(options, "%s", config.rsync_options);
if (force)
strcat(options, " --delete");

View File

@@ -17,14 +17,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef _REPMGR_H_
#define _REPMGR_H_
#include "postgres_fe.h"
#include "getopt_long.h"
#include "libpq-fe.h"
#ifndef _REPMGR_H_
#define _REPMGR_H_
#include "dbutils.h"
@@ -32,7 +32,6 @@
#define STANDBY_MODE 1
#define CONFIG_FILE "repmgr.conf"
#define QUERY_STR_LEN 8192
#include "config.h"

View File

@@ -178,7 +178,9 @@ main(int argc, char **argv)
else
{
/* I need the id of the primary as well as a connection to it */
primaryConn = getMasterConnection(myLocalConn, config.node, config.cluster_name, &primaryId);
primaryConn = getMasterConnection(myLocalConn, config.node,
config.cluster_name, &primaryId,
NULL);
if (primaryConn == NULL)
exit(1);
@@ -249,7 +251,9 @@ MonitorExecute(void)
for (connection_retries = 0; connection_retries < 6;
connection_retries++)
{
primaryConn = getMasterConnection(myLocalConn, config.node, config.cluster_name, &primaryId);
primaryConn = getMasterConnection(myLocalConn, config.node,
config.cluster_name, &primaryId,
NULL);
if (PQstatus(primaryConn) == CONNECTION_OK)
{

View File

@@ -8,6 +8,9 @@
#ifndef _STRUTIL_H_
#define _STRUTIL_H_
#include <stdlib.h>
#define QUERY_STR_LEN 8192
#define MAXLEN 1024
#define MAXLINELENGTH 4096