Skip to content

Commit

Permalink
Merge pull request #240 from v-xiangs/TNIR-Fix
Browse files Browse the repository at this point in the history
Tnir fix
  • Loading branch information
xiangyushawn authored Apr 25, 2017
2 parents 77be8d7 + a262878 commit cf732fe
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ private enum State {
}

private final static float TIMEOUTSTEP = 0.08F; // fraction of timeout to use for fast failover connections
private final static float TIMEOUTSTEP_TNIR = 0.125F;
final static int TnirFirstAttemptTimeoutMs = 500; // fraction of timeout to use for fast failover connections

/*
Expand Down Expand Up @@ -281,6 +282,8 @@ final int getQueryTimeoutSeconds() {
final int getSocketTimeoutMilliseconds() {
return socketTimeoutMilliseconds;
}

boolean userSetTNIR = true;

private boolean sendTimeAsDatetime = SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue();

Expand Down Expand Up @@ -1126,6 +1129,7 @@ Connection connectInternal(Properties propsIn,
sPropKey = SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
if (sPropValue == null) {
userSetTNIR = false;
sPropValue = Boolean.toString(SQLServerDriverBooleanProperty.TRANSPARENT_NETWORK_IP_RESOLUTION.getDefaultValue());
activeConnectionProperties.setProperty(sPropKey, sPropValue);
}
Expand Down Expand Up @@ -1286,6 +1290,13 @@ Connection connectInternal(Properties propsIn,
&& (authenticationString.equalsIgnoreCase(SqlAuthentication.ActiveDirectoryIntegrated.toString()))) {
throw new SQLServerException(SQLServerException.getErrString("R_AADIntegratedOnNonWindows"), null);
}

// Turn off TNIR for FedAuth if user does not set TNIR explicitly
if (!userSetTNIR) {
if ((!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) || (null != accessTokenInByte)) {
transparentNetworkIPResolution = false;
}
}

sPropKey = SQLServerDriverStringProperty.WORKSTATION_ID.toString();
sPropValue = activeConnectionProperties.getProperty(sPropKey);
Expand Down Expand Up @@ -1467,9 +1478,11 @@ else if (0 == requestedPacketSize)
false);
}

// transparentNetworkIPResolution is ignored if multiSubnetFailover or DBMirroring is true.
// transparentNetworkIPResolution is ignored if multiSubnetFailover or DBMirroring is true and user does not set TNIR explicitly
if (multiSubnetFailover || (null != failOverPartnerPropertyValue)) {
transparentNetworkIPResolution = false;
if (!userSetTNIR) {
transparentNetworkIPResolution = false;
}
}

// failoverPartner and applicationIntent=ReadOnly cannot be used together
Expand Down Expand Up @@ -1581,9 +1594,12 @@ private void login(String primary,
timerExpire = timerStart + timerTimeout;

// For non-dbmirroring, non-tnir and non-multisubnetfailover scenarios, full time out would be used as time slice.
if (isDBMirroring || useParallel || useTnir) {
if (isDBMirroring || useParallel) {
timeoutUnitInterval = (long) (TIMEOUTSTEP * timerTimeout);
}
else if (useTnir) {
timeoutUnitInterval = (long) (TIMEOUTSTEP_TNIR * timerTimeout);
}
else {
timeoutUnitInterval = timerTimeout;
}
Expand Down Expand Up @@ -1771,12 +1787,22 @@ else if (null == currentPrimaryPlaceHolder) {
// Update timeout interval (but no more than the point where we're supposed to fail: timerExpire)
attemptNumber++;

if (useParallel || useTnir) {
if (useParallel) {
intervalExpire = System.currentTimeMillis() + (timeoutUnitInterval * (attemptNumber + 1));
}
else if (isDBMirroring) {
intervalExpire = System.currentTimeMillis() + (timeoutUnitInterval * ((attemptNumber / 2) + 1));
}
else if (useTnir) {
long timeSlice = timeoutUnitInterval * (1 << attemptNumber);

// In case the timeout for the first slice is less than 500 ms then bump it up to 500 ms
if ((1 == attemptNumber) && (500 > timeSlice)) {
timeSlice = 500;
}

intervalExpire = System.currentTimeMillis() + timeSlice;
}
else
intervalExpire = timerExpire;
// Due to the below condition and the timerHasExpired check in catch block,
Expand Down

0 comments on commit cf732fe

Please sign in to comment.