use of com.actiontech.dble.backend.mysql.xa.TxState in project dble by actiontech.
the class XACommitNodesHandler method executeCommit.
@Override
protected boolean executeCommit(MySQLConnection mysqlCon, int position) {
TxState state = session.getXaState();
if (state == TxState.TX_STARTED_STATE) {
if (participantLogEntry == null) {
participantLogEntry = new ParticipantLogEntry[nodeCount];
CoordinatorLogEntry coordinatorLogEntry = new CoordinatorLogEntry(session.getSessionXaID(), participantLogEntry, session.getXaState());
XAStateLog.flushMemoryRepository(session.getSessionXaID(), coordinatorLogEntry);
}
XAStateLog.initRecoveryLog(session.getSessionXaID(), position, mysqlCon);
endPhase(mysqlCon);
} else if (state == TxState.TX_ENDED_STATE) {
if (position == 0) {
if (!XAStateLog.saveXARecoveryLog(session.getSessionXaID(), TxState.TX_PREPARING_STATE)) {
String errMsg = "saveXARecoveryLog error, the stage is TX_PREPARING_STATE";
this.setFail(errMsg);
sendData = makeErrorPacket(errMsg);
nextParse();
return false;
}
this.debugCommitDelay();
}
preparePhase(mysqlCon);
} else if (state == TxState.TX_PREPARED_STATE) {
if (position == 0) {
if (!XAStateLog.saveXARecoveryLog(session.getSessionXaID(), TxState.TX_COMMITTING_STATE)) {
String errMsg = "saveXARecoveryLog error, the stage is TX_COMMITTING_STATE";
this.setFail(errMsg);
sendData = makeErrorPacket(errMsg);
nextParse();
return false;
}
this.debugCommitDelay();
}
commitPhase(mysqlCon);
} else if (state == TxState.TX_COMMIT_FAILED_STATE) {
if (position == 0) {
XAStateLog.saveXARecoveryLog(session.getSessionXaID(), TxState.TX_COMMIT_FAILED_STATE);
}
commitPhase(mysqlCon);
} else if (state == TxState.TX_PREPARE_UNCONNECT_STATE) {
final String errorMsg = this.error;
LOGGER.warn(AlarmCode.CORE_XA_WARN + "commit error and rollback the xa");
if (decrementCountBy(1)) {
DbleServer.getInstance().getComplexQueryExecutor().execute(new Runnable() {
@Override
public void run() {
ErrorPacket error = new ErrorPacket();
error.setErrNo(ER_ERROR_DURING_COMMIT);
error.setMessage(errorMsg == null ? "unknown error".getBytes() : errorMsg.getBytes());
XAAutoRollbackNodesHandler nextHandler = new XAAutoRollbackNodesHandler(session, error.toBytes(), null, null);
nextHandler.rollback();
}
});
}
}
return true;
}
use of com.actiontech.dble.backend.mysql.xa.TxState 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.xa.TxState in project dble by actiontech.
the class NIOProcessor method frontendCheck.
private void frontendCheck() {
Iterator<Entry<Long, FrontendConnection>> it = frontends.entrySet().iterator();
while (it.hasNext()) {
FrontendConnection c = it.next().getValue();
// remove empty conn
if (c == null) {
it.remove();
this.frontEndsLength.decrementAndGet();
continue;
}
// clean closed conn or check timeout
if (c.isClosed()) {
c.cleanup();
it.remove();
this.frontEndsLength.decrementAndGet();
} else {
// very important ,for some data maybe not sent
checkConSendQueue(c);
if (c instanceof ServerConnection && c.isIdleTimeout()) {
ServerConnection s = (ServerConnection) c;
TxState state = s.getSession2().getXaState();
if (state != null && state != TxState.TX_INITIALIZE_STATE) {
if (state != TxState.TX_COMMIT_FAILED_STATE && state != TxState.TX_ROLLBACK_FAILED_STATE) {
// Active/IDLE/PREPARED XA FrontendS will be rollbacked
s.close("Idle Timeout");
DbleServer.getInstance().getXaSessionCheck().addRollbackSession(s.getSession2());
}
continue;
}
}
c.idleCheck();
}
}
}
Aggregations