-
Notifications
You must be signed in to change notification settings - Fork 426
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
Server Message Handler and SQLException Chaining #2251
Server Message Handler and SQLException Chaining #2251
Conversation
…down-grade serv messages, and Chained Exceptions so we can see many srv messages in a SQLException
…ServerStatement Simplified some code and formatted it to meet requirements Added test cases
Also fixed smaller code format mishaps
@microsoft-github-policy-service agree |
…'ISQLServerConnection' this might solve my strange problem! Also added get/setServerMessageHandler to getVerifiedMethodNames() in RequestBoundaryMethodsTest.java
Thanks for the contribution. In case review gets a bit delayed, just to let you know PR is on our radar. |
Thanks for the update, it would be nice to have it in release 12.5.0, if possible ;) |
Hi @goranschwarz, With our 12.5.0 release planned for today (Nov 16), that doesn't look likely. The next release to include these changes will likely be a version bump. It's unclear at this time when this would be released. |
Adding on to my previous comment. This PR will NOT be included for the January 31 GA release. We'll look into including it in one of the following stable releases after 12.6.0. |
Just out of curiosity, what's the reason:
|
Hi @goranschwarz, In summary, your second point; there is not enough time. In detail, because of what this PR changes, and its size, this necessitates a approach to testing and review, different than what we would typically use with smaller PRs. With release planned for January 31, this gives us 7 weeks until a code freeze, plenty of time, but the team is currently engaged with other, high profile items. Its unclear when we would be able to start testing and reviewing, and we wouldn't want to rush such a large enhancement. We'll try to get to this as soon as we can, we don't want a community-contributed PR to sit for an extended amount of time, but timing-wise, it doesn't look like this can make our 12.6.0 GA release. |
OK; That sounds fare! Let me know if I can help in any way... |
as mentioned above, this isn't going to make the GA release. I've put this into the backlog for now we will look at this again after the Jan release. |
Note: Very early checkin for Counter Collector Configuration from DbxCentral Web UI Generic * NO-GUI now starts a Management Web Server (localhost:89##), so we can do some management of configuration etc from DbxCentral web ui Note: This is still in development... * Added extra "Graph Properties", so individual graphs can set "sampleType" to other than "AUTO" (for example Disk Space Available can have MIN_OVER_SAMPLES) * Updated libraries * Jetty web server 9.4.53 2023-10-09 * MySQL JDBC driver 8.2.0 * Postgres JDBC driver 42.6.0 * mssql JDBC driver 12.5.0 SNAPSHOT DbxCentral * Added "Exception handler" to intercept some Exceptions and restart the server if they happens (like OutOfMemoryError and H2 'The database has been closed') * PCS JDBC Cleaner -- added some more trace statements to detect what oldest date that will be deleted SqlServerTune * PCS Transfer new QueryStore tables for SQL Server 2022 PostgresTune * CmPgArchive -- new alarm: AlarmEventPgArchiveRate -- When 'archived_mb_last_hour' is greater than 1024 MB then do alarm (property 'CmPgArchive.alarm.system.if.archived_mb_last_hour.gt=##') SQL Window * Changes for SQL Server JDBC Driver that supports message handler (new PR microsoft/mssql-jdbc#2251 hopefully soon merged) This enables us to see messages from long running statement that sends feedback messages (like 'BACKUP DATABASE ...' or 'RAISERROR ('...', 0, 1) WITH NOWAIT')
Looks good in our internal pipelines. But, it looks like exception chaining isn't working for the scenario described in #2115. From debugging, it looks like the TDS stream is returning only one error message and so only one error message is set. |
I wanted to change as little as possible! @tkyc Regarding
To solve #2115 (several error messages in nested procedures), or multiple TDS_ERR in the TDS Stream
What I'm trying to accomplish with the "Server Message Handler", is to be able to downgrade a I did some test of the "nested" procedure errors (with some debug printing in the MS JDBC Driver)This to trace what TDS Stream Tokens that was received (hence where did the Error messages go...) Simple Test code (I can post the full if you want to):
And it's output
Extra info trying to "fix" that we Read more TDS Tokens before Throwing SQLExceptionYes I did some test, which initially looked good but I "scrapped" them pretty quickly
Then it worked... For completeness here are the Stored procedure code
For even more completeness here are a "path" of what I LOCALLY changed to get the DEBUG Prints
hmmm... This become longer than initially intended :) |
src/test/java/com/microsoft/sqlserver/jdbc/msghandler/MsgHandlerTest.java
Outdated
Show resolved
Hide resolved
src/test/java/com/microsoft/sqlserver/jdbc/msghandler/MsgHandlerTest.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
// Any changes to SQLWarnings should be synchronized. | ||
void addWarning(ISQLServerMessage sqlServerMessage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since we now have 2 of these, add comment on how they differ and how they are used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* This simply create a SQLServerError from this SQLServerInfoMessage. | ||
* | ||
* @param newErrorSeverity - If you want to change the ErrorSeverity (-1: leave unchanged) | ||
* @param newErrorNumber - If you want to change the ErrorNumber (-1: leave unchanged) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using -1 seem a bit of a hack, can we just create diff overloaded helpers to handle diff scenarios instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not 100% sure what you say here!
But I have:
toSQLServerError()
to be used if no changes to the 'errorNumber' and 'errorSeverity'toSQLServerError(int newErrorSeverity)
to be used if only 'errorNumber' should be changedtoSQLServerError(int newErrorSeverity, int newErrorNumber)
to be used if you want to change both the 'errorNumber' and 'errorSeverity'
The first two methods just calls: toSQLServerError(int newErrorSeverity, int newErrorNumber)
So we don't have to duplicate the code...
Give me an example of how I should do it...
*/ | ||
package com.microsoft.sqlserver.jdbc; | ||
|
||
public interface ISQLServerMessageHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc class description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure to use the formatter on all files. I'm seeing a lot of spacing diffs when I pulled this branch.
Also, pls resolve conflicts
* </li> | ||
* </ul> | ||
*/ | ||
ISQLServerMessage messageHandler(ISQLServerMessage srvErrorOrWarning); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: since this is a public API, can you please use a full spelling instead
ISQLServerMessage messageHandler(ISQLServerMessage srvErrorOrWarning); | |
ISQLServerMessage messageHandler(ISQLServerMessage serverErrorOrWarning); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* Set current message handler | ||
* | ||
* @param messageHandler | ||
* @return The previously installed message handler (null if none) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does the setter need to return anything? there is already a getter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just convenience...
Meaning: not have to call getter if you want to save the previous installed handler...
Which may be used if you want to restore previous installed handler at a later point!
For example the java Properties.getProperty("someName") does the same thing!
https://docs.oracle.com/javase/8/docs/api/java/util/Properties.html#setProperty-java.lang.String-java.lang.String-
public ISQLServerMessageHandler setServerMessageHandler(ISQLServerMessageHandler messageHandler) | ||
{ | ||
ISQLServerMessageHandler installedMessageHandler = this.serverMessageHandler; | ||
this.serverMessageHandler = messageHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this overwrites any existing, maybe should check and log a message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes a setter usually overwrites previous values...
If you don't want to overwrite it, use the getter and check if you have one...
If you want: I can generate a log message (let me know the LogLevel)
But from my perspective, I would leave it as is
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2251 +/- ##
=============================================
- Coverage 73.56% 50.00% -23.56%
+ Complexity 6079 3806 -2273
=============================================
Files 143 145 +2
Lines 33179 33279 +100
Branches 5631 5643 +12
=============================================
- Hits 24407 16641 -7766
- Misses 6255 14251 +7996
+ Partials 2517 2387 -130 ☔ View full report in Codecov by Sentry. |
@lilgreenbird |
This is a solution to issue #1299
ServerMessageHandler
You can use the message handler for the following
RAISERROR ('Progress message...', 0, 1) WITH NOWAIT
However, you may want to upgrade the severity in other circumstances.
SQLException Chaining
I also found out that Exceptions do not contains any "extra messages" that is produced by the SQL Server.
For example when creating a stored proc with several errors in it, you will only see the first problem...
So this just adds any "extra" Messages to the first
SQLWarning
bysetNextException