Add configure option --with-bdr-only

Builds repmgr with only BDR functionality; other code is disabled
at critical points.
This commit is contained in:
Ian Barwick
2017-07-16 17:13:45 +09:00
parent a6f8d59f77
commit ec00202a31
7 changed files with 54 additions and 25 deletions

View File

@@ -3,20 +3,3 @@
/* Only build repmgr for BDR */ /* Only build repmgr for BDR */
#undef BDR_ONLY #undef BDR_ONLY
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the home page for this package. */
#undef PACKAGE_URL
/* Define to the version of this package. */
#undef PACKAGE_VERSION

View File

@@ -5,8 +5,8 @@
* *
*/ */
#ifndef _REPMGR_CONFIG_H_ #ifndef _REPMGR_CONFIGFILE_H_
#define _REPMGR_CONFIG_H_ #define _REPMGR_CONFIGFILE_H_
#include <getopt_long.h> #include <getopt_long.h>

View File

@@ -574,6 +574,7 @@ main(int argc, char **argv)
if (repmgr_node_type != NULL) if (repmgr_node_type != NULL)
{ {
#ifndef BDR_ONLY
if (strcasecmp(repmgr_node_type, "PRIMARY") == 0 || strcasecmp(repmgr_node_type, "MASTER") == 0 ) if (strcasecmp(repmgr_node_type, "PRIMARY") == 0 || strcasecmp(repmgr_node_type, "MASTER") == 0 )
{ {
if (strcasecmp(repmgr_action, "REGISTER") == 0) if (strcasecmp(repmgr_action, "REGISTER") == 0)
@@ -601,8 +602,10 @@ main(int argc, char **argv)
else if (strcasecmp(repmgr_action, "RESTORE-CONFIG") == 0) else if (strcasecmp(repmgr_action, "RESTORE-CONFIG") == 0)
action = STANDBY_RESTORE_CONFIG; action = STANDBY_RESTORE_CONFIG;
} }
else if (strcasecmp(repmgr_node_type, "BDR") == 0) else if (strcasecmp(repmgr_node_type, "BDR") == 0)
#else
if (strcasecmp(repmgr_node_type, "BDR") == 0)
#endif
{ {
if (strcasecmp(repmgr_action, "REGISTER") == 0) if (strcasecmp(repmgr_action, "REGISTER") == 0)
action = BDR_REGISTER; action = BDR_REGISTER;
@@ -776,8 +779,7 @@ main(int argc, char **argv)
*/ */
if (config_file_options.node_id == NODE_NOT_FOUND) if (config_file_options.node_id == NODE_NOT_FOUND)
{ {
log_error(_("no node information was found - " log_error(_("no node information was found - please supply a configuration file"));
"please supply a configuration file"));
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }
} }
@@ -856,6 +858,7 @@ main(int argc, char **argv)
switch (action) switch (action)
{ {
#ifndef BDR_ONLY
/* PRIMARY */ /* PRIMARY */
case PRIMARY_REGISTER: case PRIMARY_REGISTER:
do_primary_register(); do_primary_register();
@@ -889,7 +892,21 @@ main(int argc, char **argv)
case STANDBY_RESTORE_CONFIG: case STANDBY_RESTORE_CONFIG:
do_standby_restore_config(); do_standby_restore_config();
break; break;
#else
/* we won't ever reach here, but stop the compiler complaining */
case PRIMARY_REGISTER:
case PRIMARY_UNREGISTER:
case STANDBY_CLONE:
case STANDBY_REGISTER:
case STANDBY_UNREGISTER:
case STANDBY_PROMOTE:
case STANDBY_FOLLOW:
case STANDBY_SWITCHOVER:
case STANDBY_ARCHIVE_CONFIG:
case STANDBY_RESTORE_CONFIG:
break;
#endif
/* BDR */ /* BDR */
case BDR_REGISTER: case BDR_REGISTER:
do_bdr_register(); do_bdr_register();
@@ -1242,12 +1259,14 @@ do_help(void)
} }
printf(_("Usage:\n")); printf(_("Usage:\n"));
#ifndef BDR_ONLY
printf(_(" %s [OPTIONS] primary register\n"), progname()); printf(_(" %s [OPTIONS] primary register\n"), progname());
printf(_(" %s [OPTIONS] primary unregister\n"), progname()); printf(_(" %s [OPTIONS] primary unregister\n"), progname());
printf(_(" %s [OPTIONS] standby clone\n"), progname()); printf(_(" %s [OPTIONS] standby clone\n"), progname());
printf(_(" %s [OPTIONS] standby register\n"), progname()); printf(_(" %s [OPTIONS] standby register\n"), progname());
printf(_(" %s [OPTIONS] standby unregister\n"), progname()); printf(_(" %s [OPTIONS] standby unregister\n"), progname());
printf(_(" %s [OPTIONS] standby promote\n"), progname()); printf(_(" %s [OPTIONS] standby promote\n"), progname());
#endif
printf(_(" %s [OPTIONS] bdr register\n"), progname()); printf(_(" %s [OPTIONS] bdr register\n"), progname());
printf(_(" %s [OPTIONS] bdr unregister\n"), progname()); printf(_(" %s [OPTIONS] bdr unregister\n"), progname());
printf(_(" %s [OPTIONS] cluster event\n"), progname()); printf(_(" %s [OPTIONS] cluster event\n"), progname());

View File

@@ -2,6 +2,12 @@
* repmgr.h * repmgr.h
* Copyright (c) 2ndQuadrant, 2010-2017 * Copyright (c) 2ndQuadrant, 2010-2017
*/ */
#ifndef _REPMGR_CONFIG_H
#define _REPMGR_CONFIG_H
#include <config.h>
#endif
#ifndef _REPMGR_H_ #ifndef _REPMGR_H_
#define _REPMGR_H_ #define _REPMGR_H_
@@ -12,6 +18,7 @@
#include <postgres_fe.h> #include <postgres_fe.h>
#include <pqexpbuffer.h> #include <pqexpbuffer.h>
#include "repmgr_version.h" #include "repmgr_version.h"
#include "errcode.h" #include "errcode.h"
#include "strutil.h" #include "strutil.h"

View File

@@ -35,14 +35,15 @@ typedef enum {
} ElectionResult; } ElectionResult;
static PGconn *upstream_conn = NULL;
static PGconn *primary_conn = NULL;
#ifndef BDR_ONLY
static FailoverState failover_state = FAILOVER_STATE_UNKNOWN; static FailoverState failover_state = FAILOVER_STATE_UNKNOWN;
static t_node_info upstream_node_info = T_NODE_INFO_INITIALIZER; static t_node_info upstream_node_info = T_NODE_INFO_INITIALIZER;
static NodeInfoList standby_nodes = T_NODE_INFO_LIST_INITIALIZER; static NodeInfoList standby_nodes = T_NODE_INFO_LIST_INITIALIZER;
static PGconn *upstream_conn = NULL;
static PGconn *primary_conn = NULL;
static ElectionResult do_election(void); static ElectionResult do_election(void);
static const char *_print_voting_status(NodeVotingStatus voting_status); static const char *_print_voting_status(NodeVotingStatus voting_status);
@@ -62,12 +63,13 @@ void close_connections_physical();
static bool do_primary_failover(void); static bool do_primary_failover(void);
static bool do_upstream_standby_failover(void); static bool do_upstream_standby_failover(void);
#endif
void void
do_physical_node_check(void) do_physical_node_check(void)
{ {
#ifndef BDR_ONLY
/* /*
* Check if node record is active - if not, and `failover_mode=automatic`, the node * Check if node record is active - if not, and `failover_mode=automatic`, the node
* won't be considered as a promotion candidate; this often happens when * won't be considered as a promotion candidate; this often happens when
@@ -128,6 +130,7 @@ do_physical_node_check(void)
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }
} }
#endif
} }
@@ -136,6 +139,7 @@ do_physical_node_check(void)
void void
monitor_streaming_primary(void) monitor_streaming_primary(void)
{ {
#ifndef BDR_ONLY
NodeStatus node_status = NODE_STATUS_UP; NodeStatus node_status = NODE_STATUS_UP;
instr_time log_status_interval_start; instr_time log_status_interval_start;
PQExpBufferData event_details; PQExpBufferData event_details;
@@ -330,12 +334,14 @@ monitor_streaming_primary(void)
sleep(config_file_options.monitor_interval_secs); sleep(config_file_options.monitor_interval_secs);
} }
#endif
} }
void void
monitor_streaming_standby(void) monitor_streaming_standby(void)
{ {
#ifndef BDR_ONLY
RecordStatus record_status; RecordStatus record_status;
NodeStatus upstream_node_status = NODE_STATUS_UP; NodeStatus upstream_node_status = NODE_STATUS_UP;
instr_time log_status_interval_start; instr_time log_status_interval_start;
@@ -661,8 +667,10 @@ monitor_streaming_standby(void)
} }
sleep(1); sleep(1);
} }
#endif
} }
#ifndef BDR_ONLY
static bool static bool
do_primary_failover(void) do_primary_failover(void)
{ {
@@ -864,10 +872,12 @@ do_primary_failover(void)
return false; return false;
} }
/* should never reach here */ /* should never reach here */
return false; return false;
} }
/* /*
* do_upstream_standby_failover() * do_upstream_standby_failover()
* *
@@ -1682,6 +1692,8 @@ reset_node_voting_status(void)
} }
#endif /* #ifndef BDR_ONLY */
void void
close_connections_physical() close_connections_physical()
{ {
@@ -1701,3 +1713,4 @@ close_connections_physical()
} }
} }

View File

@@ -362,12 +362,18 @@ start_monitoring(void)
{ {
switch (local_node_info.type) switch (local_node_info.type)
{ {
#ifndef BDR_ONLY
case PRIMARY: case PRIMARY:
monitor_streaming_primary(); monitor_streaming_primary();
break; break;
case STANDBY: case STANDBY:
monitor_streaming_standby(); monitor_streaming_standby();
break; break;
#else
case PRIMARY:
case STANDBY:
return;
#endif
case BDR: case BDR:
monitor_bdr(); monitor_bdr();
return; return;

View File

@@ -3,6 +3,7 @@
* Copyright (c) 2ndQuadrant, 2010-2017 * Copyright (c) 2ndQuadrant, 2010-2017
*/ */
#ifndef _REPMGRD_H_ #ifndef _REPMGRD_H_
#define _REPMGRD_H_ #define _REPMGRD_H_