From 1ed4be71fc261bdd4bc52f8f828f170c23229c1f Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Wed, 4 May 2022 09:12:14 -0400 Subject: [PATCH] Rename variables and move check for prefill. See . Do the check of the new primary in the very beginning. Improves also the logs in debug mode to clearly indicate what is going to happen to the old and new server. Close #224 --- src/libpgagroal/pool.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libpgagroal/pool.c b/src/libpgagroal/pool.c index 87fe5e50..29e0726f 100644 --- a/src/libpgagroal/pool.c +++ b/src/libpgagroal/pool.c @@ -802,14 +802,20 @@ void pgagroal_flush_server(signed char server) { struct configuration* config; - int newPrimary = (int)server; + int primary = -1; + bool prefill = false; pgagroal_start_logging(); pgagroal_memory_init(); config = (struct configuration*)shmem; - pgagroal_log_debug("pgagroal_flush_server %s", config->servers[server].name); + if (!pgagroal_get_primary(&primary)) + prefill = server != (unsigned char)primary && primary != -1; + else + prefill = false; + + pgagroal_log_debug("pgagroal_flush_server %s with%s prefill to %s", config->servers[server].name, prefill ? "" : "out", config->servers[primary].name); for (int i = 0; i < config->max_connections; i++) { if (config->connections[i].server == server) @@ -850,10 +856,7 @@ pgagroal_flush_server(signed char server) { if (!fork()) { - if (!pgagroal_get_primary(&newPrimary)) - pgagroal_prefill(newPrimary != server); - else - pgagroal_prefill(false); + pgagroal_prefill(prefill); } }