RaigorJiang commented on code in PR #24483:
URL: https://github.com/apache/shardingsphere/pull/24483#discussion_r1127323012


##########
proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/UnlockClusterUpdater.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.backend.handler.distsql.ral.updatable;
+
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+import org.apache.shardingsphere.distsql.handler.ral.update.RALUpdater;
+import 
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.UnlockClusterStatement;
+import org.apache.shardingsphere.infra.lock.LockContext;
+import org.apache.shardingsphere.infra.state.cluster.ClusterState;
+import 
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
+import 
org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
+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;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+
+/**
+ * Unlock cluster updater.
+ */
+@RequiredArgsConstructor
+@Setter
+public final class UnlockClusterUpdater implements 
RALUpdater<UnlockClusterStatement> {
+    
+    @Override
+    @SuppressWarnings({"unchecked", "rawtypes"})
+    public void executeUpdate(final String databaseName, final 
UnlockClusterStatement sqlStatement) {
+        checkMode();
+        checkState();
+        ContextManager contextManager = 
ProxyContext.getInstance().getContextManager();
+        LockContext lockContext = 
contextManager.getInstanceContext().getLockContext();
+        lockContext.unlock(new GlobalLockDefinition("cluster_lock"));
+        contextManager.getInstanceContext().getEventBusContext().post(new 
ClusterStatusChangedEvent(ClusterState.OK));
+        // TODO unlock csn if locked
+    }
+    
+    private void checkMode() {
+        
ShardingSpherePreconditions.checkState(ProxyContext.getInstance().getContextManager().getInstanceContext().isCluster(),
+                () -> new UnsupportedSQLOperationException("Only allowed in 
cluster mode"));
+    }
+    
+    private void checkState() {
+        ClusterState currentState = 
ProxyContext.getInstance().getContextManager().getClusterStateContext().getCurrentState();
+        ShardingSpherePreconditions.checkState(ClusterState.OK != 
currentState, () -> new IllegalStateException("Cluster does not locked"));

Review Comment:
   `is` not locked.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to