Search in sources :

Example 6 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class OutputHandler method rowEofResponse.

@Override
public void rowEofResponse(byte[] data, boolean isLeft, BackendConnection conn) {
    if (terminate.get()) {
        return;
    }
    logger.info("--------sql execute end!");
    ServerConnection source = session.getSource();
    lock.lock();
    try {
        EOFPacket eofPacket = new EOFPacket();
        if (data != null) {
            eofPacket.read(data);
        }
        eofPacket.setPacketId(++packetId);
        if (hasNext) {
            eofPacket.setStatus(eofPacket.getStatus() | StatusFlags.SERVER_MORE_RESULTS_EXISTS);
        }
        HandlerTool.terminateHandlerTree(this);
        byte[] eof = eofPacket.toBytes();
        buffer = source.writeToBuffer(eof, buffer);
        session.setResponseTime();
        if (hasNext) {
            source.write(buffer);
        // source.executeNext(packetId, false);
        } else {
            // source.executeNext(packetId, false);
            source.write(buffer);
        }
    } finally {
        lock.unlock();
    }
}
Also used : ServerConnection(com.actiontech.dble.server.ServerConnection)

Example 7 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class MultiNodeDdlHandler method rowEofResponse.

@Override
public void rowEofResponse(final byte[] eof, boolean isLeft, BackendConnection conn) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("on row end response " + conn);
    }
    if (errorResponse.get()) {
        return;
    }
    final ServerConnection source = session.getSource();
    if (clearIfSessionClosed(session)) {
        return;
    }
    lock.lock();
    try {
        if (this.isFail() || session.closed()) {
            tryErrorFinished(true);
            return;
        }
        if (--nodeCount > 0)
            return;
        if (errConn) {
            handleEndPacket(err.toBytes(), AutoTxOperation.ROLLBACK, conn);
        } else {
            try {
                if (session.isPrepared()) {
                    handler.setPrepared(true);
                }
                handler.execute();
            } catch (Exception e) {
                LOGGER.warn(AlarmCode.CORE_DDL_WARN + String.valueOf(source) + oriRrs, e);
                session.handleSpecial(oriRrs, source.getSchema(), false);
                source.writeErrMessage(ErrorCode.ERR_HANDLE_DATA, e.toString());
            }
            if (session.isPrepared()) {
                session.setPrepared(false);
            }
        }
    } finally {
        lock.unlock();
    }
}
Also used : ServerConnection(com.actiontech.dble.server.ServerConnection)

Example 8 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class ShowSession method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    buffer = EOF.write(buffer, c, true);
    // write rows
    byte packetId = EOF.getPacketId();
    for (NIOProcessor process : DbleServer.getInstance().getFrontProcessors()) {
        for (FrontendConnection front : process.getFrontends().values()) {
            if (!(front instanceof ServerConnection)) {
                continue;
            }
            ServerConnection sc = (ServerConnection) front;
            RowDataPacket row = getRow(sc, c.getCharset().getResults());
            if (row != null) {
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : FrontendConnection(com.actiontech.dble.net.FrontendConnection) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ServerConnection(com.actiontech.dble.server.ServerConnection) NIOProcessor(com.actiontech.dble.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 9 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class ShowBinlogStatus method getNeedWaitSession.

private static List<NonBlockingSession> getNeedWaitSession() {
    List<NonBlockingSession> fcList = new ArrayList<>();
    for (NIOProcessor process : DbleServer.getInstance().getFrontProcessors()) {
        for (FrontendConnection front : process.getFrontends().values()) {
            if (!(front instanceof ServerConnection)) {
                continue;
            }
            ServerConnection sc = (ServerConnection) front;
            NonBlockingSession session = sc.getSession2();
            if (session.isNeedWaitFinished()) {
                fcList.add(session);
            }
        }
    }
    return fcList;
}
Also used : FrontendConnection(com.actiontech.dble.net.FrontendConnection) NonBlockingSession(com.actiontech.dble.server.NonBlockingSession) ServerConnection(com.actiontech.dble.server.ServerConnection) NIOProcessor(com.actiontech.dble.net.NIOProcessor)

Example 10 with ServerConnection

use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.

the class ShowConnection method getRow.

private static RowDataPacket getRow(FrontendConnection c, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(c.getProcessor().getName().getBytes());
    row.add(LongUtil.toBytes(c.getId()));
    row.add(StringUtil.encode(c.getHost(), charset));
    row.add(IntegerUtil.toBytes(c.getPort()));
    row.add(IntegerUtil.toBytes(c.getLocalPort()));
    row.add(StringUtil.encode(c.getUser(), charset));
    row.add(StringUtil.encode(c.getSchema(), charset));
    row.add(StringUtil.encode(c.getCharset().getClient(), charset));
    row.add(StringUtil.encode(c.getCharset().getCollation(), charset));
    row.add(StringUtil.encode(c.getCharset().getResults(), charset));
    row.add(LongUtil.toBytes(c.getNetInBytes()));
    row.add(LongUtil.toBytes(c.getNetOutBytes()));
    row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
    ByteBuffer bb = c.getReadBuffer();
    row.add(IntegerUtil.toBytes(bb == null ? 0 : bb.capacity()));
    row.add(IntegerUtil.toBytes(c.getWriteQueue().size()));
    String txLevel = "";
    String autocommit = "";
    if (c instanceof ServerConnection) {
        ServerConnection serverConn = (ServerConnection) c;
        txLevel = serverConn.getTxIsolation() + "";
        autocommit = serverConn.isAutocommit() + "";
    }
    row.add(txLevel.getBytes());
    row.add(autocommit.getBytes());
    row.add(StringUtil.encode(c.getStringOfSysVariables(), charset));
    row.add(StringUtil.encode(c.getStringOfUsrVariables(), charset));
    return row;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) ServerConnection(com.actiontech.dble.server.ServerConnection) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ServerConnection (com.actiontech.dble.server.ServerConnection)20 FrontendConnection (com.actiontech.dble.net.FrontendConnection)3 NIOProcessor (com.actiontech.dble.net.NIOProcessor)3 BackendConnection (com.actiontech.dble.backend.BackendConnection)2 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)2 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)2 ByteBuffer (java.nio.ByteBuffer)2 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)1 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)1 NormalAutoCommitNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.normal.NormalAutoCommitNodesHandler)1 NormalAutoRollbackNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.normal.NormalAutoRollbackNodesHandler)1 XAAutoCommitNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.xa.XAAutoCommitNodesHandler)1 XAAutoRollbackNodesHandler (com.actiontech.dble.backend.mysql.nio.handler.transaction.xa.XAAutoRollbackNodesHandler)1 TxState (com.actiontech.dble.backend.mysql.xa.TxState)1 ServerConfig (com.actiontech.dble.config.ServerConfig)1 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)1 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)1 MySQLItemVisitor (com.actiontech.dble.plan.visitor.MySQLItemVisitor)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1 NonBlockingSession (com.actiontech.dble.server.NonBlockingSession)1