use of io.mycat.net.mysql.EOFPacket in project Mycat-Server by MyCATApache.
the class ShowConnection method execute.
public static void execute(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.packetId;
String charset = c.getCharset();
NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
for (NIOProcessor p : processors) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (fc != null) {
RowDataPacket row = getRow(fc, charset);
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.EOFPacket in project Mycat-Server by MyCATApache.
the class ShowDataSource method execute.
public static void execute(ManagerConnection c, String name) {
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.packetId;
MycatConfig conf = MycatServer.getInstance().getConfig();
Map<String, List<PhysicalDatasource>> dataSources = new HashMap<String, List<PhysicalDatasource>>();
if (null != name) {
PhysicalDBNode dn = conf.getDataNodes().get(name);
if (dn != null) {
List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
dslst.addAll(dn.getDbPool().getAllDataSources());
dataSources.put(dn.getName(), dslst);
}
} else {
for (PhysicalDBNode dn : conf.getDataNodes().values()) {
List<PhysicalDatasource> dslst = new LinkedList<PhysicalDatasource>();
dslst.addAll(dn.getDbPool().getAllDataSources());
dataSources.put(dn.getName(), dslst);
}
}
for (Map.Entry<String, List<PhysicalDatasource>> dsEntry : dataSources.entrySet()) {
String dnName = dsEntry.getKey();
for (PhysicalDatasource ds : dsEntry.getValue()) {
RowDataPacket row = getRow(dnName, ds, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of io.mycat.net.mysql.EOFPacket in project Mycat-Server by MyCATApache.
the class ShowDatabase method execute.
public static void execute(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.packetId;
Map<String, SchemaConfig> schemas = MycatServer.getInstance().getConfig().getSchemas();
for (String name : new TreeSet<String>(schemas.keySet())) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(name, c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
// write lastEof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.EOFPacket in project Mycat-Server by MyCATApache.
the class ShowSQLHigh method execute.
public static void execute(ManagerConnection c, boolean isClear) {
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.packetId;
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<SqlFrequency> list = userStat.getSqlHigh().getSqlFrequency(isClear);
if (list != null) {
int i = 1;
for (SqlFrequency sqlFrequency : list) {
if (sqlFrequency != null) {
RowDataPacket row = getRow(i, user, sqlFrequency.getSql(), sqlFrequency.getCount(), sqlFrequency.getAvgTime(), sqlFrequency.getMaxTime(), sqlFrequency.getMinTime(), sqlFrequency.getExecuteTime(), sqlFrequency.getLastTime(), c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
i++;
}
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.EOFPacket in project Mycat-Server by MyCATApache.
the class ShowSQLSlow method execute.
public static void execute(ManagerConnection c, boolean isClear) {
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.packetId;
Map<String, UserStat> statMap = UserStatAnalyzer.getInstance().getUserStatMap();
for (UserStat userStat : statMap.values()) {
String user = userStat.getUser();
List<SQLRecord> keyList = userStat.getSqlRecorder().getRecords();
for (SQLRecord key : keyList) {
if (key != null) {
RowDataPacket row = getRow(user, key, c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
if (isClear) {
//读取慢SQL后,清理
userStat.getSqlRecorder().clear();
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations