use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class ShowBackendOld method getRow.
private static RowDataPacket getRow(BackendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(c.getId()));
long threadId = 0;
if (c instanceof MySQLConnection) {
threadId = ((MySQLConnection) c).getThreadId();
}
row.add(LongUtil.toBytes(threadId));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(IntegerUtil.toBytes(c.getPort()));
row.add(IntegerUtil.toBytes(c.getLocalPort()));
row.add(LongUtil.toBytes(c.getNetInBytes()));
row.add(LongUtil.toBytes(c.getNetOutBytes()));
row.add(LongUtil.toBytes((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000L));
row.add(LongUtil.toBytes(c.getLastTime()));
boolean isBorrowed = c.isBorrowed();
row.add(isBorrowed ? "true".getBytes() : "false".getBytes());
return row;
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class ConMap method clearConnections.
public void clearConnections(String reason, PhysicalDatasource dataSource) {
for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
ConcurrentMap<Long, BackendConnection> map = processor.getBackends();
Iterator<Entry<Long, BackendConnection>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Entry<Long, BackendConnection> entry = iterator.next();
BackendConnection con = entry.getValue();
if (con instanceof MySQLConnection) {
if (((MySQLConnection) con).getPool() == dataSource) {
con.close(reason);
iterator.remove();
}
}
}
}
items.clear();
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class NIOProcessor method backendCheck.
private void backendCheck() {
long sqlTimeout = DbleServer.getInstance().getConfig().getSystem().getSqlExecuteTimeout() * 1000L;
Iterator<Entry<Long, BackendConnection>> it = backends.entrySet().iterator();
while (it.hasNext()) {
BackendConnection c = it.next().getValue();
// remove empty
if (c == null) {
it.remove();
continue;
}
// Active/IDLE/PREPARED XA backends will not be checked
if (c instanceof MySQLConnection) {
MySQLConnection m = (MySQLConnection) c;
if (m.isClosedOrQuit()) {
it.remove();
continue;
}
if (m.getXaStatus() != null && m.getXaStatus() != TxState.TX_INITIALIZE_STATE) {
continue;
}
}
// close the conn which executeTimeOut
if (!c.isDDL() && c.isBorrowed() && c.getLastTime() < TimeUtil.currentTimeMillis() - sqlTimeout) {
LOGGER.info("found backend connection SQL timeout ,close it " + c);
c.close("sql timeout");
}
// clean closed conn or check time out
if (c.isClosed()) {
it.remove();
} else {
// very important ,for some data maybe not sent
if (c instanceof AbstractConnection) {
checkConSendQueue((AbstractConnection) c);
}
c.idleCheck();
}
}
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class NonBlockingSession method freshConn.
public MySQLConnection freshConn(MySQLConnection errConn, ResponseHandler queryHandler) {
for (final RouteResultsetNode node : this.getTargetKeys()) {
final MySQLConnection mysqlCon = (MySQLConnection) this.getTarget(node);
if (errConn.equals(mysqlCon)) {
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
try {
MySQLConnection newConn = (MySQLConnection) dn.getConnection(dn.getDatabase(), errConn.isAutocommit(), false);
newConn.setXaStatus(errConn.getXaStatus());
if (!newConn.setResponseHandler(queryHandler)) {
return errConn;
}
this.bindConnection(node, newConn);
return newConn;
} catch (Exception e) {
return errConn;
}
}
}
return errConn;
}
use of com.actiontech.dble.backend.mysql.nio.MySQLConnection in project dble by actiontech.
the class NotInHandler method ownThreadJob.
@Override
protected void ownThreadJob(Object... objects) {
MySQLConnection conn = (MySQLConnection) objects[0];
LocalResult leftLocal = null, rightLocal = null;
try {
Comparator<RowDataPacket> notInComparator = new TwoTableComparator(leftFieldPackets, rightFieldPackets, leftOrders, rightOrders, this.isAllPushDown(), this.type());
leftLocal = takeFirst(leftQueue);
rightLocal = takeFirst(rightQueue);
while (true) {
RowDataPacket leftRow = leftLocal.getLastRow();
RowDataPacket rightRow = rightLocal.getLastRow();
if (leftRow.getFieldCount() == 0) {
break;
}
if (rightRow.getFieldCount() == 0) {
sendLeft(leftLocal, conn);
leftLocal.close();
leftLocal = takeFirst(leftQueue);
continue;
}
int rs = notInComparator.compare(leftRow, rightRow);
if (rs < 0) {
sendLeft(leftLocal, conn);
leftLocal.close();
leftLocal = takeFirst(leftQueue);
continue;
} else if (rs > 0) {
rightLocal.close();
rightLocal = takeFirst(rightQueue);
} else {
// because not in, if equal left should move to next value
leftLocal.close();
rightLocal.close();
leftLocal = takeFirst(leftQueue);
rightLocal = takeFirst(rightQueue);
}
}
nextHandler.rowEofResponse(null, isLeft, conn);
HandlerTool.terminateHandlerTree(this);
} catch (Exception e) {
String msg = "notIn thread error, " + e.getLocalizedMessage();
LOGGER.info(msg, e);
session.onQueryError(msg.getBytes());
} finally {
if (leftLocal != null)
leftLocal.close();
if (rightLocal != null)
rightLocal.close();
}
}
Aggregations