]> granicus.if.org Git - pgbouncer/commitdiff
Improve fast-fail code comments and debug logging
authorPeter Eisentraut <peter@eisentraut.org>
Sun, 29 Sep 2019 09:07:47 +0000 (11:07 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sun, 29 Sep 2019 09:07:47 +0000 (11:07 +0200)
no changes in functionality

include/bouncer.h
src/objects.c

index e14cf34dff5aa0cfcd1587d92c43638ba6dc967b..5f8fd2737352bbd781f063ac60a3c20a2f31916f 100644 (file)
@@ -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;
index f5f1465d75932b4f2c2655d8fab93e13522b4a5d..19d89afad008eef87d3495cc11764bda21804e5e 100644 (file)
@@ -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;
                }
        }