use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class SelectSessionTxReadOnly 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.getPacketId();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.setPacketId(++packetId);
row.add(LongUtil.toBytes(0));
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 ShowBackend method getRow.
private static RowDataPacket getRow(BackendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
if (!(c instanceof MySQLConnection)) {
return null;
}
MySQLConnection conn = (MySQLConnection) c;
row.add(conn.getProcessor().getName().getBytes());
row.add(LongUtil.toBytes(c.getId()));
row.add(LongUtil.toBytes(conn.getThreadId()));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(IntegerUtil.toBytes(c.getPort()));
row.add(IntegerUtil.toBytes(c.getLocalPort()));
row.add(LongUtil.toBytes(c.getNetInBytes()));
row.add(LongUtil.toBytes(c.getNetOutBytes()));
row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
row.add(c.isClosed() ? "true".getBytes() : "false".getBytes());
row.add(c.isBorrowed() ? "true".getBytes() : "false".getBytes());
row.add(IntegerUtil.toBytes(conn.getWriteQueue().size()));
row.add(conn.getSchema().getBytes());
row.add(conn.getCharset().getClient().getBytes());
row.add(conn.getCharset().getCollation().getBytes());
row.add(conn.getCharset().getResults().getBytes());
row.add((conn.getTxIsolation() + "").getBytes());
row.add((conn.isAutocommit() + "").getBytes());
row.add(StringUtil.encode(conn.getStringOfSysVariables(), charset));
row.add(StringUtil.encode(conn.getStringOfUsrVariables(), charset));
row.add(StringUtil.encode(conn.getXaStatus().toString(), charset));
return row;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowBackendOld method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = HEADER.write(buffer, c, true);
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
buffer = EOF.write(buffer, c, true);
byte packetId = EOF.getPacketId();
for (BackendConnection bc : NIOProcessor.BACKENDS_OLD) {
if (bc != null) {
RowDataPacket row = getRow(bc, c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowBackendOld method getRow.
private static RowDataPacket getRow(BackendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(c.getId()));
long threadId = 0;
if (c instanceof MySQLConnection) {
threadId = ((MySQLConnection) c).getThreadId();
}
row.add(LongUtil.toBytes(threadId));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(IntegerUtil.toBytes(c.getPort()));
row.add(IntegerUtil.toBytes(c.getLocalPort()));
row.add(LongUtil.toBytes(c.getNetInBytes()));
row.add(LongUtil.toBytes(c.getNetOutBytes()));
row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
row.add(LongUtil.toBytes(c.getLastTime()));
boolean isBorrowed = c.isBorrowed();
row.add(isBorrowed ? "true".getBytes() : "false".getBytes());
return row;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowTableDataNode method execute.
public static void execute(ManagerConnection c, String tableInfo) {
Matcher ma = PATTERN_FOR_TABLE_INFO.matcher(tableInfo);
if (!ma.matches()) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "The Correct Query Format Is:show @@datanodes where schema=? and table =?");
return;
}
String schemaName = ma.group(2);
String tableName = ma.group(4);
if (DbleServer.getInstance().getSystemVariables().isLowerCaseTableNames()) {
schemaName = schemaName.toLowerCase();
tableName = tableName.toLowerCase();
}
SchemaConfig schemaConfig = DbleServer.getInstance().getConfig().getSchemas().get(schemaName);
List<String> dataNodes;
if (schemaConfig == null) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "the schema [" + schemaName + "] does not exists");
return;
} else if (schemaConfig.isNoSharding()) {
dataNodes = Collections.singletonList(schemaConfig.getDataNode());
} else {
TableConfig tableConfig = schemaConfig.getTables().get(tableName);
if (tableConfig == null) {
if (schemaConfig.getDataNode() == null) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, "the table [" + tableName + "] in schema [" + schemaName + "] does not exists");
return;
} else {
dataNodes = Collections.singletonList(schemaConfig.getDataNode());
}
} else {
dataNodes = tableConfig.getDataNodes();
}
}
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(dataNodes, 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);
}
Aggregations