use of io.mycat.net.mysql.EOFPacket in project Mycat-Server by MyCATApache.
the class EngineCtx method writeEof.
public void writeEof() {
ServerConnection sc = session.getSource();
EOFPacket eofPckg = new EOFPacket();
eofPckg.packetId = incPackageId();
ByteBuffer buf = eofPckg.write(sc.allocate(), sc, false);
sc.write(buf);
LOGGER.info("write eof ,packgId:" + eofPckg.packetId);
}
use of io.mycat.net.mysql.EOFPacket in project Mycat-Server by MyCATApache.
the class EngineCtx method writeHeader.
public void writeHeader(List<byte[]> afields) {
if (headerWrited.compareAndSet(false, true)) {
try {
writeLock.lock();
// write new header
ResultSetHeaderPacket headerPkg = new ResultSetHeaderPacket();
// -1;
headerPkg.fieldCount = afields.size();
headerPkg.packetId = incPackageId();
LOGGER.debug("packge id " + headerPkg.packetId);
ServerConnection sc = session.getSource();
ByteBuffer buf = headerPkg.write(sc.allocate(), sc, true);
// wirte a fields
for (byte[] field : afields) {
field[3] = incPackageId();
buf = sc.writeToBuffer(field, buf);
}
// write field eof
EOFPacket eofPckg = new EOFPacket();
eofPckg.packetId = incPackageId();
buf = eofPckg.write(buf, sc, true);
sc.write(buf);
//LOGGER.info("header outputed ,packgId:" + eofPckg.packetId);
} finally {
writeLock.unlock();
}
}
}
use of io.mycat.net.mysql.EOFPacket in project Mycat_plus by coderczp.
the class PackageBufINf method handle.
public static void handle(String stmt, 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;
PackageBufINf bufInf = null;
// show log key=warn limit=0,30
Map<String, String> condPairMap = getCondPair(stmt);
if (condPairMap.isEmpty()) {
bufInf = showLogSum(c, buffer, packetId);
} else {
String logFile = condPairMap.get("file");
if (logFile == null) {
logFile = DEFAULT_LOGFILE;
}
String limitStr = condPairMap.get("limit");
limitStr = (limitStr != null) ? limitStr : "0," + 100000;
String[] limtArry = limitStr.split("\\s|,");
int start = Integer.parseInt(limtArry[0]);
int page = Integer.parseInt(limtArry[1]);
int end = Integer.valueOf(start + page);
String key = condPairMap.get("key");
String regex = condPairMap.get("regex");
bufInf = showLogRange(c, buffer, packetId, key, regex, start, end, logFile);
}
packetId = bufInf.packetId;
buffer = bufInf.buffer;
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_plus by coderczp.
the class SelectSessionAutoIncrement 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;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.packetId = ++packetId;
row.add(LongUtil.toBytes(1));
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_plus by coderczp.
the class SelectVersionComment 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;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(VERSION_COMMENT);
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);
}
Aggregations