From: Peter Eisentraut Date: Sun, 29 Sep 2019 09:07:47 +0000 (+0200) Subject: Improve fast-fail code comments and debug logging X-Git-Tag: pgbouncer_1_12_0~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b42631932b6114bd6b3c185a4d1bf698fae855b4;p=pgbouncer Improve fast-fail code comments and debug logging no changes in functionality --- diff --git a/include/bouncer.h b/include/bouncer.h index e14cf34..5f8fd27 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -250,7 +250,7 @@ struct PgPool { usec_t last_lifetime_disconnect;/* last time when server_lifetime was applied */ - /* if last connect failed, there should be delay before next */ + /* if last connect to server failed, there should be delay before next */ usec_t last_connect_time; unsigned last_connect_failed:1; unsigned last_login_failed:1; diff --git a/src/objects.c b/src/objects.c index f5f1465..19d89af 100644 --- a/src/objects.c +++ b/src/objects.c @@ -575,7 +575,7 @@ void activate_client(PgSocket *client) } /* - * Don't let clients queue at all, if there is no working server connection. + * Don't let clients queue at all if there is no working server connection. * * It must still allow following cases: * - empty pool on startup @@ -586,22 +586,35 @@ void activate_client(PgSocket *client) * - new server connections fail due to server_connect_timeout, or other failure * * So here we drop client if all server connections have been dropped - * and new one's fail. + * and new ones fail. + * + * Return true if the client connection should be allowed, false if it + * should be rejected. */ bool check_fast_fail(PgSocket *client) { int cnt; PgPool *pool = client->pool; - /* reject if no servers are available and the last login failed */ + /* If last login succeeded, client can go ahead. */ if (!pool->last_login_failed) return true; + + /* If there are servers available, client can go ahead. */ cnt = pool_server_count(pool) - statlist_count(&pool->new_server_list); if (cnt) return true; + + /* Else we fail the client. */ disconnect_client(client, true, "pgbouncer cannot connect to server"); - /* usual relaunch won't work, as there are no waiting clients */ + /* + * Try to launch a new connection. (launch_new_connection() + * will check for server_login_retry etc.) The usual relaunch + * from janitor.c won't do anything, as there are no waiting + * clients, so we need to do it here to get any new servers + * eventually. + */ launch_new_connection(pool); return false; @@ -1129,7 +1142,8 @@ void launch_new_connection(PgPool *pool) if (pool->last_connect_failed) { usec_t now = get_cached_time(); if (now - pool->last_connect_time < cf_server_login_retry) { - log_debug("launch_new_connection: last failed, wait"); + log_debug("launch_new_connection: last failed, not launching new connection yet, still waiting %" PRIu64 " s", + (cf_server_login_retry - (now - pool->last_connect_time)) / USEC); return; } }