Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefill after switch-to #224

Closed
fluca1978 opened this issue Apr 28, 2022 · 10 comments
Closed

prefill after switch-to #224

fluca1978 opened this issue Apr 28, 2022 · 10 comments
Assignees
Labels
enhancement Improvement to an existing feature

Comments

@fluca1978
Copy link
Collaborator

Don't know if this is a valuable feature, but with 1.5 when I do a switch-to and/or a reset-server the prefill seems to be dropped.
I mean, when I start pgagroal the "initial" connections from pgagroal_databases.conf are established. When I do a switch-to to another server, the new server does not get the "initial" connection number but only the "minimum".
The same when I come back with another switch-to the original server.
Is there a reason or should pgagroal honor the "initial" connection every time a server is changed as primary?

@fluca1978 fluca1978 added the feature New feature label Apr 28, 2022
@jesperpedersen jesperpedersen self-assigned this Apr 28, 2022
@jesperpedersen jesperpedersen added enhancement Improvement to an existing feature and removed feature New feature labels Apr 28, 2022
@jesperpedersen
Copy link
Collaborator

I agree. switch-to should trigger prefill, since the connections on the previous primary should go into graceful

@fluca1978
Copy link
Collaborator Author

The problem, at least in my configuration, is when the old server is flushed: https://github.com/agroal/pgagroal/blob/master/src/libpgagroal/pool.c#L852.
There are however other places where the prefill is invoked with a false argument, that measn "use min values", while we would like to get with "initial" values.
I think there is the need to understand if pgagroal_flush_server has been invoked by a flush command, in which case it is correct to set connections to the minimum, or by a switch-to, in such case it should be prefil with "initial".
Adding a parameter to the pgagroal_flush_server?

@jesperpedersen
Copy link
Collaborator

That is likely one way to do it

@fluca1978
Copy link
Collaborator Author

I could spend some time and effort on this, if you believe there are no other tricks and dangerous zones...

@jesperpedersen
Copy link
Collaborator

Go for it !

@jesperpedersen
Copy link
Collaborator

There is a bit more to it.

The old primary should never prefill no matter what the min_size is - in the case of switch-to.

@fluca1978
Copy link
Collaborator Author

The old primary should never prefill no matter what the min_size is - in the case of switch-to.

I'm going to work on this starting from the next week, but in the meantime I'm reasoning about this.
When I switch-to a new server, the old primary will be graceful and the new one is going to get prefilled, and this is the problem I'm going to try to fix. If I then switch-to back to the old primary, why should I don't prefill it?

@jesperpedersen
Copy link
Collaborator

In relation to the switch-to.

pgagroal_databases.conf

mydb myuser 100 20 10

Initial

host1(20)(Primary)
host2(0)(Not init)

switch-to(host2)

host1(0)(Not init)
host2(20)(Primary)

switch-to(host1)

host1(20)(Primary)
host2(0)(Not init)

So, I think we agree, right ?

@fluca1978
Copy link
Collaborator Author

Yes, it was what I was thinking about.

@jesperpedersen
Copy link
Collaborator

👍

fluca1978 added a commit to fluca1978/pgagroal that referenced this issue May 4, 2022
When a `switch-to` operation is issued, the old server is flushed
(i.e., connections are closed) and new connections to the new primary
server are established.
When such connections are established, the system does a full prefill
against the new primary, so that when the `switch-to` completes, the
new primary is prefilled as the old one was.

Adds also a better detail about the server that is going to be
flushed.

Close agroal#224
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue May 4, 2022
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.
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue May 4, 2022
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
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue May 5, 2022
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.

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 agroal#224
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue May 5, 2022
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.

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 agroal#224
jesperpedersen pushed a commit that referenced this issue May 6, 2022
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
<#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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants