mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56: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];
|
||||
|
||||
15
config.h
15
config.h
@@ -16,15 +16,22 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#include "strutil.h"
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char cluster_name[MAXLEN];
|
||||
int node;
|
||||
char conninfo[MAXLEN];
|
||||
char rsync_options[QUERY_STR_LEN];
|
||||
char cluster_name[MAXLEN];
|
||||
int node;
|
||||
char conninfo[MAXLEN];
|
||||
char rsync_options[QUERY_STR_LEN];
|
||||
} repmgr_config;
|
||||
|
||||
void parse_config(const char *config_file, repmgr_config *config);
|
||||
void parse_line(char *buff, char *name, char *value);
|
||||
char *trim(char *s);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -199,7 +199,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
||||
/* find all nodes belonging to this cluster */
|
||||
sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
||||
" WHERE cluster = '%s' and id <> %d",
|
||||
cluster, cluster, id);
|
||||
cluster, cluster, id);
|
||||
|
||||
res1 = PQexec(standby_conn, sqlquery);
|
||||
if (PQresultStatus(res1) != PGRES_TUPLES_OK)
|
||||
|
||||
97
repmgr.c
97
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)
|
||||
{
|
||||
@@ -372,7 +373,7 @@ do_master_register(void)
|
||||
if (!PQexec(conn, sqlquery))
|
||||
{
|
||||
fprintf(stderr, "Cannot create the schema repmgr_%s: %s\n",
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return;
|
||||
}
|
||||
@@ -381,11 +382,11 @@ do_master_register(void)
|
||||
sqlquery_snprintf(sqlquery, "CREATE TABLE repmgr_%s.repl_nodes ( "
|
||||
" id integer primary key, "
|
||||
" cluster text not null, "
|
||||
" conninfo text not null)", config.cluster_name);
|
||||
" conninfo text not null)", config.cluster_name);
|
||||
if (!PQexec(conn, sqlquery))
|
||||
{
|
||||
fprintf(stderr,
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return;
|
||||
}
|
||||
@@ -397,33 +398,34 @@ 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);
|
||||
if (!PQexec(conn, sqlquery))
|
||||
{
|
||||
fprintf(stderr,
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return;
|
||||
}
|
||||
" apply_lag BIGINT NOT NULL) ",
|
||||
config.cluster_name);
|
||||
}
|
||||
|
||||
/* and the view */
|
||||
sqlquery_snprintf(sqlquery, "CREATE VIEW repmgr_%s.repl_status AS "
|
||||
" WITH monitor_info AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY primary_node, standby_node "
|
||||
" ORDER BY last_monitor_time desc) "
|
||||
" FROM repmgr_%s.repl_monitor) "
|
||||
" SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, "
|
||||
" last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, "
|
||||
" pg_size_pretty(apply_lag) apply_lag, age(now(), last_monitor_time) AS time_lag "
|
||||
" FROM monitor_info a "
|
||||
" WHERE row_number = 1", config.cluster_name, config.cluster_name);
|
||||
if (!PQexec(conn, sqlquery))
|
||||
{
|
||||
fprintf(stderr,
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return;
|
||||
}
|
||||
if (!PQexec(conn, sqlquery))
|
||||
{
|
||||
fprintf(stderr,
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
/* and the view */
|
||||
sqlquery_snprintf(sqlquery, "CREATE VIEW repmgr_%s.repl_status AS "
|
||||
" WITH monitor_info AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY primary_node, standby_node "
|
||||
" ORDER BY last_monitor_time desc) "
|
||||
" FROM repmgr_%s.repl_monitor) "
|
||||
" SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, "
|
||||
" last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, "
|
||||
" pg_size_pretty(apply_lag) apply_lag, age(now(), last_monitor_time) AS time_lag "
|
||||
" FROM monitor_info a "
|
||||
" WHERE row_number = 1", config.cluster_name, config.cluster_name);
|
||||
if (!PQexec(conn, sqlquery))
|
||||
{
|
||||
fprintf(stderr,
|
||||
config.cluster_name, PQerrorMessage(conn));
|
||||
PQfinish(conn);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -431,8 +433,9 @@ do_master_register(void)
|
||||
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);
|
||||
@@ -446,7 +449,7 @@ do_master_register(void)
|
||||
{
|
||||
sqlquery_snprintf(sqlquery, "DELETE FROM repmgr_%s.repl_nodes "
|
||||
" WHERE id = %d",
|
||||
config.cluster_name, config.node);
|
||||
config.cluster_name, config.node);
|
||||
|
||||
if (!PQexec(conn, sqlquery))
|
||||
{
|
||||
@@ -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,11 +1373,13 @@ 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