vertx-mysql-postgresql-client icon indicating copy to clipboard operation
vertx-mysql-postgresql-client copied to clipboard

Implement reconnections

Open ernestojpg opened this issue 6 years ago • 5 comments

Hi all!

It would be nice if the library could recover from temporary database outages, such as those which occur during a database restart or brief loss of network connectivity.

Because the underlying library from mauricio does not support this functionality yet, we could implement it easily in our AsyncConnectionPool.createConnection() method, just using a counter and Vert.x timers.

I would create a couple of new configuration properties. For example:

  • maxConnectionRetries
  • connectionRetryDelay

When our AsyncConnectionPool attempts to acquire an open Connection and fails, it will retry up to maxConnectionRetries times, with a delay of connectionRetryDelay between each attempt. If all attempts fail, any clients waiting for Connections from our AsyncConnectionPool will see an Exception, indicating that a Connection could not be acquired.

For keeping full compatibility with the current code, I would set maxConnectionRetries to 0 by default, that means that no reconnections will be done. If we set maxConnectionRetries to -1 our AsyncConnectionPool will attempt to acquire new Connections indefinitely.

What do you think? If you are happy with that I can create a pull request with the changes.

Regards.

ernestojpg avatar Feb 16 '18 09:02 ernestojpg

it looks like a good feature to provide

vietj avatar Feb 16 '18 09:02 vietj

Cool, I will try to implement it soon.

ernestojpg avatar Feb 16 '18 09:02 ernestojpg

@ernestojpg perhaps you can look at Vert.x HttpClient pool that is now reusable. If we could reuse it, it would be great and keep only a single pool to maintain

vietj avatar Feb 16 '18 14:02 vietj

Hi @vietj , sorry for the delay in answering.

I'm not 100% sure, but yes, we could probably use the new http client pool for this service as well, but it would require a big refactoring of the "vertx-mysql-postgresql-client" service first (for using the new pool), and then implementing the reconnections logic in the new pool without breaking anything else. I don't know if I will have so much time :)

For now, I have implemented the change easily in the current pool, and I will try to implement the new pool in the future. Let me know what you think.

Regards.

ernestojpg avatar Feb 21 '18 14:02 ernestojpg

@ernestojpg ok

vietj avatar Feb 21 '18 14:02 vietj