reactor-pool icon indicating copy to clipboard operation
reactor-pool copied to clipboard

Allow POOLABLE health check verifications

Open markitovtr1 opened this issue 10 months ago • 2 comments

I'm having some issues with r2dbc-pool and after much reading, I got to these issues:

I think I have a better proposal here that would be great for this project.

Motivation

reactor-pool supports lifecycle management for any POOLABLE object via time or size configurations, either life time, pool size or idle time.

Problem is, for whatever reason, POOLABLE objects might be within healthy time parameters but become invalid. Let's say a connection that is supposed to be alive for 30s, but after 5s a problem in a node between source and target might make this connection invalid for both source and target. Database connections might suffer from these problems as well.

In these scenarios, r2dbc-pool "solves" this by adding a validation query that is executed right before returning a POOLABLE connection to a consumer. In case all connections became invalid, this would mean that a failure would invalidate entire pool and that would only be fixed when a connection is needed. In this scenario, pool consumer application would be hit with a acquire time penalty.

Desired solution

Pool should manage that POOLABLE objects are healthy and ready to be used by pool consumers. Besides eviction, I would like to have the ability to configure an isHealthy reactive predicates, maxHealthTimeCheck and also configure healthCheckInterval, much like background eviction intervals. In case an object is not healthy, it is removed from pool.

Additionally, I would like to configure a healthCheckParallelCount to maximize this validations and also that pool is smart enough to create new POOLABLE objects during these validations in case it would leave not enough connections in pool (e.g.: minIdle = 5 and healthCheckParallelCount = 3, it would need to create new 1 object if all objects are idle).

Considered alternatives

  1. Consume pool regularly to force object validations. Problem with this is I cannot access directly pool objects, so I could be checking the same object over and over again, without checking the rest of what is inside pool.
  2. Implement a custom object that keeps itself healthy and recovers itself This one almost works. Problem is in case it cannot recover itself and needs to be removed from pool because of an specific failure. In that scenario, it can't signal pool to be removed.

Additional context

In case this makes sense, I would love to discuss implementation details and try to submit a PR to address this myself, as I believe it would be a great addition to this project.

markitovtr1 avatar Mar 01 '25 19:03 markitovtr1

@markitovtr1 If you would like to work on this, I'm happy to review a PR. Thank you!

violetagg avatar Mar 17 '25 06:03 violetagg

@violetagg , thanks! I'll start working on this as soon as I can.

markitovtr1 avatar Mar 17 '25 12:03 markitovtr1