Search in sources :

Example 1 with ErrorPacket

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

the class BaseHandlerBuilder method handleBlockingSubQuery.

protected void handleBlockingSubQuery() {
    if (node.getSubQueries().size() == 0) {
        return;
    }
    final ReentrantLock lock = new ReentrantLock();
    final Condition finishSubQuery = lock.newCondition();
    final AtomicBoolean finished = new AtomicBoolean(false);
    final AtomicInteger subNodes = new AtomicInteger(node.getSubQueries().size());
    final CopyOnWriteArrayList<ErrorPacket> errorPackets = new CopyOnWriteArrayList<>();
    for (ItemSubQuery itemSubQuery : node.getSubQueries()) {
        if (itemSubQuery instanceof ItemSingleRowSubQuery) {
            final SubQueryHandler tempHandler = new SingleRowSubQueryHandler(getSequenceId(), session, (ItemSingleRowSubQuery) itemSubQuery);
            if (isExplain) {
                handleSubQueryForExplain(lock, finishSubQuery, finished, subNodes, itemSubQuery.getPlanNode(), tempHandler);
            } else {
                handleSubQuery(lock, finishSubQuery, finished, subNodes, errorPackets, itemSubQuery.getPlanNode(), tempHandler);
            }
        } else if (itemSubQuery instanceof ItemInSubQuery) {
            final SubQueryHandler tempHandler = new InSubQueryHandler(getSequenceId(), session, (ItemInSubQuery) itemSubQuery);
            if (isExplain) {
                handleSubQueryForExplain(lock, finishSubQuery, finished, subNodes, itemSubQuery.getPlanNode(), tempHandler);
            } else {
                handleSubQuery(lock, finishSubQuery, finished, subNodes, errorPackets, itemSubQuery.getPlanNode(), tempHandler);
            }
        } else if (itemSubQuery instanceof ItemAllAnySubQuery) {
            final SubQueryHandler tempHandler = new AllAnySubQueryHandler(getSequenceId(), session, (ItemAllAnySubQuery) itemSubQuery);
            if (isExplain) {
                handleSubQueryForExplain(lock, finishSubQuery, finished, subNodes, itemSubQuery.getPlanNode(), tempHandler);
            } else {
                handleSubQuery(lock, finishSubQuery, finished, subNodes, errorPackets, itemSubQuery.getPlanNode(), tempHandler);
            }
        }
    }
    lock.lock();
    try {
        while (!finished.get()) {
            finishSubQuery.await();
        }
    } catch (InterruptedException e) {
        LOGGER.info("execute ScalarSubQuery " + e);
        ErrorPacket errorPackage = new ErrorPacket();
        errorPackage.setErrNo(ErrorCode.ER_UNKNOWN_ERROR);
        String errorMsg = e.getMessage() == null ? e.toString() : e.getMessage();
        errorPackage.setMessage(errorMsg.getBytes(StandardCharsets.UTF_8));
        errorPackets.add(errorPackage);
    } finally {
        lock.unlock();
    }
    if (errorPackets.size() > 0) {
        throw new MySQLOutPutException(errorPackets.get(0).getErrNo(), "", new String(errorPackets.get(0).getMessage(), StandardCharsets.UTF_8));
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Condition(java.util.concurrent.locks.Condition) SingleRowSubQueryHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.SingleRowSubQueryHandler) InSubQueryHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.InSubQueryHandler) AllAnySubQueryHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.AllAnySubQueryHandler) SubQueryHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.SubQueryHandler) SingleRowSubQueryHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.SingleRowSubQueryHandler) ItemAllAnySubQuery(com.actiontech.dble.plan.common.item.subquery.ItemAllAnySubQuery) ItemInSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemInSubQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AllAnySubQueryHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.AllAnySubQueryHandler) InSubQueryHandler(com.actiontech.dble.backend.mysql.nio.handler.query.impl.subquery.InSubQueryHandler) ItemSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemSubQuery) ItemSingleRowSubQuery(com.actiontech.dble.plan.common.item.subquery.ItemSingleRowSubQuery) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MySQLOutPutException(com.actiontech.dble.plan.common.exception.MySQLOutPutException)

Example 2 with ErrorPacket

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

the class MultiNodeHandler method errorResponse.

public void errorResponse(byte[] data, BackendConnection conn) {
    session.releaseConnectionIfSafe(conn, false);
    ErrorPacket errPacket = new ErrorPacket();
    errPacket.read(data);
    String errMsg = new String(errPacket.getMessage());
    LOGGER.info("error response from " + conn + " err " + errMsg + " code:" + errPacket.getErrNo());
    this.tryErrorFinished(this.decrementCountBy(1));
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 3 with ErrorPacket

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

the class MultiNodeHandler method createErrPkg.

protected ErrorPacket createErrPkg(String errMsg) {
    ErrorPacket err = new ErrorPacket();
    lock.lock();
    try {
        err.setPacketId(++packetId);
    } finally {
        lock.unlock();
    }
    err.setErrNo(ErrorCode.ER_UNKNOWN_ERROR);
    err.setMessage(StringUtil.encode(errMsg, session.getSource().getCharset().getResults()));
    return err;
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 4 with ErrorPacket

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

the class SubQueryHandler method genErrorPackage.

protected void genErrorPackage(int errorNum, String msg) {
    if (errorPacket == null) {
        errorPacket = new ErrorPacket();
        errorPacket.setErrNo(errorNum);
        errorPacket.setMessage(msg.getBytes(StandardCharsets.UTF_8));
    }
}
Also used : ErrorPacket(com.actiontech.dble.net.mysql.ErrorPacket)

Example 5 with ErrorPacket

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

the class MultiNodeDdlHandler method connectionClose.

@Override
public void connectionClose(BackendConnection conn, String reason) {
    if (checkClosedConn(conn)) {
        return;
    }
    LOGGER.info("backend connect" + reason);
    ErrorPacket errPacket = new ErrorPacket();
    errPacket.setPacketId(++packetId);
    errPacket.setErrNo(ErrorCode.ER_ABORTING_CONNECTION);
    errPacket.setMessage(StringUtil.encode(reason, session.getSource().getCharset().getResults()));
    err = errPacket;
    executeConnError(conn);
}
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