use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.
the class ReloadConfig method recycleOldBackendConnections.
private static void recycleOldBackendConnections(ServerConfig config, boolean closeFrontCon) {
/* 2.4 put the old connection into a queue */
Map<String, PhysicalDBPool> oldDataHosts = config.getBackupDataHosts();
for (PhysicalDBPool dbPool : oldDataHosts.values()) {
dbPool.stopHeartbeat();
for (PhysicalDatasource ds : dbPool.getAllDataSources()) {
for (NIOProcessor processor : DbleServer.getInstance().getBackendProcessors()) {
for (BackendConnection con : processor.getBackends().values()) {
if (con instanceof MySQLConnection) {
MySQLConnection mysqlCon = (MySQLConnection) con;
if (mysqlCon.getPool() == ds) {
if (con.isBorrowed()) {
if (closeFrontCon) {
findAndcloseFrontCon(con);
} else {
NIOProcessor.BACKENDS_OLD.add(con);
}
} else {
con.close("old idle conn for reload");
}
}
}
}
}
}
}
LOGGER.info("the size of old backend connection to be recycled is: " + NIOProcessor.BACKENDS_OLD.size());
}
use of com.actiontech.dble.net.NIOProcessor 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.net.NIOProcessor in project dble by actiontech.
the class KillHandler method handle.
public static void handle(String stmt, int offset, ServerConnection c) {
String id = stmt.substring(offset).trim();
if (StringUtil.isEmpty(id)) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "NULL connection id");
} else {
// get value
long value = 0;
try {
value = Long.parseLong(id);
} catch (NumberFormatException e) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Invalid connection id:" + id);
return;
}
// kill myself
if (value == c.getId()) {
getOkPacket().write(c);
c.write(c.allocate());
return;
}
// get connection and close it
FrontendConnection fc = null;
NIOProcessor[] processors = DbleServer.getInstance().getFrontProcessors();
for (NIOProcessor p : processors) {
if ((fc = p.getFrontends().get(value)) != null) {
break;
}
}
if (fc != null) {
if (!fc.getUser().equals(c.getUser())) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "can't kill other user's connection" + id);
return;
}
fc.killAndClose("killed");
getOkPacket().write(c);
} else {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Unknown connection id:" + id);
}
}
}
use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.
the class ShowBackendStat method stat.
private static HashMap<String, BackendStat> stat() {
HashMap<String, BackendStat> all = new HashMap<String, BackendStat>();
for (NIOProcessor p : DbleServer.getInstance().getBackendProcessors()) {
for (BackendConnection bc : p.getBackends().values()) {
if ((bc == null) || !(bc instanceof MySQLConnection)) {
break;
}
MySQLConnection con = (MySQLConnection) bc;
String host = con.getHost();
long port = con.getPort();
BackendStat info = all.get(host + Long.toString(port));
if (info == null) {
info = new BackendStat(host, port);
all.put(host + Long.toString(port), info);
}
if (con.isBorrowed()) {
info.addActive();
}
info.addTotal();
}
}
return all;
}
use of com.actiontech.dble.net.NIOProcessor in project dble by actiontech.
the class ShowCommand method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = EOF.write(buffer, c, true);
// write rows
byte packetId = EOF.getPacketId();
for (NIOProcessor p : DbleServer.getInstance().getFrontProcessors()) {
RowDataPacket row = getRow(p);
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations