This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 800964f Do not use disable to control circuit breaker status (#12505)
800964f is described below
commit 800964f0feefc9b3cf3acbfc6464c39739199d24
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Sep 16 23:42:05 2021 +0800
Do not use disable to control circuit breaker status (#12505)
* Add more test case with StorageNodeStateChangedWatcher
* Rename ComputeNodeStateChangedWatcher
---
.../coordinator/registry/status/ResourceState.java | 29 ---------------
...er.java => ComputeNodeStateChangedWatcher.java} | 10 ++---
.../watcher/StorageNodeStateChangedWatcher.java | 1 -
....cluster.coordinator.registry.GovernanceWatcher | 2 +-
...ava => ComputeNodeStateChangedWatcherTest.java} | 13 +++----
.../StorageNodeStateChangedWatcherTest.java | 43 +++++++++++++++++++---
6 files changed, 50 insertions(+), 48 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/registry/status/ResourceState.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/ResourceState.java
deleted file mode 100644
index 9d43765..0000000
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/ResourceState.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.mode.manager.cluster.coordinator.registry.status;
-
-/**
- * Resource state.
- */
-public enum ResourceState {
-
- /**
- * Disabled state.
- */
- DISABLED
-}
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/registry/status/watcher/TerminalStateChangedWatcher.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcher.java
similarity index 82%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcher.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcher.java
index 3951e06..7fd38ad 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcher.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcher.java
@@ -20,19 +20,19 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.stat
import org.apache.shardingsphere.infra.state.StateEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ComputeNodeStatus;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ResourceState;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.node.StatusNode;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent.Type;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
/**
- * Terminal state changed watcher.
+ * Compute node state changed watcher.
*/
-public final class TerminalStateChangedWatcher implements
GovernanceWatcher<StateEvent> {
+public final class ComputeNodeStateChangedWatcher implements
GovernanceWatcher<StateEvent> {
@Override
public Collection<String> getWatchingKeys() {
@@ -41,11 +41,11 @@ public final class TerminalStateChangedWatcher implements
GovernanceWatcher<Stat
@Override
public Collection<Type> getWatchingTypes() {
- return Collections.singleton(Type.UPDATED);
+ return Arrays.asList(Type.ADDED, Type.DELETED);
}
@Override
public Optional<StateEvent> createGovernanceEvent(final DataChangedEvent
event) {
- return Optional.of(new StateEvent("CIRCUIT_BREAK",
ResourceState.DISABLED.toString().equalsIgnoreCase(event.getValue())));
+ return Optional.of(new StateEvent("CIRCUIT_BREAK", Type.ADDED ==
event.getType()));
}
}
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/registry/status/watcher/StorageNodeStateChangedWatcher.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
index 2f7342e..3baa790 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
@@ -54,5 +54,4 @@ public final class StorageNodeStateChangedWatcher implements
GovernanceWatcher<G
}
return StatusNode.getClusterSchema(StorageNodeStatus.DISABLE,
event.getKey()).map(schema -> new DisabledStateChangedEvent(schema, Type.ADDED
== event.getType()));
}
-
}
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
index 28bfe68..461341a 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher
@@ -20,5 +20,5 @@
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.wat
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher.GlobalRuleChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.authority.watcher.PrivilegeNodeChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher.PropertiesChangedWatcher
-org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.watcher.TerminalStateChangedWatcher
+org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.watcher.ComputeNodeStateChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.watcher.LockChangedWatcher
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/registry/status/watcher/TerminalStateChangedWatcherTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcherTest.java
similarity index 76%
rename from
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcherTest.java
rename to
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcherTest.java
index 13435f4..b928c95 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/TerminalStateChangedWatcherTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/ComputeNodeStateChangedWatcherTest.java
@@ -17,10 +17,9 @@
package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.watcher;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.ResourceState;
+import org.apache.shardingsphere.infra.state.StateEvent;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent.Type;
-import org.apache.shardingsphere.infra.state.StateEvent;
import org.junit.Test;
import java.util.Optional;
@@ -28,19 +27,19 @@ import java.util.Optional;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-public final class TerminalStateChangedWatcherTest {
+public final class ComputeNodeStateChangedWatcherTest {
@Test
public void assertCreateEventWhenEnabled() {
- Optional<StateEvent> actual = new
TerminalStateChangedWatcher().createGovernanceEvent(new
DataChangedEvent("/test_ds", "", Type.UPDATED));
+ Optional<StateEvent> actual = new
ComputeNodeStateChangedWatcher().createGovernanceEvent(new
DataChangedEvent("/test_ds/circuit_breaker", "", Type.ADDED));
assertTrue(actual.isPresent());
- assertFalse(actual.get().isOn());
+ assertTrue(actual.get().isOn());
}
@Test
public void assertCreateEventWhenDisabled() {
- Optional<StateEvent> actual = new
TerminalStateChangedWatcher().createGovernanceEvent(new
DataChangedEvent("/test_ds", ResourceState.DISABLED.name(), Type.UPDATED));
+ Optional<StateEvent> actual = new
ComputeNodeStateChangedWatcher().createGovernanceEvent(new
DataChangedEvent("/test_ds/circuit_breaker", "", Type.DELETED));
assertTrue(actual.isPresent());
- assertTrue(actual.get().isOn());
+ assertFalse(actual.get().isOn());
}
}
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/registry/status/watcher/StorageNodeStateChangedWatcherTest.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcherTest.java
index 82980a6..ef4c92b 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcherTest.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcherTest.java
@@ -17,9 +17,9 @@
package
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.watcher;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.schema.ClusterSchema;
-import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.event.DisabledStateChangedEvent;
import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.event.DisabledStateChangedEvent;
+import
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.event.PrimaryStateChangedEvent;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent;
import
org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEvent.Type;
import org.junit.Test;
@@ -27,16 +27,49 @@ import org.junit.Test;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public final class StorageNodeStateChangedWatcherTest {
@Test
- public void assertCreateEvent() {
+ public void assertCreatePrimaryStateChangedEvent() {
+ Optional<GovernanceEvent> actual = new
StorageNodeStateChangedWatcher().createGovernanceEvent(
+ new
DataChangedEvent("/status/storage_nodes/primary/replica_query_db.replica_ds_0",
"new_db", Type.ADDED));
+ assertTrue(actual.isPresent());
+ PrimaryStateChangedEvent actualEvent = (PrimaryStateChangedEvent)
actual.get();
+ assertThat(actualEvent.getClusterSchema().getSchemaName(),
is("replica_query_db"));
+ assertThat(actualEvent.getClusterSchema().getDataSourceName(),
is("replica_ds_0"));
+ assertThat(actualEvent.getPrimaryDataSourceName(), is("new_db"));
+ }
+
+ @Test
+ public void assertCreateEnabledStateChangedEvent() {
+ Optional<GovernanceEvent> actual = new
StorageNodeStateChangedWatcher().createGovernanceEvent(
+ new
DataChangedEvent("/status/storage_nodes/disable/replica_query_db.replica_ds_0",
"", Type.ADDED));
+ assertTrue(actual.isPresent());
+ DisabledStateChangedEvent actualEvent = (DisabledStateChangedEvent)
actual.get();
+ assertThat(actualEvent.getClusterSchema().getSchemaName(),
is("replica_query_db"));
+ assertThat(actualEvent.getClusterSchema().getDataSourceName(),
is("replica_ds_0"));
+ assertTrue(actualEvent.isDisabled());
+ }
+
+ @Test
+ public void assertCreateDisabledStateChangedEvent() {
Optional<GovernanceEvent> actual = new
StorageNodeStateChangedWatcher().createGovernanceEvent(
- new
DataChangedEvent("/status/storage_nodes/disable/replica_query_db.replica_ds_0",
"", Type.UPDATED));
+ new
DataChangedEvent("/status/storage_nodes/disable/replica_query_db.replica_ds_0",
"", Type.DELETED));
assertTrue(actual.isPresent());
- assertThat(((DisabledStateChangedEvent)
actual.get()).getClusterSchema().getSchemaName(), is(new
ClusterSchema("replica_query_db", "replica_ds_0").getSchemaName()));
+ DisabledStateChangedEvent actualEvent = (DisabledStateChangedEvent)
actual.get();
+ assertThat(actualEvent.getClusterSchema().getSchemaName(),
is("replica_query_db"));
+ assertThat(actualEvent.getClusterSchema().getDataSourceName(),
is("replica_ds_0"));
+ assertFalse(actualEvent.isDisabled());
+ }
+
+ @Test
+ public void assertCreateEmptyEvent() {
+ Optional<GovernanceEvent> actual = new
StorageNodeStateChangedWatcher().createGovernanceEvent(
+ new
DataChangedEvent("/status/storage_nodes/other/replica_query_db.replica_ds_0",
"new_db", Type.ADDED));
+ assertFalse(actual.isPresent());
}
}