From a6076a62b521cab3538fd9082796e7764b9aa4b8 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Wed, 4 May 2022 08:08:24 -0400 Subject: [PATCH] [#224] Prefill when doing a `switch-to` or primary change. Whenever the primary host is changed, by means of an explicit `switch-to` command or by a primary failure, the connection flushing is activated. If possible, the prefill should be also restored on the new server. As suggested in it would be nice to check if the specified new server is the same as the old one (failure of the primary) or a different one (`switch-to`), and in the case they are different the prefill is forced. The prefill will always be to the `INITIAL` size when needed. If the primary is not set, there is no need to prefill with the `MIN_SIZE` value. Close #224 --- src/libpgagroal/pool.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libpgagroal/pool.c b/src/libpgagroal/pool.c index 1381b1f7..9c687c50 100644 --- a/src/libpgagroal/pool.c +++ b/src/libpgagroal/pool.c @@ -802,13 +802,14 @@ void pgagroal_flush_server(signed char server) { struct configuration* config; + int primary = -1; pgagroal_start_logging(); pgagroal_memory_init(); config = (struct configuration*)shmem; - pgagroal_log_debug("pgagroal_flush_server"); + pgagroal_log_debug("pgagroal_flush_server %s", config->servers[server].name); for (int i = 0; i < config->max_connections; i++) { if (config->connections[i].server == server) @@ -845,11 +846,16 @@ pgagroal_flush_server(signed char server) } } - if (config->number_of_users > 0 && config->number_of_limits > 0) + if (pgagroal_get_primary(&primary)) + pgagroal_log_debug("No primary defined"); + else { - if (!fork()) + if (config->number_of_users > 0 && config->number_of_limits > 0 && server != (unsigned char)primary && primary != -1) { - pgagroal_prefill(false); + if (!fork()) + { + pgagroal_prefill(true); + } } }