Skip to content

Commit

Permalink
[agroal#224] Prefill when doing a switch-to or primary change.
Browse files Browse the repository at this point in the history
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
<agroal#225 (comment)>
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.
  • Loading branch information
fluca1978 committed May 4, 2022
1 parent 08f1ca2 commit b891a9a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/libpgagroal/pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b891a9a

Please sign in to comment.