Search in sources :

Example 11 with PhysicalDBPool

use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.

the class ShowDataNode method getRow.

private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
    PhysicalDBPool pool = node.getDbPool();
    PhysicalDatasource ds = pool.getSource();
    if (ds != null) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(node.getName(), charset));
        row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
        int active = ds.getActiveCountForSchema(node.getDatabase());
        int idle = ds.getIdleCountForSchema(node.getDatabase());
        row.add(IntegerUtil.toBytes(pool.getActiveIndex()));
        row.add(IntegerUtil.toBytes(active));
        row.add(IntegerUtil.toBytes(idle));
        row.add(IntegerUtil.toBytes(ds.getSize()));
        row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
        long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
        row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
        return row;
    } else {
        return null;
    }
}
Also used : PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool)

Example 12 with PhysicalDBPool

use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.

the class ShowDatasourceSyn method getRows.

private static List<RowDataPacket> getRows(String charset) {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            DataSourceSyncRecorder record = hb.getAsyncRecorder();
            Map<String, String> states = record.getRecords();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            if (!states.isEmpty()) {
                row.add(StringUtil.encode(ds.getName(), charset));
                row.add(StringUtil.encode(ds.getConfig().getIp(), charset));
                row.add(LongUtil.toBytes(ds.getConfig().getPort()));
                row.add(StringUtil.encode(states.get("Master_Host"), charset));
                row.add(LongUtil.toBytes(Long.parseLong(states.get("Master_Port"))));
                row.add(StringUtil.encode(states.get("Master_User"), charset));
                String seconds = states.get("Seconds_Behind_Master");
                row.add(seconds == null ? null : LongUtil.toBytes(Long.parseLong(seconds)));
                row.add(StringUtil.encode(states.get("Slave_IO_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_SQL_Running"), charset));
                row.add(StringUtil.encode(states.get("Slave_IO_State"), charset));
                row.add(LongUtil.toBytes(Long.parseLong(states.get("Connect_Retry"))));
                row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
                list.add(row);
            }
        }
    }
    return list;
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) DataSourceSyncRecorder(com.actiontech.dble.statistic.DataSourceSyncRecorder) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList)

Example 13 with PhysicalDBPool

use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.

the class ShowHeartbeat method getRows.

private static List<RowDataPacket> getRows() {
    List<RowDataPacket> list = new LinkedList<>();
    ServerConfig conf = DbleServer.getInstance().getConfig();
    // host nodes
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            DBHeartbeat hb = ds.getHeartbeat();
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(ds.getName().getBytes());
            if (hb != null) {
                row.add(ds.getConfig().getIp().getBytes());
                row.add(IntegerUtil.toBytes(ds.getConfig().getPort()));
                row.add(IntegerUtil.toBytes(hb.getStatus()));
                row.add(IntegerUtil.toBytes(hb.getErrorCount()));
                row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
                row.add(LongUtil.toBytes(hb.getTimeout()));
                row.add(hb.getRecorder().get().getBytes());
                String lat = hb.getLastActiveTime();
                row.add(lat == null ? null : lat.getBytes());
                row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
            } else {
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
                row.add(null);
            }
            list.add(row);
        }
    }
    return list;
}
Also used : ServerConfig(com.actiontech.dble.config.ServerConfig) PhysicalDatasource(com.actiontech.dble.backend.datasource.PhysicalDatasource) DBHeartbeat(com.actiontech.dble.backend.heartbeat.DBHeartbeat) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) LinkedList(java.util.LinkedList)

Example 14 with PhysicalDBPool

use of com.actiontech.dble.backend.datasource.PhysicalDBPool 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 15 with PhysicalDBPool

use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.

the class SwitchDataSource method response.

public static void response(String stmt, ManagerConnection c) {
    int count = 0;
    Pair<String[], Integer> pair = ManagerParseSwitch.getPair(stmt);
    Map<String, PhysicalDBPool> dns = DbleServer.getInstance().getConfig().getDataHosts();
    Integer idx = pair.getValue();
    for (String key : pair.getKey()) {
        PhysicalDBPool dn = dns.get(key);
        if (dn != null) {
            int m = dn.getActiveIndex();
            int n = (idx == null) ? dn.next(m) : idx;
            if (dn.switchSource(n, false, "MANAGER")) {
                ++count;
            }
        // TODO:ELSE?
        }
    }
    OkPacket packet = new OkPacket();
    packet.setPacketId(1);
    packet.setAffectedRows(count);
    packet.setServerStatus(2);
    packet.write(c);
}
Also used : OkPacket(com.actiontech.dble.net.mysql.OkPacket) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool)

Aggregations

PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)31 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)16 ServerConfig (com.actiontech.dble.config.ServerConfig)9 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)8 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)7 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 ERTable (com.actiontech.dble.config.model.ERTable)3 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)3 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)3 UserConfig (com.actiontech.dble.config.model.UserConfig)3 DataSourceSyncRecorder (com.actiontech.dble.statistic.DataSourceSyncRecorder)3 Set (java.util.Set)3 ConfigInitializer (com.actiontech.dble.config.ConfigInitializer)2 ConfigException (com.actiontech.dble.config.util.ConfigException)2 OkPacket (com.actiontech.dble.net.mysql.OkPacket)2 OneRawSQLQueryResultHandler (com.actiontech.dble.sqlengine.OneRawSQLQueryResultHandler)2