You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/09/27 11:57:21 UTC
[shardingsphere] branch master updated: Add InvalidExecutorSuitableException (#21224)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 a468c7cc152 Add InvalidExecutorSuitableException (#21224)
a468c7cc152 is described below
commit a468c7cc152194cee8802c95c45c0b334564b6ac
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Sep 27 19:57:13 2022 +0800
Add InvalidExecutorSuitableException (#21224)
---
.../user-manual/error-code/sql-error-code.cn.md | 3 +-
.../user-manual/error-code/sql-error-code.en.md | 3 +-
.../InvalidExecutorSuitableException.java | 33 ++++++++++++++++++++++
.../frontend/state/impl/JDBCOKProxyState.java | 9 ++++--
.../frontend/state/impl/JDBCOKProxyStateTest.java | 3 +-
5 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index ad1fbf1ccc5..d90b41bf87f 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -23,7 +23,8 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 42S02 | 10020 | Schema \`%s\` does not exist |
| 42S02 | 10021 | Single table \`%s\` does not exist |
| HY000 | 10022 | Can not load table with database name \`%s\` and data source name \`%s\` |
-| 0A000 | 11030 | Can not drop schema \`%s\` because of contains tables |
+| 0A000 | 10030 | Can not drop schema \`%s\` because of contains tables |
+| 0A000 | 10050 | The property \`proxy-backend-executor-suitable\` must be \`OLAP\` or \`OLTP\` |
### 数据
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 913694465a3..bf2ef9fc6d2 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -23,7 +23,8 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| 42S02 | 10020 | Schema \`%s\` does not exist |
| 42S02 | 10021 | Single table \`%s\` does not exist |
| HY000 | 10022 | Can not load table with database name \`%s\` and data source name \`%s\` |
-| 0A000 | 11030 | Can not drop schema \`%s\` because of contains tables |
+| 0A000 | 10030 | Can not drop schema \`%s\` because of contains tables |
+| 0A000 | 10050 | The property \`proxy-backend-executor-suitable\` must be \`OLAP\` or \`OLTP\` |
### Data
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/InvalidExecutorSuitableException.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/InvalidExecutorSuitableException.java
new file mode 100644
index 00000000000..cf37572a944
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/exception/InvalidExecutorSuitableException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.frontend.exception;
+
+import org.apache.shardingsphere.infra.exception.ConnectionSQLException;
+import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Invalid executor suitable exception.
+ */
+public final class InvalidExecutorSuitableException extends ConnectionSQLException {
+
+ private static final long serialVersionUID = 8481186245119374721L;
+
+ public InvalidExecutorSuitableException() {
+ super(XOpenSQLState.GENERAL_ERROR, 50, "The property `proxy-backend-executor-suitable` must be `OLAP` or `OLTP`");
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyState.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyState.java
index 0ef4ea6977c..ecfeb239760 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyState.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyState.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
+import org.apache.shardingsphere.proxy.frontend.exception.InvalidExecutorSuitableException;
import org.apache.shardingsphere.proxy.frontend.executor.ConnectionThreadExecutorGroup;
import org.apache.shardingsphere.proxy.frontend.executor.UserExecutorGroup;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
@@ -45,9 +46,11 @@ public final class JDBCOKProxyState implements OKProxyState {
final ConnectionSession connectionSession) {
if (requireOccupyThreadForConnection(connectionSession)) {
return ConnectionThreadExecutorGroup.getInstance().get(connectionSession.getConnectionId());
- } else if (isPreferNettyEventLoop()) {
+ }
+ if (isPreferNettyEventLoop()) {
return context.executor();
- } else if (databaseProtocolFrontendEngine.getFrontendContext().isRequiredSameThreadForConnection(message)) {
+ }
+ if (databaseProtocolFrontendEngine.getFrontendContext().isRequiredSameThreadForConnection(message)) {
return ConnectionThreadExecutorGroup.getInstance().get(connectionSession.getConnectionId());
}
return UserExecutorGroup.getInstance().getExecutorService();
@@ -65,7 +68,7 @@ public final class JDBCOKProxyState implements OKProxyState {
case "OLAP":
return false;
default:
- throw new IllegalArgumentException("The property proxy-backend-executor-suitable must be 'OLAP' or 'OLTP'");
+ throw new InvalidExecutorSuitableException();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyStateTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyStateTest.java
index c2e160d8cf7..9f7117e3cfa 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyStateTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/test/java/org/apache/shardingsphere/proxy/frontend/state/impl/JDBCOKProxyStateTest.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.frontend.ProxyContextRestorer;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask;
+import org.apache.shardingsphere.proxy.frontend.exception.InvalidExecutorSuitableException;
import org.apache.shardingsphere.proxy.frontend.executor.ConnectionThreadExecutorGroup;
import org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -108,7 +109,7 @@ public final class JDBCOKProxyStateTest extends ProxyContextRestorer {
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(1);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = InvalidExecutorSuitableException.class)
public void assertExecuteWithProxyBackendExecutorSuitableForInvalidValue() {
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_HINT_ENABLED)).thenReturn(false);
when(ProxyContext.getInstance().getContextManager()