Search in sources :

Example 6 with ErrorPacket

use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.

the class MultiNodeDdlHandler method errorResponse.

@Override
public void errorResponse(byte[] data, BackendConnection conn) {
    ErrorPacket errPacket = new ErrorPacket();
    errPacket.read(data);
    errPacket.setPacketId(1);
    err = errPacket;
    lock.lock();
    try {
        if (!isFail()) {
            setFail(new String(errPacket.getMessage()));
        }
        if (!conn.syncAndExecute()) {
            return;
        }
        if (--nodeCount > 0)
            return;
        handleEndPacket(err.toBytes(), AutoTxOperation.ROLLBACK, conn);
    } finally {
        lock.unlock();
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 7 with ErrorPacket

use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.

the class NormalRollbackNodesHandler method errorResponse.

@Override
public void errorResponse(byte[] err, BackendConnection conn) {
    ErrorPacket errPacket = new ErrorPacket();
    errPacket.read(err);
    String errMsg = new String(errPacket.getMessage());
    this.setFail(errMsg);
    // quit to rollback
    conn.quit();
    if (decrementCountBy(1)) {
        cleanAndFeedback();
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 8 with ErrorPacket

use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.

the class XARollbackNodesHandler method errorResponse.

@Override
public void errorResponse(byte[] err, BackendConnection conn) {
    this.waitUntilSendFinish();
    if (conn instanceof MySQLConnection) {
        MySQLConnection mysqlCon = (MySQLConnection) conn;
        if (mysqlCon.getXaStatus() == TxState.TX_STARTED_STATE) {
            mysqlCon.quit();
            mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                session.setXaState(TxState.TX_ENDED_STATE);
                rollback();
            }
        // 'xa rollback' ok without prepared
        } else if (mysqlCon.getXaStatus() == TxState.TX_ENDED_STATE) {
            mysqlCon.quit();
            mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_STATE);
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            if (decrementCountBy(1)) {
                session.setXaState(TxState.TX_INITIALIZE_STATE);
                cleanAndFeedback();
            }
        // 'xa rollback' err
        } else if (mysqlCon.getXaStatus() == TxState.TX_ROLLBACK_FAILED_STATE || mysqlCon.getXaStatus() == TxState.TX_PREPARED_STATE) {
            mysqlCon.setXaStatus(TxState.TX_ROLLBACK_FAILED_STATE);
            mysqlCon.quit();
            XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
            session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
            if (decrementCountBy(1)) {
                cleanAndFeedback();
            }
        // we don't know if the conn prepared or not
        } else if (mysqlCon.getXaStatus() == TxState.TX_PREPARE_UNCONNECT_STATE) {
            ErrorPacket errPacket = new ErrorPacket();
            errPacket.read(err);
            if (errPacket.getErrNo() == ErrorCode.ER_XAER_NOTA) {
                // ERROR 1397 (XAE04): XAER_NOTA: Unknown XID, not prepared
                mysqlCon.setXaStatus(TxState.TX_ROLLBACKED_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 {
                session.setXaState(TxState.TX_ROLLBACK_FAILED_STATE);
                XAStateLog.saveXARecoveryLog(session.getSessionXaID(), mysqlCon);
                if (decrementCountBy(1)) {
                    cleanAndFeedback();
                }
            }
        } else {
            LOGGER.info("Wrong XA status flag!");
        }
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 9 with ErrorPacket

use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.

the class UViewChildResponse method notifyProcess.

@Override
public void notifyProcess(UKvBean configValue) throws Exception {
    LOGGER.debug("notify " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
    if (configValue.getKey().split("/").length != UcorePathUtil.getViewChangePath().split("/").length + 1) {
        // only with the type u.../d.../clu.../view/update(delete)/schema.table
        return;
    }
    String schema = configValue.getKey().split("/")[5].split(Repository.SCHEMA_VIEW_SPLIT)[0];
    String viewName = configValue.getKey().split(Repository.SCHEMA_VIEW_SPLIT)[1];
    if ("".equals(configValue.getValue())) {
        // the value of key is empty,just doing nothing
        return;
    }
    String serverId = configValue.getValue().split(Repository.SCHEMA_VIEW_SPLIT)[0];
    String optionType = configValue.getValue().split(Repository.SCHEMA_VIEW_SPLIT)[1];
    String myId = UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
    if (myId.equals(serverId) || configValue.getChangeType() == UKvBean.DELETE) {
        // self node do noting
        return;
    } else {
        try {
            if (Repository.DELETE.equals(optionType)) {
                LOGGER.debug("delete view " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
                if (!DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().containsKey(viewName)) {
                    return;
                }
                DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().remove(viewName);
                ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, UcorePathUtil.SUCCESS);
            } else if (Repository.UPDATE.equals(optionType)) {
                LOGGER.debug("update view " + configValue.getKey() + " " + configValue.getValue() + " " + configValue.getChangeType());
                String stmt = ClusterUcoreSender.getKey(UcorePathUtil.getViewPath() + SEPARATOR + schema + Repository.SCHEMA_VIEW_SPLIT + viewName).getValue();
                if (DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().get(viewName) != null && stmt.equals(DbleServer.getInstance().getTmManager().getCatalogs().get(schema).getViewMetas().get(viewName).getCreateSql())) {
                    return;
                }
                ViewMeta vm = new ViewMeta(stmt, schema, DbleServer.getInstance().getTmManager());
                ErrorPacket error = vm.initAndSet(true);
                Map<String, Map<String, String>> viewCreateSqlMap = DbleServer.getInstance().getTmManager().getRepository().getViewCreateSqlMap();
                Map<String, String> schemaMap = viewCreateSqlMap.get(schema);
                schemaMap.put(viewName, stmt);
                LOGGER.debug("update view result == " + error);
                if (error != null) {
                    ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, new String(error.getMessage()));
                    return;
                }
                ClusterUcoreSender.sendDataToUcore(configValue.getKey() + SEPARATOR + myId, UcorePathUtil.SUCCESS);
            }
        } catch (Exception e) {
            ClusterUcoreSender.sendDataToUcore(configValue.getKey() + "/" + myId, e.toString());
        }
    }
}
Also used : ViewMeta(com.actiontech.dble.meta.ViewMeta) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) Map(java.util.Map)

Example 10 with ErrorPacket

use of com.actiontech.dble.net.mysql.ErrorPacket in project dble by actiontech.

the class SQLJob method errorResponse.

@Override
public void errorResponse(byte[] err, BackendConnection conn) {
    ErrorPacket errPg = new ErrorPacket();
    errPg.read(err);
    String errMsg = "error response errNo:" + errPg.getErrNo() + ", " + new String(errPg.getMessage()) + " from of sql :" + sql + " at con:" + conn;
    if (errPg.getErrNo() == ErrorCode.ER_SPECIFIC_ACCESS_DENIED_ERROR) {
        // @see https://dev.mysql.com/doc/refman/5.6/en/error-messages-server.html
        LOGGER.info(errMsg);
    } else if (errPg.getErrNo() == ErrorCode.ER_XAER_NOTA) {
        // ERROR 1397 (XAE04): XAER_NOTA: Unknown XID, not prepared
        conn.release();
        doFinished(false);
        return;
    } else {
        LOGGER.info(errMsg);
    }
    conn.release();
    doFinished(true);
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

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