Handle edge cases and support autocommit=false #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Handles #14
Only tries to disable autocommit if needed.
Also handles edge cases, we internally hit a bug in where in the
catch
block we were callingconn.setAutoCommit(true);
and there it failed, so the finally block conditionif (null != didWeStartWork.get() && conn.getAutoCommit()) {
wasn't true, and that made the connection not get released back to the connection pool, since the connection is released only during the ending of the unit of work.So I've simplified the logic to have everything in a try catch finally block and now we are always releasing the connection to the pool.
Improved the
readTransactionMetadata
cache, as there it is a concurrent hash map, soget
doesn't block, so if it is a cache miss, concurrent calculations will use the compute if absent, which synchronizes the calls, so we don't perform multiple calculations for the same thing at once.Reduced the number of thread locals, and fixed it as ideally it should be a static field.
Also fixed a possible leak as if closing a the connection were to throw an error the thread local wouldn't never be removed.