Search in sources :

Example 6 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor 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 7 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.

the class ConMap method clearConnections.

public void clearConnections(String reason, PhysicalDatasource dataSource) {
    for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
        ConcurrentMap<Long, BackendConnection> map = processor.getBackends();
        Iterator<Entry<Long, BackendConnection>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<Long, BackendConnection> entry = iterator.next();
            BackendConnection con = entry.getValue();
            if (con instanceof MySQLConnection) {
                if (((MySQLConnection) con).getPool() == dataSource) {
                    con.close(reason);
                    iterator.remove();
                }
            }
        }
    }
    items.clear();
}
Also used : Entry(java.util.Map.Entry) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 8 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.

the class KillHandler method handle.

public static void handle(String stmt, int offset, ServerConnection c) {
    String id = stmt.substring(offset).trim();
    if (StringUtil.isEmpty(id)) {
        c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "NULL connection id");
    } else {
        // get value
        long value = 0;
        try {
            value = Long.parseLong(id);
        } catch (NumberFormatException e) {
            c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Invalid connection id:" + id);
            return;
        }
        // kill myself
        if (value == c.getId()) {
            getOkPacket().write(c);
            c.write(c.allocate());
            return;
        }
        // get connection and close it
        FrontendConnection fc = null;
        NIOProcessor[] processors = DbleServer.getInstance().getFrontProcessors();
        for (NIOProcessor p : processors) {
            if ((fc = p.getFrontends().get(value)) != null) {
                break;
            }
        }
        if (fc != null) {
            if (!fc.getUser().equals(c.getUser())) {
                c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "can't kill other user's connection" + id);
                return;
            }
            fc.killAndClose("killed");
            getOkPacket().write(c);
        } else {
            c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Unknown connection id:" + id);
        }
    }
}
Also used : FrontendConnection(com.actiontech.dble.net.FrontendConnection) NIOProcessor(com.actiontech.dble.net.NIOProcessor)

Example 9 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.

the class ShowBackendStat method stat.

private static HashMap<String, BackendStat> stat() {
    HashMap<String, BackendStat> all = new HashMap<String, BackendStat>();
    for (NIOProcessor p : DbleServer.getInstance().getBackendProcessors()) {
        for (BackendConnection bc : p.getBackends().values()) {
            if ((bc == null) || !(bc instanceof MySQLConnection)) {
                break;
            }
            MySQLConnection con = (MySQLConnection) bc;
            String host = con.getHost();
            long port = con.getPort();
            BackendStat info = all.get(host + Long.toString(port));
            if (info == null) {
                info = new BackendStat(host, port);
                all.put(host + Long.toString(port), info);
            }
            if (con.isBorrowed()) {
                info.addActive();
            }
            info.addTotal();
        }
    }
    return all;
}
Also used : BackendConnection(com.actiontech.dble.backend.BackendConnection) HashMap(java.util.HashMap) NIOProcessor(com.actiontech.dble.net.NIOProcessor) MySQLConnection(com.actiontech.dble.backend.mysql.nio.MySQLConnection)

Example 10 with NIOProcessor

use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.

the class ShowCommand 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 p : DbleServer.getInstance().getFrontProcessors()) {
        RowDataPacket row = getRow(p);
        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 : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) NIOProcessor(com.actiontech.dble.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Aggregations

NIOProcessor (com.actiontech.dble.net.NIOProcessor)16 FrontendConnection (com.actiontech.dble.net.FrontendConnection)8 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)8 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)6 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 ByteBuffer (java.nio.ByteBuffer)6 BackendConnection (com.actiontech.dble.backend.BackendConnection)4 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)4 ServerConnection (com.actiontech.dble.server.ServerConnection)3 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1 NonBlockingSession (com.actiontech.dble.server.NonBlockingSession)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1