use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class ResetConnHandler method okResponse.
@Override
public void okResponse(byte[] ok, BackendConnection conn) {
MySQLConnection mysqlConn = (MySQLConnection) conn;
mysqlConn.resetContextStatus();
conn.release();
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection 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.nio.MySQLConnection in project dble by actiontech.
the class BaseSelectHandler method initConnection.
public MySQLConnection initConnection() throws Exception {
if (session.closed()) {
return null;
}
MySQLConnection exeConn = (MySQLConnection) session.getTarget(rrss);
if (session.tryExistsCon(exeConn, rrss)) {
return exeConn;
} else {
PhysicalDBNode dn = DbleServer.getInstance().getConfig().getDataNodes().get(rrss.getName());
// autocommit is session.getSource().isAutocommit() && !session.getSource().isTxStart()
final BackendConnection newConn = dn.getConnection(dn.getDatabase(), autocommit, autocommit);
session.bindConnection(rrss, newConn);
return (MySQLConnection) newConn;
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class MultiNodeMergeHandler method rowResponse.
@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
if (terminate.get() || noNeedRows)
return true;
if (isEasyMerge) {
nextHandler.rowResponse(null, rowPacket, this.isLeft, conn);
} else {
MySQLConnection mySQLConn = (MySQLConnection) conn;
BlockingQueue<HeapItem> queue = queues.get(mySQLConn);
if (queue == null)
return true;
HeapItem item = new HeapItem(row, rowPacket, mySQLConn);
try {
queue.put(item);
} catch (InterruptedException e) {
// ignore error
}
}
return false;
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class FetchStoreNodeOfChildTableHandler method execute.
public String execute(String schema, ArrayList<String> dataNodes) {
String key = schema + ":" + sql;
CachePool cache = DbleServer.getInstance().getCacheService().getCachePool("ER_SQL2PARENTID");
if (cache != null) {
String cacheResult = (String) cache.get(key);
if (cacheResult != null) {
return cacheResult;
}
}
int totalCount = dataNodes.size();
LOGGER.debug("find child node with sql:" + sql);
for (String dn : dataNodes) {
if (!LOGGER.isDebugEnabled()) {
// no early return when debug
if (dataNode != null) {
LOGGER.debug(" found return ");
return dataNode;
}
}
PhysicalDBNode mysqlDN = DbleServer.getInstance().getConfig().getDataNodes().get(dn);
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("execute in data_node " + dn);
}
RouteResultsetNode node = new RouteResultsetNode(dn, ServerParse.SELECT, sql);
// get child node from master
node.setRunOnSlave(false);
BackendConnection conn = session.getTarget(node);
if (session.tryExistsCon(conn, node)) {
if (session.closed()) {
session.clearResources(true);
return null;
}
conn.setResponseHandler(this);
conn.setSession(session);
((MySQLConnection) conn).setComplexQuery(true);
conn.execute(node, session.getSource(), isAutoCommit());
} else {
mysqlDN.getConnection(mysqlDN.getDatabase(), session.getSource().isTxStart(), session.getSource().isAutocommit(), node, this, node);
}
} catch (Exception e) {
LOGGER.info("get connection err " + e);
}
}
lock.lock();
try {
while (dataNode == null) {
try {
result.await(50, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
break;
}
if (dataNode != null || finished.get() >= totalCount) {
break;
}
}
} finally {
lock.unlock();
}
if (!LOGGER.isDebugEnabled()) {
// no cached when debug
if (dataNode != null && cache != null) {
cache.putIfAbsent(key, dataNode);
}
}
return dataNode;
}
Aggregations