Search in sources :

Example 26 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class UnLockTablesHandler method execute.

public void execute() {
    Map<RouteResultsetNode, BackendConnection> lockedCons = session.getTargetMap();
    this.reset(lockedCons.size());
    // if client just send an unlock tables, theres is no lock tables statement, just send back OK
    if (lockedCons.size() == 0) {
        LOGGER.info("find no locked backend connection!" + session.getSource());
        OkPacket ok = new OkPacket();
        ok.setPacketId(++packetId);
        // the size of unlock table's response OK packet is 7
        ok.setPacketLength(7);
        ok.setServerStatus(session.getSource().isAutocommit() ? 2 : 1);
        ok.write(session.getSource());
        return;
    }
    for (Map.Entry<RouteResultsetNode, BackendConnection> entry : lockedCons.entrySet()) {
        RouteResultsetNode dataNode = entry.getKey();
        RouteResultsetNode node = new RouteResultsetNode(dataNode.getName(), ServerParse.UNLOCK, srcStatement);
        BackendConnection conn = lockedCons.get(dataNode);
        if (clearIfSessionClosed(session)) {
            return;
        }
        conn.setResponseHandler(this);
        conn.setSession(session);
        try {
            conn.execute(node, session.getSource(), autocommit);
        } catch (Exception e) {
            connectionError(e, conn);
        }
    }
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) OkPacket(com.actiontech.dble.net.mysql.OkPacket) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) Map(java.util.Map)

Example 27 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class PhysicalDatasource method getConnection.

public BackendConnection getConnection(String schema, boolean autocommit) throws IOException {
    BackendConnection con = this.conMap.tryTakeCon(schema, autocommit);
    if (con == null) {
        // the max active
        int activeCons = this.getActiveCount();
        if (activeCons + 1 > size) {
            LOGGER.warn(AlarmCode.CORE_PERFORMANCE_WARN + "the max activeConnnections size can not be max than maxconnections");
            throw new IOException("the max activeConnnections size can not be max than maxconnections");
        } else {
            // create connection
            LOGGER.info("no ilde connection in pool,create new connection for " + this.name + " of schema " + schema);
            NewConnectionRespHandler simpleHandler = new NewConnectionRespHandler();
            this.createNewConnection(simpleHandler, schema);
            con = simpleHandler.getBackConn();
        }
    }
    return takeCon(con, schema);
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) NewConnectionRespHandler(com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler) IOException(java.io.IOException)

Example 28 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class LockTablesHandler method execute.

public void execute() throws Exception {
    super.reset(this.rrs.getNodes().length);
    for (final RouteResultsetNode node : rrs.getNodes()) {
        BackendConnection conn = session.getTarget(node);
        if (session.tryExistsCon(conn, node)) {
            innerExecute(conn, node);
        } else {
            // create new connection
            PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(node.getName());
            dn.getConnection(dn.getDatabase(), session.getSource().isTxStart(), autocommit, node, this, node);
        }
    }
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 29 with BackendConnection

use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.

the class PhysicalDatasource method getConnection.

public void getConnection(String schema, boolean autocommit, final ResponseHandler handler, final Object attachment) throws IOException {
    if (dying.get()) {
        closeByDyingAll();
        LOGGER.info(this.name + "will to die");
        throw new IOException(this.name + "will to die");
    }
    BackendConnection con = this.conMap.tryTakeCon(schema, autocommit);
    if (con != null) {
        takeCon(con, handler, attachment, schema);
        return;
    } else {
        int activeCons = this.getActiveCount();
        if (activeCons + 1 > size) {
            LOGGER.warn(AlarmCode.CORE_PERFORMANCE_WARN + "the max activeConnnections size can not be max than maxconnections");
            throw new IOException("the max activeConnnections size can not be max than maxconnections");
        } else {
            // create connection
            LOGGER.info("no idle connection in pool,create new connection for " + this.name + " of schema " + schema);
            createNewConnection(handler, attachment, schema);
        }
    }
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) IOException(java.io.IOException)

Aggregations

BackendConnection (com.actiontech.dble.backend.BackendConnection)29 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)12 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)8 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)7 NIOProcessor (com.actiontech.dble.net.NIOProcessor)4 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 IOException (java.io.IOException)3 ServerConfig (com.actiontech.dble.config.ServerConfig)2 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)2 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)2 ServerConnection (com.actiontech.dble.server.ServerConnection)2 ByteBuffer (java.nio.ByteBuffer)2 Entry (java.util.Map.Entry)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConQueue (com.actiontech.dble.backend.ConQueue)1 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 GetConnectionHandler (com.actiontech.dble.backend.mysql.nio.handler.GetConnectionHandler)1 NewConnectionRespHandler (com.actiontech.dble.backend.mysql.nio.handler.NewConnectionRespHandler)1 ArrayMinHeap (com.actiontech.dble.backend.mysql.nio.handler.util.ArrayMinHeap)1