Search in sources :

Example 16 with ServerConnection

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

the class ShowTablesHandler method fieldEofResponse.

@Override
public void fieldEofResponse(byte[] header, List<byte[]> fields, List<FieldPacket> fieldPacketsNull, byte[] eof, boolean isLeft, BackendConnection conn) {
    ServerConnection source = session.getSource();
    buffer = allocBuffer();
    PackageBufINf bufInf;
    if (info.isFull()) {
        List<FieldPacket> fieldPackets = new ArrayList<>(2);
        bufInf = ShowTables.writeFullTablesHeader(buffer, source, showTableSchema, fieldPackets);
        packetId = bufInf.getPacketId();
        buffer = bufInf.getBuffer();
        if (info.getWhere() != null) {
            MySQLItemVisitor mev = new MySQLItemVisitor(source.getSchema(), source.getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager());
            info.getWhereExpr().accept(mev);
            sourceFields = HandlerTool.createFields(fieldPackets);
            whereItem = HandlerTool.createItem(mev.getItem(), sourceFields, 0, false, DMLResponseHandler.HandlerType.WHERE);
            bufInf = ShowTables.writeFullTablesRow(buffer, source, shardingTablesMap, packetId, whereItem, sourceFields);
            packetId = bufInf.getPacketId();
            buffer = bufInf.getBuffer();
        } else {
            bufInf = ShowTables.writeFullTablesRow(buffer, source, shardingTablesMap, packetId, null, null);
            packetId = bufInf.getPacketId();
            buffer = bufInf.getBuffer();
        }
    } else {
        bufInf = ShowTables.writeTablesHeaderAndRows(buffer, source, shardingTablesMap, showTableSchema);
        packetId = bufInf.getPacketId();
        buffer = bufInf.getBuffer();
    }
}
Also used : MySQLItemVisitor(com.actiontech.dble.plan.visitor.MySQLItemVisitor) PackageBufINf(com.actiontech.dble.manager.handler.PackageBufINf) ArrayList(java.util.ArrayList) ServerConnection(com.actiontech.dble.server.ServerConnection) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 17 with ServerConnection

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

the class SingleNodeHandler method execute.

public void execute() throws Exception {
    startTime = System.currentTimeMillis();
    ServerConnection sc = session.getSource();
    waitingResponse = true;
    this.packetId = 0;
    final BackendConnection conn = session.getTarget(node);
    node.setRunOnSlave(rrs.getRunOnSlave());
    if (session.tryExistsCon(conn, node)) {
        execute(conn);
    } else {
        // create new connection
        node.setRunOnSlave(rrs.getRunOnSlave());
        ServerConfig conf = DbleServer.getInstance().getConfig();
        PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
        dn.getConnection(dn.getDatabase(), session.getSource().isTxStart(), sc.isAutocommit(), node, this, node);
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ServerConfig(com.actiontech.dble.config.ServerConfig) BackendConnection(com.actiontech.dble.backend.BackendConnection) ServerConnection(com.actiontech.dble.server.ServerConnection)

Example 18 with ServerConnection

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

the class SingleNodeHandler method rowEofResponse.

/**
 * select
 * <p>
 * write EOF to Queue
 */
@Override
public void rowEofResponse(byte[] eof, boolean isLeft, BackendConnection conn) {
    this.netOutBytes += eof.length;
    ServerConnection source = session.getSource();
    // if it's call statement,it will not release connection
    if (!rrs.isCallStatement() || rrs.getProcedure().isResultSimpleValue()) {
        session.releaseConnectionIfSafe(conn, false);
    }
    eof[3] = ++packetId;
    buffer = source.writeToBuffer(eof, allocBuffer());
    int resultSize = source.getWriteQueue().size() * DbleServer.getInstance().getConfig().getSystem().getBufferPoolPageSize();
    resultSize = resultSize + buffer.position();
    session.setResponseTime();
    source.write(buffer);
    waitingResponse = false;
    if (DbleServer.getInstance().getConfig().getSystem().getUseSqlStat() == 1) {
        if (rrs.getStatement() != null) {
            netInBytes += rrs.getStatement().getBytes().length;
        }
        QueryResult queryResult = new QueryResult(session.getSource().getUser(), rrs.getSqlType(), rrs.getStatement(), selectRows, netInBytes, netOutBytes, startTime, System.currentTimeMillis(), resultSize);
        QueryResultDispatcher.dispatchQuery(queryResult);
    }
}
Also used : QueryResult(com.actiontech.dble.statistic.stat.QueryResult) ServerConnection(com.actiontech.dble.server.ServerConnection)

Example 19 with ServerConnection

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

the class OutputHandler method okResponse.

@Override
public void okResponse(byte[] ok, BackendConnection conn) {
    OkPacket okPacket = new OkPacket();
    okPacket.read(ok);
    ServerConnection source = session.getSource();
    lock.lock();
    try {
        ok[3] = ++packetId;
        if ((okPacket.getServerStatus() & StatusFlags.SERVER_MORE_RESULTS_EXISTS) > 0) {
            buffer = source.writeToBuffer(ok, buffer);
        } else {
            HandlerTool.terminateHandlerTree(this);
            if (hasNext) {
                okPacket.setServerStatus(okPacket.getServerStatus() | StatusFlags.SERVER_MORE_RESULTS_EXISTS);
            }
            buffer = source.writeToBuffer(ok, buffer);
            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 20 with ServerConnection

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

the class MultiNodeDdlHandler method handleEndPacket.

private void handleEndPacket(byte[] data, AutoTxOperation txOperation, BackendConnection conn) {
    ServerConnection source = session.getSource();
    boolean inTransaction = !source.isAutocommit() || source.isTxStart();
    if (!inTransaction) {
        // normal query
        session.releaseConnection(conn);
    }
    // Explicit distributed transaction
    if (inTransaction && (AutoTxOperation.ROLLBACK == txOperation)) {
        source.setTxInterrupt("ROLLBACK");
    }
    if (nodeCount == 0) {
        session.getSource().write(data);
    }
}
Also used : ServerConnection(com.actiontech.dble.server.ServerConnection)

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