-
Notifications
You must be signed in to change notification settings - Fork 427
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
Configurable Retry Logic I - Statement Retry #2396
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java
Outdated
Show resolved
Hide resolved
lilgreenbird
previously approved these changes
Sep 20, 2024
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2396 +/- ##
============================================
+ Coverage 50.66% 50.95% +0.28%
- Complexity 3826 3890 +64
============================================
Files 145 147 +2
Lines 33133 33368 +235
Branches 5558 5592 +34
============================================
+ Hits 16788 17002 +214
- Misses 13944 13960 +16
- Partials 2401 2406 +5 ☔ View full report in Codecov by Sentry. |
src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java
Outdated
Show resolved
Hide resolved
src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java
Outdated
Show resolved
Hide resolved
barryw-mssql
previously approved these changes
Sep 20, 2024
barryw-mssql
approved these changes
Sep 23, 2024
tkyc
approved these changes
Sep 23, 2024
lilgreenbird
approved these changes
Sep 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ConfigurableRetryLogic
Rules can be defined either in the connection string or the
mssql-jdbc.properties
file. In both cases, the rules follow this format:retryExec={rule1;rule2;rule3}
.During connection initialization, the static instance of
ConfigurableRetryLogic
is fetched (getInstance()
). Since the instance is null, a reread is triggered (reread()
).Within the reread, the
lastTimeRead
is set up, this is to ensure that in the future, the CRL instance is not updated all the time, only when the interval has been reached (default 30 seconds).Next the rules are setup (
setUpRules()
). If there are rules to read from the connection string, they are used to populate the internal ruleset, if not, then rules are read from themssql-jdbc.properties
file. That is, the connection string takes priority over the properties file. After the rules are read, they are parsed intoConfigRetryRule
objects increateRules()
.In
createRules()
, the list of String rules are used to create a HashMap ofConfigRetryRule
objectsConfigRetryRule
The rules are parsed in
parse()
removing extra elements that could remain after reading from connection string or file. As well the rules is split based on a:
.Valid rules can have the following formats:
The elements from each rule are fetched using
addElement
. If a rule is <2 or >3 parts, an error is returned. Otherwise, the first part is set as theretryError
, and the second part (the timings) are parsed further. The first part of the timings is always theretryCount
. We check if its an integer and greater than 0, if so it is set asretryCount
. If there are two parts to the timing, then the second part can be theinitalRetryTime
(initial time to wait between retries), theinitialRetryTime
+operand
(the change we make to the retry time each retry, * or +), or theinitialRetryTime
+operand
+retryChange
(the numeric change that is applied to each wait time).The second part of timings is parsed, if it contains a *, this is the multiplicative change. We store this in
operand
. The value proceeding the operand is theinitialRetryTime
, and and value following the operand is theretryChange
. If it doesn't exist, its set to the default.The same applies to +. If there is neither operand, then we know we only have the
initialRetryTime
and so we setinitialRetryTime
from the value left in the timings.If the rule is 3 parts, then the optional query part has been included (apply this rule to only specific queries). This part of the rules is then set under
retryQueries
.Wait time is calculated from the elements we parsed (
calcWaitTimes
) and stored in an ArrayListwaitTimes
.With this the rule has been turned into a
ConfigRetryRule
. Another check has to be done to ensure that there is only oneretryError
per rule. If multiple errors were passed in (separated by a comma), then we need to create new rules from the rule, each containing only oneretryError
. Finally all of the rules are put into the stmtRules HashMap.SQLServerStatement
cont
) to false, and attempt to determine whether we can retry. We attempt to fetch theConfigRetryRule
that corresponds to the sqlServerError. If there is none, behavior continues as previously defined.retryAttempt
and compared to theConfigRetryRule
'sretryCount
.retryAttempt
.retryAttempt
, and set thecont
flag to true, allowing us to repeat and try executing again.retryError
andquery
).