Search in sources :

Example 31 with PhysicalDatasource

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

the class GlobalTableUtil method reGetColumnsForTable.

/**
 * 重新获得table 的列list
 * @param tableName
 */
private static void reGetColumnsForTable(String tableName) {
    MycatConfig config = MycatServer.getInstance().getConfig();
    if (globalTableMap != null && globalTableMap.get(tableName.toUpperCase()) != null) {
        TableConfig tableConfig = globalTableMap.get(tableName.toUpperCase());
        if (// consistencyCheck 在运行中
        tableConfig == null || isInnerColumnCheckFinished != 1)
            return;
        String nodeName = tableConfig.getDataNodes().get(0);
        Map<String, PhysicalDBNode> map = config.getDataNodes();
        for (String k2 : map.keySet()) {
            PhysicalDBNode dBnode = map.get(k2);
            if (nodeName.equals(dBnode.getName())) {
                PhysicalDBPool pool = dBnode.getDbPool();
                List<PhysicalDatasource> dsList = (List<PhysicalDatasource>) pool.genAllDataSources();
                for (PhysicalDatasource ds : dsList) {
                    if (ds instanceof MySQLDataSource) {
                        MySQLDataSource mds = (MySQLDataSource) dsList.get(0);
                        MySQLConsistencyChecker checker = new MySQLConsistencyChecker(mds, tableConfig.getName());
                        checker.checkInnerColumnExist();
                        // 运行一次就行了,不需要像consistencyCheck那样每个db都运行一次
                        return;
                    }
                }
            }
        }
    }
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) MySQLConsistencyChecker(io.mycat.backend.heartbeat.MySQLConsistencyChecker) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) MySQLDataSource(io.mycat.backend.mysql.nio.MySQLDataSource) TableConfig(io.mycat.config.model.TableConfig) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) ArrayList(java.util.ArrayList) List(java.util.List) MycatConfig(io.mycat.config.MycatConfig)

Example 32 with PhysicalDatasource

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

the class ConfigTest method getPhysicalDBPool.

private PhysicalDBPool getPhysicalDBPool(DataHostConfig conf, ConfigLoader configLoader) {
    String name = conf.getName();
    String dbType = conf.getDbType();
    String dbDriver = conf.getDbDriver();
    PhysicalDatasource[] writeSources = createDataSource(conf, name, dbType, dbDriver, conf.getWriteHosts(), false);
    Map<Integer, DBHostConfig[]> readHostsMap = conf.getReadHosts();
    Map<Integer, PhysicalDatasource[]> readSourcesMap = new HashMap<Integer, PhysicalDatasource[]>(readHostsMap.size());
    for (Map.Entry<Integer, DBHostConfig[]> entry : readHostsMap.entrySet()) {
        PhysicalDatasource[] readSources = createDataSource(conf, name, dbType, dbDriver, entry.getValue(), true);
        readSourcesMap.put(entry.getKey(), readSources);
    }
    PhysicalDBPool pool = new PhysicalDBPool(conf.getName(), conf, writeSources, readSourcesMap, conf.getBalance(), conf.getWriteType());
    return pool;
}
Also used : PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) HashMap(java.util.HashMap) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) HashMap(java.util.HashMap) Map(java.util.Map)

Example 33 with PhysicalDatasource

use of io.mycat.backend.datasource.PhysicalDatasource 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 34 with PhysicalDatasource

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

the class ShowDataSource method execute.

public static void execute(ManagerConnection c, String name) {
    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.packetId;
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, List<PhysicalDatasource>> dataSources = new HashMap<String, List<PhysicalDatasource>>();
    if (null != name) {
        PhysicalDBNode dn = conf.getDataNodes().get(name);
        if (dn != null) {
            List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
            dslst.addAll(dn.getDbPool().getAllDataSources());
            dataSources.put(dn.getName(), dslst);
        }
    } else {
        for (PhysicalDBNode dn : conf.getDataNodes().values()) {
            List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
            dslst.addAll(dn.getDbPool().getAllDataSources());
            dataSources.put(dn.getName(), dslst);
        }
    }
    for (Map.Entry<String, List<PhysicalDatasource>> dsEntry : dataSources.entrySet()) {
        String dnName = dsEntry.getKey();
        for (PhysicalDatasource ds : dsEntry.getValue()) {
            RowDataPacket row = getRow(dnName, ds, c.getCharset());
            row.packetId = ++packetId;
            buffer = row.write(buffer, c, true);
        }
    }
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) HashMap(java.util.HashMap) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) MycatConfig(io.mycat.config.MycatConfig) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) PhysicalDatasource(io.mycat.backend.datasource.PhysicalDatasource) List(java.util.List) LinkedList(java.util.LinkedList) FieldPacket(io.mycat.net.mysql.FieldPacket) HashMap(java.util.HashMap) Map(java.util.Map)

Example 35 with PhysicalDatasource

use of io.mycat.backend.datasource.PhysicalDatasource 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)

Aggregations

PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)52 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)43 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)20 MycatConfig (io.mycat.config.MycatConfig)20 RowDataPacket (io.mycat.net.mysql.RowDataPacket)14 DBHostConfig (io.mycat.config.model.DBHostConfig)12 LinkedList (java.util.LinkedList)12 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)11 HashMap (java.util.HashMap)10 MySQLDataSource (io.mycat.backend.mysql.nio.MySQLDataSource)8 Connection (java.sql.Connection)8 Map (java.util.Map)8 ConfigException (io.mycat.config.util.ConfigException)6 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 MySQLConsistencyChecker (io.mycat.backend.heartbeat.MySQLConsistencyChecker)4 JDBCDatasource (io.mycat.backend.jdbc.JDBCDatasource)4 TableConfig (io.mycat.config.model.TableConfig)4 SimpleDateFormat (java.text.SimpleDateFormat)4