use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class SelectVersionComment method response.
public static void response(ServerConnection 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 = new RowDataPacket(FIELD_COUNT);
row.add(VERSION_COMMENT);
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowCobarCluster method getRows.
private static List<RowDataPacket> getRows(ServerConnection c) {
List<RowDataPacket> rows = new LinkedList<RowDataPacket>();
CobarConfig config = CobarServer.getInstance().getConfig();
CobarCluster cluster = config.getCluster();
Map<String, SchemaConfig> schemas = config.getSchemas();
SchemaConfig schema = (c.getSchema() == null) ? null : schemas.get(c.getSchema());
// 如果没有指定schema或者schema为null,则使用全部集群。
if (schema == null) {
Map<String, CobarNode> nodes = cluster.getNodes();
for (CobarNode n : nodes.values()) {
if (n != null && n.isOnline()) {
rows.add(getRow(n, c.getCharset()));
}
}
} else {
String group = (schema.getGroup() == null) ? "default" : schema.getGroup();
List<String> nodeList = cluster.getGroups().get(group);
if (nodeList != null && nodeList.size() > 0) {
Map<String, CobarNode> nodes = cluster.getNodes();
for (String id : nodeList) {
CobarNode n = nodes.get(id);
if (n != null && n.isOnline()) {
rows.add(getRow(n, c.getCharset()));
}
}
}
// 如果schema对应的group或者默认group都没有有效的节点,则使用全部集群。
if (rows.size() == 0) {
Map<String, CobarNode> nodes = cluster.getNodes();
for (CobarNode n : nodes.values()) {
if (n != null && n.isOnline()) {
rows.add(getRow(n, c.getCharset()));
}
}
}
}
if (rows.size() == 0) {
alarm.error(Alarms.CLUSTER_EMPTY + c.toString());
}
return rows;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ExplainHandler method handle.
public static void handle(String stmt, ServerConnection c, int offset) {
stmt = stmt.substring(offset);
RouteResultset rrs = getRouteResultset(c, stmt);
if (rrs == null)
return;
ByteBuffer buffer = c.allocate();
// write header
ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
byte packetId = header.packetId;
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
field.packetId = ++packetId;
buffer = field.write(buffer, c);
}
// write eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c);
// write rows
RouteResultsetNode[] rrsn = (rrs != null) ? rrs.getNodes() : EMPTY_ARRAY;
for (RouteResultsetNode node : rrsn) {
RowDataPacket row = getRow(node, 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);
// post write
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ExplainHandler method getRow.
private static RowDataPacket getRow(RouteResultsetNode node, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(node.getName(), charset));
row.add(StringUtil.encode(node.getStatement(), charset));
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowThreadPool 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;
List<NameableExecutor> executors = getExecutors();
for (NameableExecutor exec : executors) {
if (exec != null) {
RowDataPacket row = getRow(exec, 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