Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Support For beginRequest and endRequest (new version) #2126

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from

Conversation

fmeheust
Copy link

@fmeheust fmeheust commented Oct 24, 2023

Continued work from pull request #2079. Addressed review comments #2079 (comment) and added tests.

@@ -56,6 +56,7 @@ final class PoolEntry implements IConcurrentBagEntry

private final boolean isReadOnly;
private final boolean isAutoCommit;
private boolean isJDBC43OrLater;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The choice of variable is inconsistent with the codebase

@@ -70,6 +71,17 @@ final class PoolEntry implements IConcurrentBagEntry
this.isAutoCommit = isAutoCommit;
this.lastAccessed = currentTime();
this.openStatements = new FastList<>(Statement.class, 16);
boolean isJDBC43OrLater = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason to use isJDBC43OrLater inside the static initializer block? Could this be moved?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine there is a desired to make the member variable final by having only a single line actually set the value. But this code still has a non-final member.

Copy link
Collaborator

@lfbayer lfbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like moving this code to HikariPool getConnection an recycle might be a little better.

I also wonder if we need to make sure there is a way to explicitly disable having the pool call the begin and end methods.

boolean isJDBC43OrLater = false;
try {
DatabaseMetaData dm = connection.getMetaData();
isJDBC43OrLater = ((dm != null) && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the connection instance has the methods "beginRequest" and "endRequest", wouldn't that be sufficient to know we can call them, rather than doing a version check?

Maybe using reflection on the connection instance?

I'm wondering if adding the call to getMetaData has any performance implications.

It also seems like it would better to set this pool-wide, rather than have the value calculated for every new connection in the pool. I can't imagine that you would have a pool that would have different JDBC versions for each connection.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the feedback. I chose to do it for each connection because I thought that one could change the version of the driver that is in the application classpath and the pool would start using a new driver, but if that is not possible I propose the following approach:

I will move the check to PoolBase.checkDriverSupport(Connection) and store the value(s) in a private member. This/these value(s) will be added as a parameter on the constructor of the PoolEntry class, and passed in the PoolBase.newEntry() method.

Concerning using relection instead of database metadata, I could argue that if Hikari starts using new JDBC functionality in the future, the code could end up with several boolean variables (one for each method present in from specific version of the JDBC standard) instead of to int values jdbcMajorVersion and jdbcMinorVersion. I am new to Hikari, so please let me know which choice you prefer and I will comply.

@@ -70,6 +71,17 @@ final class PoolEntry implements IConcurrentBagEntry
this.isAutoCommit = isAutoCommit;
this.lastAccessed = currentTime();
this.openStatements = new FastList<>(Statement.class, 16);
boolean isJDBC43OrLater = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine there is a desired to make the member variable final by having only a single line actually set the value. But this code still has a non-final member.

@fmeheust
Copy link
Author

Given that this is a Java 11+ version of HikariCP and that request boundaries (Connection.beginRequest() and Connection.endRequest()) are present since Java 9, I have removed the check for JDBC version.
I have added a property that allows to explicitly enable request boundaries. Calls to Connection.beginRequest() and Connection.endRequest() have been moved to HikariPool.getConnection and HikariPool.recycle respectively.

@fmeheust
Copy link
Author

fmeheust commented Nov 6, 2023

@lfbayer Can you please review my latest changes to this pull request ?

@jeandelavarene
Copy link

@lfbayer could you please review this request? Thank you!

@krismohan
Copy link

Hi @lfbayer any update on the merge? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants