Remove unused function

And standardized nomenclature on "master" rather than "primary".
This commit is contained in:
Ian Barwick
2015-03-24 14:29:54 +09:00
parent 8de0deddf9
commit 96255b988a
2 changed files with 7 additions and 88 deletions

View File

@@ -195,15 +195,16 @@ is_pgup(PGconn *conn, int timeout)
return true; return true;
} }
/* /*
* Return the id of the active primary node, or -1 if no * Return the id of the active master node, or -1 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
* does not verify whether the node is actually available * does not verify whether the node is actually available
*/ */
int int
get_primary_node_id(PGconn *conn, char *cluster) get_master_node_id(PGconn *conn, char *cluster)
{ {
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
PGresult *res; PGresult *res;
@@ -221,13 +222,13 @@ get_primary_node_id(PGconn *conn, char *cluster)
res = PQexec(conn, sqlquery); res = PQexec(conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK) if (PQresultStatus(res) != PGRES_TUPLES_OK)
{ {
log_err(_("get_primary_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 = -1;
} }
else if (PQntuples(res) == 0) else if (PQntuples(res) == 0)
{ {
log_warning(_("get_primary_node_id(): no active primary found\n")); log_warning(_("get_master_node_id(): no active primary found\n"));
retval = -1; retval = -1;
} }
else else
@@ -409,81 +410,6 @@ get_pg_setting(PGconn *conn, const char *setting, char *output)
} }
/*
* get_primary_connection()
*
* Returns connection to cluster's primary node
*
* This assumes that the primary node information in `repl_nodes`
* is correct. See get_master_connection(), which polls all known
* servers to find out which one is currently primary.
*/
PGconn *
get_primary_connection(PGconn *standby_conn, char *cluster,
int *primary_node_id_ptr, char *primary_conninfo_out)
{
PGconn *primary_conn = NULL;
PGresult *res;
char sqlquery[QUERY_STR_LEN];
char primary_conninfo_stack[MAXCONNINFO];
char *primary_conninfo = &*primary_conninfo_stack;
/*
* If the caller wanted to get a copy of the connection info string, sub
* out the local stack pointer for the pointer passed by the caller.
*/
if (primary_conninfo_out != NULL)
primary_conninfo = primary_conninfo_out;
sqlquery_snprintf(sqlquery,
" SELECT n.conninfo, n.name, n.id "
" FROM %s.repl_nodes n "
" WHERE n.cluster = '%s' "
" AND n.type = 'master' ",
get_repmgr_schema_quoted(standby_conn),
cluster);
log_debug("get_primary_connection(): %s\n", sqlquery);
res = PQexec(standby_conn, sqlquery);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
log_err(_("unable to get conninfo for master server: %s\n"),
PQerrorMessage(standby_conn));
PQclear(res);
return NULL;
}
if(!PQntuples(res))
{
log_notice(_("no master server record found"));
PQclear(res);
return NULL;
}
strncpy(primary_conninfo, PQgetvalue(res, 0, 0), MAXCONNINFO);
if(primary_node_id_ptr != NULL)
*primary_node_id_ptr = atoi(PQgetvalue(res, 0, 1));
PQclear(res);
log_debug("conninfo is: '%s'\n", primary_conninfo);
primary_conn = establish_db_connection(primary_conninfo, false);
if (PQstatus(primary_conn) != CONNECTION_OK)
{
log_err(_("unable to connect to master node: %s\n"),
PQerrorMessage(primary_conn));
return NULL;
}
return primary_conn;
}
/* /*
* get_upstream_connection() * get_upstream_connection()
* *
@@ -567,9 +493,6 @@ get_upstream_connection(PGconn *standby_conn, char *cluster, int node_id,
* NB: If master_conninfo_out may be NULL. If it is non-null, it is assumed to * NB: If master_conninfo_out may be NULL. If it is non-null, it is assumed to
* point to allocated memory of MAXCONNINFO in length, and the master server * point to allocated memory of MAXCONNINFO in length, and the master server
* connection string is placed there. * connection string is placed there.
*
* To get the primary node from the metadata (i.e. without polling all servers),
* use `get_primary_connection()`.
*/ */
PGconn * PGconn *
@@ -1015,7 +938,7 @@ create_node_record(PGconn *conn, char *action, int node, char *type, int upstrea
*/ */
if(strcmp(type, "standby") == 0) if(strcmp(type, "standby") == 0)
{ {
int primary_node_id = get_primary_node_id(conn, cluster_name); int primary_node_id = get_master_node_id(conn, cluster_name);
maxlen_snprintf(upstream_node_id, "%i", primary_node_id); maxlen_snprintf(upstream_node_id, "%i", primary_node_id);
} }
else else

View File

@@ -33,7 +33,7 @@ PGconn *establish_db_connection_by_params(const char *keywords[],
bool check_cluster_schema(PGconn *conn); bool check_cluster_schema(PGconn *conn);
int is_standby(PGconn *conn); int is_standby(PGconn *conn);
bool is_pgup(PGconn *conn, int timeout); bool is_pgup(PGconn *conn, int timeout);
int get_primary_node_id(PGconn *conn, char *cluster); int get_master_node_id(PGconn *conn, char *cluster);
int get_server_version(PGconn *conn, char *server_version); int get_server_version(PGconn *conn, char *server_version);
bool get_cluster_size(PGconn *conn, char *size); bool get_cluster_size(PGconn *conn, char *size);
bool get_pg_setting(PGconn *conn, const char *setting, char *output); bool get_pg_setting(PGconn *conn, const char *setting, char *output);
@@ -43,10 +43,6 @@ int guc_set(PGconn *conn, const char *parameter, const char *op,
int guc_set_typed(PGconn *conn, const char *parameter, const char *op, int guc_set_typed(PGconn *conn, const char *parameter, const char *op,
const char *value, const char *datatype); const char *value, const char *datatype);
PGconn *get_primary_connection(PGconn *standby_conn, char *cluster,
int *primary_node_id_ptr,
char *primary_conninfo_out);
PGconn *get_upstream_connection(PGconn *standby_conn, char *cluster, PGconn *get_upstream_connection(PGconn *standby_conn, char *cluster,
int node_id, int node_id,
int *upstream_node_id_ptr, int *upstream_node_id_ptr,