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

duanzhengqiang 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 08eaaffce10 Add LockedClusterException (#31251)
08eaaffce10 is described below

commit 08eaaffce106ae40ec327b869e6b2d0bc9d9d29d
Author: Liang Zhang <[email protected]>
AuthorDate: Thu May 16 19:53:02 2024 +0800

    Add LockedClusterException (#31251)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  2 ++
 .../user-manual/error-code/sql-error-code.en.md    |  2 ++
 .../mode/exception/LockedClusterException.java     | 33 ++++++++++++++++++++++
 .../mode/exception/NotLockedClusterException.java  | 33 ++++++++++++++++++++++
 .../distsql/ral/updatable/LockClusterExecutor.java |  3 +-
 .../ral/updatable/UnlockClusterExecutor.java       |  3 +-
 6 files changed, 74 insertions(+), 2 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 8a1f6354f96..f12a2ee5852 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
@@ -106,6 +106,8 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 17001       | HY000     | Work ID assigned failed, which can not exceed 
1024.           |
 | 17010       | HY000     | Cluster persist repository error, reason is: %s    
           |
 | 17020       | HY000     | The cluster status is %s, can not support SQL 
statement '%s'. |
+| 17030       | HY000     | Cluster is already locked.                         
           |
+| 17031       | HY000     | Cluster is not locked.                             
           |
 
 ### 数据管道
 
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 8a15a3c76f4..0956c810281 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
@@ -106,6 +106,8 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 17001       | HY000     | Work ID assigned failed, which can not exceed 
1024.           |
 | 17010       | HY000     | Cluster persist repository error, reason is: %s    
           |
 | 17020       | HY000     | The cluster status is %s, can not support SQL 
statement '%s'. |
+| 17030       | HY000     | Cluster is already locked.                         
           |
+| 17031       | HY000     | Cluster is not locked.                             
           |
 
 ### Data Pipeline
 
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/LockedClusterException.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/LockedClusterException.java
new file mode 100644
index 00000000000..88f24c2f253
--- /dev/null
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/LockedClusterException.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.mode.exception;
+
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ClusterSQLException;
+
+/**
+ * Locked cluster exception.
+ */
+public final class LockedClusterException extends ClusterSQLException {
+    
+    private static final long serialVersionUID = 122184861309346827L;
+    
+    public LockedClusterException() {
+        super(XOpenSQLState.GENERAL_ERROR, 30, "Cluster is already locked.");
+    }
+}
diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/NotLockedClusterException.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/NotLockedClusterException.java
new file mode 100644
index 00000000000..117cd86978a
--- /dev/null
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/exception/NotLockedClusterException.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.mode.exception;
+
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+import 
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ClusterSQLException;
+
+/**
+ * Not locked cluster exception.
+ */
+public final class NotLockedClusterException extends ClusterSQLException {
+    
+    private static final long serialVersionUID = -9181518142445461894L;
+    
+    public NotLockedClusterException() {
+        super(XOpenSQLState.GENERAL_ERROR, 31, "Cluster is not locked.");
+    }
+}
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java
index 04982d8ca52..55be2aca0db 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/LockClusterExecutor.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.infra.lock.GlobalLockNames;
 import org.apache.shardingsphere.infra.lock.LockContext;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.infra.state.cluster.ClusterState;
+import org.apache.shardingsphere.mode.exception.LockedClusterException;
 import org.apache.shardingsphere.mode.lock.GlobalLockDefinition;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.proxy.backend.lock.spi.ClusterLockStrategy;
@@ -55,7 +56,7 @@ public final class LockClusterExecutor implements 
DistSQLUpdateExecutor<LockClus
     }
     
     private void checkState(final ContextManager contextManager) {
-        ShardingSpherePreconditions.checkState(ClusterState.OK == 
contextManager.getClusterStateContext().getCurrentState(), () -> new 
IllegalStateException("Cluster is already locked"));
+        ShardingSpherePreconditions.checkState(ClusterState.OK == 
contextManager.getClusterStateContext().getCurrentState(), 
LockedClusterException::new);
     }
     
     private void checkAlgorithm(final LockClusterStatement sqlStatement) {
diff --git 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java
 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java
index f2f98d4bc5d..b152fef63b3 100644
--- 
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java
+++ 
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterExecutor.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.infra.exception.core.ShardingSpherePrecondition
 import org.apache.shardingsphere.infra.lock.GlobalLockNames;
 import org.apache.shardingsphere.infra.lock.LockContext;
 import org.apache.shardingsphere.infra.state.cluster.ClusterState;
+import org.apache.shardingsphere.mode.exception.NotLockedClusterException;
 import org.apache.shardingsphere.mode.lock.GlobalLockDefinition;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterStatusChangedEvent;
@@ -52,7 +53,7 @@ public final class UnlockClusterExecutor implements 
DistSQLUpdateExecutor<Unlock
     }
     
     private void checkState(final ContextManager contextManager) {
-        ShardingSpherePreconditions.checkState(ClusterState.OK != 
contextManager.getClusterStateContext().getCurrentState(), () -> new 
IllegalStateException("Cluster is not locked"));
+        ShardingSpherePreconditions.checkState(ClusterState.OK != 
contextManager.getClusterStateContext().getCurrentState(), 
NotLockedClusterException::new);
     }
     
     @Override

Reply via email to