From 663b5af54286f7506973acb405de34002bc88af3 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Fri, 12 Feb 2010 19:09:02 +0000 Subject: [PATCH] Don't let clients queue in case no servers and connections fail. That allows to avoid unnecessary delays in hopeless situations. --- src/janitor.c | 7 +++++++ src/objects.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/janitor.c b/src/janitor.c index 842ff98..2e6ece0 100644 --- a/src/janitor.c +++ b/src/janitor.c @@ -429,6 +429,13 @@ static void check_pool_size(PgPool *pool) disconnect_server(server, true, "too many servers in the pool"); many--; } + + /* + * Because of fast-fail we may not have any waiting clients that would + * trigger server re-connect. So do it explicitly. + */ + if (cur == 0 && pool->last_connect_failed) + launch_new_connection(pool); } /* maintain servers in a pool */ diff --git a/src/objects.c b/src/objects.c index 7076876..4078355 100644 --- a/src/objects.c +++ b/src/objects.c @@ -509,6 +509,25 @@ bool find_server(PgSocket *client) else break; } + + /* + * Don't let clients queue at all, if there is no working server connection. + * + * It must still allow following cases: + * - empty pool on startup + * - idle pool where all servers are removed + * + * Current logic: + * - old server connections will be dropped by query_timeout + * - new server connections fail due to server_connect_timeout, or other failure + */ + if (!server && pool->last_connect_failed) { + int cnt = pool_server_count(pool) - statlist_count(&pool->new_server_list); + if (!cnt) { + disconnect_client(client, true, "no working server connection"); + return false; + } + } } Assert(!server || server->state == SV_IDLE); -- 2.39.5