From ce2d4fb86f897845481004da4b1ae2dffe7f82ac Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 25 Nov 2015 11:16:45 +0900 Subject: [PATCH] Make t_node_info generally available And have it include all the fields from the repl_nodes table. --- dbutils.h | 41 +++++++++++++++++++++++++++++++++++++++++ repmgr.h | 7 ------- repmgrd.c | 22 +++------------------- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/dbutils.h b/dbutils.h index caa4a2fa..88d70dac 100644 --- a/dbutils.h +++ b/dbutils.h @@ -20,10 +20,51 @@ #ifndef _REPMGR_DBUTILS_H_ #define _REPMGR_DBUTILS_H_ +#include "access/xlogdefs.h" + #include "config.h" #include "strutil.h" +typedef enum { + UNKNOWN = 0, + MASTER, + STANDBY, + WITNESS +} t_server_type; + +/* + * Struct to store node information + */ +typedef struct s_node_info +{ + int node_id; + int upstream_node_id; + t_server_type type; + char name[MAXLEN]; + char conninfo_str[MAXLEN]; + char slot_name[MAXLEN]; + int priority; + bool active; + bool is_ready; + bool is_visible; + XLogRecPtr xlog_location; +} t_node_info; + + +#define T_NODE_INFO_INITIALIZER { \ + NODE_NOT_FOUND, \ + NO_UPSTREAM_NODE, \ + UNKNOWN, \ + "", \ + "", \ + "", \ + DEFAULT_PRIORITY, \ + true, \ + false, \ + false, \ + InvalidXLogRecPtr \ +} PGconn *establish_db_connection(const char *conninfo, const bool exit_on_error); diff --git a/repmgr.h b/repmgr.h index 34c40d5a..71cc447a 100644 --- a/repmgr.h +++ b/repmgr.h @@ -50,13 +50,6 @@ #define NO_UPSTREAM_NODE -1 -typedef enum { - UNKNOWN = 0, - MASTER, - STANDBY, - WITNESS -} t_server_type; - /* Run time options type */ diff --git a/repmgrd.c b/repmgrd.c index 110dc0d7..234ba40e 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -41,22 +41,6 @@ #include "access/xlogdefs.h" #include "pqexpbuffer.h" -/* - * Struct to store node information - */ -typedef struct s_node_info -{ - int node_id; - int upstream_node_id; - char conninfo_str[MAXLEN]; - XLogRecPtr xlog_location; - t_server_type type; - bool is_ready; - bool is_visible; - char slot_name[MAXLEN]; - bool active; -} t_node_info; - /* Local info */ @@ -1097,10 +1081,10 @@ do_master_failover(void) t_node_info nodes[FAILOVER_NODES_MAX_CHECK]; /* Store details of the failed node here */ - t_node_info failed_master = {-1, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false}; + t_node_info failed_master = T_NODE_INFO_INITIALIZER; /* Store details of the best candidate for promotion to master here */ - t_node_info best_candidate = {-1, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false}; + t_node_info best_candidate = T_NODE_INFO_INITIALIZER; /* get a list of standby nodes, including myself */ sprintf(sqlquery, @@ -2286,7 +2270,7 @@ get_node_info(PGconn *conn, char *cluster, int node_id) { PGresult *res; - t_node_info node_info = { NODE_NOT_FOUND, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false}; + t_node_info node_info = T_NODE_INFO_INITIALIZER; res = get_node_record(conn, cluster, node_id);