mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-28 01:16:29 +00:00
Fix a myriad of problems introduced by merging
Signed-off-by: Dan Farina <drfarina@acm.org>
This commit is contained in:
4
config.c
4
config.c
@@ -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];
|
||||
|
||||
7
config.h
7
config.h
@@ -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
|
||||
|
||||
41
repmgr.c
41
repmgr.c
@@ -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");
|
||||
|
||||
9
repmgr.h
9
repmgr.h
@@ -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"
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user