node-mysql2
node-mysql2 copied to clipboard
Allow to restore nodes after failed connections
In the mysql library which is used as inspiration for this library and has quite similar API, PoolCluster has the attribute restoreNodeTimeout: a node which failed the number of times removeNodeErrorCount can be recovered to the cluster after the time specified in restoreNodeTimeout.
mysql2 has a more radical behavior by which a node is removed from the cluster forever after the removeNodeErrorCount
In our use case, we have several remote nodes; anytime one of the nodes could become unavailable, and be later recovered. With the current mysql2 behavior it will not be included again in the cluster; eventually, all nodes could become unavailable at some points, meaning the cluster will be empty, even when some nodes are available.
Rather than trying to solve it on the application, by detecting that a node has been removed from the cluster and adding it again, it would be nice if mysql2 could recover those nodes after an specified time, in a similar way as mysql implements.
PoolCluster is almost entirely reused/copied from mysqljs/mysql, if there are newer changes there I'm happy to see them backported. PRs welcome @juliomarmin :)
For context
From mysqljs/mysql Documentation:
PoolCluster options
* `restoreNodeTimeout`: If connection fails, specifies the number of milliseconds
Server disconnects
With PoolCluster, disconnected connections will count as errors against the
related node, incrementing the error code for that node. Once there are more than
`removeNodeErrorCount` errors on a given node, it is removed from the cluster.
When this occurs, the PoolCluster may emit a `POOL_NONEONLINE` error if there are
no longer any matching nodes for the pattern. The `restoreNodeTimeout` config can
be set to restore offline nodes after a given timeout.