]> granicus.if.org Git - pgbouncer/commitdiff
fix launching new connections during maintenance
authorCody Cutrer <cody@instructure.com>
Mon, 26 Aug 2013 20:30:27 +0000 (14:30 -0600)
committerCody Cutrer <cody@instructure.com>
Fri, 27 Sep 2013 19:37:37 +0000 (13:37 -0600)
match up waiting connections with tested/used until we run out.
launches new connection if there are more waiting than could be
fulfilled by refreshing current connections. this situation can
happen if you have high churn on client connections (i.e. with
transaction pooling), such that there is *always* at least one
connection in sv_tested or sv_used.

src/janitor.c

index 083da52f82eb160ab7886d6ea428266bba18c2fa..26c7c57fd1a05d42dff235217a2af1131180bc77 100644 (file)
@@ -171,8 +171,11 @@ static void per_loop_activate(PgPool *pool)
 {
        struct List *item, *tmp;
        PgSocket *client;
+       int sv_tested, sv_used;
 
        /* see if any server have been freed */
+       sv_tested = statlist_count(&pool->tested_server_list);
+       sv_used = statlist_count(&pool->used_server_list);
        statlist_for_each_safe(item, &pool->waiting_client_list, tmp) {
                client = container_of(item, PgSocket, head);
                if (!statlist_empty(&pool->idle_server_list)) {
@@ -185,13 +188,13 @@ static void per_loop_activate(PgPool *pool)
 
                        /* there is a ready server already */
                        activate_client(client);
-               } else if (!statlist_empty(&pool->tested_server_list)) {
+               } else if (sv_tested > 0) {
                        /* some connections are in testing process */
-                       break;
-               } else if (!statlist_empty(&pool->used_server_list)) {
+                       --sv_tested;
+               } else if (sv_used > 0) {
                        /* ask for more connections to be tested */
                        launch_recheck(pool);
-                       break;
+                       --sv_used;
                } else {
                        /* not enough connections */
                        launch_new_connection(pool);