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

[SimpleConnectionPool] Add release option to connection pool Lease #4736

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chandramouli-r
Copy link

@chandramouli-r chandramouli-r commented Jun 13, 2023

Conformance:

You should have signed the Eclipse Contributor Agreement as explained in https://github.com/eclipse/vert.x/blob/master/CONTRIBUTING.md
Please also make sure you adhere to the code style guidelines: https://github.com/vert-x3/wiki/wiki/Vert.x-code-style-guidelines

Motivation:
This PR tries to implement #4680.

A new method, release(Handler<AsyncResult<T>> handler) is added to the Lease interface, with the default implementation calling recycle().

In SimpleConnectionPool, LeaseImpl implements the release() method by invoking slot.pool.release().

The release() method in the Pool reduces slot.usage by 1, and if the usage count reaches 0, it invokes pool.remove(slot).

The PR also introduces another member variable within the Slot object, called inactive (boolean). When release() is invoked on a slot, the slot is marked as inactive irrespective of the usage count. inactive is also set to true in Evict, before we remove the slot (when usage count is 0).

A new Slot is initialized with inactive as true. The only time inactive gets set to false is when a connection is successfully established for the slot (ConnectSuccess).

In pool.acquire, we skip slots that are marked as inactive. This behavior means it is better to invoke pool.connect() whenever a slot is removed (pool.remove()), even when there are no Waiters. This change will be made in a follow-up PR. Additionally, remove can maintain the minIdle invariant.

release() can subsequently be used by SqlConnectionPool instead of recycle(), when it determines that a given connection is past its maxLifetime (else it uses recycle()).

This PR tries to implement eclipse-vertx#4680.
A new method, release(Handler<AsyncResult<T>> handler) is added to the Lease
interface, with the default implementation calling recycle().

In SimpleConnectionPool, LeaseImpl implements the release() method by invoking
slot.pool.release().

The release() method in the Pool reduces slot.usage by 1, and if the usage count
reaches 0, it invokes pool.remove(slot).

The PR also introduces another member variable within the Slot object, called
inactive (boolean). When release() is invoked on a slot, the slot is marked as
inactive irrespective of the usage count. inactive is also set to true in Evict,
before we remove the slot (when usage count is 0).

A new Slot is initialized with inactive as true. The only time inactive gets set
to false is when a connection is successfully established for the slot.

In pool.acquire, we skip slots that are marked as inactive. This behavior means
it is better to invoke pool.connect() whenever a slot is removed, even when
there are no Waiters. This change will be made in a follow-up PR.

release() can subsequently be used by SqlConnectionPool instead of recycle(),
when it determines that a given connection is past its maxLifetime (else it uses
recycle()).
@chandramouli-r
Copy link
Author

@vietj

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.

None yet

1 participant