use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.
the class ShowDataNode method getRow.
private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
PhysicalDBPool pool = node.getDbPool();
PhysicalDatasource ds = pool.getSource();
if (ds != null) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(node.getName(), charset));
row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
int active = ds.getActiveCountForSchema(node.getDatabase());
int idle = ds.getIdleCountForSchema(node.getDatabase());
row.add(IntegerUtil.toBytes(pool.getActiveIndex()));
row.add(IntegerUtil.toBytes(active));
row.add(IntegerUtil.toBytes(idle));
row.add(IntegerUtil.toBytes(ds.getSize()));
row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
return row;
} else {
return null;
}
}
use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.
the class ShowDatasourceSyn method getRows.
private static List<RowDataPacket> getRows(String charset) {
List<RowDataPacket> list = new LinkedList<>();
ServerConfig conf = DbleServer.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.getAsyncRecorder();
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.parseLong(states.get("Master_Port"))));
row.add(StringUtil.encode(states.get("Master_User"), charset));
String seconds = states.get("Seconds_Behind_Master");
row.add(seconds == null ? null : LongUtil.toBytes(Long.parseLong(seconds)));
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.parseLong(states.get("Connect_Retry"))));
row.add(StringUtil.encode(states.get("Last_IO_Error"), charset));
list.add(row);
}
}
}
return list;
}
use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.
the class ShowHeartbeat method getRows.
private static List<RowDataPacket> getRows() {
List<RowDataPacket> list = new LinkedList<>();
ServerConfig conf = DbleServer.getInstance().getConfig();
// host nodes
Map<String, PhysicalDBPool> dataHosts = conf.getDataHosts();
for (PhysicalDBPool pool : dataHosts.values()) {
for (PhysicalDatasource ds : pool.getAllDataSources()) {
DBHeartbeat hb = ds.getHeartbeat();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(ds.getName().getBytes());
if (hb != null) {
row.add(ds.getConfig().getIp().getBytes());
row.add(IntegerUtil.toBytes(ds.getConfig().getPort()));
row.add(IntegerUtil.toBytes(hb.getStatus()));
row.add(IntegerUtil.toBytes(hb.getErrorCount()));
row.add(hb.isChecking() ? "checking".getBytes() : "idle".getBytes());
row.add(LongUtil.toBytes(hb.getTimeout()));
row.add(hb.getRecorder().get().getBytes());
String lat = hb.getLastActiveTime();
row.add(lat == null ? null : lat.getBytes());
row.add(hb.isStop() ? "true".getBytes() : "false".getBytes());
} else {
row.add(null);
row.add(null);
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 com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.
the class ReloadConfig method recycleOldBackendConnections.
private static void recycleOldBackendConnections(ServerConfig config, boolean closeFrontCon) {
/* 2.4 put the old connection into a queue */
Map<String, PhysicalDBPool> oldDataHosts = config.getBackupDataHosts();
for (PhysicalDBPool dbPool : oldDataHosts.values()) {
dbPool.stopHeartbeat();
for (PhysicalDatasource ds : dbPool.getAllDataSources()) {
for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
for (BackendConnection con : processor.getBackends().values()) {
if (con instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) con;
if (mysqlCon.getPool() == ds) {
if (con.isBorrowed()) {
if (closeFrontCon) {
findAndcloseFrontCon(con);
} else {
NIOProcessor.BACKENDS_OLD.add(con);
}
} else {
con.close("old idle conn for reload");
}
}
}
}
}
}
}
LOGGER.info("the size of old backend connection to be recycled is: " + NIOProcessor.BACKENDS_OLD.size());
}
use of com.actiontech.dble.backend.datasource.PhysicalDBPool in project dble by actiontech.
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 = DbleServer.getInstance().getConfig().getDataHosts();
Integer idx = pair.getValue();
for (String key : pair.getKey()) {
PhysicalDBPool dn = dns.get(key);
if (dn != null) {
int m = dn.getActiveIndex();
int n = (idx == null) ? dn.next(m) : idx;
if (dn.switchSource(n, false, "MANAGER")) {
++count;
}
// TODO:ELSE?
}
}
OkPacket packet = new OkPacket();
packet.setPacketId(1);
packet.setAffectedRows(count);
packet.setServerStatus(2);
packet.write(c);
}
Aggregations