Add constant NODE_NOT_FOUND

Which is what the magic number means in those contexts.
This commit is contained in:
Ian Barwick
2015-03-31 14:35:16 +09:00
parent 18544c82ca
commit 4dfeffe087
4 changed files with 10 additions and 10 deletions

View File

@@ -197,7 +197,7 @@ is_pgup(PGconn *conn, int timeout)
/* /*
* Return the id of the active master node, or -1 if no * Return the id of the active master node, or NODE_NOT_FOUND if no
* record available. * record available.
* *
* This reports the value stored in the database only and * This reports the value stored in the database only and
@@ -224,12 +224,12 @@ get_master_node_id(PGconn *conn, char *cluster)
{ {
log_err(_("get_master_node_id(): query failed\n%s\n"), log_err(_("get_master_node_id(): query failed\n%s\n"),
PQerrorMessage(conn)); PQerrorMessage(conn));
retval = -1; retval = NODE_NOT_FOUND;
} }
else if (PQntuples(res) == 0) else if (PQntuples(res) == 0)
{ {
log_warning(_("get_master_node_id(): no active primary found\n")); log_warning(_("get_master_node_id(): no active primary found\n"));
retval = -1; retval = NODE_NOT_FOUND;
} }
else else
{ {
@@ -511,7 +511,7 @@ get_master_connection(PGconn *standby_conn, char *cluster,
if(master_id != NULL) if(master_id != NULL)
{ {
*master_id = -1; *master_id = NODE_NOT_FOUND;
} }
/* find all nodes belonging to this cluster */ /* find all nodes belonging to this cluster */

View File

@@ -485,7 +485,7 @@ main(int argc, char **argv)
*/ */
if (config_file_required) if (config_file_required)
{ {
if (options.node == -1) if (options.node == NODE_NOT_FOUND)
{ {
if(config_file_parsed == true) if(config_file_parsed == true)
{ {
@@ -2701,7 +2701,6 @@ create_schema(PGconn *conn)
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
PGresult *res; PGresult *res;
/* create schema */ /* create schema */
sqlquery_snprintf(sqlquery, "CREATE SCHEMA %s", get_repmgr_schema_quoted(conn)); sqlquery_snprintf(sqlquery, "CREATE SCHEMA %s", get_repmgr_schema_quoted(conn));
log_debug(_("master register: %s\n"), sqlquery); log_debug(_("master register: %s\n"), sqlquery);

View File

@@ -49,6 +49,7 @@
#define MANUAL_FAILOVER 0 #define MANUAL_FAILOVER 0
#define AUTOMATIC_FAILOVER 1 #define AUTOMATIC_FAILOVER 1
#define NODE_NOT_FOUND -1
#define NO_UPSTREAM_NODE -1 #define NO_UPSTREAM_NODE -1

View File

@@ -288,7 +288,7 @@ main(int argc, char **argv)
node_info = get_node_info(my_local_conn, local_options.cluster_name, local_options.node); node_info = get_node_info(my_local_conn, local_options.cluster_name, local_options.node);
/* No node record found - exit gracefully */ /* No node record found - exit gracefully */
if(node_info.node_id == -1) if(node_info.node_id == NODE_NOT_FOUND)
{ {
log_err(_("No metadata record found for this node - terminating\n")); log_err(_("No metadata record found for this node - terminating\n"));
log_notice(_("HINT: was this node registered with 'repmgr (master|standby) register'?\n")); log_notice(_("HINT: was this node registered with 'repmgr (master|standby) register'?\n"));
@@ -1757,7 +1757,7 @@ set_local_node_failed(void)
{ {
PGresult *res; PGresult *res;
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
int active_master_node_id = -1; int active_master_node_id = NODE_NOT_FOUND;
char master_conninfo[MAXLEN]; char master_conninfo[MAXLEN];
if (!check_connection(master_conn, "master")) if (!check_connection(master_conn, "master"))
@@ -2242,7 +2242,7 @@ get_node_info(PGconn *conn, char *cluster, int node_id)
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
PGresult *res; PGresult *res;
t_node_info node_info = {-1, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false}; t_node_info node_info = { NODE_NOT_FOUND, NO_UPSTREAM_NODE, "", InvalidXLogRecPtr, UNKNOWN, false, false};
sprintf(sqlquery, sprintf(sqlquery,
"SELECT id, upstream_node_id, conninfo, type, slot_name, active " "SELECT id, upstream_node_id, conninfo, type, slot_name, active "
@@ -2282,7 +2282,7 @@ get_node_info(PGconn *conn, char *cluster, int node_id)
if (!PQntuples(res)) { if (!PQntuples(res)) {
log_warning(_("No record found record for node %i\n"), node_id); log_warning(_("No record found record for node %i\n"), node_id);
PQclear(res); PQclear(res);
node_info.node_id = -1; node_info.node_id = NODE_NOT_FOUND;
return node_info; return node_info;
} }