Skip to content
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

Enable Recover after MSDTC is restarted #581

Merged
merged 3 commits into from
Jan 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
Expand Down Expand Up @@ -165,7 +163,10 @@ public final class SQLServerXAResource implements javax.transaction.xa.XAResourc
public static final int SSTRANSTIGHTLYCPLD = 0x8000;
private SQLServerCallableStatement[] xaStatements = {null, null, null, null, null, null, null, null, null, null};
private final String traceID;

/**
* Variable that shows how many times we attempt the recovery, e.g in case of MSDTC restart
*/
private int recoveryAttempt = 0;
static {
xaInitLock = new Object();
}
Expand Down Expand Up @@ -381,7 +382,7 @@ private String typeDisplay(int type) {
SQLServerCallableStatement cs = null;
try {
synchronized (this) {
if (!xaInitDone) {
if (!xaInitDone) {
try {
synchronized (xaInitLock) {
SQLServerCallableStatement initCS = null;
Expand Down Expand Up @@ -634,6 +635,14 @@ else if (-1 != version.indexOf('.')) {
}
}
}
if (XA_RECOVER == nType && XA_OK != nStatus && recoveryAttempt < 1) {
// if recover failed, attempt to start again - adding the variable to check to attempt only once otherwise throw exception that recovery fails
// this is added since before this change, if we restart the MSDTC and attempt to do recovery, driver will throw exception
//"The function RECOVER: failed. The status is: -3"
recoveryAttempt++;
DTC_XA_Interface(XA_START, xid, TMNOFLAGS);
return DTC_XA_Interface(XA_RECOVER, xid, xaFlags);
}
// prepare and end can return XA_RDONLY
// Think should we just check for nStatus to be greater than or equal to zero instead of this check
if (((XA_RDONLY == nStatus) && (XA_END != nType && XA_PREPARE != nType)) || (XA_OK != nStatus && XA_RDONLY != nStatus)) {
Expand All @@ -658,7 +667,6 @@ else if (-1 != version.indexOf('.')) {
xaLogger.finer(toString() + " Ignoring exception:" + e1);
}
}

throw e;
}
else {
Expand Down