From f7caeb6ad26f3a4dbb0a2c4e55358c51209aefb2 Mon Sep 17 00:00:00 2001 From: baofengqi Date: Thu, 3 Jun 2021 10:38:50 +0800 Subject: [PATCH] fix CastException when executing show @@connection --- .../dble/net/connection/FrontendConnection.java | 4 ++++ .../information/tables/DbleFrontConnections.java | 10 ++++++---- .../dble/services/manager/response/ShowConnection.java | 4 ++-- .../services/manager/response/ShowConnectionSQL.java | 10 +++++----- .../services/manager/response/ShowProcessList.java | 7 +++---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/actiontech/dble/net/connection/FrontendConnection.java b/src/main/java/com/actiontech/dble/net/connection/FrontendConnection.java index 15be8ac87..a2f304d45 100644 --- a/src/main/java/com/actiontech/dble/net/connection/FrontendConnection.java +++ b/src/main/java/com/actiontech/dble/net/connection/FrontendConnection.java @@ -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 + "]"; } diff --git a/src/main/java/com/actiontech/dble/services/manager/information/tables/DbleFrontConnections.java b/src/main/java/com/actiontech/dble/services/manager/information/tables/DbleFrontConnections.java index 02d12844c..36885b762 100644 --- a/src/main/java/com/actiontech/dble/services/manager/information/tables/DbleFrontConnections.java +++ b/src/main/java/com/actiontech/dble/services/manager/information/tables/DbleFrontConnections.java @@ -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) + ""); diff --git a/src/main/java/com/actiontech/dble/services/manager/response/ShowConnection.java b/src/main/java/com/actiontech/dble/services/manager/response/ShowConnection.java index 6ab2318fc..71ceba6ce 100644 --- a/src/main/java/com/actiontech/dble/services/manager/response/ShowConnection.java +++ b/src/main/java/com/actiontech/dble/services/manager/response/ShowConnection.java @@ -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); diff --git a/src/main/java/com/actiontech/dble/services/manager/response/ShowConnectionSQL.java b/src/main/java/com/actiontech/dble/services/manager/response/ShowConnectionSQL.java index c78fe340e..316cfa684 100644 --- a/src/main/java/com/actiontech/dble/services/manager/response/ShowConnectionSQL.java +++ b/src/main/java/com/actiontech/dble/services/manager/response/ShowConnectionSQL.java @@ -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); diff --git a/src/main/java/com/actiontech/dble/services/manager/response/ShowProcessList.java b/src/main/java/com/actiontech/dble/services/manager/response/ShowProcessList.java index b6ff33ee6..7aaebcd67 100644 --- a/src/main/java/com/actiontech/dble/services/manager/response/ShowProcessList.java +++ b/src/main/java/com/actiontech/dble/services/manager/response/ShowProcessList.java @@ -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 backendConns = null;