use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class MultiNodeSelectHandler method rowResponse.
@Override
public boolean rowResponse(final byte[] row, RowDataPacket rowPacketNull, boolean isLeft, BackendConnection conn) {
if (errorResponse.get() || noNeedRows) {
return true;
}
BlockingQueue<HeapItem> queue = queues.get(conn);
if (queue == null)
return true;
RowDataPacket rp = new RowDataPacket(fieldCount);
rp.read(row);
HeapItem item = new HeapItem(row, rp, (MySQLConnection) conn);
try {
queue.put(item);
} catch (InterruptedException e) {
LOGGER.info("rowResponse error", e);
}
return false;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class ShowVariablesHandler method rowResponse.
@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
String charset = session.getSource().getCharset().getResults();
RowDataPacket rowDataPacket = new RowDataPacket(2);
/* Fixme: the accurate statistics of netOutBytes.
*
* We read net packet, but don't do Stat here. So the statistical magnitude -- netOutBytes is not exact.
* Of course, we can do that.
* But it is tiresome: re-implement the function of method rowResponse that have been implemented in super class.
*/
rowDataPacket.read(row);
String varName = StringUtil.decode(rowDataPacket.fieldValues.get(0), charset);
if (shadowVars.containsKey(varName)) {
rowDataPacket.setValue(1, StringUtil.encode(shadowVars.get(varName), charset));
super.rowResponse(rowDataPacket.toBytes(), rowPacket, isLeft, conn);
} else {
super.rowResponse(row, rowPacket, isLeft, conn);
}
return false;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class JoinHandler method rowEofResponse.
@Override
public void rowEofResponse(byte[] data, boolean isLeft, BackendConnection conn) {
logger.debug("roweof");
if (terminate.get()) {
return;
}
RowDataPacket eofRow = new RowDataPacket(0);
try {
if (isLeft) {
logger.debug("row eof left");
addRowToDeque(eofRow, leftFieldPackets.size(), leftQueue, leftComparator);
} else {
logger.debug("row eof right");
addRowToDeque(eofRow, rightFieldPackets.size(), rightQueue, rightComparator);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class JoinHandler method ownThreadJob.
@Override
protected void ownThreadJob(Object... objects) {
MySQLConnection conn = (MySQLConnection) objects[0];
LocalResult leftLocal = null, rightLocal = null;
try {
Comparator<RowDataPacket> joinComparator = new TwoTableComparator(leftFieldPackets, rightFieldPackets, leftOrders, rightOrders, this.isAllPushDown(), this.type());
// logger.debug("merge Join start");
leftLocal = takeFirst(leftQueue);
rightLocal = takeFirst(rightQueue);
while (true) {
if (terminate.get())
return;
RowDataPacket leftRow = leftLocal.getLastRow();
RowDataPacket rightRow = rightLocal.getLastRow();
if (leftRow.getFieldCount() == 0) {
break;
}
if (rightRow.getFieldCount() == 0) {
if (isLeftJoin) {
if (connectLeftAndNull(leftLocal, conn))
break;
leftLocal = takeFirst(leftQueue);
continue;
} else {
break;
}
}
int rs = joinComparator.compare(leftRow, rightRow);
if (rs < 0) {
if (isLeftJoin) {
if (connectLeftAndNull(leftLocal, conn))
break;
leftLocal = takeFirst(leftQueue);
continue;
} else {
leftLocal.close();
leftLocal = takeFirst(leftQueue);
}
} else if (rs > 0) {
rightLocal.close();
rightLocal = takeFirst(rightQueue);
} else {
if (connectLeftAndRight(leftLocal, rightLocal, conn))
break;
leftLocal = takeFirst(leftQueue);
rightLocal = takeFirst(rightQueue);
}
}
nextHandler.rowEofResponse(null, isLeft, conn);
HandlerTool.terminateHandlerTree(this);
} catch (Exception e) {
String msg = "join thread error, " + e.getLocalizedMessage();
logger.info(msg, e);
session.onQueryError(msg.getBytes());
} finally {
if (leftLocal != null)
leftLocal.close();
if (rightLocal != null)
rightLocal.close();
}
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class JoinHandler method takeFirst.
private LocalResult takeFirst(FairLinkedBlockingDeque<LocalResult> deque) throws InterruptedException {
/**
* it must be in single thread
*/
deque.waitUtilCount(1);
LocalResult result = deque.peekFirst();
RowDataPacket lastRow = result.getLastRow();
if (lastRow.getFieldCount() == 0)
return deque.takeFirst();
else {
deque.waitUtilCount(2);
return deque.takeFirst();
}
}
Aggregations