Search in sources :

Example 21 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat-Server by MyCATApache.

the class ShowDatasourceSyn method getRows.

private static List<RowDataPacket> getRows(String charset) {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.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.getAsynRecorder();
            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.valueOf(states.get("Master_Port"))));
                row.add(StringUtil.encode(states.get("Master_Use"), charset));
                String secords = states.get("Seconds_Behind_Master");
                row.add(secords == null ? null : LongUtil.toBytes(Long.valueOf(secords)));
                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.valueOf(states.get("Connect_Retry"))));
                row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
                list.add(row);
            }
        }
    }
    return list;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) DBHeartbeat(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) DataSourceSyncRecorder(io.mycat.statistic.DataSourceSyncRecorder) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList)

Example 22 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat-Server by MyCATApache.

the class ShowHeartbeatDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.getInstance().getConfig();
    // host nodes
    String type = "";
    String ip = "";
    int port = 0;
    DBHeartbeat hb = null;
    Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
    for (PhysicalDBPool pool : dataHosts.values()) {
        for (PhysicalDatasource ds : pool.getAllDataSources()) {
            if (name.equals(ds.getName())) {
                hb = ds.getHeartbeat();
                type = ds.getConfig().getDbType();
                ip = ds.getConfig().getIp();
                port = ds.getConfig().getPort();
                break;
            }
        }
    }
    if (hb != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Queue<HeartbeatRecorder.Record> heatbeartRecorders = hb.getRecorder().getRecordsAll();
        for (HeartbeatRecorder.Record record : heatbeartRecorders) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, charset));
            row.add(StringUtil.encode(type, charset));
            row.add(StringUtil.encode(ip, charset));
            row.add(IntegerUtil.toBytes(port));
            long time = record.getTime();
            String timeStr = sdf.format(new Date(time));
            row.add(StringUtil.encode(timeStr, charset));
            row.add(LongUtil.toBytes(record.getValue()));
            list.add(row);
        }
    } else {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        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 : DBHeartbeat(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList) Date(java.util.Date) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) HeartbeatRecorder(io.mycat.statistic.HeartbeatRecorder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 23 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat-Server by MyCATApache.

the class ShowDatasourceSynDetail method getRows.

private static List<RowDataPacket> getRows(String name, String charset) {
    List<RowDataPacket> list = new LinkedList<RowDataPacket>();
    MycatConfig conf = MycatServer.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.getAsynRecorder();
            Map<String, String> states = record.getRecords();
            if (name.equals(ds.getName())) {
                List<Record> data = record.getAsynRecords();
                for (Record r : data) {
                    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
                    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.valueOf(states.get("Master_Port"))));
                    row.add(StringUtil.encode(states.get("Master_Use"), charset));
                    // DateFormat非线程安全
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String time = sdf.format(new Date(r.getTime()));
                    row.add(StringUtil.encode(time, charset));
                    row.add(LongUtil.toBytes((Long) r.getValue()));
                    list.add(row);
                }
                break;
            }
        }
    }
    return list;
}
Also used : DBHeartbeat(io.mycat.backend.heartbeat.DBHeartbeat) RowDataPacket(io.mycat.net.mysql.RowDataPacket) DataSourceSyncRecorder(io.mycat.statistic.DataSourceSyncRecorder) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) LinkedList(java.util.LinkedList) Date(java.util.Date) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) Record(io.mycat.statistic.DataSourceSyncRecorder.Record) SimpleDateFormat(java.text.SimpleDateFormat)

Example 24 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat-Server by MyCATApache.

the class RollbackConfig method rollback.

private static boolean rollback() {
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, UserConfig> users = conf.getBackupUsers();
    Map<String, SchemaConfig> schemas = conf.getBackupSchemas();
    Map<String, PhysicalDBNode> dataNodes = conf.getBackupDataNodes();
    Map<String, PhysicalDBPool> dataHosts = conf.getBackupDataHosts();
    MycatCluster cluster = conf.getBackupCluster();
    FirewallConfig firewall = conf.getBackupFirewall();
    // 检查可回滚状态
    if (!conf.canRollback()) {
        return false;
    }
    // 如果回滚已经存在的pool
    boolean rollbackStatus = true;
    Map<String, PhysicalDBPool> cNodes = conf.getDataHosts();
    for (PhysicalDBPool dn : dataHosts.values()) {
        dn.init(dn.getActivedIndex());
        if (!dn.isInitSuccess()) {
            rollbackStatus = false;
            break;
        }
    }
    // 如果回滚不成功,则清理已初始化的资源。
    if (!rollbackStatus) {
        for (PhysicalDBPool dn : dataHosts.values()) {
            dn.clearDataSources("rollbackup config");
            dn.stopHeartbeat();
        }
        return false;
    }
    // 应用回滚
    conf.rollback(users, schemas, dataNodes, dataHosts, cluster, firewall);
    // 处理旧的资源
    for (PhysicalDBPool dn : cNodes.values()) {
        dn.clearDataSources("clear old config ");
        dn.stopHeartbeat();
    }
    // 清理缓存
    MycatServer.getInstance().getCacheService().clearCache();
    return true;
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) SchemaConfig(io.mycat.config.model.SchemaConfig) MycatCluster(io.mycat.config.MycatCluster) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) MycatConfig(io.mycat.config.MycatConfig) UserConfig(io.mycat.config.model.UserConfig) FirewallConfig(io.mycat.config.model.FirewallConfig)

Example 25 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat-Server by MyCATApache.

the class ConfigTest method initDataHosts.

private Map<String, PhysicalDBPool> initDataHosts(ConfigLoader configLoader) {
    Map<String, DataHostConfig> nodeConfs = configLoader.getDataHosts();
    Map<String, PhysicalDBPool> nodes = new HashMap<String, PhysicalDBPool>(nodeConfs.size());
    for (DataHostConfig conf : nodeConfs.values()) {
        PhysicalDBPool pool = getPhysicalDBPool(conf, configLoader);
        nodes.put(pool.getHostName(), pool);
    }
    return nodes;
}
Also used : HashMap(java.util.HashMap) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) DataHostConfig(io.mycat.config.model.DataHostConfig)

Aggregations

PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)69 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)43 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)28 MycatConfig (io.mycat.config.MycatConfig)22 HashMap (java.util.HashMap)14 DBHostConfig (io.mycat.config.model.DBHostConfig)12 RowDataPacket (io.mycat.net.mysql.RowDataPacket)12 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)11 LinkedList (java.util.LinkedList)10 Connection (java.sql.Connection)8 MycatCluster (io.mycat.config.MycatCluster)6 DataHostConfig (io.mycat.config.model.DataHostConfig)6 FirewallConfig (io.mycat.config.model.FirewallConfig)6 SchemaConfig (io.mycat.config.model.SchemaConfig)6 UserConfig (io.mycat.config.model.UserConfig)6 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)6 IOException (java.io.IOException)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 MySQLConsistencyChecker (io.mycat.backend.heartbeat.MySQLConsistencyChecker)4