Merge pull request #300 from actiontech/issue-289

Issue-289 fix the error handling when xa transaction error in prepare
This commit is contained in:
tiger.yan
2017-10-23 04:06:38 -05:00
committed by GitHub
2 changed files with 15 additions and 5 deletions
@@ -11,6 +11,7 @@ import com.actiontech.dble.net.mysql.RowDataPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
@@ -21,16 +22,19 @@ public class NewConnectionRespHandler implements ResponseHandler {
private ReentrantLock lock = new ReentrantLock();
private Condition initiated = lock.newCondition();
public BackendConnection getBackConn() {
public BackendConnection getBackConn() throws IOException {
lock.lock();
try {
while (backConn == null) {
if (backConn == null) {
initiated.await();
}
if (backConn == null) {
throw new IOException("get backend connection error ");
}
return backConn;
} catch (InterruptedException e) {
LOGGER.warn("getBackConn " + e);
return null;
throw new IOException(e.getMessage());
} finally {
lock.unlock();
}
@@ -39,7 +43,12 @@ public class NewConnectionRespHandler implements ResponseHandler {
@Override
public void connectionError(Throwable e, BackendConnection conn) {
LOGGER.warn(conn + " connectionError " + e);
lock.lock();
try {
initiated.signal();
} finally {
lock.unlock();
}
}
@Override
@@ -341,7 +341,8 @@ public class XARollbackNodesHandler extends AbstractRollbackNodesHandler {
session.getSource().write(send);
//partitionly commited,must commit again
} else if (session.getXaState() == TxState.TX_ROLLBACK_FAILED_STATE || session.getXaState() == TxState.TX_PREPARED_STATE) {
} else if (session.getXaState() == TxState.TX_ROLLBACK_FAILED_STATE || session.getXaState() == TxState.TX_PREPARED_STATE ||
session.getXaState() == TxState.TX_PREPARE_UNCONNECT_STATE) {
MySQLConnection errConn = session.releaseExcept(session.getXaState());
if (errConn != null) {
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), session.getXaState());