This is an automated email from the ASF dual-hosted git repository.

yx9o pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new a1cc582f123 Refactor exception for TOO_MANY_CONNECTIONS (#20135)
a1cc582f123 is described below

commit a1cc582f123c1db886f9df3db03e73ae85806bc1
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Aug 13 11:07:07 2022 +0800

    Refactor exception for TOO_MANY_CONNECTIONS (#20135)
    
    * Remove StandardSQLErrorCode.TOO_MANY_CONNECTIONS
    
    * Refactor exception for TOO_MANY_CONNECTIONS
    
    * Refactor exception for TOO_MANY_CONNECTIONS
---
 .../apache/shardingsphere/error/code/StandardSQLErrorCode.java    | 2 --
 .../error/mysql/mapper/MySQLSQLExceptionMapper.java               | 6 +++++-
 .../shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java | 2 ++
 .../error/postgresql/mapper/PostgreSQLSQLExceptionMapper.java     | 6 +++++-
 .../infra/exception/dialect/TooManyConnectionsException.java      | 8 +++++---
 .../frontend/netty/FrontendChannelLimitationInboundHandler.java   | 4 ++--
 .../proxy/frontend/mysql/err/MySQLErrPacketFactory.java           | 4 ----
 .../proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java       | 2 +-
 8 files changed, 20 insertions(+), 14 deletions(-)

diff --git 
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
 
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
index 87b583c78db..5c53b48c90c 100644
--- 
a/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
+++ 
b/shardingsphere-error/shardingsphere-common-error/src/main/java/org/apache/shardingsphere/error/code/StandardSQLErrorCode.java
@@ -39,8 +39,6 @@ public enum StandardSQLErrorCode implements SQLErrorCode {
     
     TABLE_LOCKED(1302, "C1302", "The table `%s` of schema `%s` is locked"),
     
-    TOO_MANY_CONNECTIONS(1040, "08004", "Too many connections"),
-    
     RESOURCE_OR_RULE_NOT_EXIST(1305, "42000", "Data source or rule does not 
exist"),
     
     UNSUPPORTED_SQL(1235, "42000", "Unsupported SQL: %s"),
diff --git 
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLSQLExceptionMapper.java
 
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLSQLExceptionMapper.java
index f51b5d44e61..35bbfbd193f 100644
--- 
a/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLSQLExceptionMapper.java
+++ 
b/shardingsphere-error/shardingsphere-mysql-error/src/main/java/org/apache/shardingsphere/error/mysql/mapper/MySQLSQLExceptionMapper.java
@@ -17,8 +17,8 @@
 
 package org.apache.shardingsphere.error.mysql.mapper;
 
-import org.apache.shardingsphere.error.code.StandardSQLErrorCode;
 import org.apache.shardingsphere.error.code.SQLErrorCode;
+import org.apache.shardingsphere.error.code.StandardSQLErrorCode;
 import org.apache.shardingsphere.error.mapper.SQLExceptionMapper;
 import org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
 import 
org.apache.shardingsphere.infra.exception.dialect.DBCreateExistsException;
@@ -28,6 +28,7 @@ import 
org.apache.shardingsphere.infra.exception.dialect.NoDatabaseSelectedExcep
 import org.apache.shardingsphere.infra.exception.dialect.NoSuchTableException;
 import org.apache.shardingsphere.infra.exception.dialect.TableExistsException;
 import 
org.apache.shardingsphere.infra.exception.dialect.TableModifyInTransactionException;
+import 
org.apache.shardingsphere.infra.exception.dialect.TooManyConnectionsException;
 import 
org.apache.shardingsphere.infra.exception.dialect.UnknownDatabaseException;
 import 
org.apache.shardingsphere.infra.util.exception.inside.InsideDialectSQLException;
 
@@ -66,6 +67,9 @@ public final class MySQLSQLExceptionMapper implements 
SQLExceptionMapper {
         if (dialectSQLException instanceof NoSuchTableException) {
             return toSQLException(MySQLServerErrorCode.ER_NO_SUCH_TABLE, 
((NoSuchTableException) dialectSQLException).getTableName());
         }
+        if (dialectSQLException instanceof TooManyConnectionsException) {
+            return toSQLException(MySQLServerErrorCode.ER_CON_COUNT_ERROR);
+        }
         return toSQLException(StandardSQLErrorCode.UNKNOWN_EXCEPTION, 
dialectSQLException.getMessage());
     }
     
diff --git 
a/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
 
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
index 6fe2a0b3e61..ac83d845b92 100644
--- 
a/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
+++ 
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/code/PostgreSQLErrorCode.java
@@ -81,6 +81,8 @@ public enum PostgreSQLErrorCode {
     
     UNDEFINED_COLUMN("42703", "undefined_column"),
     
+    TOO_MANY_CONNECTIONS("53300", "too_many_connections"),
+    
     SYSTEM_ERROR("58000", "system_error");
     
     private final String errorCode;
diff --git 
a/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/mapper/PostgreSQLSQLExceptionMapper.java
 
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/mapper/PostgreSQLSQLExceptionMapper.java
index 23fd1aaa39d..69ffaf5c8e6 100644
--- 
a/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/mapper/PostgreSQLSQLExceptionMapper.java
+++ 
b/shardingsphere-error/shardingsphere-postgresql-error/src/main/java/org/apache/shardingsphere/error/postgresql/mapper/PostgreSQLSQLExceptionMapper.java
@@ -21,8 +21,9 @@ import 
org.apache.shardingsphere.error.mapper.SQLExceptionMapper;
 import org.apache.shardingsphere.error.postgresql.code.PostgreSQLErrorCode;
 import 
org.apache.shardingsphere.infra.exception.dialect.DBCreateExistsException;
 import 
org.apache.shardingsphere.infra.exception.dialect.InTransactionException;
-import 
org.apache.shardingsphere.infra.exception.dialect.InvalidParameterValueException;
 import 
org.apache.shardingsphere.infra.exception.dialect.InsertColumnsAndValuesMismatchedException;
+import 
org.apache.shardingsphere.infra.exception.dialect.InvalidParameterValueException;
+import 
org.apache.shardingsphere.infra.exception.dialect.TooManyConnectionsException;
 import 
org.apache.shardingsphere.infra.util.exception.inside.InsideDialectSQLException;
 import org.postgresql.util.PSQLException;
 import org.postgresql.util.PSQLState;
@@ -50,6 +51,9 @@ public final class PostgreSQLSQLExceptionMapper implements 
SQLExceptionMapper {
         if (dialectSQLException instanceof DBCreateExistsException) {
             return new 
PSQLException(PostgreSQLErrorCode.DUPLICATE_DATABASE.getConditionName(), null);
         }
+        if (dialectSQLException instanceof TooManyConnectionsException) {
+            return new 
PSQLException(PostgreSQLErrorCode.TOO_MANY_CONNECTIONS.getConditionName(), 
null);
+        }
         return new PSQLException(dialectSQLException.getMessage(), null);
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/FrontendTooManyConnectionsException.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/dialect/TooManyConnectionsException.java
similarity index 77%
rename from 
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/FrontendTooManyConnectionsException.java
rename to 
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/dialect/TooManyConnectionsException.java
index 6c921a7d81c..05d9c84b8d5 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/FrontendTooManyConnectionsException.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/exception/dialect/TooManyConnectionsException.java
@@ -15,12 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.frontend.exception;
+package org.apache.shardingsphere.infra.exception.dialect;
+
+import 
org.apache.shardingsphere.infra.util.exception.inside.InsideDialectSQLException;
 
 /**
- * Frontend too many connections exception.
+ * Too many connections exception.
  */
-public final class FrontendTooManyConnectionsException extends 
FrontendException {
+public final class TooManyConnectionsException extends 
InsideDialectSQLException {
     
     private static final long serialVersionUID = -4397915988239251541L;
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelLimitationInboundHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelLimitationInboundHandler.java
index 60cc842e204..ce41f2017f9 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelLimitationInboundHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelLimitationInboundHandler.java
@@ -22,7 +22,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import 
org.apache.shardingsphere.proxy.frontend.connection.ConnectionLimitContext;
-import 
org.apache.shardingsphere.proxy.frontend.exception.FrontendTooManyConnectionsException;
+import 
org.apache.shardingsphere.infra.exception.dialect.TooManyConnectionsException;
 import 
org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
 
 /**
@@ -42,7 +42,7 @@ public class FrontendChannelLimitationInboundHandler extends 
ChannelInboundHandl
         }
         log.debug("Closing channel {} due to the number of server connections 
has reached max connections {}", ctx.channel().remoteAddress(), 
ConnectionLimitContext.getInstance().getMaxConnections());
         // TODO This is not how actual databases does and should be refactored.
-        
ctx.writeAndFlush(databaseProtocolFrontendEngine.getCommandExecuteEngine().getErrorPacket(new
 FrontendTooManyConnectionsException()));
+        
ctx.writeAndFlush(databaseProtocolFrontendEngine.getCommandExecuteEngine().getErrorPacket(new
 TooManyConnectionsException()));
         ctx.close();
     }
     
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
index bff403f5383..aaaedf9a2d4 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactory.java
@@ -28,7 +28,6 @@ import 
org.apache.shardingsphere.error.mysql.code.MySQLServerErrorCode;
 import 
org.apache.shardingsphere.infra.util.exception.inside.ShardingSphereInsideException;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLErrorCode;
 import 
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.common.exception.DistSQLException;
-import 
org.apache.shardingsphere.proxy.frontend.exception.FrontendTooManyConnectionsException;
 import 
org.apache.shardingsphere.proxy.frontend.exception.UnsupportedPreparedStatementException;
 
 import java.nio.charset.UnsupportedCharsetException;
@@ -66,9 +65,6 @@ public final class MySQLErrPacketFactory {
         if (cause instanceof PipelineJobNotFoundException) {
             return new MySQLErrPacket(1, 
StandardSQLErrorCode.SCALING_JOB_NOT_EXIST, ((PipelineJobNotFoundException) 
cause).getJobId());
         }
-        if (cause instanceof FrontendTooManyConnectionsException) {
-            return new MySQLErrPacket(0, 
MySQLServerErrorCode.ER_CON_COUNT_ERROR, 
MySQLServerErrorCode.ER_CON_COUNT_ERROR.getErrorMessage());
-        }
         if (cause instanceof UnsupportedCharsetException) {
             return new MySQLErrPacket(1, 
MySQLServerErrorCode.ER_UNKNOWN_CHARACTER_SET, cause.getMessage());
         }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
index 9498fd80499..52228d44a97 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/err/MySQLErrPacketFactoryTest.java
@@ -78,7 +78,7 @@ public final class MySQLErrPacketFactoryTest {
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getErrorCode(), is(11001));
         assertThat(actual.getSqlState(), is("11001"));
-        assertThat(actual.getErrorMessage(), is("Could not support variable 
[test]."));
+        assertThat(actual.getErrorMessage(), is("Could not support variable 
`test`."));
     }
     
     @Test

Reply via email to