use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class MultiNodeQueryHandler method rowResponse.
@Override
public boolean rowResponse(final byte[] row, RowDataPacket rowPacketNull, boolean isLeft, BackendConnection conn) {
if (errorResponse.get()) {
// conn.close(error);
return true;
}
lock.lock();
try {
this.selectRows++;
RouteResultsetNode rNode = (RouteResultsetNode) conn.getAttachment();
String dataNode = rNode.getName();
if (rrs.getLimitSize() >= 0) {
if (selectRows <= rrs.getLimitStart() || (selectRows > (rrs.getLimitStart() < 0 ? 0 : rrs.getLimitStart()) + rrs.getLimitSize())) {
return false;
}
}
RowDataPacket rowDataPkg = null;
// cache primaryKey-> dataNode
if (primaryKeyIndex != -1) {
rowDataPkg = new RowDataPacket(fieldCount);
rowDataPkg.read(row);
String primaryKey = new String(rowDataPkg.fieldValues.get(primaryKeyIndex));
LayerCachePool pool = DbleServer.getInstance().getRouterService().getTableId2DataNodeCache();
if (pool != null) {
pool.putIfAbsent(primaryKeyTable, primaryKey, dataNode);
}
}
row[3] = ++packetId;
if (prepared) {
if (rowDataPkg == null) {
rowDataPkg = new RowDataPacket(fieldCount);
rowDataPkg.read(row);
}
BinaryRowDataPacket binRowDataPk = new BinaryRowDataPacket();
binRowDataPk.read(fieldPackets, rowDataPkg);
binRowDataPk.write(byteBuffer, session.getSource(), true);
} else {
byteBuffer = session.getSource().writeToBuffer(row, byteBuffer);
}
} catch (Exception e) {
handleDataProcessException(e);
} finally {
lock.unlock();
}
return false;
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class MultiNodeQueryHandler method connectionAcquired.
@Override
public void connectionAcquired(final BackendConnection conn) {
final RouteResultsetNode node = (RouteResultsetNode) conn.getAttachment();
session.bindConnection(node, conn);
innerExecute(conn, node);
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class SingleNodeHandler method rowResponse.
@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
this.netOutBytes += row.length;
this.selectRows++;
row[3] = ++packetId;
RowDataPacket rowDataPk = null;
// cache primaryKey-> dataNode
if (primaryKeyIndex != -1) {
rowDataPk = new RowDataPacket(fieldCount);
rowDataPk.read(row);
String primaryKey = new String(rowDataPk.fieldValues.get(primaryKeyIndex));
RouteResultsetNode rNode = (RouteResultsetNode) conn.getAttachment();
LayerCachePool pool = DbleServer.getInstance().getRouterService().getTableId2DataNodeCache();
if (pool != null) {
pool.putIfAbsent(primaryKeyTable, primaryKey, rNode.getName());
}
}
if (prepared) {
if (rowDataPk == null) {
rowDataPk = new RowDataPacket(fieldCount);
rowDataPk.read(row);
}
BinaryRowDataPacket binRowDataPk = new BinaryRowDataPacket();
binRowDataPk.read(fieldPackets, rowDataPk);
binRowDataPk.setPacketId(rowDataPk.getPacketId());
buffer = binRowDataPk.write(buffer, session.getSource(), true);
} else {
buffer = session.getSource().writeToBuffer(row, allocBuffer());
// session.getSource().write(row);
}
return false;
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class UnLockTablesHandler method execute.
public void execute() {
Map<RouteResultsetNode, BackendConnection> lockedCons = session.getTargetMap();
this.reset(lockedCons.size());
// if client just send an unlock tables, theres is no lock tables statement, just send back OK
if (lockedCons.size() == 0) {
LOGGER.info("find no locked backend connection!" + session.getSource());
OkPacket ok = new OkPacket();
ok.setPacketId(++packetId);
// the size of unlock table's response OK packet is 7
ok.setPacketLength(7);
ok.setServerStatus(session.getSource().isAutocommit() ? 2 : 1);
ok.write(session.getSource());
return;
}
for (Map.Entry<RouteResultsetNode, BackendConnection> entry : lockedCons.entrySet()) {
RouteResultsetNode dataNode = entry.getKey();
RouteResultsetNode node = new RouteResultsetNode(dataNode.getName(), ServerParse.UNLOCK, srcStatement);
BackendConnection conn = lockedCons.get(dataNode);
if (clearIfSessionClosed(session)) {
return;
}
conn.setResponseHandler(this);
conn.setSession(session);
try {
conn.execute(node, session.getSource(), autocommit);
} catch (Exception e) {
connectionError(e, conn);
}
}
}
use of com.actiontech.dble.route.RouteResultsetNode in project dble by actiontech.
the class LockTablesHandler method connectionAcquired.
@Override
public void connectionAcquired(BackendConnection conn) {
final RouteResultsetNode node = (RouteResultsetNode) conn.getAttachment();
session.bindConnection(node, conn);
innerExecute(conn, node);
}
Aggregations