use of com.actiontech.dble.backend.heartbeat.DBHeartbeat 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.heartbeat.DBHeartbeat 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.heartbeat.DBHeartbeat in project dble by actiontech.
the class PhysicalDBPool method switchSourceIfNeed.
public synchronized void switchSourceIfNeed(PhysicalDatasource ds, String reason) {
int switchType = ds.getHostConfig().getSwitchType();
int curDsHbStatus = getSource().getHeartbeat().getStatus();
// read node can't switch, only write node can switch
if (!ds.isReadNode() && curDsHbStatus != DBHeartbeat.OK_STATUS && getSources().length > 1) {
// try to see if need switch datasource
if (curDsHbStatus != DBHeartbeat.INIT_STATUS) {
int curIndex = getActiveIndex();
int nextId = next(curIndex);
PhysicalDatasource[] allWriteNodes = getSources();
while (true) {
if (nextId == curIndex) {
break;
}
PhysicalDatasource theDs = allWriteNodes[nextId];
DBHeartbeat theDsHb = theDs.getHeartbeat();
if (theDsHb.getStatus() == DBHeartbeat.OK_STATUS) {
if (switchType == DataHostConfig.SYN_STATUS_SWITCH_DS) {
if (Integer.valueOf(0).equals(theDsHb.getSlaveBehindMaster())) {
LOGGER.warn(AlarmCode.CORE_BACKEND_SWITCH + "try to switch datasource, slave is " + "synchronized to master " + theDs.getConfig());
switchSource(nextId, true, reason);
break;
} else {
LOGGER.info("ignored datasource ,slave is not " + "synchronized to master, slave " + "behind master :" + theDsHb.getSlaveBehindMaster() + " " + theDs.getConfig());
}
} else {
// normal switch
LOGGER.warn(AlarmCode.CORE_BACKEND_SWITCH + "try to switch datasource ,not checked slave" + "synchronize status " + theDs.getConfig());
switchSource(nextId, true, reason);
break;
}
}
nextId = next(nextId);
}
}
}
}
use of com.actiontech.dble.backend.heartbeat.DBHeartbeat in project dble by actiontech.
the class ShowDatasourceCluster 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("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;
}
use of com.actiontech.dble.backend.heartbeat.DBHeartbeat in project dble by actiontech.
the class ShowDatasourceSynDetail method getRows.
private static List<RowDataPacket> getRows(String name, 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();
if (name.equals(ds.getName())) {
List<Record> data = record.getAsyncRecords();
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.parseLong(states.get("Master_Port"))));
row.add(StringUtil.encode(states.get("Master_User"), charset));
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;
}
Aggregations