You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2023/06/24 06:15:09 UTC
[shardingsphere] branch master updated: Add global props refresh logic (#26508)
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 fa9c2f18da4 Add global props refresh logic (#26508)
fa9c2f18da4 is described below
commit fa9c2f18da4de3a3741de9132d93798930a98663
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Sat Jun 24 14:15:01 2023 +0800
Add global props refresh logic (#26508)
* Add global props refresh logic
* Add unit test
---
...NodeConverter.java => GlobalNodeConverter.java} | 34 +++++++++++++++++-----
...erterTest.java => GlobalNodeConverterTest.java} | 15 ++++++----
.../NewYamlAuthorityRuleConfigurationSwapper.java | 4 +--
...NewYamlGlobalClockRuleConfigurationSwapper.java | 4 +--
.../NewYamlLoggingRuleConfigurationSwapper.java | 4 +--
...wYamlSQLFederationRuleConfigurationSwapper.java | 4 +--
.../NewYamlSQLParserRuleConfigurationSwapper.java | 4 +--
...wYamlSQLTranslatorRuleConfigurationSwapper.java | 4 +--
.../NewYamlTrafficRuleConfigurationSwapper.java | 4 +--
...NewYamlTransactionRuleConfigurationSwapper.java | 4 +--
.../event/config/global/AlterPropertiesEvent.java} | 18 +++++-------
.../watcher/NewGlobalRuleChangedWatcher.java | 6 ++--
.../watcher/NewPropertiesChangedWatcher.java} | 32 ++++++++++----------
.../data/ShardingSphereDataChangedWatcher.java | 3 +-
.../watcher/ClusterStateChangedWatcher.java | 3 +-
.../watcher/ComputeNodeStateChangedWatcher.java | 3 +-
.../watcher/StorageNodeStateChangedWatcher.java | 3 +-
.../NewConfigurationChangedSubscriber.java | 14 +++++++++
...uster.coordinator.registry.NewGovernanceWatcher | 5 ++++
19 files changed, 105 insertions(+), 63 deletions(-)
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverter.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalNodeConverter.java
similarity index 72%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverter.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalNodeConverter.java
index 58fa450f2cd..95df3b176d6 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverter.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/config/converter/GlobalNodeConverter.java
@@ -25,12 +25,14 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * Global rule node converter.
+ * Global node converter.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class GlobalRuleNodeConverter {
+public final class GlobalNodeConverter {
- private static final String ROOT_NODE = "rules";
+ private static final String RULES_NODE = "rules";
+
+ private static final String PROPS_NODE = "props";
private static final String VERSIONS = "versions";
@@ -48,21 +50,37 @@ public final class GlobalRuleNodeConverter {
}
private static String getVersionsNode(final String ruleName) {
- return String.join("/", "", ROOT_NODE, ruleName, VERSIONS);
+ return String.join("/", "", RULES_NODE, ruleName, VERSIONS);
}
/**
- * Is active version path.
+ * Is rule active version path.
*
* @param rulePath rule path
- * @return version
+ * @return true or false
*/
- public static boolean isActiveVersionPath(final String rulePath) {
+ public static boolean isRuleActiveVersionPath(final String rulePath) {
Pattern pattern = Pattern.compile(getRuleNameNode() + "/([\\w\\-]+)/active_version$", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(rulePath);
return matcher.find();
}
+ /**
+ * Is props active version path.
+ *
+ * @param propsPath props path
+ * @return true or false
+ */
+ public static boolean isPropsActiveVersionPath(final String propsPath) {
+ Pattern pattern = Pattern.compile(getPropsNode() + "/active_version$", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(propsPath);
+ return matcher.find();
+ }
+
+ private static String getPropsNode() {
+ return String.join("/", "", PROPS_NODE);
+ }
+
/**
* Get rule name.
*
@@ -76,6 +94,6 @@ public final class GlobalRuleNodeConverter {
}
private static String getRuleNameNode() {
- return String.join("/", "", ROOT_NODE);
+ return String.join("/", "", RULES_NODE);
}
}
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverterTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalNodeConverterTest.java
similarity index 73%
rename from infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverterTest.java
rename to infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalNodeConverterTest.java
index d76a934ea3f..1d520a76e98 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalRuleNodeConverterTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/converter/GlobalNodeConverterTest.java
@@ -25,23 +25,28 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class GlobalRuleNodeConverterTest {
+class GlobalNodeConverterTest {
@Test
void assertGetVersion() {
- Optional<String> actual = GlobalRuleNodeConverter.getVersion("transaction", "/rules/transaction/versions/0");
+ Optional<String> actual = GlobalNodeConverter.getVersion("transaction", "/rules/transaction/versions/0");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("0"));
}
@Test
- void assertIsActiveVersionPath() {
- assertTrue(GlobalRuleNodeConverter.isActiveVersionPath("/rules/transaction/active_version"));
+ void assertIsRuleActiveVersionPath() {
+ assertTrue(GlobalNodeConverter.isRuleActiveVersionPath("/rules/transaction/active_version"));
+ }
+
+ @Test
+ void assertIsPropsActiveVersionPath() {
+ assertTrue(GlobalNodeConverter.isPropsActiveVersionPath("/props/active_version"));
}
@Test
void assertGetRuleName() {
- Optional<String> actual = GlobalRuleNodeConverter.getRuleName("/rules/transaction/active_version");
+ Optional<String> actual = GlobalNodeConverter.getRuleName("/rules/transaction/active_version");
assertTrue(actual.isPresent());
assertThat(actual.get(), is("transaction"));
}
diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
index c0f521a7332..c02b20cd885 100644
--- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
+++ b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/yaml/swapper/NewYamlAuthorityRuleConfigurationSwapper.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.authority.converter.YamlUsersConfigurationConve
import org.apache.shardingsphere.authority.rule.builder.DefaultAuthorityRuleConfigurationBuilder;
import org.apache.shardingsphere.authority.yaml.config.YamlAuthorityRuleConfiguration;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
@@ -61,7 +61,7 @@ public final class NewYamlAuthorityRuleConfigurationSwapper implements NewYamGlo
@Override
public AuthorityRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java
index 92b4861062c..844206429b6 100644
--- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java
+++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/core/yaml/swapper/NewYamlGlobalClockRuleConfigurationSwapper.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.globalclock.core.yaml.swapper;
import org.apache.shardingsphere.globalclock.api.config.GlobalClockRuleConfiguration;
import org.apache.shardingsphere.globalclock.core.rule.constant.GlobalClockOrder;
import org.apache.shardingsphere.globalclock.core.yaml.config.YamlGlobalClockRuleConfiguration;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamGlobalRuleConfigurationSwapper;
@@ -53,7 +53,7 @@ public final class NewYamlGlobalClockRuleConfigurationSwapper implements NewYamG
@Override
public GlobalClockRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java
index 91cce84760f..fb11547affe 100644
--- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java
+++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/yaml/swapper/NewYamlLoggingRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.logging.yaml.swapper;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamGlobalRuleConfigurationSwapper;
@@ -53,7 +53,7 @@ public final class NewYamlLoggingRuleConfigurationSwapper implements NewYamGloba
@Override
public LoggingRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
index 4f10b140bc3..6852bf1888b 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/yaml/swapper/NewYamlSQLFederationRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sqlfederation.yaml.swapper;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamGlobalRuleConfigurationSwapper;
@@ -53,7 +53,7 @@ public final class NewYamlSQLFederationRuleConfigurationSwapper implements NewYa
@Override
public SQLFederationRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java
index 097be60d265..2613aa50a91 100644
--- a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java
+++ b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/yaml/swapper/NewYamlSQLParserRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.parser.yaml.swapper;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamGlobalRuleConfigurationSwapper;
@@ -55,7 +55,7 @@ public final class NewYamlSQLParserRuleConfigurationSwapper implements NewYamGlo
@Override
public SQLParserRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java
index 76a448b3081..90b02ed65ba 100644
--- a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java
+++ b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/yaml/swapper/NewYamlSQLTranslatorRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sqltranslator.yaml.swapper;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamGlobalRuleConfigurationSwapper;
@@ -50,7 +50,7 @@ public final class NewYamlSQLTranslatorRuleConfigurationSwapper implements NewYa
@Override
public SQLTranslatorRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java
index 6908d7ce2f4..ed02c672440 100644
--- a/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java
+++ b/kernel/traffic/core/src/main/java/org/apache/shardingsphere/traffic/yaml/swapper/NewYamlTrafficRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.traffic.yaml.swapper;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.algorithm.YamlAlgorithmConfigurationSwapper;
@@ -66,7 +66,7 @@ public final class NewYamlTrafficRuleConfigurationSwapper implements NewYamGloba
@Override
public TrafficRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
index 89d72f2f9b1..19c371b031a 100644
--- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
+++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/yaml/swapper/NewYamlTransactionRuleConfigurationSwapper.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.transaction.yaml.swapper;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
import org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamGlobalRuleConfigurationSwapper;
@@ -52,7 +52,7 @@ public final class NewYamlTransactionRuleConfigurationSwapper implements NewYamG
@Override
public TransactionRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
for (YamlDataNode each : dataNodes) {
- Optional<String> version = GlobalRuleNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
+ Optional<String> version = GlobalNodeConverter.getVersion(getRuleTagName().toLowerCase(), each.getKey());
if (!version.isPresent()) {
continue;
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/rule/readwritesplitting/LoadBalanceConfigurationChangedEvent.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/AlterPropertiesEvent.java
similarity index 67%
rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/rule/readwritesplitting/LoadBalanceConfigurationChangedEvent.java
rename to mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/AlterPropertiesEvent.java
index 404865c0a15..26fdc54d0ee 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/event/rule/readwritesplitting/LoadBalanceConfigurationChangedEvent.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/config/global/AlterPropertiesEvent.java
@@ -15,24 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.readwritesplitting;
+package org.apache.shardingsphere.mode.event.config.global;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
+import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
/**
- * Load-balance configuration changed event.
+ * Alter properties event.
*/
-@Getter
@RequiredArgsConstructor
-public final class LoadBalanceConfigurationChangedEvent {
-
- private final String databaseName;
-
- private final String loadBalanceName;
+@Getter
+public final class AlterPropertiesEvent implements GovernanceEvent {
- private final String data;
+ private final String activeVersionKey;
- private final Type eventType;
+ private final String activeVersion;
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java
index a36e5ed2c78..f24ea644271 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewGlobalRuleChangedWatcher.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.infra.config.converter.GlobalRuleNodeConverter;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
import org.apache.shardingsphere.metadata.persist.node.GlobalNode;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
@@ -53,8 +53,8 @@ public final class NewGlobalRuleChangedWatcher implements NewGovernanceWatcher<G
}
private Optional<GovernanceEvent> createGlobalRuleEvent(final DataChangedEvent event) {
- if (GlobalRuleNodeConverter.isActiveVersionPath(event.getKey())) {
- Optional<String> ruleName = GlobalRuleNodeConverter.getRuleName(event.getKey());
+ if (GlobalNodeConverter.isRuleActiveVersionPath(event.getKey())) {
+ Optional<String> ruleName = GlobalNodeConverter.getRuleName(event.getKey());
if (!ruleName.isPresent()) {
return Optional.empty();
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/watcher/ClusterStateChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewPropertiesChangedWatcher.java
similarity index 56%
copy from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/watcher/ClusterStateChangedWatcher.java
copy to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewPropertiesChangedWatcher.java
index 5d60abb8f4b..10b9b387adc 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/watcher/ClusterStateChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/config/watcher/NewPropertiesChangedWatcher.java
@@ -15,41 +15,41 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.watcher;
+package org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher;
-import com.google.common.base.Strings;
-import org.apache.shardingsphere.metadata.persist.node.ComputeNode;
-import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
-import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterStateEvent;
+import org.apache.shardingsphere.infra.config.converter.GlobalNodeConverter;
+import org.apache.shardingsphere.metadata.persist.node.GlobalNode;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
+import org.apache.shardingsphere.mode.event.config.global.AlterPropertiesEvent;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
+import java.util.Collection;
import java.util.Optional;
/**
- * Cluster state changed watcher.
+ * TODO Rename PropertiesChangedWatcher when metadata structure adjustment completed. #25485
+ * Properties changed watcher.
*/
-public final class ClusterStateChangedWatcher implements GovernanceWatcher<GovernanceEvent> {
+public final class NewPropertiesChangedWatcher implements NewGovernanceWatcher<AlterPropertiesEvent> {
@Override
public Collection<String> getWatchingKeys(final String databaseName) {
- return Collections.singleton(ComputeNode.getClusterStatusNodePath());
+ return Collections.singleton(GlobalNode.getPropsPath());
}
@Override
public Collection<Type> getWatchingTypes() {
- return Arrays.asList(Type.ADDED, Type.UPDATED, Type.DELETED);
+ return Arrays.asList(Type.ADDED, Type.UPDATED);
}
@Override
- public Optional<GovernanceEvent> createGovernanceEvent(final DataChangedEvent event) {
- String clusterStatus = ComputeNode.getClusterStatusNodePath();
- return Strings.isNullOrEmpty(clusterStatus) || Type.DELETED == event.getType() || !event.getKey().equals(ComputeNode.getClusterStatusNodePath())
- ? Optional.empty()
- : Optional.of(new ClusterStateEvent(event.getValue()));
+ public Optional<AlterPropertiesEvent> createGovernanceEvent(final DataChangedEvent event) {
+ if (GlobalNodeConverter.isPropsActiveVersionPath(event.getKey())) {
+ return Optional.of(new AlterPropertiesEvent(event.getKey(), event.getValue()));
+ }
+ return Optional.empty();
}
}
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/data/ShardingSphereDataChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/data/ShardingSphereDataChangedWatcher.java
index 04d6a87f9eb..e28ed0704eb 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/data/ShardingSphereDataChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/data/ShardingSphereDataChangedWatcher.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData;
import org.apache.shardingsphere.metadata.persist.node.ShardingSphereDataNode;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.data.event.DatabaseDataAddedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.data.event.DatabaseDataDeletedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.data.event.SchemaDataAddedEvent;
@@ -42,7 +43,7 @@ import java.util.Optional;
/**
* ShardingSphere data changed watcher.
*/
-public final class ShardingSphereDataChangedWatcher implements GovernanceWatcher<GovernanceEvent> {
+public final class ShardingSphereDataChangedWatcher implements GovernanceWatcher<GovernanceEvent>, NewGovernanceWatcher<GovernanceEvent> {
@Override
public Collection<String> getWatchingKeys(final String databaseName) {
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/watcher/ClusterStateChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/watcher/ClusterStateChangedWatcher.java
index 5d60abb8f4b..758ea1daeb2 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/watcher/ClusterStateChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/cluster/watcher/ClusterStateChangedWatcher.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
import org.apache.shardingsphere.metadata.persist.node.ComputeNode;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.event.ClusterStateEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent;
import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
@@ -33,7 +34,7 @@ import java.util.Optional;
/**
* Cluster state changed watcher.
*/
-public final class ClusterStateChangedWatcher implements GovernanceWatcher<GovernanceEvent> {
+public final class ClusterStateChangedWatcher implements GovernanceWatcher<GovernanceEvent>, NewGovernanceWatcher<GovernanceEvent> {
@Override
public Collection<String> getWatchingKeys(final String databaseName) {
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
index 57b3e7c7471..38dcb2f976b 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/compute/watcher/ComputeNodeStateChangedWatcher.java
@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.metadata.persist.node.ComputeNode;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOfflineEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.InstanceOnlineEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.event.KillLocalProcessEvent;
@@ -49,7 +50,7 @@ import java.util.regex.Pattern;
/**
* Compute node state changed watcher.
*/
-public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<GovernanceEvent> {
+public final class ComputeNodeStateChangedWatcher implements GovernanceWatcher<GovernanceEvent>, NewGovernanceWatcher<GovernanceEvent> {
@Override
public Collection<String> getWatchingKeys(final String databaseName) {
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
index cc41c827c02..8e31e520dc5 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/storage/watcher/StorageNodeStateChangedWatcher.java
@@ -22,6 +22,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabas
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.GovernanceWatcher;
+import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.event.StorageNodeChangedEvent;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node.StorageNode;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.yaml.YamlStorageNodeDataSource;
@@ -38,7 +39,7 @@ import java.util.Optional;
/**
* Storage node state changed watcher.
*/
-public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<GovernanceEvent> {
+public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<GovernanceEvent>, NewGovernanceWatcher<GovernanceEvent> {
@Override
public Collection<String> getWatchingKeys(final String databaseName) {
diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java
index e8e6c4837d6..8bfa7a800b2 100644
--- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java
+++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/NewConfigurationChangedSubscriber.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber;
import com.google.common.eventbus.Subscribe;
import org.apache.shardingsphere.mode.event.config.DatabaseRuleConfigurationChangedEvent;
import org.apache.shardingsphere.mode.event.config.global.AlterGlobalRuleConfigurationEvent;
+import org.apache.shardingsphere.mode.event.config.global.AlterPropertiesEvent;
import org.apache.shardingsphere.mode.event.config.global.DeleteGlobalRuleConfigurationEvent;
import org.apache.shardingsphere.mode.manager.ContextManager;
@@ -70,4 +71,17 @@ public final class NewConfigurationChangedSubscriber {
public synchronized void renew(final DeleteGlobalRuleConfigurationEvent event) {
contextManager.dropGlobalRuleConfiguration(event.getRuleSimpleName());
}
+
+ /**
+ * Renew for global properties.
+ *
+ * @param event global properties alter event
+ */
+ @Subscribe
+ public synchronized void renew(final AlterPropertiesEvent event) {
+ if (!event.getActiveVersion().equals(contextManager.getInstanceContext().getModeContextManager().getActiveVersionByKey(event.getActiveVersionKey()))) {
+ return;
+ }
+ contextManager.alterProperties(contextManager.getMetaDataContexts().getPersistService().getPropsService().load());
+ }
}
diff --git a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher
index b0a0e3a3258..474d36e9d35 100644
--- a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher
+++ b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.NewGovernanceWatcher
@@ -15,5 +15,10 @@
# limitations under the License.
#
+org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.watcher.StorageNodeStateChangedWatcher
+org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.compute.watcher.ComputeNodeStateChangedWatcher
+org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.cluster.watcher.ClusterStateChangedWatcher
+org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.data.ShardingSphereDataChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.metadata.watcher.NewMetaDataChangedWatcher
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher.NewGlobalRuleChangedWatcher
+org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.watcher.NewPropertiesChangedWatcher