Skip to content

Commit 69553a2

Browse files
authored
Remove useless cluster mode check when using DistSQLExecutorClusterModeRequired (#34999)
* Remove useless cluster mode check when using DistSQLExecutorClusterModeRequired on * Remove useless cluster mode check when using DistSQLExecutorClusterModeRequired
1 parent 9ae4b22 commit 69553a2

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/dispatch/handler/global/node/compute/type/ComputeNodeOnlineHandlerTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.mockito.junit.jupiter.MockitoExtension;
3434

3535
import static org.mockito.ArgumentMatchers.any;
36-
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
3736
import static org.mockito.Mockito.mock;
3837
import static org.mockito.Mockito.times;
3938
import static org.mockito.Mockito.verify;
@@ -47,10 +46,14 @@ class ComputeNodeOnlineHandlerTest {
4746
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
4847
private ContextManager contextManager;
4948

49+
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
50+
private ClusterPersistServiceFacade clusterPersistServiceFacade;
51+
5052
@BeforeEach
5153
void setUp() {
5254
handler = ShardingSphereServiceLoader.getServiceInstances(GlobalDataChangedEventHandler.class).stream()
5355
.filter(each -> NodePathGenerator.toPath(each.getSubscribedNodePath()).equals("/nodes/compute_nodes/online")).findFirst().orElse(null);
56+
when(contextManager.getPersistServiceFacade().getModeFacade()).thenReturn(clusterPersistServiceFacade);
5457
}
5558

5659
@Test
@@ -62,9 +65,7 @@ void assertHandleWithInvalidInstanceOnlinePath() {
6265
@Test
6366
void assertHandleWithInstanceOnlineEvent() {
6467
ComputeNodeInstance computeNodeInstance = mock(ComputeNodeInstance.class);
65-
ClusterPersistServiceFacade clusterPersistServiceFacade = mock(ClusterPersistServiceFacade.class, RETURNS_DEEP_STUBS);
6668
when(clusterPersistServiceFacade.getComputeNodeService().loadInstance(any())).thenReturn(computeNodeInstance);
67-
when(contextManager.getPersistServiceFacade().getModeFacade()).thenReturn(clusterPersistServiceFacade);
6869
handler.handle(contextManager, new DataChangedEvent("/nodes/compute_nodes/online/proxy/foo_instance_id", "{attribute: 127.0.0.1@3307,version: 1}", Type.ADDED));
6970
verify(contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry()).add(computeNodeInstance);
7071
}

proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/computenode/SetComputeNodeStateExecutor.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ public void executeUpdate(final SetComputeNodeStateStatement sqlStatement, final
3939
} else {
4040
checkEnablingIsValid(contextManager, sqlStatement.getInstanceId());
4141
}
42-
if (contextManager.getComputeNodeInstanceContext().getModeConfiguration().isCluster()) {
43-
ClusterPersistServiceFacade clusterPersistServiceFacade = (ClusterPersistServiceFacade) contextManager.getPersistServiceFacade().getModeFacade();
44-
clusterPersistServiceFacade.getComputeNodeService().updateState(sqlStatement.getInstanceId(),
45-
"DISABLE".equals(sqlStatement.getState()) ? InstanceState.CIRCUIT_BREAK : InstanceState.OK);
46-
}
42+
ClusterPersistServiceFacade clusterPersistServiceFacade = (ClusterPersistServiceFacade) contextManager.getPersistServiceFacade().getModeFacade();
43+
clusterPersistServiceFacade.getComputeNodeService().updateState(sqlStatement.getInstanceId(), "DISABLE".equals(sqlStatement.getState()) ? InstanceState.CIRCUIT_BREAK : InstanceState.OK);
4744
}
4845

4946
private void checkEnablingIsValid(final ContextManager contextManager, final String instanceId) {

proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/label/LabelComputeNodeExecutor.java

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public final class LabelComputeNodeExecutor implements DistSQLUpdateExecutor<Lab
3838

3939
@Override
4040
public void executeUpdate(final LabelComputeNodeStatement sqlStatement, final ContextManager contextManager) throws SQLException {
41-
if (!contextManager.getComputeNodeInstanceContext().getModeConfiguration().isCluster()) {
42-
return;
43-
}
4441
String instanceId = sqlStatement.getInstanceId();
4542
Optional<ComputeNodeInstance> computeNodeInstance = contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find(instanceId);
4643
if (computeNodeInstance.isPresent()) {

proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/label/UnlabelComputeNodeExecutor.java

-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public final class UnlabelComputeNodeExecutor implements DistSQLUpdateExecutor<U
3838

3939
@Override
4040
public void executeUpdate(final UnlabelComputeNodeStatement sqlStatement, final ContextManager contextManager) {
41-
if (!contextManager.getComputeNodeInstanceContext().getModeConfiguration().isCluster()) {
42-
return;
43-
}
4441
String instanceId = sqlStatement.getInstanceId();
4542
Optional<ComputeNodeInstance> computeNodeInstance = contextManager.getComputeNodeInstanceContext().getClusterInstanceRegistry().find(instanceId);
4643
if (computeNodeInstance.isPresent()) {

0 commit comments

Comments
 (0)