use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class OutputHandler method rowEofResponse.
@Override
public void rowEofResponse(byte[] data, boolean isLeft, BackendConnection conn) {
if (terminate.get()) {
return;
}
logger.info("--------sql execute end!");
ServerConnection source = session.getSource();
lock.lock();
try {
EOFPacket eofPacket = new EOFPacket();
if (data != null) {
eofPacket.read(data);
}
eofPacket.setPacketId(++packetId);
if (hasNext) {
eofPacket.setStatus(eofPacket.getStatus() | StatusFlags.SERVER_MORE_RESULTS_EXISTS);
}
HandlerTool.terminateHandlerTree(this);
byte[] eof = eofPacket.toBytes();
buffer = source.writeToBuffer(eof, buffer);
session.setResponseTime();
if (hasNext) {
source.write(buffer);
// source.executeNext(packetId, false);
} else {
// source.executeNext(packetId, false);
source.write(buffer);
}
} finally {
lock.unlock();
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class MultiNodeDdlHandler method rowEofResponse.
@Override
public void rowEofResponse(final byte[] eof, boolean isLeft, BackendConnection conn) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("on row end response " + conn);
}
if (errorResponse.get()) {
return;
}
final ServerConnection source = session.getSource();
if (clearIfSessionClosed(session)) {
return;
}
lock.lock();
try {
if (this.isFail() || session.closed()) {
tryErrorFinished(true);
return;
}
if (--nodeCount > 0)
return;
if (errConn) {
handleEndPacket(err.toBytes(), AutoTxOperation.ROLLBACK, conn);
} else {
try {
if (session.isPrepared()) {
handler.setPrepared(true);
}
handler.execute();
} catch (Exception e) {
LOGGER.warn(AlarmCode.CORE_DDL_WARN + String.valueOf(source) + oriRrs, e);
session.handleSpecial(oriRrs, source.getSchema(), false);
source.writeErrMessage(ErrorCode.ERR_HANDLE_DATA, e.toString());
}
if (session.isPrepared()) {
session.setPrepared(false);
}
}
} finally {
lock.unlock();
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class ShowSession 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();
for (NIOProcessor process : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection front : process.getFrontends().values()) {
if (!(front instanceof ServerConnection)) {
continue;
}
ServerConnection sc = (ServerConnection) front;
RowDataPacket row = getRow(sc, c.getCharset().getResults());
if (row != null) {
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);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class ShowBinlogStatus method getNeedWaitSession.
private static List<NonBlockingSession> getNeedWaitSession() {
List<NonBlockingSession> fcList = new ArrayList<>();
for (NIOProcessor process : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection front : process.getFrontends().values()) {
if (!(front instanceof ServerConnection)) {
continue;
}
ServerConnection sc = (ServerConnection) front;
NonBlockingSession session = sc.getSession2();
if (session.isNeedWaitFinished()) {
fcList.add(session);
}
}
}
return fcList;
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class ShowConnection method getRow.
private static RowDataPacket getRow(FrontendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(c.getProcessor().getName().getBytes());
row.add(LongUtil.toBytes(c.getId()));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(IntegerUtil.toBytes(c.getPort()));
row.add(IntegerUtil.toBytes(c.getLocalPort()));
row.add(StringUtil.encode(c.getUser(), charset));
row.add(StringUtil.encode(c.getSchema(), charset));
row.add(StringUtil.encode(c.getCharset().getClient(), charset));
row.add(StringUtil.encode(c.getCharset().getCollation(), charset));
row.add(StringUtil.encode(c.getCharset().getResults(), charset));
row.add(LongUtil.toBytes(c.getNetInBytes()));
row.add(LongUtil.toBytes(c.getNetOutBytes()));
row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
ByteBuffer bb = c.getReadBuffer();
row.add(IntegerUtil.toBytes(bb == null ? 0 : bb.capacity()));
row.add(IntegerUtil.toBytes(c.getWriteQueue().size()));
String txLevel = "";
String autocommit = "";
if (c instanceof ServerConnection) {
ServerConnection serverConn = (ServerConnection) c;
txLevel = serverConn.getTxIsolation() + "";
autocommit = serverConn.isAutocommit() + "";
}
row.add(txLevel.getBytes());
row.add(autocommit.getBytes());
row.add(StringUtil.encode(c.getStringOfSysVariables(), charset));
row.add(StringUtil.encode(c.getStringOfUsrVariables(), charset));
return row;
}
Aggregations