[SimpleConnectionPool] Add release option to connection pool Lease #4736
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theLease
interface, with the default implementation callingrecycle()
.In
SimpleConnectionPool
,LeaseImpl
implements therelease()
method by invokingslot.pool.release()
.The
release()
method in the Pool reducesslot.usage
by 1, and if the usage count reaches 0, it invokespool.remove(slot)
.The PR also introduces another member variable within the Slot object, called
inactive (boolean)
. Whenrelease()
is invoked on a slot, the slot is marked as inactive irrespective of the usage count.inactive
is also set to true inEvict
, before we remove the slot (when usage count is 0).A new
Slot
is initialized withinactive
astrue
. The only timeinactive
gets set tofalse
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 invokepool.connect()
whenever a slot isremoved
(pool.remove()), even when there are no Waiters. This change will be made in a follow-up PR. Additionally,remove
can maintain theminIdle
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()).