use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class AbstractCommitNodesHandler method commit.
@Override
public void commit() {
final int initCount = session.getTargetCount();
lock.lock();
try {
reset(initCount);
} finally {
lock.unlock();
}
int position = 0;
// then the XA transaction will be not killed, if killed ,then we will not commit
if (session.getXaState() != null && session.getXaState() == TxState.TX_ENDED_STATE) {
if (!session.cancelableStatusSet(NonBlockingSession.CANCEL_STATUS_COMMITTING)) {
return;
}
}
try {
sendFinishedFlag = false;
for (RouteResultsetNode rrn : session.getTargetKeys()) {
final BackendConnection conn = session.getTarget(rrn);
conn.setResponseHandler(this);
if (!executeCommit((MySQLConnection) conn, position++)) {
break;
}
}
} finally {
lockForErrorHandle.lock();
try {
sendFinishedFlag = true;
sendFinished.signalAll();
} finally {
lockForErrorHandle.unlock();
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XACommitNodesHandler method errorResponse.
@Override
public void errorResponse(byte[] err, BackendConnection conn) {
this.waitUntilSendFinish();
ErrorPacket errPacket = new ErrorPacket();
errPacket.read(err);
String errMsg = new String(errPacket.getMessage());
this.setFail(errMsg);
sendData = makeErrorPacket(errMsg);
if (conn instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) conn;
if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
mysqlCon.quit();
mysqlCon.setXaStatus(TxState.TX_CONN_QUIT);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_ENDED_STATE);
nextParse();
}
// 'xa prepare' error
} else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
mysqlCon.quit();
mysqlCon.setXaStatus(TxState.TX_CONN_QUIT);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
if (session.getXaState() == TxState.TX_ENDED_STATE) {
session.setXaState(TxState.TX_PREPARED_STATE);
}
nextParse();
}
// 'xa commit' err
} else if (mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
// TODO:service degradation?
mysqlCon.setXaStatus(TxState.TX_COMMIT_FAILED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
session.setXaState(TxState.TX_COMMIT_FAILED_STATE);
if (decrementCountBy(1)) {
cleanAndFeedback();
}
} else if (mysqlCon.getXaStatus() == TxState.TX_COMMIT_FAILED_STATE) {
if (errPacket.getErrNo() == ErrorCode.ER_XAER_NOTA) {
// Unknown XID ,if xa transaction only contains select statement, xid will lost after restart server although prepared
mysqlCon.setXaStatus(TxState.TX_COMMITTED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
if (decrementCountBy(1)) {
if (session.getXaState() == TxState.TX_PREPARED_STATE) {
session.setXaState(TxState.TX_INITIALIZE_STATE);
}
cleanAndFeedback();
}
} else {
mysqlCon.setXaStatus(TxState.TX_COMMIT_FAILED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
session.setXaState(TxState.TX_COMMIT_FAILED_STATE);
if (decrementCountBy(1)) {
cleanAndFeedback();
}
}
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XACommitNodesHandler method okResponse.
@Override
public void okResponse(byte[] ok, BackendConnection conn) {
this.waitUntilSendFinish();
MySQLConnection mysqlCon = (MySQLConnection) conn;
TxState state = mysqlCon.getXaStatus();
if (state == TxState.TX_STARTED_STATE) {
mysqlCon.setXaStatus(TxState.TX_ENDED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_ENDED_STATE);
nextParse();
}
} else if (state == TxState.TX_ENDED_STATE) {
// PREPARE OK
mysqlCon.setXaStatus(TxState.TX_PREPARED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
if (session.getXaState() == TxState.TX_ENDED_STATE) {
session.setXaState(TxState.TX_PREPARED_STATE);
}
nextParse();
}
} else if (state == TxState.TX_COMMIT_FAILED_STATE || state == TxState.TX_PREPARED_STATE) {
// COMMIT OK
// XA reset status now
mysqlCon.setXaStatus(TxState.TX_COMMITTED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
mysqlCon.setXaStatus(TxState.TX_INITIALIZE_STATE);
if (decrementCountBy(1)) {
if (session.getXaState() == TxState.TX_PREPARED_STATE) {
session.setXaState(TxState.TX_INITIALIZE_STATE);
}
cleanAndFeedback();
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XACommitNodesHandler method innerConnectError.
private void innerConnectError(BackendConnection conn) {
if (conn instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) conn;
if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
mysqlCon.quit();
mysqlCon.setXaStatus(TxState.TX_CONN_QUIT);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
if (decrementCountBy(1)) {
session.setXaState(TxState.TX_ENDED_STATE);
nextParse();
}
// 'xa prepare' connectionClose,conn has quit
} else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
mysqlCon.setXaStatus(TxState.TX_PREPARE_UNCONNECT_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
session.setXaState(TxState.TX_PREPARE_UNCONNECT_STATE);
if (decrementCountBy(1)) {
nextParse();
}
// 'xa commit' connectionClose
} else if (mysqlCon.getXaStatus() == TxState.TX_COMMIT_FAILED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
// TODO:service degradation?
mysqlCon.setXaStatus(TxState.TX_COMMIT_FAILED_STATE);
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
session.setXaState(TxState.TX_COMMIT_FAILED_STATE);
if (decrementCountBy(1)) {
cleanAndFeedback();
}
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class XACommitNodesHandler method commitPhase.
private void commitPhase(MySQLConnection mysqlCon) {
if (session.getXaState() == TxState.TX_COMMIT_FAILED_STATE) {
MySQLConnection newConn = session.freshConn(mysqlCon, this);
if (!newConn.equals(mysqlCon)) {
mysqlCon = newConn;
} else if (decrementCountBy(1)) {
cleanAndFeedback();
return;
}
}
String xaTxId = mysqlCon.getConnXID(session);
mysqlCon.execCmd("XA COMMIT " + xaTxId);
}
Aggregations