Skip to content

Can HikariCP offer new "suspend" function that can immediately throw "suspend“ exception. #1060

Closed
@jiyong8086

Description

@jiyong8086

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

brettwooldridge commented on Jan 9, 2018

@brettwooldridge
Owner

@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:

  • Suspend the pool.
  • Alter the pool configuration, or alter DNS configuration (to point to a new master).
  • Soft-evict existing connections.
  • Resume the pool.

Help me understand the scenario where an exception is preferred.

jiyong8086

jiyong8086 commented on Jan 15, 2018

@jiyong8086
Author

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

brettwooldridge commented on Jan 15, 2018

@brettwooldridge
Owner

@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:

mvn clean package

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:

-Dcom.zaxxer.hikari.throwIfSuspended=true

or

System.setProperty("com.zaxxer.hikari.throwIfSuspended", "true");
jiyong8086

jiyong8086 commented on Jan 16, 2018

@jiyong8086
Author

@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

johnou commented on Jan 16, 2018

@johnou
Contributor

@brettwooldridge maybe something like this?

if (Boolean.getBoolean("com.zaxxer.hikari.throwIfSuspended")) {
   if (acquisitionSemaphore.tryAcquire()) {
      return;
   }
   throw new SQLTransientException("The pool is currently suspended and configured to throw exceptions upon acquisition");
}
added a commit that references this issue on Jan 17, 2018

Fixes #1060 Support experimental throw-if-suspended functionality.

bef929c
brettwooldridge

brettwooldridge commented on Jan 17, 2018

@brettwooldridge
Owner

@jiyong8086 Fixed.

@johnou Thanks.

johnou

johnou commented on Jan 17, 2018

@johnou
Contributor

@brettwooldridge I added a comment to the commit, I don't think it's quite right.

added a commit that references this issue on Jan 17, 2018

Fixes #1060 (Really) support experimental throw-if-suspended function…

64d91e8
added 6 commits that reference this issue on Feb 4, 2021

Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…

1e144b5

Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…

7d06e40

Fixes brettwooldridge#1060 (Really) support experimental throw-if-sus…

29097e2

Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…

72631e1

Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…

ee06e2a

Fixes brettwooldridge#1060 (Really) support experimental throw-if-sus…

5c64843
added a commit that references this issue on May 13, 2024

Fixes brettwooldridge#1060 Support experimental throw-if-suspended fu…

1f73e9a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @johnou@brettwooldridge@jiyong8086

        Issue actions

          Can HikariCP offer new "suspend" function that can immediately throw "suspend“ exception. · Issue #1060 · brettwooldridge/HikariCP