fix CastException when executing show @@connection

This commit is contained in:
baofengqi
2021-06-03 10:38:50 +08:00
parent 3b484f3839
commit f7caeb6ad2
5 changed files with 20 additions and 15 deletions
@@ -93,6 +93,10 @@ public class FrontendConnection extends AbstractConnection {
return (FrontEndService) getService();
}
public boolean isAuthorized() {
return !(getService() instanceof AuthService);
}
public String toString() {
return "FrontendConnection[id = " + id + " port = " + port + " host = " + host + " local_port = " + localPort + " isManager = " + isManager() + " startupTime = " + startupTime + "]";
}
@@ -13,7 +13,6 @@ import com.actiontech.dble.meta.ColumnMeta;
import com.actiontech.dble.net.IOProcessor;
import com.actiontech.dble.net.connection.FrontendConnection;
import com.actiontech.dble.services.FrontEndService;
import com.actiontech.dble.services.manager.ManagerService;
import com.actiontech.dble.services.manager.information.ManagerBaseTable;
import com.actiontech.dble.services.mysqlsharding.ShardingService;
import com.actiontech.dble.util.TimeUtil;
@@ -130,12 +129,15 @@ public final class DbleFrontConnections extends ManagerBaseTable {
if (c.isManager()) {
row.put("sql_stage", "Manager connection");
row.put("in_transaction", "Manager connection");
row.put("schema", ((ManagerService) service).getSchema() == null ? "NULL" : ((ManagerService) service).getSchema());
} else {
row.put("sql_stage", ((ShardingService) service).getSession2().getSessionStage().toString());
if (service instanceof ShardingService) {
row.put("sql_stage", ((ShardingService) service).getSession2().getSessionStage().toString());
} else {
row.put("sql_stage", "NULL");
}
row.put("in_transaction", !service.isAutocommit() + "");
row.put("schema", ((ShardingService) service).getSchema() == null ? "NULL" : ((ShardingService) service).getSchema());
}
row.put("schema", service.getSchema() == null ? "NULL" : service.getSchema());
row.put("conn_net_in", c.getNetInBytes() + "");
row.put("conn_net_out", c.getNetOutBytes() + "");
row.put("conn_estab_time", ((TimeUtil.currentTimeMillis() - c.getStartupTime()) / 1000) + "");
@@ -168,7 +168,7 @@ public final class ShowConnection {
continue;
}
whereInfo.remove("front_id");
if (whereInfo.isEmpty() || checkConn(fc, whereInfo)) {
if (fc.isAuthorized() && (whereInfo.isEmpty() || checkConn(fc, whereInfo))) {
RowDataPacket row = getRow(fc, service.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, service, true);
@@ -177,7 +177,7 @@ public final class ShowConnection {
}
for (FrontendConnection fc : p.getFrontends().values()) {
if (fc != null && (whereInfo.isEmpty() || checkConn(fc, whereInfo))) {
if (fc != null && fc.isAuthorized() && (whereInfo.isEmpty() || checkConn(fc, whereInfo))) {
RowDataPacket row = getRow(fc, service.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, service, true);
@@ -1,8 +1,8 @@
/*
* Copyright (C) 2016-2020 ActionTech.
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
*/
* Copyright (C) 2016-2020 ActionTech.
* based on code by MyCATCopyrightHolder Copyright (c) 2013, OpenCloudDB/MyCAT.
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher.
*/
package com.actiontech.dble.services.manager.response;
import com.actiontech.dble.DbleServer;
@@ -82,7 +82,7 @@ public final class ShowConnectionSQL {
byte packetId = EOF.getPacketId();
for (IOProcessor p : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (!fc.isClosed()) {
if (!fc.isClosed() && fc.isAuthorized()) {
RowDataPacket row = getRow(fc, service.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, service, true);
@@ -2,17 +2,16 @@ package com.actiontech.dble.services.manager.response;
import com.actiontech.dble.DbleServer;
import com.actiontech.dble.backend.mysql.PacketUtil;
import com.actiontech.dble.config.ErrorCode;
import com.actiontech.dble.config.Fields;
import com.actiontech.dble.net.ConnectionException;
import com.actiontech.dble.net.IOProcessor;
import com.actiontech.dble.net.connection.BackendConnection;
import com.actiontech.dble.net.connection.FrontendConnection;
import com.actiontech.dble.net.mysql.*;
import com.actiontech.dble.route.RouteResultsetNode;
import com.actiontech.dble.services.manager.ManagerService;
import com.actiontech.dble.services.manager.handler.ShowProcesslistHandler;
import com.actiontech.dble.net.ConnectionException;
import com.actiontech.dble.route.RouteResultsetNode;
import com.actiontech.dble.services.mysqlsharding.ShardingService;
import com.actiontech.dble.util.CollectionUtil;
import com.actiontech.dble.util.LongUtil;
@@ -86,7 +85,7 @@ public final class ShowProcessList {
for (IOProcessor p : DbleServer.getInstance().getFrontProcessors()) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (fc == null)
if (fc == null || !fc.isAuthorized())
break;
Map<RouteResultsetNode, BackendConnection> backendConns = null;