Permalink
Browse files

Merge branch 'REL2_0_STABLE'

Conflicts:
	HISTORY
	dbutils.h
	repmgr.c
	repmgrd.c
	version.h
  • Loading branch information...
Christian Kruse
Christian Kruse committed Jan 10, 2014
2 parents 079a7c9 + a0fdadd commit c41030b40e241c61907b58dc2abcf264d5b870f4
Showing with 669 additions and 272 deletions.
  1. +4 −0 CREDITS
  2. +8 −1 HISTORY
  3. +6 −6 check_dir.c
  4. +26 −10 config.c
  5. +5 −0 config.h
  6. +37 −3 dbutils.c
  7. +3 −0 dbutils.h
  8. +3 −3 debian/DEBIAN/control
  9. +14 −0 debian/repmgr.repmgrd.default
  10. +48 −0 debian/repmgr.repmgrd.init
  11. +1 −0 errcode.h
  12. +26 −1 log.c
  13. +10 −8 log.h
  14. +45 −43 repmgr.c
  15. +10 −1 repmgr.conf.sample
  16. +2 −0 repmgr.h
  17. +420 −196 repmgrd.c
  18. +1 −0 version.h
View
@@ -10,3 +10,7 @@ Hannu Krosing <hannu@2ndQuadrant.com>
Cédric Villemain <cedric@2ndquadrant.com>
Charles Duffy <charles@dyfis.net>
Daniel Farina <daniel@heroku.com>
+Shawn Ellis <shawn.ellis17@gmail.com>
+Jay Taylor <jay@jaytaylor.com>
+Christian Kruse <christian@2ndQuadrant.com>
+Krzysztof Gajdemski <songo@debian.org.pl>
View
@@ -1,4 +1,11 @@
-2.0beta 2012-07-27
+2.0beta2 2013-12-19
+ Improve autofailover logic and algorithms (Jaime, Andres)
+ Ignore pg_log when cloning (Jaime)
+ Add timestamps to log line in stderr (Christian)
+ Correctly check wal_keep_segments (Jay Taylor)
+ Add a ssh_options parameter (Jay Taylor)
+
+2.0beta1 2012-07-27
Make CLONE command try to make an exact copy including $PGDATA location (Cedric)
Add detection of master failure (Jaime)
Add the notion of a witness server (Jaime)
View
@@ -225,12 +225,12 @@ is_pg_dir(char *dir)
struct stat sb;
int r;
- // test pgdata
+ /* test pgdata */
xsnprintf(path, buf_sz, "%s/PG_VERSION", dir);
if (stat(path, &sb) == 0)
return true;
- // test tablespace dir
+ /* test tablespace dir */
sprintf(path, "ls %s/PG_*/ -I*", dir);
r = system(path);
if (r == 0)
@@ -256,7 +256,7 @@ create_pgdir(char *dir, bool force)
{
log_err(_("couldn't create directory \"%s\"...\n"),
dir);
- exit(ERR_BAD_CONFIG);
+ return false;
}
break;
case 1:
@@ -268,7 +268,7 @@ create_pgdir(char *dir, bool force)
{
log_err(_("could not change permissions of directory \"%s\": %s\n"),
dir, strerror(errno));
- exit(ERR_BAD_CONFIG);
+ return false;
}
break;
case 2:
@@ -293,15 +293,15 @@ create_pgdir(char *dir, bool force)
"If you are sure you want to clone here, "
"please check there is no PostgreSQL server "
"running and use the --force option\n"));
- exit(ERR_BAD_CONFIG);
+ return false;
}
return false;
default:
/* Trouble accessing directory */
log_err(_("could not access directory \"%s\": %s\n"),
dir, strerror(errno));
- exit(ERR_BAD_CONFIG);
+ return false;
}
return true;
}
View
@@ -41,6 +41,9 @@ parse_config(const char *config_file, t_configuration_options *options)
memset(options->promote_command, 0, sizeof(options->promote_command));
memset(options->follow_command, 0, sizeof(options->follow_command));
memset(options->rsync_options, 0, sizeof(options->rsync_options));
+ memset(options->ssh_options, 0, sizeof(options->ssh_options));
+ memset(options->pg_bindir, 0, sizeof(options->pg_bindir));
+ memset(options->pgctl_options, 0, sizeof(options->pgctl_options));
/* if nothing has been provided defaults to 60 */
options->master_response_timeout = 60;
@@ -78,6 +81,8 @@ parse_config(const char *config_file, t_configuration_options *options)
strncpy (options->conninfo, value, MAXLEN);
else if (strcmp(name, "rsync_options") == 0)
strncpy (options->rsync_options, value, QUERY_STR_LEN);
+ else if (strcmp(name, "ssh_options") == 0)
+ strncpy (options->ssh_options, value, QUERY_STR_LEN);
else if (strcmp(name, "loglevel") == 0)
strncpy (options->loglevel, value, MAXLEN);
else if (strcmp(name, "logfacility") == 0)
@@ -111,6 +116,10 @@ parse_config(const char *config_file, t_configuration_options *options)
options->reconnect_attempts = atoi(value);
else if (strcmp(name, "reconnect_interval") == 0)
options->reconnect_intvl = atoi(value);
+ else if (strcmp(name, "pg_bindir") == 0)
+ strncpy (options->pg_bindir, value, MAXLEN);
+ else if (strcmp(name, "pg_ctl_options") == 0)
+ strncpy (options->pgctl_options, value, MAXLEN);
else
log_warning(_("%s/%s: Unknown name/value pair!\n"), name, value);
}
@@ -148,6 +157,12 @@ parse_config(const char *config_file, t_configuration_options *options)
log_err(_("Reconnect intervals must be zero or greater. Check the configuration file.\n"));
exit(ERR_BAD_CONFIG);
}
+
+ if (*options->pg_bindir == '\0')
+ {
+ log_err(_("pg_bindir config value not found. Check the configuration file.\n"));
+ exit(ERR_BAD_CONFIG);
+ }
}
@@ -218,57 +233,57 @@ reload_configuration(char *config_file, t_configuration_options *orig_options)
parse_config(config_file, &new_options);
if (new_options.node == -1)
{
- log_warning(_("\nCannot load new configuration, will keep current one.\n"));
+ log_warning(_("Cannot load new configuration, will keep current one.\n"));
return false;
}
if (strcmp(new_options.cluster_name, orig_options->cluster_name) != 0)
{
- log_warning(_("\nCannot change cluster name, will keep current configuration.\n"));
+ log_warning(_("Cannot change cluster name, will keep current configuration.\n"));
return false;
}
if (new_options.node != orig_options->node)
{
- log_warning(_("\nCannot change node number, will keep current configuration.\n"));
+ log_warning(_("Cannot change node number, will keep current configuration.\n"));
return false;
}
- if (new_options.node_name != orig_options->node_name)
+ if (strcmp(new_options.node_name, orig_options->node_name) != 0)
{
- log_warning(_("\nCannot change standby name, will keep current configuration.\n"));
+ log_warning(_("Cannot change standby name, will keep current configuration.\n"));
return false;
}
if (new_options.failover != MANUAL_FAILOVER && new_options.failover != AUTOMATIC_FAILOVER)
{
- log_warning(_("\nNew value for failover is not valid. Should be MANUAL or AUTOMATIC.\n"));
+ log_warning(_("New value for failover is not valid. Should be MANUAL or AUTOMATIC.\n"));
return false;
}
if (new_options.master_response_timeout <= 0)
{
- log_warning(_("\nNew value for master_response_timeout is not valid. Should be greater than zero.\n"));
+ log_warning(_("New value for master_response_timeout is not valid. Should be greater than zero.\n"));
return false;
}
if (new_options.reconnect_attempts < 0)
{
- log_warning(_("\nNew value for reconnect_attempts is not valid. Should be greater or equal than zero.\n"));
+ log_warning(_("New value for reconnect_attempts is not valid. Should be greater or equal than zero.\n"));
return false;
}
if (new_options.reconnect_intvl < 0)
{
- log_warning(_("\nNew value for reconnect_interval is not valid. Should be greater or equal than zero.\n"));
+ log_warning(_("New value for reconnect_interval is not valid. Should be greater or equal than zero.\n"));
return false;
}
/* Test conninfo string */
conn = establishDBConnection(new_options.conninfo, false);
if (!conn || (PQstatus(conn) != CONNECTION_OK))
{
- log_warning(_("\nconninfo string is not valid, will keep current configuration.\n"));
+ log_warning(_("conninfo string is not valid, will keep current configuration.\n"));
return false;
}
PQfinish(conn);
@@ -283,6 +298,7 @@ reload_configuration(char *config_file, t_configuration_options *orig_options)
strcpy(orig_options->promote_command, new_options.promote_command);
strcpy(orig_options->follow_command, new_options.follow_command);
strcpy(orig_options->rsync_options, new_options.rsync_options);
+ strcpy(orig_options->ssh_options, new_options.ssh_options);
orig_options->master_response_timeout = new_options.master_response_timeout;
orig_options->reconnect_attempts = new_options.reconnect_attempts;
orig_options->reconnect_intvl = new_options.reconnect_intvl;
View
@@ -36,11 +36,16 @@ typedef struct
char loglevel[MAXLEN];
char logfacility[MAXLEN];
char rsync_options[QUERY_STR_LEN];
+ char ssh_options[QUERY_STR_LEN];
int master_response_timeout;
int reconnect_attempts;
int reconnect_intvl;
+ char pg_bindir[MAXLEN];
+ char pgctl_options[MAXLEN];
} t_configuration_options;
+#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", -1, -1, -1, "", "" }
+
void parse_config(const char *config_file, t_configuration_options *options);
void parse_line(char *buff, char *name, char *value);
char *trim(char *s);
View
@@ -138,7 +138,7 @@ is_pgup(PGconn *conn, int timeout)
{
if (twice)
return false;
- PQreset(conn); // reconnect
+ PQreset(conn); /* reconnect */
twice = true;
}
else
@@ -164,10 +164,10 @@ is_pgup(PGconn *conn, int timeout)
break;
failed:
- // we need to retry, because we might just have loose the connection once
+ /* we need to retry, because we might just have loose the connection once */
if (twice)
return false;
- PQreset(conn); // reconnect
+ PQreset(conn); /* reconnect */
twice = true;
}
}
@@ -250,6 +250,40 @@ guc_setted(PGconn *conn, const char *parameter, const char *op,
return true;
}
+/**
+ * Just like guc_setted except with an extra parameter containing the name of
+ * the pg datatype so that the comparison can be done properly.
+ */
+bool
+guc_setted_typed(PGconn *conn, const char *parameter, const char *op,
+ const char *value, const char *datatype)
+{
+ PGresult *res;
+ char sqlquery[QUERY_STR_LEN];
+
+ sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings "
+ " WHERE name = '%s' AND setting::%s %s '%s'::%s",
+ parameter, datatype, op, value, datatype);
+
+ res = PQexec(conn, sqlquery);
+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
+ {
+ log_err(_("GUC setting check PQexec failed: %s"),
+ PQerrorMessage(conn));
+ PQclear(res);
+ PQfinish(conn);
+ exit(ERR_DB_QUERY);
+ }
+ if (PQntuples(res) == 0)
+ {
+ PQclear(res);
+ return false;
+ }
+ PQclear(res);
+
+ return true;
+}
+
const char *
get_cluster_size(PGconn *conn)
View
@@ -32,6 +32,9 @@ bool is_pgup(PGconn *conn, int timeout);
char *pg_version(PGconn *conn, char* major_version);
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
const char *value);
+bool guc_setted_typed(PGconn *conn, const char *parameter, const char *op,
+ const char *value, const char *datatype);
+
const char *get_cluster_size(PGconn *conn);
PGconn *getMasterConnection(PGconn *standby_conn, char *schema, char *cluster,
int *master_id, char *master_conninfo_out);
View
@@ -1,9 +1,9 @@
Package: repmgr-auto
-Version: 1.0-1
+Version: 2.0beta2
Section: database
Priority: optional
Architecture: all
-Depends: rsync, postgresql-9.0
-Maintainer: Greg Smith <greg@2ndQuadrant.com>
+Depends: rsync, postgresql-9.0 | postgresql-9.1 | postgresql-9.2 | postgresql-9.3
+Maintainer: Jaime Casanova <jaime@2ndQuadrant.com>
Description: PostgreSQL replication setup, magament and monitoring
has two main executables
@@ -0,0 +1,14 @@
+#!/bin/sh
+# default settings for repmgrd. This file is source by /bin/sh from
+# /etc/init.d/repmgrd
+
+# Options for repmgrd
+REPMGRD_OPTS=""
+
+# repmgrd binary
+REPMGR_BIN="/usr/bin/repmgr"
+
+# pid file
+REPMGR_PIDFILE="/var/run/repmgrd.pid"
+
+
View
@@ -0,0 +1,48 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: repmgrd
+# Required-Start: $local_fs $remote_fs $network $syslog $postgresql
+# Required-Stop: $local_fs $remote_fs $network $syslog $postgresql
+# Should-Start: $syslog $postgresql
+# Should-Start: $syslog $postgresql
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start/stop repmgrd
+### END INIT INFO
+
+set -e
+
+if test -f /etc/default/repmgrd; then
+ . /etc/default/repmgrd
+fi
+
+if [ -z "$REPMGRD_BIN" ]; then
+ REPMGRD_BIN="/usr/bin/repmgrd"
+fi
+
+if [ -z "$REPMGRD_PIDFILE" ]; then
+ REPMGRD_PIDFILE="/var/run/repmgrd.pid"
+fi
+
+test -x $REPMGRD_BIN || exit 0
+
+case "$1" in
+ start)
+ start-stop-daemon --start --quiet --make-pidfile --pidfile $REPMGRD_PIDFILE --exec $REPMGRD_BIN $REPMGRD_OPTS
+ ;;
+
+ stop)
+ start-stop-daemon --stop --oknodo --quiet --pidfile $REPMGRD_PIDFILE
+ ;;
+
+ restart)
+ $0 stop && $0 start || exit 1
+ ;;
+
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+ ;;
+esac
+
+exit 0
View
@@ -35,5 +35,6 @@
#define ERR_STR_OVERFLOW 10
#define ERR_FAILOVER_FAIL 11
#define ERR_BAD_SSH 12
+#define ERR_SYS_FAILURE 13
#endif /* _ERRCODE_H_ */
Oops, something went wrong.

0 comments on commit c41030b

Please sign in to comment.