use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class ShowTablesHandler method fieldEofResponse.
@Override
public void fieldEofResponse(byte[] header, List<byte[]> fields, List<FieldPacket> fieldPacketsNull, byte[] eof, boolean isLeft, BackendConnection conn) {
ServerConnection source = session.getSource();
buffer = allocBuffer();
PackageBufINf bufInf;
if (info.isFull()) {
List<FieldPacket> fieldPackets = new ArrayList<>(2);
bufInf = ShowTables.writeFullTablesHeader(buffer, source, showTableSchema, fieldPackets);
packetId = bufInf.getPacketId();
buffer = bufInf.getBuffer();
if (info.getWhere() != null) {
MySQLItemVisitor mev = new MySQLItemVisitor(source.getSchema(), source.getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager());
info.getWhereExpr().accept(mev);
sourceFields = HandlerTool.createFields(fieldPackets);
whereItem = HandlerTool.createItem(mev.getItem(), sourceFields, 0, false, DMLResponseHandler.HandlerType.WHERE);
bufInf = ShowTables.writeFullTablesRow(buffer, source, shardingTablesMap, packetId, whereItem, sourceFields);
packetId = bufInf.getPacketId();
buffer = bufInf.getBuffer();
} else {
bufInf = ShowTables.writeFullTablesRow(buffer, source, shardingTablesMap, packetId, null, null);
packetId = bufInf.getPacketId();
buffer = bufInf.getBuffer();
}
} else {
bufInf = ShowTables.writeTablesHeaderAndRows(buffer, source, shardingTablesMap, showTableSchema);
packetId = bufInf.getPacketId();
buffer = bufInf.getBuffer();
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class SingleNodeHandler method execute.
public void execute() throws Exception {
startTime = System.currentTimeMillis();
ServerConnection sc = session.getSource();
waitingResponse = true;
this.packetId = 0;
final BackendConnection conn = session.getTarget(node);
node.setRunOnSlave(rrs.getRunOnSlave());
if (session.tryExistsCon(conn, node)) {
execute(conn);
} else {
// create new connection
node.setRunOnSlave(rrs.getRunOnSlave());
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
dn.getConnection(dn.getDatabase(), session.getSource().isTxStart(), sc.isAutocommit(), node, this, node);
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class SingleNodeHandler method rowEofResponse.
/**
* select
* <p>
* write EOF to Queue
*/
@Override
public void rowEofResponse(byte[] eof, boolean isLeft, BackendConnection conn) {
this.netOutBytes += eof.length;
ServerConnection source = session.getSource();
// if it's call statement,it will not release connection
if (!rrs.isCallStatement() || rrs.getProcedure().isResultSimpleValue()) {
session.releaseConnectionIfSafe(conn, false);
}
eof[3] = ++packetId;
buffer = source.writeToBuffer(eof, allocBuffer());
int resultSize = source.getWriteQueue().size() * DbleServer.getInstance().getConfig().getSystem().getBufferPoolPageSize();
resultSize = resultSize + buffer.position();
session.setResponseTime();
source.write(buffer);
waitingResponse = false;
if (DbleServer.getInstance().getConfig().getSystem().getUseSqlStat() == 1) {
if (rrs.getStatement() != null) {
netInBytes += rrs.getStatement().getBytes().length;
}
QueryResult queryResult = new QueryResult(session.getSource().getUser(), rrs.getSqlType(), rrs.getStatement(), selectRows, netInBytes, netOutBytes, startTime, System.currentTimeMillis(), resultSize);
QueryResultDispatcher.dispatchQuery(queryResult);
}
}
use of com.actiontech.dble.server.ServerConnection in project dble by actiontech.
the class OutputHandler method okResponse.
@Override
public void okResponse(byte[] ok, BackendConnection conn) {
OkPacket okPacket = new OkPacket();
okPacket.read(ok);
ServerConnection source = session.getSource();
lock.lock();
try {
ok[3] = ++packetId;
if ((okPacket.getServerStatus() & StatusFlags.SERVER_MORE_RESULTS_EXISTS) > 0) {
buffer = source.writeToBuffer(ok, buffer);
} else {
HandlerTool.terminateHandlerTree(this);
if (hasNext) {
okPacket.setServerStatus(okPacket.getServerStatus() | StatusFlags.SERVER_MORE_RESULTS_EXISTS);
}
buffer = source.writeToBuffer(ok, buffer);
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 handleEndPacket.
private void handleEndPacket(byte[] data, AutoTxOperation txOperation, BackendConnection conn) {
ServerConnection source = session.getSource();
boolean inTransaction = !source.isAutocommit() || source.isTxStart();
if (!inTransaction) {
// normal query
session.releaseConnection(conn);
}
// Explicit distributed transaction
if (inTransaction && (AutoTxOperation.ROLLBACK == txOperation)) {
source.setTxInterrupt("ROLLBACK");
}
if (nodeCount == 0) {
session.getSource().write(data);
}
}
Aggregations