use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.
the class SubQueryHandler method errorResponse.
@Override
public void errorResponse(byte[] err, BackendConnection conn) {
lock.lock();
try {
ErrorPacket errPacket = new ErrorPacket();
errPacket.read(err);
String errorMsg = new String(errPacket.getMessage(), StandardCharsets.UTF_8);
LOGGER.info(errorMsg);
genErrorPackage(errPacket.getErrNo(), errorMsg);
HandlerTool.terminateHandlerTree(this);
tempDoneCallBack.call();
} catch (Exception callback) {
LOGGER.info("callback exception!", callback);
} finally {
lock.unlock();
}
}
use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.
the class NormalCommitNodesHandler 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);
conn.quit();
if (decrementCountBy(1)) {
cleanAndFeedback();
}
}
use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.
the class XACommitNodesHandler method makeErrorPacket.
private byte[] makeErrorPacket(String errMsg) {
ErrorPacket errPacket = new ErrorPacket();
errPacket.setErrNo(ErrorCode.ER_UNKNOWN_ERROR);
errPacket.setMessage(StringUtil.encode(errMsg, session.getSource().getCharset().getResults()));
return errPacket.toBytes();
}
use of com.actiontech.dble.net.mysql.ErrorPacket 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.net.mysql.ErrorPacket 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();
}
}
}
}
}
Aggregations