Search in sources :

Example 16 with ErrorPacket

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();
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 17 with ErrorPacket

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();
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 18 with ErrorPacket

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();
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 19 with ErrorPacket

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;
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) TxState(com.actiontech.dble.backend.mysql.xa.TxState) CoordinatorLogEntry(com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry)

Example 20 with ErrorPacket

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();
                }
            }
        }
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Aggregations

ErrorPacket (com.actiontech.dble.net.mysql.ErrorPacket)33 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)3 QueryNode (com.actiontech.dble.plan.node.QueryNode)3 ViewMeta (com.actiontech.dble.meta.ViewMeta)2 MySQLOutPutException (com.actiontech.dble.plan.common.exception.MySQLOutPutException)2 PlanNode (com.actiontech.dble.plan.node.PlanNode)2 MySQLPlanNodeVisitor (com.actiontech.dble.plan.visitor.MySQLPlanNodeVisitor)2 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)2 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)1 DMLResponseHandler (com.actiontech.dble.backend.mysql.nio.handler.query.DMLResponseHandler)1 AllAnySubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.AllAnySubQueryHandler)1 InSubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.InSubQueryHandler)1 SingleRowSubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.SingleRowSubQueryHandler)1 SubQueryHandler (com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.SubQueryHandler)1 CallBackHandler (com.actiontech.dble.backend.mysql.nio.handler.util.CallBackHandler)1 CoordinatorLogEntry (com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry)1 TxState (com.actiontech.dble.backend.mysql.xa.TxState)1 HeartbeatPacket (com.actiontech.dble.net.mysql.HeartbeatPacket)1 OkPacket (com.actiontech.dble.net.mysql.OkPacket)1 ItemAllAnySubQuery (com.actiontech.dble.plan.common.item.subquery.ItemAllAnySubQuery)1