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 c78fac0c9c8 Refactor ClusterContextManagerBuilder (#31577)
c78fac0c9c8 is described below

commit c78fac0c9c8560cc5fe24e9aa0823d9772b7d085
Author: Haoran Meng <[email protected]>
AuthorDate: Tue Jun 4 14:05:31 2024 +0800

    Refactor ClusterContextManagerBuilder (#31577)
---
 .../mode/manager/cluster/ClusterContextManagerBuilder.java     | 10 +---------
 .../cluster/coordinator/lock/GlobalLockPersistService.java     |  8 ++++----
 .../coordinator/fixture/ClusterPersistRepositoryFixture.java   |  4 +++-
 .../process/ProcessListClusterPersistRepositoryFixture.java    |  4 +++-
 .../proxy/fixture/ClusterPersistRepositoryFixture.java         |  4 +++-
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index be9560ee83f..461d62281dc 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -41,15 +41,12 @@ import 
org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory;
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
-import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
-import 
org.apache.shardingsphere.mode.repository.cluster.lock.impl.props.DefaultLockTypedProperties;
 import 
org.apache.shardingsphere.mode.service.persist.QualifiedDataSourceStatePersistService;
 import org.apache.shardingsphere.mode.state.StatePersistService;
 
 import java.sql.SQLException;
 import java.util.Collections;
 import java.util.Optional;
-import java.util.Properties;
 
 /**
  * Cluster context manager builder.
@@ -82,12 +79,7 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
                                                                        final 
InstanceMetaData instanceMetaData, final ClusterPersistRepository repository, 
final EventBusContext eventBusContext) {
         return new ComputeNodeInstanceContext(new 
ComputeNodeInstance(instanceMetaData),
                 new ClusterWorkerIdGenerator(repository, 
instanceMetaData.getId()), modeConfig,
-                new GlobalLockContext(new 
GlobalLockPersistService(initDistributedLockHolder(repository))), 
eventBusContext);
-    }
-    
-    private DistributedLockHolder initDistributedLockHolder(final 
ClusterPersistRepository repository) {
-        DistributedLockHolder distributedLockHolder = 
repository.getDistributedLockHolder();
-        return null == distributedLockHolder ? new 
DistributedLockHolder("default", repository, new DefaultLockTypedProperties(new 
Properties())) : distributedLockHolder;
+                new GlobalLockContext(new 
GlobalLockPersistService(repository)), eventBusContext);
     }
     
     // TODO remove the method, only keep ZooKeeper's events, remove all 
decouple events
diff --git 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/GlobalLockPersistService.java
 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/GlobalLockPersistService.java
index f7eae5f52d9..470a795bfa8 100644
--- 
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/GlobalLockPersistService.java
+++ 
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/GlobalLockPersistService.java
@@ -20,7 +20,7 @@ package 
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock;
 import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.mode.lock.GlobalLockDefinition;
 import org.apache.shardingsphere.mode.lock.LockPersistService;
-import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
+import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
 
 /**
  * Global lock persist service.
@@ -28,15 +28,15 @@ import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.Distributed
 @RequiredArgsConstructor
 public final class GlobalLockPersistService implements 
LockPersistService<GlobalLockDefinition> {
     
-    private final DistributedLockHolder distributedLockHolder;
+    private final ClusterPersistRepository repository;
     
     @Override
     public boolean tryLock(final GlobalLockDefinition lockDefinition, final 
long timeoutMillis) {
-        return 
distributedLockHolder.getDistributedLock(lockDefinition.getLockKey()).tryLock(timeoutMillis);
+        return 
repository.getDistributedLockHolder().getDistributedLock(lockDefinition.getLockKey()).tryLock(timeoutMillis);
     }
     
     @Override
     public void unlock(final GlobalLockDefinition lockDefinition) {
-        
distributedLockHolder.getDistributedLock(lockDefinition.getLockKey()).unlock();
+        
repository.getDistributedLockHolder().getDistributedLock(lockDefinition.getLockKey()).unlock();
     }
 }
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
index b2d716bb810..8b3f8c65898 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/fixture/ClusterPersistRepositoryFixture.java
@@ -22,9 +22,11 @@ import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositor
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
 import 
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
 import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
+import 
org.apache.shardingsphere.mode.repository.cluster.lock.impl.props.DefaultLockTypedProperties;
 
 import java.util.Collections;
 import java.util.List;
+import java.util.Properties;
 
 public final class ClusterPersistRepositoryFixture implements 
ClusterPersistRepository {
     
@@ -62,7 +64,7 @@ public final class ClusterPersistRepositoryFixture implements 
ClusterPersistRepo
     
     @Override
     public DistributedLockHolder getDistributedLockHolder() {
-        return null;
+        return new DistributedLockHolder("default", this, new 
DefaultLockTypedProperties(new Properties()));
     }
     
     @Override
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java
index 9e63ea850fa..0df0ca5219d 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/process/ProcessListClusterPersistRepositoryFixture.java
@@ -22,11 +22,13 @@ import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositor
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
 import 
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
 import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
+import 
org.apache.shardingsphere.mode.repository.cluster.lock.impl.props.DefaultLockTypedProperties;
 
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 public final class ProcessListClusterPersistRepositoryFixture implements 
ClusterPersistRepository {
     
@@ -72,7 +74,7 @@ public final class ProcessListClusterPersistRepositoryFixture 
implements Cluster
     
     @Override
     public DistributedLockHolder getDistributedLockHolder() {
-        return null;
+        return new DistributedLockHolder("default", this, new 
DefaultLockTypedProperties(new Properties()));
     }
     
     @Override
diff --git 
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
 
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
index cf9924afaba..935e5cbb657 100644
--- 
a/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
+++ 
b/proxy/bootstrap/src/test/java/org/apache/shardingsphere/proxy/fixture/ClusterPersistRepositoryFixture.java
@@ -22,11 +22,13 @@ import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositor
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
 import 
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener;
 import 
org.apache.shardingsphere.mode.repository.cluster.lock.holder.DistributedLockHolder;
+import 
org.apache.shardingsphere.mode.repository.cluster.lock.impl.props.DefaultLockTypedProperties;
 
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 public final class ClusterPersistRepositoryFixture implements 
ClusterPersistRepository {
     
@@ -72,7 +74,7 @@ public final class ClusterPersistRepositoryFixture implements 
ClusterPersistRepo
     
     @Override
     public DistributedLockHolder getDistributedLockHolder() {
-        return null;
+        return new DistributedLockHolder("default", this, new 
DefaultLockTypedProperties(new Properties()));
     }
     
     @Override

Reply via email to