Detect changes to configuration file

This will prevent unnecessary reconnects to the upstream and
updates of the node record on the primary.
This commit is contained in:
Ian Barwick
2015-02-10 12:20:48 +09:00
parent 4f36b2c085
commit 1803a16c7e
2 changed files with 165 additions and 23 deletions

160
config.c
View File

@@ -24,6 +24,18 @@
static void tablespace_list_append(t_configuration_options *options, const char *arg); static void tablespace_list_append(t_configuration_options *options, const char *arg);
/*
* parse_config()
*
* Set default options and overwrite with values from provided configuration
* file.
*
* Returns true if a configuration file could be parsed, otherwise false.
*
* Any configuration options changed in this function must also be changed in
* reload_config()
*/
bool bool
parse_config(const char *config_file, t_configuration_options * options) parse_config(const char *config_file, t_configuration_options * options)
{ {
@@ -252,8 +264,8 @@ bool
reload_config(char *config_file, t_configuration_options * orig_options) reload_config(char *config_file, t_configuration_options * orig_options)
{ {
PGconn *conn; PGconn *conn;
t_configuration_options new_options; t_configuration_options new_options;
bool config_changed = false;
/* /*
* Re-read the configuration file: repmgr.conf * Re-read the configuration file: repmgr.conf
@@ -308,6 +320,8 @@ reload_config(char *config_file, t_configuration_options * orig_options)
return false; return false;
} }
if(strcmp(orig_options->conninfo, new_options.conninfo) != 0)
{
/* Test conninfo string */ /* Test conninfo string */
conn = establish_db_connection(new_options.conninfo, false); conn = establish_db_connection(new_options.conninfo, false);
if (!conn || (PQstatus(conn) != CONNECTION_OK)) if (!conn || (PQstatus(conn) != CONNECTION_OK))
@@ -316,21 +330,70 @@ reload_config(char *config_file, t_configuration_options * orig_options)
return false; return false;
} }
PQfinish(conn); PQfinish(conn);
}
/* Configuration seems ok, will load new values */ /*
* No configuration problems detected - copy any changed values
*
* NB: keep these in the same order as in config.h to make it easier
* to manage them
*/
/* cluster_name */
if(strcmp(orig_options->cluster_name, new_options.cluster_name) != 0)
{
strcpy(orig_options->cluster_name, new_options.cluster_name); strcpy(orig_options->cluster_name, new_options.cluster_name);
orig_options->node = new_options.node; config_changed = true;
}
/* conninfo */
if(strcmp(orig_options->conninfo, new_options.conninfo) != 0)
{
strcpy(orig_options->conninfo, new_options.conninfo); strcpy(orig_options->conninfo, new_options.conninfo);
config_changed = true;
}
/* node */
if(orig_options->node != new_options.node)
{
orig_options->node = new_options.node;
config_changed = true;
}
/* failover */
if(orig_options->failover != new_options.failover)
{
orig_options->failover = new_options.failover; orig_options->failover = new_options.failover;
config_changed = true;
}
/* priority */
if(orig_options->priority != new_options.priority)
{
orig_options->priority = new_options.priority; orig_options->priority = new_options.priority;
config_changed = true;
}
/* node_name */
if(strcmp(orig_options->node_name, new_options.node_name) != 0)
{
strcpy(orig_options->node_name, new_options.node_name); strcpy(orig_options->node_name, new_options.node_name);
config_changed = true;
}
/* promote_command */
if(strcmp(orig_options->promote_command, new_options.promote_command) != 0)
{
strcpy(orig_options->promote_command, new_options.promote_command); strcpy(orig_options->promote_command, new_options.promote_command);
config_changed = true;
}
/* follow_command */
if(strcmp(orig_options->follow_command, new_options.follow_command) != 0)
{
strcpy(orig_options->follow_command, new_options.follow_command); strcpy(orig_options->follow_command, new_options.follow_command);
strcpy(orig_options->rsync_options, new_options.rsync_options); config_changed = true;
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;
/* /*
* XXX These ones can change with a simple SIGHUP? * XXX These ones can change with a simple SIGHUP?
@@ -342,7 +405,86 @@ reload_config(char *config_file, t_configuration_options * orig_options)
* orig_options.loglevel, orig_options.logfacility); * orig_options.loglevel, orig_options.logfacility);
*/ */
return true; /* rsync_options */
if(strcmp(orig_options->rsync_options, new_options.rsync_options) != 0)
{
strcpy(orig_options->rsync_options, new_options.rsync_options);
config_changed = true;
}
/* ssh_options */
if(strcmp(orig_options->ssh_options, new_options.ssh_options) != 0)
{
strcpy(orig_options->ssh_options, new_options.ssh_options);
config_changed = true;
}
/* master_response_timeout */
if(orig_options->master_response_timeout != new_options.master_response_timeout)
{
orig_options->master_response_timeout = new_options.master_response_timeout;
config_changed = true;
}
/* reconnect_attempts */
if(orig_options->reconnect_attempts != new_options.reconnect_attempts)
{
orig_options->reconnect_attempts = new_options.reconnect_attempts;
config_changed = true;
}
/* reconnect_intvl */
if(orig_options->reconnect_intvl != new_options.reconnect_intvl)
{
orig_options->reconnect_intvl = new_options.reconnect_intvl;
config_changed = true;
}
/* pgctl_options */
if(strcmp(orig_options->pgctl_options, new_options.pgctl_options) != 0)
{
strcpy(orig_options->pgctl_options, new_options.pgctl_options);
config_changed = true;
}
/* pg_basebackup_options */
if(strcmp(orig_options->pg_basebackup_options, new_options.pg_basebackup_options) != 0)
{
strcpy(orig_options->pg_basebackup_options, new_options.pg_basebackup_options);
config_changed = true;
}
/* monitor_interval_secs */
if(orig_options->monitor_interval_secs != new_options.monitor_interval_secs)
{
orig_options->monitor_interval_secs = new_options.monitor_interval_secs;
config_changed = true;
}
/* retry_promote_interval_secs */
if(orig_options->retry_promote_interval_secs != new_options.retry_promote_interval_secs)
{
orig_options->retry_promote_interval_secs = new_options.retry_promote_interval_secs;
config_changed = true;
}
/* use_replication_slots */
if(orig_options->use_replication_slots != new_options.use_replication_slots)
{
orig_options->use_replication_slots = new_options.use_replication_slots;
config_changed = true;
}
if(config_changed == true)
{
log_debug(_("reload_config(): configuration has changed\n"));
}
else
{
log_debug(_("reload_config(): configuration has not changed"));
}
return config_changed;
} }

View File

@@ -376,7 +376,7 @@ main(int argc, char **argv)
case WITNESS: case WITNESS:
case STANDBY: case STANDBY:
/* We need the node id of the upstream server as well as a connection to it */ /* We need the node id of the primary server as well as a connection to it */
log_info(_("%s Connecting to primary for cluster '%s'\n"), log_info(_("%s Connecting to primary for cluster '%s'\n"),
progname, local_options.cluster_name); progname, local_options.cluster_name);