Skip to content

Commit

Permalink
Add is_server_available_quiet()
Browse files Browse the repository at this point in the history
For use in cases where the caller collates node availability information
and doesn't want to prematurely emit log output.
  • Loading branch information
ibarwick committed Apr 1, 2019
1 parent 1906ea8 commit 83e492d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
23 changes: 21 additions & 2 deletions dbutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ int bdr_version_num = UNKNOWN_BDR_VERSION_NUM;
static void log_db_error(PGconn *conn, const char *query_text, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));

static bool _is_server_available(const char *conninfo, bool quiet);

static PGconn *_establish_db_connection(const char *conninfo,
const bool exit_on_error,
const bool log_notice,
Expand Down Expand Up @@ -4312,15 +4314,32 @@ wait_connection_availability(PGconn *conn, int timeout)

bool
is_server_available(const char *conninfo)
{
return _is_server_available(conninfo, false);
}


bool
is_server_available_quiet(const char *conninfo)
{
return _is_server_available(conninfo, true);
}


static bool
_is_server_available(const char *conninfo, bool quiet)
{
PGPing status = PQping(conninfo);

log_verbose(LOG_DEBUG, "is_server_available(): ping status for \"%s\" is %s", conninfo, print_pqping_status(status));
if (status == PQPING_OK)
return true;

log_warning(_("unable to ping \"%s\""), conninfo);
log_detail(_("PQping() returned \"%s\""), print_pqping_status(status));
if (quiet == false)
{
log_warning(_("unable to ping \"%s\""), conninfo);
log_detail(_("PQping() returned \"%s\""), print_pqping_status(status));
}

return false;
}
Expand Down
1 change: 1 addition & 0 deletions dbutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ int wait_connection_availability(PGconn *conn, int timeout);

/* node availability functions */
bool is_server_available(const char *conninfo);
bool is_server_available_quiet(const char *conninfo);
bool is_server_available_params(t_conninfo_param_list *param_list);
ExecStatusType connection_ping(PGconn *conn);
ExecStatusType connection_ping_reconnect(PGconn *conn);
Expand Down
2 changes: 1 addition & 1 deletion repmgr-action-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ do_cluster_show(void)
else
{
/* check if node is reachable, but just not letting us in */
if (is_server_available(cell->node_info->conninfo))
if (is_server_available_quiet(cell->node_info->conninfo))
cell->node_info->node_status = NODE_STATUS_REJECTED;
else
cell->node_info->node_status = NODE_STATUS_DOWN;
Expand Down

0 comments on commit 83e492d

Please sign in to comment.