Avoid side-effects of calling Statement.getUpdateCount#1139
Avoid side-effects of calling Statement.getUpdateCount#1139felixbarny merged 7 commits intoelastic:masterfrom
Conversation
|
Allocation rate is definitely higher with this change:
|
|
Detecting non-idempotent implementations at runtime allows to avoid this workaround for most implementations, which allows to keep our very low allocation rate 🎉 |
felixbarny
left a comment
There was a problem hiding this comment.
I wonder if we should disable update count monitoring for non-idempotent drivers but I don't have a strong preference.
| } | ||
|
|
||
| @Advice.OnMethodEnter(suppress = Throwable.class) | ||
| private static int onEnter(@Advice.This Statement statement) { |
There was a problem hiding this comment.
Enter advice not needed when moving this to exit advice?
There was a problem hiding this comment.
Good point, there would be no difference to move this to the exit advice.
However, we could bypass the original method call when we have a stored value, just in case there are other side-effects of calling getUpdateCount further in the driver or DB implementation.
There was a problem hiding this comment.
I've finally took the "move everything to the exit advice" path, we can still improve this implementation later only if needed, as skipping default method implementation brings some extra complexity, especially on testing side.
What does this PR do?
Current instrumentation of
java.sql.StatementcallsStatement.getUpdateCount()just after SQL statement execution in order to retrieve the number of modified rows by the statement.While there is a warning in Javadoc about calling this method only once, in practice most implementations allow to call it multiple times without any problem. We had integration tests that covered most common databases thus we were confident on that hypothesis.
However, it seems that some database servers (or JDBC drivers) like Oracle strictly follow the specification and just allow for a single call to
getUpdateCount. As a result, our agent would capture the first value, and then an invalid value would then be returned.Impacted applications would be those for which both statements are true
Statement.getUpdateCount()Checklist
I have made corresponding changes to the documentationI have updated supported-technologies.asciidocAdded an API method or config option? Document in which version this will be introducedAdded an instrumentation plugin? How did you make sure that old, non-supported versions are not instrumented by accident?Author's Checklist