You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/04/12 03:57:17 UTC

[shardingsphere] branch master updated: Optimize is locked schema (#16752)

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

zhaojinchao 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 8e4bb3765e4 Optimize is locked schema (#16752)
8e4bb3765e4 is described below

commit 8e4bb3765e4d036db78612c431853fbc96470c6b
Author: gin <ja...@163.com>
AuthorDate: Tue Apr 12 11:57:09 2022 +0800

    Optimize is locked schema (#16752)
---
 .../manager/cluster/coordinator/lock/DistributeLockContext.java  | 9 ++++++++-
 .../proxy/backend/communication/DatabaseCommunicationEngine.java | 3 ---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java
index b00d776eabb..22f2b9fbbfc 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContext.java
@@ -107,7 +107,14 @@ public final class DistributeLockContext implements LockContext {
     @Override
     public boolean isLockedSchema(final String schemaName) {
         Preconditions.checkNotNull(schemaName, "Is locked schema args schema name can not be null.");
-        return getGlobalLock(schemaName).map(shardingSphereGlobalLock -> shardingSphereGlobalLock.isLocked(schemaName)).orElse(false);
+        if (globalLocks.isEmpty()) {
+            return false;
+        }
+        ShardingSphereGlobalLock shardingSphereGlobalLock = globalLocks.get(schemaName);
+        if (null != shardingSphereGlobalLock) {
+            return shardingSphereGlobalLock.isLocked(schemaName);
+        }
+        return false;
     }
     
     private Optional<ShardingSphereGlobalLock> getGlobalLock(final String schemaName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 5bb6f6f4945..95ddb8c0627 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -225,9 +225,6 @@ public abstract class DatabaseCommunicationEngine<T> {
     }
     
     private boolean isLockedSchema(final String schemaName) {
-        if (null == schemaName) {
-            return false;
-        }
         return ProxyContext.getInstance().getContextManager().getInstanceContext().getLockContext().isLockedSchema(schemaName);
     }