use of com.actiontech.dble.backend.mysql.store.LocalResult 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.backend.mysql.store.LocalResult 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();
}
}
use of com.actiontech.dble.backend.mysql.store.LocalResult in project dble by actiontech.
the class NotInHandler method addEndRowToDeque.
/**
* only for terminate.
*
* @param row
* @param columnCount
* @param deque
* @throws InterruptedException
*/
private void addEndRowToDeque(RowDataPacket row, int columnCount, FairLinkedBlockingDeque<LocalResult> deque) throws InterruptedException {
LocalResult newLocalResult = new UnSortedLocalResult(columnCount, pool, this.charset).setMemSizeController(session.getJoinBufferMC());
newLocalResult.add(row);
newLocalResult.done();
LocalResult localResult = deque.addOrReplaceLast(newLocalResult);
if (localResult != null)
localResult.close();
}
use of com.actiontech.dble.backend.mysql.store.LocalResult in project dble by actiontech.
the class NotInHandler method takeFirst.
private LocalResult takeFirst(FairLinkedBlockingDeque<LocalResult> deque) throws InterruptedException {
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();
}
}
use of com.actiontech.dble.backend.mysql.store.LocalResult in project dble by actiontech.
the class JoinHandler method clearDeque.
private void clearDeque(FairLinkedBlockingDeque<LocalResult> deque) {
if (deque == null)
return;
LocalResult local = deque.poll();
while (local != null) {
local.close();
local = deque.poll();
}
}
Aggregations