-
Couldn't load subscription status.
- Fork 442
Configurable Retry Logic I - Statement Retry #2396
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
Conversation
src/main/java/com/microsoft/sqlserver/jdbc/ConfigurableRetryLogic.java
Outdated
Show resolved
Hide resolved
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. |
ConfigurableRetryLogic
Rules can be defined either in the connection string or the
mssql-jdbc.propertiesfile. In both cases, the rules follow this format:retryExec={rule1;rule2;rule3}.During connection initialization, the static instance of
ConfigurableRetryLogicis fetched (getInstance()). Since the instance is null, a reread is triggered (reread()).Within the reread, the
lastTimeReadis 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.propertiesfile. That is, the connection string takes priority over the properties file. After the rules are read, they are parsed intoConfigRetryRuleobjects increateRules().In
createRules(), the list of String rules are used to create a HashMap ofConfigRetryRuleobjectsConfigRetryRule
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
initialRetryTimeand so we setinitialRetryTimefrom 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 oneretryErrorper 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 theConfigRetryRulethat corresponds to the sqlServerError. If there is none, behavior continues as previously defined.retryAttemptand compared to theConfigRetryRule'sretryCount.retryAttempt.retryAttempt, and set thecontflag to true, allowing us to repeat and try executing again.retryErrorandquery).