Search in sources :

Example 41 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat_plus by coderczp.

the class ConfigTest method testReadHostWeight.

/**
 * 测试 读服务的 权重
 *
 * @throws Exception
 */
@Test
public void testReadHostWeight() throws Exception {
    ArrayList<PhysicalDatasource> okSources = new ArrayList<PhysicalDatasource>();
    PhysicalDBPool pool = this.dataHosts.get("localhost2");
    okSources.addAll(pool.getAllDataSources());
    PhysicalDatasource source = pool.randomSelect(okSources);
    Assert.assertTrue(source != null);
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) ArrayList(java.util.ArrayList) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) Test(org.junit.Test)

Example 42 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat_plus by coderczp.

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)

Example 43 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat_plus by coderczp.

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 = MycatServer.getInstance().getConfig().getDataHosts();
    Integer idx = pair.getValue();
    for (String key : pair.getKey()) {
        PhysicalDBPool dn = dns.get(key);
        if (dn != null) {
            int m = dn.getActivedIndex();
            int n = (idx == null) ? dn.next(m) : idx.intValue();
            if (dn.switchSource(n, false, "MANAGER")) {
                ++count;
            }
        }
    }
    OkPacket packet = new OkPacket();
    packet.packetId = 1;
    packet.affectedRows = count;
    packet.serverStatus = 2;
    packet.write(c);
}
Also used : OkPacket(io.mycat.net.mysql.OkPacket) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool)

Example 44 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat_plus by coderczp.

the class ShowDatasourceCluster 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("wsrep_incoming_addresses") == null ? "" : states.get("wsrep_incoming_addresses"), charset));
                row.add(StringUtil.encode(states.get("wsrep_cluster_size") == null ? "" : states.get("wsrep_cluster_size"), charset));
                row.add(StringUtil.encode(states.get("wsrep_cluster_status") == null ? "" : states.get("wsrep_cluster_status"), charset));
                row.add(StringUtil.encode(states.get("wsrep_connected") == null ? "" : states.get("wsrep_connected"), charset));
                row.add(StringUtil.encode(states.get("wsrep_flow_control_paused") == null ? "" : states.get("wsrep_flow_control_paused"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_state_comment") == null ? "" : states.get("wsrep_local_state_comment"), charset));
                row.add(StringUtil.encode(states.get("wsrep_ready") == null ? "" : states.get("wsrep_ready"), charset));
                row.add(StringUtil.encode(states.get("wsrep_flow_control_paused_ns") == null ? "" : states.get("wsrep_flow_control_paused_ns"), charset));
                row.add(StringUtil.encode(states.get("wsrep_flow_control_recv") == null ? "" : states.get("wsrep_flow_control_recv"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_bf_aborts") == null ? "" : states.get("wsrep_local_bf_aborts"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_recv_queue_avg") == null ? "" : states.get("wsrep_local_recv_queue_avg"), charset));
                row.add(StringUtil.encode(states.get("wsrep_local_send_queue_avg") == null ? "" : states.get("wsrep_local_recv_queue_avg"), charset));
                row.add(StringUtil.encode(states.get("wsrep_apply_oool") == null ? "" : states.get("wsrep_apply_oool"), charset));
                row.add(StringUtil.encode(states.get("wsrep_apply_oooe") == null ? "" : states.get("wsrep_apply_oooe"), 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 45 with PhysicalDBPool

use of io.mycat.backend.datasource.PhysicalDBPool in project Mycat_plus by coderczp.

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)

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