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

menghaoran 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 cf06a3f5236 Rename InstanceContext.computeNodeInstances to 
allClusterInstances (#19276)
cf06a3f5236 is described below

commit cf06a3f52361b6b94aa57b0fbbda339a9ad123dc
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 17 00:12:08 2022 +0800

    Rename InstanceContext.computeNodeInstances to allClusterInstances (#19276)
---
 .../infra/instance/InstanceContext.java              | 20 ++++++++++----------
 .../jdbc/core/connection/ConnectionManager.java      |  2 +-
 .../jdbc/core/connection/ConnectionManagerTest.java  |  2 +-
 .../shardingsphere/traffic/engine/TrafficEngine.java |  2 +-
 .../traffic/algorithm/engine/TrafficEngineTest.java  |  2 +-
 .../cluster/ClusterContextManagerBuilder.java        |  2 +-
 .../coordinator/lock/DistributedLockContext.java     |  2 +-
 .../ClusterContextManagerCoordinatorTest.java        | 12 ++++++------
 .../distsql/ral/queryable/ShowInstanceHandler.java   |  2 +-
 9 files changed, 23 insertions(+), 23 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
index d26e9bf9c0c..4405d3be99e 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/instance/InstanceContext.java
@@ -50,7 +50,7 @@ public final class InstanceContext {
     
     private final EventBusContext eventBusContext;
     
-    private final Collection<ComputeNodeInstance> computeNodeInstances = new 
LinkedList<>();
+    private final Collection<ComputeNodeInstance> allClusterInstances = new 
LinkedList<>();
     
     public InstanceContext(final ComputeNodeInstance instance, final 
WorkerIdGenerator workerIdGenerator,
                            final ModeConfiguration modeConfiguration, final 
LockContext lockContext, final EventBusContext eventBusContext) {
@@ -76,7 +76,7 @@ public final class InstanceContext {
     }
     
     private void updateRelatedComputeNodeInstancesStatus(final String 
instanceId, final Collection<String> status) {
-        for (ComputeNodeInstance each : computeNodeInstances) {
+        for (ComputeNodeInstance each : allClusterInstances) {
             if (each.getMetaData().getId().equals(instanceId)) {
                 each.switchState(status);
             }
@@ -93,7 +93,7 @@ public final class InstanceContext {
         if (instance.getMetaData().getId().equals(instanceId)) {
             instance.setLabels(labels);
         }
-        computeNodeInstances.stream().filter(each -> 
each.getMetaData().getId().equals(instanceId)).forEach(each -> 
each.setLabels(labels));
+        allClusterInstances.stream().filter(each -> 
each.getMetaData().getId().equals(instanceId)).forEach(each -> 
each.setLabels(labels));
     }
     
     /**
@@ -112,8 +112,8 @@ public final class InstanceContext {
      * @param instance compute node instance
      */
     public void addComputeNodeInstance(final ComputeNodeInstance instance) {
-        computeNodeInstances.removeIf(each -> 
each.getMetaData().getId().equalsIgnoreCase(instance.getMetaData().getId()));
-        computeNodeInstances.add(instance);
+        allClusterInstances.removeIf(each -> 
each.getMetaData().getId().equalsIgnoreCase(instance.getMetaData().getId()));
+        allClusterInstances.add(instance);
     }
     
     /**
@@ -122,7 +122,7 @@ public final class InstanceContext {
      * @param instance compute node instance
      */
     public void deleteComputeNodeInstance(final ComputeNodeInstance instance) {
-        computeNodeInstances.removeIf(each -> 
each.getMetaData().getId().equalsIgnoreCase(instance.getMetaData().getId()));
+        allClusterInstances.removeIf(each -> 
each.getMetaData().getId().equalsIgnoreCase(instance.getMetaData().getId()));
     }
     
     /**
@@ -132,9 +132,9 @@ public final class InstanceContext {
      * @param labels collection of contained label
      * @return compute node instances
      */
-    public List<InstanceMetaData> getComputeNodeInstances(final InstanceType 
instanceType, final Collection<String> labels) {
-        List<InstanceMetaData> result = new 
ArrayList<>(computeNodeInstances.size());
-        for (ComputeNodeInstance each : computeNodeInstances) {
+    public List<InstanceMetaData> getAllClusterInstances(final InstanceType 
instanceType, final Collection<String> labels) {
+        List<InstanceMetaData> result = new 
ArrayList<>(allClusterInstances.size());
+        for (ComputeNodeInstance each : allClusterInstances) {
             if (each.getMetaData().getType() == instanceType && 
labels.stream().anyMatch(((Collection<String>) each.getLabels())::contains)) {
                 result.add(each.getMetaData());
             }
@@ -149,7 +149,7 @@ public final class InstanceContext {
      * @return compute node instance
      */
     public Optional<ComputeNodeInstance> getComputeNodeInstanceById(final 
String instanceId) {
-        return computeNodeInstances.stream().filter(each -> 
instanceId.equals(each.getCurrentInstanceId())).findFirst();
+        return allClusterInstances.stream().filter(each -> 
instanceId.equals(each.getCurrentInstanceId())).findFirst();
     }
     
     /**
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
index 38d0ecf8ff9..57edc56814e 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManager.java
@@ -93,7 +93,7 @@ public final class ConnectionManager implements 
ExecutorJDBCConnectionManager, A
         Preconditions.checkState(!dataSourcePropsMap.isEmpty(), "Can not get 
data source properties from meta data.");
         DataSourceProperties dataSourcePropsSample = 
dataSourcePropsMap.values().iterator().next();
         Collection<ShardingSphereUser> users = 
persistService.getGlobalRuleService().loadUsers();
-        Collection<InstanceMetaData> instances = 
contextManager.getInstanceContext().getComputeNodeInstances(InstanceType.PROXY, 
trafficRule.getLabels());
+        Collection<InstanceMetaData> instances = 
contextManager.getInstanceContext().getAllClusterInstances(InstanceType.PROXY, 
trafficRule.getLabels());
         return 
DataSourcePoolCreator.create(createDataSourcePropertiesMap(instances, users, 
dataSourcePropsSample, schema));
     }
     
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
index 748e088b9a4..63358105244 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ConnectionManagerTest.java
@@ -90,7 +90,7 @@ public final class ConnectionManagerTest {
         
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData);
         
when(globalRuleMetaData.getSingleRule(TransactionRule.class)).thenReturn(mock(TransactionRule.class,
 RETURNS_DEEP_STUBS));
         
when(globalRuleMetaData.getSingleRule(TrafficRule.class)).thenReturn(mock(TrafficRule.class,
 RETURNS_DEEP_STUBS));
-        
when(result.getInstanceContext().getComputeNodeInstances(InstanceType.PROXY, 
Arrays.asList("OLTP", "OLAP"))).thenReturn(
+        
when(result.getInstanceContext().getAllClusterInstances(InstanceType.PROXY, 
Arrays.asList("OLTP", "OLAP"))).thenReturn(
                 Collections.singletonList(new ProxyInstanceMetaData("foo_id", 
"127.0.0.1@3307")));
         dataSourcePoolCreator = mockStatic(DataSourcePoolCreator.class);
         Map<String, DataSource> trafficDataSourceMap = 
mockTrafficDataSourceMap();
diff --git 
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java
 
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java
index 41287d63272..89cd23255e7 100644
--- 
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java
+++ 
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/main/java/org/apache/shardingsphere/traffic/engine/TrafficEngine.java
@@ -53,7 +53,7 @@ public final class TrafficEngine {
         if (!strategyRule.isPresent() || 
isInvalidStrategyRule(strategyRule.get())) {
             return result;
         }
-        List<InstanceMetaData> instances = 
instanceContext.getComputeNodeInstances(InstanceType.PROXY, 
strategyRule.get().getLabels());
+        List<InstanceMetaData> instances = 
instanceContext.getAllClusterInstances(InstanceType.PROXY, 
strategyRule.get().getLabels());
         if (!instances.isEmpty()) {
             TrafficLoadBalanceAlgorithm loadBalancer = 
strategyRule.get().getLoadBalancer();
             InstanceMetaData instanceMetaData = 1 == instances.size() ? 
instances.iterator().next() : 
loadBalancer.getInstanceId(strategyRule.get().getName(), instances);
diff --git 
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
 
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
index a2b1202326f..72cf85298d7 100644
--- 
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
+++ 
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-core/src/test/java/org/apache/shardingsphere/traffic/algorithm/engine/TrafficEngineTest.java
@@ -96,7 +96,7 @@ public final class TrafficEngineTest {
         when(loadBalancer.getInstanceId("traffic", 
instanceIds)).thenReturn(new ProxyInstanceMetaData("foo_id", 3307));
         when(strategyRule.getLoadBalancer()).thenReturn(loadBalancer);
         when(strategyRule.getName()).thenReturn("traffic");
-        when(instanceContext.getComputeNodeInstances(InstanceType.PROXY, 
Arrays.asList("OLTP", "OLAP"))).thenReturn(instanceIds);
+        when(instanceContext.getAllClusterInstances(InstanceType.PROXY, 
Arrays.asList("OLTP", "OLAP"))).thenReturn(instanceIds);
         TrafficContext actual = trafficEngine.dispatch(logicSQL, false);
         assertThat(actual.getInstanceId(), is("foo_id"));
     }
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 93cff78ec19..9ef5f72d344 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -77,7 +77,7 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
     private void registerOnline(final MetaDataPersistService persistService, 
final RegistryCenter registryCenter,
                                 final ContextManagerBuilderParameter 
parameter, final ContextManager contextManager) {
         
contextManager.getInstanceContext().getInstance().setLabels(parameter.getLabels());
-        
contextManager.getInstanceContext().getComputeNodeInstances().addAll(registryCenter.getComputeNodeStatusService().loadAllComputeNodeInstances());
+        
contextManager.getInstanceContext().getAllClusterInstances().addAll(registryCenter.getComputeNodeStatusService().loadAllComputeNodeInstances());
         new ClusterContextManagerCoordinator(persistService, registryCenter, 
contextManager);
         
registryCenter.onlineInstance(contextManager.getInstanceContext().getInstance());
     }
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/DistributedLockContext.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/DistributedLockContext.java
index f7ed155258b..db6bde12e5b 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/DistributedLockContext.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/DistributedLockContext.java
@@ -46,7 +46,7 @@ public final class DistributedLockContext extends 
AbstractLockContext {
     
     @Override
     public void initLockState(final InstanceContext instanceContext) {
-        loadLockManager(new ShardingSphereInternalLockHolder(repository, 
instanceContext.getInstance(), instanceContext.getComputeNodeInstances()), 
instanceContext.getEventBusContext());
+        loadLockManager(new ShardingSphereInternalLockHolder(repository, 
instanceContext.getInstance(), instanceContext.getAllClusterInstances()), 
instanceContext.getEventBusContext());
     }
     
     private void loadLockManager(final ShardingSphereInternalLockHolder 
lockHolder, final EventBusContext eventBusContext) {
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
index bee98ff900a..de1155d1e74 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/ClusterContextManagerCoordinatorTest.java
@@ -329,16 +329,16 @@ public final class ClusterContextManagerCoordinatorTest {
         InstanceMetaData instanceMetaData1 = new 
ProxyInstanceMetaData("foo_instance_3307", 3307);
         InstanceOnlineEvent instanceOnlineEvent1 = new 
InstanceOnlineEvent(instanceMetaData1);
         coordinator.renew(instanceOnlineEvent1);
-        
assertThat(contextManager.getInstanceContext().getComputeNodeInstances().size(),
 is(1));
-        assertThat(((LinkedList<ComputeNodeInstance>) 
contextManager.getInstanceContext().getComputeNodeInstances()).get(0).getMetaData(),
 is(instanceMetaData1));
+        
assertThat(contextManager.getInstanceContext().getAllClusterInstances().size(), 
is(1));
+        assertThat(((LinkedList<ComputeNodeInstance>) 
contextManager.getInstanceContext().getAllClusterInstances()).get(0).getMetaData(),
 is(instanceMetaData1));
         InstanceMetaData instanceMetaData2 = new 
ProxyInstanceMetaData("foo_instance_3308", 3308);
         InstanceOnlineEvent instanceOnlineEvent2 = new 
InstanceOnlineEvent(instanceMetaData2);
         coordinator.renew(instanceOnlineEvent2);
-        
assertThat(contextManager.getInstanceContext().getComputeNodeInstances().size(),
 is(2));
-        assertThat(((LinkedList<ComputeNodeInstance>) 
contextManager.getInstanceContext().getComputeNodeInstances()).get(1).getMetaData(),
 is(instanceMetaData2));
+        
assertThat(contextManager.getInstanceContext().getAllClusterInstances().size(), 
is(2));
+        assertThat(((LinkedList<ComputeNodeInstance>) 
contextManager.getInstanceContext().getAllClusterInstances()).get(1).getMetaData(),
 is(instanceMetaData2));
         coordinator.renew(instanceOnlineEvent1);
-        
assertThat(contextManager.getInstanceContext().getComputeNodeInstances().size(),
 is(2));
-        assertThat(((LinkedList<ComputeNodeInstance>) 
contextManager.getInstanceContext().getComputeNodeInstances()).get(1).getMetaData(),
 is(instanceMetaData1));
+        
assertThat(contextManager.getInstanceContext().getAllClusterInstances().size(), 
is(2));
+        assertThat(((LinkedList<ComputeNodeInstance>) 
contextManager.getInstanceContext().getAllClusterInstances()).get(1).getMetaData(),
 is(instanceMetaData1));
     }
     
     @Test
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/queryable/ShowInstanceHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/queryable/ShowInstanceHandler.java
index 771133528ac..1e8c93f64cc 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/queryable/ShowInstanceHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/queryable/ShowInstanceHandler.java
@@ -60,7 +60,7 @@ public final class ShowInstanceHandler extends 
QueryableRALBackendHandler<ShowIn
         if ("Standalone".equalsIgnoreCase(modeType)) {
             return 
Collections.singletonList(buildRow(contextManager.getInstanceContext().getInstance(),
 modeType));
         }
-        Collection<ComputeNodeInstance> instances = 
contextManager.getInstanceContext().getComputeNodeInstances().stream()
+        Collection<ComputeNodeInstance> instances = 
contextManager.getInstanceContext().getAllClusterInstances().stream()
                 .filter(each -> InstanceType.PROXY == 
each.getMetaData().getType()).collect(Collectors.toList());
         return instances.isEmpty() ? Collections.emptyList() : 
instances.stream().filter(Objects::nonNull).map(each -> buildRow(each, 
modeType)).collect(Collectors.toList());
     }

Reply via email to