This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 1fb788d8036 Refactor ClusterStatusException (#30757)
1fb788d8036 is described below
commit 1fb788d80364d69b833a71d249fdbe09fa70e448
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Apr 3 17:29:47 2024 +0800
Refactor ClusterStatusException (#30757)
* Rename SQLSupportedJudgeEngine
* Refactor ClusterStatusException
---
.../user-manual/error-code/sql-error-code.cn.md | 13 ++++-----
.../user-manual/error-code/sql-error-code.en.md | 13 ++++-----
.../exception/connection/UnavailableException.java | 33 ----------------------
.../mode/exception/ClusterStatusException.java | 13 +++++----
.../proxy/backend/state/ProxyClusterState.java | 4 +--
...dgeEngine.java => SQLSupportedJudgeEngine.java} | 6 ++--
.../backend/state/impl/ReadOnlyProxyState.java | 8 +++---
.../backend/state/impl/UnavailableProxyState.java | 8 +++---
...eTest.java => SQLSupportedJudgeEngineTest.java} | 10 +++----
.../backend/state/impl/ReadOnlyProxyStateTest.java | 4 +--
.../state/impl/UnavailableProxyStateTest.java | 4 +--
11 files changed, 41 insertions(+), 75 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 17372bad8d4..d54811652fb 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
@@ -70,8 +70,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 08000 | 13002 | The URL '%s' is not recognized, please refer to
the pattern '%s'.
|
| 0A000 | 13003 | Unsupported storage type of URL '%s'.
|
| 01000 | 13010 | Circuit break open, the request has been ignored.
|
-| 01000 | 13011 | The cluster status is read-only.
|
-| 01000 | 13012 | The cluster status is unavailable.
|
| 08000 | 13020 | Can not get %d connections one time, partition
succeed connection(%d) have released. Please consider increasing the
\`maxPoolSize\` of the data sources or decreasing the
\`max-connections-size-per-query\` in properties. |
| 08000 | 13032 | SQL execution has been interrupted.
|
| HY000 | 13090 | Load datetime from database failed, reason: %s
|
@@ -109,11 +107,12 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
### 集群
-| SQL State | Vendor Code | 错误信息
|
-|-----------|-------------|-----------------------------------------------------|
-| HY000 | 17000 | Work ID assigned failed, which can not exceed
1024. |
-| HY000 | 17002 | File access failed, file is: %s
|
-| HY000 | 17010 | Cluster persist repository error, reason is: %s
|
+| SQL State | Vendor Code | 错误信息
|
+|-----------|-------------|---------------------------------------------------------------|
+| HY000 | 17000 | Work ID assigned failed, which can not exceed
1024. |
+| HY000 | 17002 | File access failed, file is: %s
|
+| HY000 | 17010 | Cluster persist repository error, reason is: %s
|
+| HY000 | 17020 | The cluster status is %s, can not support SQL
statement '%s'. |
### 迁移
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 e1169f81a9e..2b94b8d10f6 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
@@ -70,8 +70,6 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 08000 | 13002 | The URL '%s' is not recognized, please refer to
the pattern '%s'.
|
| 0A000 | 13003 | Unsupported storage type of URL '%s'.
|
| 01000 | 13010 | Circuit break open, the request has been ignored.
|
-| 01000 | 13011 | The cluster status is read-only.
|
-| 01000 | 13012 | The cluster status is unavailable.
|
| 08000 | 13020 | Can not get %d connections one time, partition
succeed connection(%d) have released. Please consider increasing the
\`maxPoolSize\` of the data sources or decreasing the
\`max-connections-size-per-query\` in properties. |
| 08000 | 13032 | SQL execution has been interrupted.
|
| HY000 | 13090 | Load datetime from database failed, reason: %s
|
@@ -109,11 +107,12 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
### Cluster
-| SQL State | Vendor Code | Reason
|
-|-----------|-------------|-----------------------------------------------------|
-| HY000 | 17000 | Work ID assigned failed, which can not exceed
1024. |
-| HY000 | 17002 | File access failed, file is: %s
|
-| HY000 | 17010 | Cluster persist repository error, reason is: %s
|
+| SQL State | Vendor Code | Reason
|
+|-----------|-------------|---------------------------------------------------------------|
+| HY000 | 17000 | Work ID assigned failed, which can not exceed
1024. |
+| HY000 | 17002 | File access failed, file is: %s
|
+| HY000 | 17010 | Cluster persist repository error, reason is: %s
|
+| HY000 | 17020 | The cluster status is %s, can not support SQL
statement '%s'. |
### Migration
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/connection/UnavailableException.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/connection/UnavailableException.java
deleted file mode 100644
index 50b0baf4a02..00000000000
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/connection/UnavailableException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.infra.exception.connection;
-
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ConnectionSQLException;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
-
-/**
- * Unavailable exception.
- */
-public final class UnavailableException extends ConnectionSQLException {
-
- private static final long serialVersionUID = 6036684043129887739L;
-
- public UnavailableException() {
- super(XOpenSQLState.GENERAL_WARNING, 12, "The cluster status is
unavailable.");
- }
-}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/connection/ReadOnlyException.java
b/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/ClusterStatusException.java
similarity index 66%
rename from
infra/common/src/main/java/org/apache/shardingsphere/infra/exception/connection/ReadOnlyException.java
rename to
mode/core/src/main/java/org/apache/shardingsphere/mode/exception/ClusterStatusException.java
index 6490bd1ae44..bf7d2e89d4f 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/connection/ReadOnlyException.java
+++
b/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/ClusterStatusException.java
@@ -15,19 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.exception.connection;
+package org.apache.shardingsphere.mode.exception;
-import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ConnectionSQLException;
import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ClusterSQLException;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
/**
- * Read only exception.
+ * Cluster status exception.
*/
-public final class ReadOnlyException extends ConnectionSQLException {
+public final class ClusterStatusException extends ClusterSQLException {
private static final long serialVersionUID = 3834132923835083492L;
- public ReadOnlyException() {
- super(XOpenSQLState.GENERAL_WARNING, 11, "The cluster status is
read-only.");
+ public ClusterStatusException(final String type, final SQLStatement
sqlStatement) {
+ super(XOpenSQLState.GENERAL_ERROR, 20, "The cluster status is %s, can
not support SQL statement '%s'.", type,
sqlStatement.getClass().getSimpleName());
}
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/ProxyClusterState.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/ProxyClusterState.java
index f7b9a9aed3a..bb383d2ad75 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/ProxyClusterState.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/ProxyClusterState.java
@@ -26,9 +26,9 @@ import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
public interface ProxyClusterState extends TypedSPI {
/**
- * Check sql statement.
+ * Check SQL statement.
*
- * @param sqlStatement sql statement
+ * @param sqlStatement SQL statement
*/
void check(SQLStatement sqlStatement);
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/SupportedSQLStatementJudgeEngine.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/SQLSupportedJudgeEngine.java
similarity index 92%
rename from
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/SupportedSQLStatementJudgeEngine.java
rename to
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/SQLSupportedJudgeEngine.java
index 38701c0b806..ed85dd11d48 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/SupportedSQLStatementJudgeEngine.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/SQLSupportedJudgeEngine.java
@@ -23,17 +23,17 @@ import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.util.Collection;
/**
- * Supported SQL statement judge engine.
+ * SQL supported judge engine.
*/
@RequiredArgsConstructor
-public final class SupportedSQLStatementJudgeEngine {
+public final class SQLSupportedJudgeEngine {
private final Collection<Class<? extends SQLStatement>>
supportedSQLStatements;
private final Collection<Class<? extends SQLStatement>>
unsupportedSQLStatements;
/**
- * Judge whether SQL statement is supported.
+ * Judge whether to support SQL.
*
* @param sqlStatement SQL statement to be judged
* @return supported or not
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyState.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyState.java
index 8df582e2057..5f309d00636 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyState.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyState.java
@@ -21,9 +21,9 @@ import
org.apache.shardingsphere.distsql.statement.ral.updatable.UpdatableRALSta
import
org.apache.shardingsphere.distsql.statement.ral.updatable.UnlockClusterStatement;
import org.apache.shardingsphere.distsql.statement.rdl.RDLStatement;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import org.apache.shardingsphere.infra.exception.connection.ReadOnlyException;
+import org.apache.shardingsphere.mode.exception.ClusterStatusException;
import org.apache.shardingsphere.proxy.backend.state.ProxyClusterState;
-import
org.apache.shardingsphere.proxy.backend.state.SupportedSQLStatementJudgeEngine;
+import org.apache.shardingsphere.proxy.backend.state.SQLSupportedJudgeEngine;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
@@ -44,11 +44,11 @@ public final class ReadOnlyProxyState implements
ProxyClusterState {
private static final Collection<Class<? extends SQLStatement>>
UNSUPPORTED_SQL_STATEMENTS = Arrays.asList(
InsertStatement.class, UpdateStatement.class,
DeleteStatement.class, DDLStatement.class, UpdatableRALStatement.class,
RDLStatement.class);
- private final SupportedSQLStatementJudgeEngine judgeEngine = new
SupportedSQLStatementJudgeEngine(SUPPORTED_SQL_STATEMENTS,
UNSUPPORTED_SQL_STATEMENTS);
+ private final SQLSupportedJudgeEngine judgeEngine = new
SQLSupportedJudgeEngine(SUPPORTED_SQL_STATEMENTS, UNSUPPORTED_SQL_STATEMENTS);
@Override
public void check(final SQLStatement sqlStatement) {
-
ShardingSpherePreconditions.checkState(judgeEngine.isSupported(sqlStatement),
ReadOnlyException::new);
+
ShardingSpherePreconditions.checkState(judgeEngine.isSupported(sqlStatement),
() -> new ClusterStatusException(getType(), sqlStatement));
}
@Override
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyState.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyState.java
index 25d00bec20c..b26aed7613a 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyState.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyState.java
@@ -22,9 +22,9 @@ import
org.apache.shardingsphere.distsql.statement.ral.updatable.ImportMetaDataS
import
org.apache.shardingsphere.distsql.statement.ral.updatable.UnlockClusterStatement;
import org.apache.shardingsphere.distsql.statement.rql.RQLStatement;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
-import
org.apache.shardingsphere.infra.exception.connection.UnavailableException;
+import org.apache.shardingsphere.mode.exception.ClusterStatusException;
import org.apache.shardingsphere.proxy.backend.state.ProxyClusterState;
-import
org.apache.shardingsphere.proxy.backend.state.SupportedSQLStatementJudgeEngine;
+import org.apache.shardingsphere.proxy.backend.state.SQLSupportedJudgeEngine;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dal.ShowStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLShowDatabasesStatement;
@@ -45,11 +45,11 @@ public final class UnavailableProxyState implements
ProxyClusterState {
private static final Collection<Class<? extends SQLStatement>>
UNSUPPORTED_SQL_STATEMENTS = Collections.singleton(SQLStatement.class);
- private final SupportedSQLStatementJudgeEngine judgeEngine = new
SupportedSQLStatementJudgeEngine(SUPPORTED_SQL_STATEMENTS,
UNSUPPORTED_SQL_STATEMENTS);
+ private final SQLSupportedJudgeEngine judgeEngine = new
SQLSupportedJudgeEngine(SUPPORTED_SQL_STATEMENTS, UNSUPPORTED_SQL_STATEMENTS);
@Override
public void check(final SQLStatement sqlStatement) {
-
ShardingSpherePreconditions.checkState(judgeEngine.isSupported(sqlStatement),
UnavailableException::new);
+
ShardingSpherePreconditions.checkState(judgeEngine.isSupported(sqlStatement),
() -> new ClusterStatusException(getType(), sqlStatement));
}
@Override
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/SupportedSQLStatementJudgeEngineTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/SQLSupportedJudgeEngineTest.java
similarity index 69%
rename from
proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/SupportedSQLStatementJudgeEngineTest.java
rename to
proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/SQLSupportedJudgeEngineTest.java
index c166c2e7341..0caa1e00c09 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/SupportedSQLStatementJudgeEngineTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/SQLSupportedJudgeEngineTest.java
@@ -29,25 +29,25 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
-class SupportedSQLStatementJudgeEngineTest {
+class SQLSupportedJudgeEngineTest {
@Test
void assertIsSupportedWithInSupportedList() {
- assertTrue(new
SupportedSQLStatementJudgeEngine(Collections.singleton(SelectStatement.class),
Collections.emptyList()).isSupported(mock(SelectStatement.class)));
+ assertTrue(new
SQLSupportedJudgeEngine(Collections.singleton(SelectStatement.class),
Collections.emptyList()).isSupported(mock(SelectStatement.class)));
}
@Test
void assertIsNotSupportedWithInUnsupportedList() {
- assertFalse(new
SupportedSQLStatementJudgeEngine(Collections.emptyList(),
Collections.singleton(SelectStatement.class)).isSupported(mock(SelectStatement.class)));
+ assertFalse(new SQLSupportedJudgeEngine(Collections.emptyList(),
Collections.singleton(SelectStatement.class)).isSupported(mock(SelectStatement.class)));
}
@Test
void assertIsSupportedWithOverlappedList() {
- assertTrue(new
SupportedSQLStatementJudgeEngine(Collections.singleton(SelectStatement.class),
Collections.singleton(SQLStatement.class)).isSupported(mock(SelectStatement.class)));
+ assertTrue(new
SQLSupportedJudgeEngine(Collections.singleton(SelectStatement.class),
Collections.singleton(SQLStatement.class)).isSupported(mock(SelectStatement.class)));
}
@Test
void assertIsSupportedWithoutList() {
- assertTrue(new
SupportedSQLStatementJudgeEngine(Collections.singleton(SelectStatement.class),
Collections.singleton(UpdateStatement.class)).isSupported(mock(DeleteStatement.class)));
+ assertTrue(new
SQLSupportedJudgeEngine(Collections.singleton(SelectStatement.class),
Collections.singleton(UpdateStatement.class)).isSupported(mock(DeleteStatement.class)));
}
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyStateTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyStateTest.java
index af084fd8dc9..cc7cc789870 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyStateTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/ReadOnlyProxyStateTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.proxy.backend.state.impl;
-import org.apache.shardingsphere.infra.exception.connection.ReadOnlyException;
+import org.apache.shardingsphere.mode.exception.ClusterStatusException;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.junit.jupiter.api.Test;
@@ -29,7 +29,7 @@ class ReadOnlyProxyStateTest {
@Test
void assertExecuteWithUnsupportedSQL() {
- assertThrows(ReadOnlyException.class, () -> new
ReadOnlyProxyState().check(mock(InsertStatement.class)));
+ assertThrows(ClusterStatusException.class, () -> new
ReadOnlyProxyState().check(mock(InsertStatement.class)));
}
@Test
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyStateTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyStateTest.java
index 94d5f2bfc3d..e617c9ec483 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyStateTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/state/impl/UnavailableProxyStateTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.proxy.backend.state.impl;
import
org.apache.shardingsphere.distsql.statement.ral.updatable.ImportMetaDataStatement;
-import
org.apache.shardingsphere.infra.exception.connection.UnavailableException;
+import org.apache.shardingsphere.mode.exception.ClusterStatusException;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
import org.junit.jupiter.api.Test;
@@ -29,7 +29,7 @@ class UnavailableProxyStateTest {
@Test
void assertExecuteWithUnsupportedSQL() {
- assertThrows(UnavailableException.class, () -> new
UnavailableProxyState().check(mock(DMLStatement.class)));
+ assertThrows(ClusterStatusException.class, () -> new
UnavailableProxyState().check(mock(DMLStatement.class)));
}
@Test