use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class ReloadConfig method findAndcloseFrontCon.
private static void findAndcloseFrontCon(BackendConnection con) {
if (con instanceof MySQLConnection) {
MySQLConnection mcon1 = (MySQLConnection) con;
for (NIOProcessor processor : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection fcon : processor.getFrontends().values()) {
if (fcon instanceof ServerConnection) {
ServerConnection scon = (ServerConnection) fcon;
Map<RouteResultsetNode, BackendConnection> bons = scon.getSession2().getTargetMap();
for (BackendConnection bcon : bons.values()) {
if (bcon instanceof MySQLConnection) {
MySQLConnection mcon2 = (MySQLConnection) bcon;
if (mcon1 == mcon2) {
scon.killAndClose("reload config all");
return;
}
}
}
}
}
}
}
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class ShowSession method getRow.
private static RowDataPacket getRow(ServerConnection sc, String charset) {
StringBuilder sb = new StringBuilder();
NonBlockingSession session = sc.getSession2();
Collection<BackendConnection> backConnections = session.getTargetMap().values();
int cnCount = backConnections.size();
if (cnCount == 0) {
return null;
}
for (BackendConnection backCon : backConnections) {
sb.append(backCon).append("\r\n");
}
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(sc.getId() + "", charset));
row.add(StringUtil.encode(cnCount + "", charset));
row.add(StringUtil.encode(sb.toString(), charset));
return row;
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class NonBlockingSession method kill.
protected void kill() {
AtomicInteger count = new AtomicInteger(0);
Map<RouteResultsetNode, BackendConnection> toKilled = new HashMap<>();
for (Map.Entry<RouteResultsetNode, BackendConnection> entry : target.entrySet()) {
BackendConnection c = entry.getValue();
if (c != null && !c.isDDL()) {
toKilled.put(entry.getKey(), c);
count.incrementAndGet();
} else if (c != null && c.isDDL()) {
// if the sql executing is a ddl,do not kill the query,just close the connection
this.terminate();
return;
}
}
for (Entry<RouteResultsetNode, BackendConnection> en : toKilled.entrySet()) {
KillConnectionHandler kill = new KillConnectionHandler(en.getValue(), this);
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(en.getKey().getName());
try {
dn.getConnectionFromSameSource(en.getValue().getSchema(), true, en.getValue(), kill, en.getKey());
} catch (Exception e) {
LOGGER.info("get killer connection failed for " + en.getKey(), e);
kill.connectionError(e, null);
}
}
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class MultiNodeSelectHandler method ownThreadJob.
private void ownThreadJob() {
try {
ArrayMinHeap<HeapItem> heap = new ArrayMinHeap<>(new Comparator<HeapItem>() {
@Override
public int compare(HeapItem o1, HeapItem o2) {
RowDataPacket row1 = o1.getRowPacket();
RowDataPacket row2 = o2.getRowPacket();
if (row1 == null || row2 == null) {
if (row1 == row2)
return 0;
if (row1 == null)
return -1;
return 1;
}
return rowComparator.compare(row1, row2);
}
});
// init heap
for (Map.Entry<BackendConnection, BlockingQueue<HeapItem>> entry : queues.entrySet()) {
HeapItem firstItem = entry.getValue().take();
heap.add(firstItem);
}
while (!heap.isEmpty()) {
if (isFail())
return;
HeapItem top = heap.peak();
if (top.isNullItem()) {
heap.poll();
} else {
BlockingQueue<HeapItem> topItemQueue = queues.get(top.getIndex());
HeapItem item = topItemQueue.take();
heap.replaceTop(item);
// limit
this.selectRows++;
if (rrs.getLimitSize() >= 0) {
if (selectRows <= rrs.getLimitStart()) {
continue;
} else if (selectRows > (rrs.getLimitStart() < 0 ? 0 : rrs.getLimitStart()) + rrs.getLimitSize()) {
noNeedRows = true;
while (!heap.isEmpty()) {
HeapItem itemToDiscard = heap.poll();
if (!itemToDiscard.isNullItem()) {
BlockingQueue<HeapItem> discardQueue = queues.get(itemToDiscard.getIndex());
while (true) {
if (discardQueue.take().isNullItem() || isFail()) {
break;
}
}
}
}
continue;
}
}
outputHandler.rowResponse(top.getRowData(), top.getRowPacket(), false, top.getIndex());
}
}
Iterator<Map.Entry<BackendConnection, BlockingQueue<HeapItem>>> iterator = this.queues.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<BackendConnection, BlockingQueue<HeapItem>> entry = iterator.next();
entry.getValue().clear();
session.releaseConnectionIfSafe(entry.getKey(), false);
iterator.remove();
}
outputHandler.rowEofResponse(null, false, null);
doSqlStat(session.getSource());
} catch (Exception e) {
String msg = "Merge thread error, " + e.getLocalizedMessage();
LOGGER.info(msg, e);
session.onQueryError(msg.getBytes());
}
}
use of com.actiontech.dble.backend.BackendConnection in project dble by actiontech.
the class SingleNodeHandler method execute.
public void execute() throws Exception {
startTime = System.currentTimeMillis();
ServerConnection sc = session.getSource();
waitingResponse = true;
this.packetId = 0;
final BackendConnection conn = session.getTarget(node);
node.setRunOnSlave(rrs.getRunOnSlave());
if (session.tryExistsCon(conn, node)) {
execute(conn);
} else {
// create new connection
node.setRunOnSlave(rrs.getRunOnSlave());
ServerConfig conf = DbleServer.getInstance().getConfig();
PhysicalDBNode dn = conf.getDataNodes().get(node.getName());
dn.getConnection(dn.getDatabase(), session.getSource().isTxStart(), sc.isAutocommit(), node, this, node);
}
}
Aggregations