Skip to content

Commit

Permalink
Rename variables and move check for prefill.
Browse files Browse the repository at this point in the history
See <agroal#226 (comment)>.
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 agroal#224
  • Loading branch information
fluca1978 committed May 4, 2022
1 parent b891a9a commit 1ed4be7
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/libpgagroal/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 1ed4be7

Please sign in to comment.