Skip to content

Implement support for pool connection rotation #307

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

Merged
merged 1 commit into from
Jun 5, 2018
Merged

Conversation

elprans
Copy link
Member

@elprans elprans commented Jun 4, 2018

The new Pool.cycle() method expires all currently open connections,
so they would be replaced with fresh ones on the next acquire()
attempt.

The new Pool.set_connect_args() allows changing the connection
arguments for an existing pool instance. Coupled with cycle(), it
allows adapting the pool to the new environment conditions without
having to replace the pool instance.

Fixes: #291

@elprans elprans requested a review from 1st1 June 4, 2018 15:49
@elprans elprans force-pushed the pool-rotation branch 2 times, most recently from 224e977 to ddff26c Compare June 4, 2018 20:10
asyncpg/pool.py Outdated
@@ -409,6 +402,73 @@ def __init__(self, *connect_args,
self._initialized = True
return self

def set_connect_args(self, dsn=None, *,
connection_class=connection.Connection, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't allow to change connection_class via set_connect_args, there's no clear use case for that.

'_working_addr', '_working_config', '_working_params',
'_holders', '_initialized', '_closing', '_closed',
'_connection_class')
'_connection_class', '_generation')

def __init__(self, *connect_args,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a DeprecationWarning if len(connect_args) > 1?

The new `Pool.expire_connections()` method expires all currently
open connections, so they would be replaced with fresh ones on
the next `acquire()` attempt.

The new `Pool.set_connect_args()` allows changing the connection
arguments for an existing pool instance.  Coupled with
`expire_connections()`, it allows adapting the pool to the new
environment conditions without having to replace the pool
instance.

Fixes: #291
@elprans elprans merged commit 4d209b7 into master Jun 5, 2018
@elprans elprans deleted the pool-rotation branch June 5, 2018 14:17
@tomalexander
Copy link

Awesome, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants