use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowSQLExecute method getRow.
private static RowDataPacket getRow(long id, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(id));
row.add(LongUtil.toBytes(100L));
row.add(StringUtil.encode(nf.format(898.9), charset));
row.add(StringUtil.encode(nf.format(8.8), charset));
row.add(StringUtil.encode(nf.format(1.0), charset));
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowSQLSlow method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
SQLRecord[] records = CobarServer.getInstance().getSqlRecorder().getRecords();
for (int i = records.length - 1; i >= 0; i--) {
if (records[i] != null) {
RowDataPacket row = getRow(records[i], c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowSQLSlow method getRow.
private static RowDataPacket getRow(SQLRecord sql, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(sql.host, charset));
row.add(StringUtil.encode(sql.schema, charset));
row.add(StringUtil.encode(sql.dataNode, charset));
row.add(IntegerUtil.toBytes(sql.dataNodeIndex));
row.add(LongUtil.toBytes(sql.startTime));
row.add(LongUtil.toBytes(sql.executeTime));
row.add(StringUtil.encode(sql.statement, charset));
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowServer method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
RowDataPacket row = getRow(c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowSlow method dataNode.
public static void dataNode(ManagerConnection c, String name) {
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
CobarConfig conf = CobarServer.getInstance().getConfig();
MySQLDataNode dn = conf.getDataNodes().get(name);
MySQLDataSource ds = null;
if (dn != null && (ds = dn.getSource()) != null) {
SQLRecord[] records = ds.getSqlRecorder().getRecords();
for (int i = records.length - 1; i >= 0; i--) {
if (records[i] != null) {
RowDataPacket row = getRow(records[i], c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
Aggregations