From b891a9a23d305d951249ce56d25e1d55fcb17d46 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. --- src/libpgagroal/pool.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libpgagroal/pool.c b/src/libpgagroal/pool.c index 1381b1f7..87fe5e50 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 newPrimary = (int)server; 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) @@ -849,7 +850,10 @@ pgagroal_flush_server(signed char server) { if (!fork()) { - pgagroal_prefill(false); + if (!pgagroal_get_primary(&newPrimary)) + pgagroal_prefill(newPrimary != server); + else + pgagroal_prefill(false); } }