Search in sources :

Example 6 with BackendConnection

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

the class PhysicalDatasource method closeByIdleMany.

private void closeByIdleMany(int idleCloseCount, int idleCons) {
    LOGGER.info("too many ilde cons ,close some for datasouce  " + name + " want close :" + idleCloseCount + " total idle " + idleCons);
    List<BackendConnection> readyCloseCons = new ArrayList<BackendConnection>(idleCloseCount);
    for (ConQueue queue : conMap.getAllConQueue()) {
        int closeNumber = (queue.getManCommitCons().size() + queue.getAutoCommitCons().size()) * idleCloseCount / idleCons;
        readyCloseCons.addAll(queue.getIdleConsToClose(closeNumber));
    }
    for (BackendConnection idleCon : readyCloseCons) {
        if (idleCon.isBorrowed()) {
            LOGGER.info("find idle con is using " + idleCon);
        }
        idleCon.close("too many idle con");
    }
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) ArrayList(java.util.ArrayList) ConQueue(com.actiontech.dble.backend.ConQueue)

Example 7 with BackendConnection

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

the class NormalAutoRollbackNodesHandler method rollback.

@Override
public void rollback() {
    if (errConnection != null && nodes.length == errConnection.size()) {
        for (BackendConnection conn : errConnection) {
            conn.quit();
        }
        errConnection.clear();
        session.getSource().write(sendData);
        return;
    }
    if (errConnection != null && errConnection.size() > 0) {
        for (RouteResultsetNode node : nodes) {
            final BackendConnection conn = session.getTarget(node);
            if (errConnection.contains(conn)) {
                session.getTargetMap().remove(node);
                conn.quit();
            }
        }
        errConnection.clear();
    }
    super.rollback();
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 8 with BackendConnection

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

the class XAAutoRollbackNodesHandler method rollback.

@Override
public void rollback() {
    if (errConnection != null && nodes.length == errConnection.size()) {
        for (BackendConnection conn : errConnection) {
            conn.quit();
        }
        errConnection.clear();
        session.getSource().write(sendData);
        return;
    }
    if (errConnection != null && errConnection.size() > 0) {
        for (RouteResultsetNode node : nodes) {
            final BackendConnection conn = session.getTarget(node);
            if (errConnection.contains(conn)) {
                session.getTargetMap().remove(node);
                conn.quit();
            }
        }
        errConnection.clear();
    }
    super.rollback();
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode)

Example 9 with BackendConnection

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

the class ReloadConfig method recycleOldBackendConnections.

private static void recycleOldBackendConnections(ServerConfig config, boolean closeFrontCon) {
    /* 2.4 put the old connection into a queue */
    Map<String, PhysicalDBPool> oldDataHosts = config.getBackupDataHosts();
    for (PhysicalDBPool dbPool : oldDataHosts.values()) {
        dbPool.stopHeartbeat();
        for (PhysicalDatasource ds : dbPool.getAllDataSources()) {
            for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
                for (BackendConnection con : processor.getBackends().values()) {
                    if (con instanceof MySQLConnection) {
                        MySQLConnection mysqlCon = (MySQLConnection) con;
                        if (mysqlCon.getPool() == ds) {
                            if (con.isBorrowed()) {
                                if (closeFrontCon) {
                                    findAndcloseFrontCon(con);
                                } else {
                                    NIOProcessor.BACKENDS_OLD.add(con);
                                }
                            } else {
                                con.close("old idle conn for reload");
                            }
                        }
                    }
                }
            }
        }
    }
    LOGGER.info("the size of old backend connection to be recycled is: " + NIOProcessor.BACKENDS_OLD.size());
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 10 with BackendConnection

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

the class ShowBackendOld method execute.

public static void execute(ManagerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = HEADER.write(buffer, c, true);
    for (FieldPacket field : FIELDS) {
        buffer = field.write(buffer, c, true);
    }
    buffer = EOF.write(buffer, c, true);
    byte packetId = EOF.getPacketId();
    for (BackendConnection bc : NIOProcessor.BACKENDS_OLD) {
        if (bc != null) {
            RowDataPacket row = getRow(bc, c.getCharset().getResults());
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
        }
    }
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    c.write(buffer);
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

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