use of com.actiontech.dble.net.mysql.RowDataPacket 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.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowDatasourceSyn method response.
public static void response(ManagerConnection c) {
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.getPacketId();
for (RowDataPacket row : getRows(c.getCharset().getResults())) {
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowDatasourceSynDetail method response.
public static void response(ManagerConnection c, String stmt) {
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.getPacketId();
String name = ManagerParseShow.getWhereParameter(stmt);
for (RowDataPacket row : getRows(name, c.getCharset().getResults())) {
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowDirectMemory method showDirectMemoryDetail.
private static void showDirectMemoryDetail(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = DETAIL_HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : DETAIL_FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = DETAIL_EOF.write(buffer, c, true);
// write rows
byte packetId = DETAIL_EOF.getPacketId();
ConcurrentMap<Long, Long> networkBufferPool = DbleServer.getInstance().getBufferPool().getNetDirectMemoryUsage();
for (Map.Entry<Long, Long> entry : networkBufferPool.entrySet()) {
RowDataPacket row = new RowDataPacket(DETAIL_FIELD_COUNT);
long value = entry.getValue();
row.add(StringUtil.encode(String.valueOf(entry.getKey()), c.getCharset().getResults()));
/* DIRECT_MEMORY belong to Buffer Pool */
row.add(StringUtil.encode("NetWorkBufferPool", c.getCharset().getResults()));
row.add(StringUtil.encode(value > 0 ? JavaUtils.bytesToString2(value) : "0", c.getCharset().getResults()));
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowDirectMemory method showDirectMemoryTotal.
private static void showDirectMemoryTotal(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = TOTAL_HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : TOTAL_FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = TOTAL_EOF.write(buffer, c, true);
ConcurrentMap<Long, Long> networkBufferPool = DbleServer.getInstance().getBufferPool().getNetDirectMemoryUsage();
RowDataPacket row = new RowDataPacket(TOTAL_FIELD_COUNT);
long usedForNetwork = 0;
/* the value of -XX:MaxDirectMemorySize */
long totalAvailable = Platform.getMaxDirectMemory();
row.add(StringUtil.encode(JavaUtils.bytesToString2(totalAvailable), c.getCharset().getResults()));
/* IO packet used in DirectMemory in buffer pool */
for (Map.Entry<Long, Long> entry : networkBufferPool.entrySet()) {
usedForNetwork += entry.getValue();
}
row.add(StringUtil.encode(JavaUtils.bytesToString2(usedForNetwork), c.getCharset().getResults()));
row.add(StringUtil.encode(JavaUtils.bytesToString2(totalAvailable - usedForNetwork), c.getCharset().getResults()));
// write rows
byte packetId = TOTAL_EOF.getPacketId();
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations