@@ -1592,7 +1592,10 @@ final SQLCollation getDatabaseCollation() {
1592
1592
.getLogger ("com.microsoft.sqlserver.jdbc.internals.SQLServerConnection" );
1593
1593
static final private java .util .logging .Logger loggerExternal = java .util .logging .Logger
1594
1594
.getLogger ("com.microsoft.sqlserver.jdbc.Connection" );
1595
-
1595
+ static final java .util .logging .Logger loggerResiliency = java .util .logging .Logger
1596
+ .getLogger ("com.microsoft.sqlserver.jdbc.Resiliency" );
1597
+ static final java .util .logging .Logger loggerRedirection = java .util .logging .Logger
1598
+ .getLogger ("com.microsoft.sqlserver.jdbc.Redirection" );
1596
1599
private static String loggingClassNameBase = "com.microsoft.sqlserver.jdbc.SQLServerConnection" ;
1597
1600
1598
1601
/** Instance-specific loggingClassName to identity the connection in logs */
@@ -3093,9 +3096,9 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3093
3096
// and the original timeout is used instead of the timeout slice.
3094
3097
long intervalExpireFullTimeout = loginStartTime + loginTimeoutMs ;
3095
3098
3096
- if (connectionlogger .isLoggable (Level .FINER )) {
3097
- connectionlogger .finer (toString () + " Start time: " + loginStartTime + " Time out time: " + timerExpire
3098
- + " Timeout Unit Interval : " + timeoutUnitInterval );
3099
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3100
+ loggerResiliency .finer (toString () + " Connection open - start time: " + loginStartTime + " time out time: " + timerExpire
3101
+ + " timeout unit interval : " + timeoutUnitInterval );
3099
3102
}
3100
3103
3101
3104
// Initialize loop variables
@@ -3127,6 +3130,9 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3127
3130
currentConnectPlaceHolder = currentFOPlaceHolder ;
3128
3131
} else {
3129
3132
if (routingInfo != null ) {
3133
+ if (loggerRedirection .isLoggable (Level .FINE )) {
3134
+ loggerRedirection .fine (toString () + " Connection open - redirecting to server and instance: " + routingInfo .getFullServerName ());
3135
+ }
3130
3136
currentPrimaryPlaceHolder = routingInfo ;
3131
3137
routingInfo = null ;
3132
3138
} else if (null == currentPrimaryPlaceHolder ) {
@@ -3136,13 +3142,17 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3136
3142
currentConnectPlaceHolder = currentPrimaryPlaceHolder ;
3137
3143
}
3138
3144
3139
- if (connectionlogger .isLoggable (Level .FINE )) {
3140
- connectionlogger
3141
- .fine (toString () + " This attempt server name: " + currentConnectPlaceHolder .getServerName ()
3145
+ if (loggerResiliency .isLoggable (Level .FINE ) && retryAttempt > 0 ) {
3146
+ loggerResiliency .fine (toString () + " Connection open - starting connection retry attempt number: " + retryAttempt );
3147
+ }
3148
+
3149
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3150
+ loggerResiliency
3151
+ .finer (toString () + " Connection open - attempt server name: " + currentConnectPlaceHolder .getServerName ()
3142
3152
+ " port: " + currentConnectPlaceHolder .getPortNumber () + " InstanceName: "
3143
3153
+ currentConnectPlaceHolder .getInstanceName () + " useParallel: " + useParallel );
3144
- connectionlogger . fine (toString () + " This attempt endtime : " + intervalExpire );
3145
- connectionlogger . fine (toString () + " This attempt No : " + retryAttempt );
3154
+ loggerResiliency . finer (toString () + " Connection open - attempt end time : " + intervalExpire );
3155
+ loggerResiliency . finer (toString () + " Connection open - attempt number : " + retryAttempt );
3146
3156
}
3147
3157
3148
3158
// Attempt login. Use Place holder to make sure that the failoverdemand is done.
@@ -3165,6 +3175,10 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3165
3175
3166
3176
noOfRedirections ++;
3167
3177
3178
+ if (loggerRedirection .isLoggable (Level .FINE )) {
3179
+ loggerRedirection .fine (toString () + " Connection open - redirection count: " + noOfRedirections );
3180
+ }
3181
+
3168
3182
if (noOfRedirections > 1 ) {
3169
3183
String msg = SQLServerException .getErrString ("R_multipleRedirections" );
3170
3184
terminate (SQLServerException .DRIVER_ERROR_UNSUPPORTED_CONFIG , msg );
@@ -3209,9 +3223,23 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3209
3223
3210
3224
continue ;
3211
3225
}
3212
- } else
3226
+ } else {
3227
+ if (loggerResiliency .isLoggable (Level .FINE ) && retryAttempt > 0 ) {
3228
+ loggerResiliency .fine (toString () + " Connection open - connection retry succeeded on attempt number: " + retryAttempt );
3229
+ }
3230
+
3213
3231
break ; // leave the while loop -- we've successfully connected
3232
+ }
3214
3233
} catch (SQLServerException e ) {
3234
+
3235
+ if (loggerResiliency .isLoggable (Level .FINE ) && retryAttempt > 0 ) {
3236
+ loggerResiliency .fine (toString () + " Connection open - connection retry failed on attempt number: " + retryAttempt );
3237
+ }
3238
+
3239
+ if (loggerResiliency .isLoggable (Level .FINER ) && (retryAttempt >= connectRetryCount )) {
3240
+ loggerResiliency .finer (toString () + " Connection open - connection failed. Maximum connection retry count " + connectRetryCount + " reached." );
3241
+ }
3242
+
3215
3243
int errorCode = e .getErrorCode ();
3216
3244
driverErrorCode = e .getDriverErrorCode ();
3217
3245
sqlServerError = e .getSQLServerError ();
@@ -3229,15 +3257,26 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3229
3257
|| timerHasExpired (timerExpire )
3230
3258
// for non-dbmirroring cases, do not retry after tcp socket connection succeeds
3231
3259
) {
3232
- if (connectionlogger .isLoggable (Level .FINE ) && (retryAttempt >= connectRetryCount )) {
3233
- connectionlogger .fine (
3234
- "Connection failed. Maximum connection retry count " + connectRetryCount + " reached." );
3260
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3261
+ loggerResiliency .finer (toString () + " Connection open - connection failed on attempt: " + retryAttempt + "." );
3262
+ loggerResiliency .finer (toString () + " Connection open - connection failure. Driver error code: " + driverErrorCode );
3263
+ if (null != sqlServerError && !sqlServerError .getErrorMessage ().isEmpty ()) {
3264
+ loggerResiliency .finer (toString () + " Connection open - connection failure. SQL Server error : " + sqlServerError .getErrorMessage ());
3265
+ }
3235
3266
}
3236
3267
3237
3268
// close the connection and throw the error back
3238
3269
close ();
3239
3270
throw e ;
3240
3271
} else {
3272
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3273
+ loggerResiliency .finer (toString () + " Connection open - connection failed on attempt: " + retryAttempt + "." );
3274
+ loggerResiliency .finer (toString () + " Connection open - connection failure. Driver error code: " + driverErrorCode );
3275
+ if (null != sqlServerError && !sqlServerError .getErrorMessage ().isEmpty ()) {
3276
+ loggerResiliency .finer (toString () + " Connection open - connection failure. SQL Server error : " + sqlServerError .getErrorMessage ());
3277
+ }
3278
+ }
3279
+
3241
3280
// Close the TDS channel from the failed connection attempt so that we don't
3242
3281
// hold onto network resources any longer than necessary.
3243
3282
if (null != tdsChannel )
@@ -3252,6 +3291,14 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3252
3291
if ((!isDBMirroring || 1 == retryAttempt % 2
3253
3292
|| TimeUnit .SECONDS .toMillis (connectRetryInterval ) >= remainingTime )
3254
3293
&& (remainingTime <= TimeUnit .SECONDS .toMillis (connectRetryInterval ))) {
3294
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3295
+ loggerResiliency .finer (toString () + " Connection open - connection failed on attempt: " + retryAttempt + "." );
3296
+ loggerResiliency .finer (toString () + " Connection open - connection failure. Driver error code: " + driverErrorCode );
3297
+ if (null != sqlServerError && !sqlServerError .getErrorMessage ().isEmpty ()) {
3298
+ loggerResiliency .finer (toString () + " Connection open - connection failure. SQL Server error : " + sqlServerError .getErrorMessage ());
3299
+ }
3300
+ }
3301
+
3255
3302
throw e ;
3256
3303
}
3257
3304
}
@@ -3265,19 +3312,19 @@ private void login(String primary, String primaryInstanceName, int primaryPortNu
3265
3312
&& tlsRetryAttempt < INTERMITTENT_TLS_MAX_RETRY && !timerHasExpired (timerExpire )) {
3266
3313
// special case for TLS intermittent failures: no wait retries
3267
3314
tlsRetryAttempt ++;
3268
- if (connectionlogger .isLoggable (Level .FINE )) {
3269
- connectionlogger . fine (
3270
- "Connection failed during SSL handshake. Retry due to an intermittent TLS 1.2 failure issue. Retry attempt = "
3315
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3316
+ loggerResiliency . finer ( toString () +
3317
+ " Connection open - connection failed during SSL handshake. Retry due to an intermittent TLS 1.2 failure issue. Retry attempt = "
3271
3318
+ tlsRetryAttempt + " of " + INTERMITTENT_TLS_MAX_RETRY );
3272
3319
}
3273
3320
} else {
3274
3321
if (retryAttempt ++ >= connectRetryCount && TransientError .isTransientError (sqlServerError )
3275
3322
&& !timerHasExpired (timerExpire ) && (!isDBMirroring || (1 == retryAttempt % 2 ))) {
3276
- if (connectionlogger .isLoggable (Level .FINE )) {
3277
- connectionlogger . fine (toString () + " sleeping milisec: " + connectRetryInterval );
3323
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3324
+ loggerResiliency . finer (toString () + " Connection open - sleeping milisec: " + connectRetryInterval );
3278
3325
}
3279
- if (connectionlogger .isLoggable (Level .FINEST )) {
3280
- connectionlogger . finest (toString () + "Connection failed on transient error "
3326
+ if (loggerResiliency .isLoggable (Level .FINER )) {
3327
+ loggerResiliency . finer (toString () + " Connection open - connection failed on transient error "
3281
3328
+ (sqlServerError != null ? sqlServerError .getErrorNumber () : "" )
3282
3329
+ ". Wait for connectRetryInterval(" + connectRetryInterval + ")s before retry #"
3283
3330
+ retryAttempt );
@@ -4102,7 +4149,12 @@ boolean executeCommand(TDSCommand newCommand) throws SQLServerException {
4102
4149
preparedStatementHandleCache .clear ();
4103
4150
}
4104
4151
4152
+ if (loggerResiliency .isLoggable (Level .FINE )) {
4153
+ loggerResiliency .fine (toString () + " Idle connection resiliency - starting idle connection resiliency reconnect." );
4154
+ }
4155
+
4105
4156
sessionRecovery .reconnect (newCommand );
4157
+
4106
4158
} catch (InterruptedException e ) {
4107
4159
// re-interrupt thread
4108
4160
Thread .currentThread ().interrupt ();
@@ -4111,10 +4163,11 @@ boolean executeCommand(TDSCommand newCommand) throws SQLServerException {
4111
4163
SQLServerException .makeFromDriverError (this , sessionRecovery , e .getMessage (), null ,
4112
4164
false );
4113
4165
}
4166
+
4114
4167
if (sessionRecovery .getReconnectException () != null ) {
4115
- if (connectionlogger .isLoggable (Level .FINER )) {
4116
- connectionlogger .finer (
4117
- this .toString () + "Connection is broken and recovery is not possible." );
4168
+ if (loggerResiliency .isLoggable (Level .FINER )) {
4169
+ loggerResiliency .finer (
4170
+ this .toString () + " Idle connection resiliency - connection is broken and recovery is not possible." );
4118
4171
}
4119
4172
throw sessionRecovery .getReconnectException ();
4120
4173
}
0 commit comments