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