Closed
Description
Environment
HikariCP version: x.x.x
JDK version : 1.8.0_111
Database : oracle
Driver version : 2.3.13
New request:
Current "suspend" function will block application when application calls getConnection method, which can cause whole application crashes。
Can HikariCP offer new "suspend" function that can immediately throw "suspend“ exception.
In some cases when database is in mantainance,we need suspend datasource temporarily which make application can still run database-fail-tolerant bussiness.
Currently Only Weblogic's datasource "suppend" function meets this need.
Have you searched the CLOSED issues already? How about checking stackoverflow?
Activity
brettwooldridge commentedon Jan 9, 2018
@jiyong8086 Thank you for the feedback. I have never encountered the requirement where an exception would be preferable compared to holding connections.
All of the suspend use cases I have heard have centered around a pattern of:
Help me understand the scenario where an exception is preferred.
jiyong8086 commentedon Jan 15, 2018
Our application provides a real-time information processing service to upstream systems.
The SLA is that the 99% requests should be responsed in 100 ms no matter the processing result is success or failure.
We use Oracle as database running in active-standby mode.
Every week our DBA shutdowns active database instance and starts standby one to make sure the standby one is in available status.
The operation makes Oracle unavailable to our application in serveral minutes.
In this period, our application blocks 1s every time when it calls getConnection() method because we set "connectionTimeout " to 1s, which make our upsteam systems wait a long time before getting a fail response.
We assume every time when DBA does maintainance operation, we can notify HikariCP that the backend database is unavailable,then HikariCP can throw "database unavailable" Exception immediately when application calls getConnection() method. Thus upstream systems can get fail response as quickly as possible.
brettwooldridge commentedon Jan 15, 2018
@jiyong8086 I have implemented this function as an experimental feature controlled by a system property. It will be available in the next release, likely in several weeks.
If you want to test this functionality now, you can checkout the
dev
branch and build the library with maven:The jar file will be located in the
target
directory when the build completes.In order to enable the feature, define the system property
com.zaxxer.hikari.throwIfSuspended
like so:or
jiyong8086 commentedon Jan 16, 2018
@brettwooldridge
Thank you for implementing this exciting feature. :)
We test it in our develop environment and it works by setting "com.zaxxer.hikari.throwIfSuspended" to true.
It is the feature that we have expected for long time.
But something confuses us:
If we set "com.zaxxer.hikari.throwIfSuspended" to true without calling "suspend" method, we still get "suspend" Exception immediately. It looks like we don't need to call suspend method,we can suspend and resume connection pool by setting property "com.zaxxer.hikari.throwIfSuspended" to true or false.
So we wonder if we misused or misunderstood this property "com.zaxxer.hikari.throwIfSuspended".
Below is our code:
public static void main(String[] args) throws Exception{
System.setProperty("com.zaxxer.hikari.throwIfSuspended", "true");
getConnection(); // throw suspend exception
System.setProperty("com.zaxxer.hikari.throwIfSuspended", "false");
getConnection(); // OK
}
johnou commentedon Jan 16, 2018
@brettwooldridge maybe something like this?
Fixes #1060 Support experimental throw-if-suspended functionality.
brettwooldridge commentedon Jan 17, 2018
@jiyong8086 Fixed.
@johnou Thanks.
johnou commentedon Jan 17, 2018
@brettwooldridge I added a comment to the commit, I don't think it's quite right.
Fixes #1060 (Really) support experimental throw-if-suspended function…
Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…
Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…
Fixes brettwooldridge#1060 (Really) support experimental throw-if-sus…
Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…
Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…
Fixes brettwooldridge#1060 (Really) support experimental throw-if-sus…
Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…