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;
}
}
}
}
}
}
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;
}
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);
}
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);
}
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;
}
Aggregations