You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/06/19 04:08:21 UTC
[shardingsphere] branch master updated: Refactor BroadcastRule to new metadata structure (#26390)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 3740ef6fd70 Refactor BroadcastRule to new metadata structure (#26390)
3740ef6fd70 is described below
commit 3740ef6fd704e682d61682d453b0621260af5006
Author: ChenJiaHao <Pa...@163.com>
AuthorDate: Mon Jun 19 12:08:14 2023 +0800
Refactor BroadcastRule to new metadata structure (#26390)
* Refactor BroadcastRule to new metadata structure
* Add unit tests
* Resolve conflicts
* Resolve conflicts
* Revert CreateBroadcastTableRuleStatementUpdater build method
* Rename broadcast metadata event
* Update comments
---
.../BroadcastRuleConfigurationEventBuilder.java | 65 +++++++++++++
.../event/config/AddBroadcastTableEvent.java | 35 +++++++
.../event/config/AlterBroadcastTableEvent.java | 35 +++++++
.../event/config/DeleteBroadcastTableEvent.java | 32 +++++++
.../metadata/converter/BroadcastNodeConverter.java | 72 +++++++++++++++
.../BroadcastConfigurationSubscriber.java | 101 +++++++++++++++++++++
.../NewYamlBroadcastRuleConfigurationSwapper.java | 70 ++++++++++++++
...nfra.rule.RuleConfigurationSubscribeCoordinator | 18 ++++
...ig.swapper.rule.NewYamlRuleConfigurationSwapper | 18 ++++
...ngsphere.mode.spi.RuleConfigurationEventBuilder | 18 ++++
.../convert/BroadcastNodeConverterTest.java | 42 +++++++++
...wYamlBroadcastRuleConfigurationSwapperTest.java | 79 ++++++++++++++++
.../DropBroadcastTableRuleStatementUpdater.java | 8 ++
13 files changed, 593 insertions(+)
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/BroadcastRuleConfigurationEventBuilder.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/BroadcastRuleConfigurationEventBuilder.java
new file mode 100644
index 00000000000..523983b9e1a
--- /dev/null
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/BroadcastRuleConfigurationEventBuilder.java
@@ -0,0 +1,65 @@
+/*
+ * 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.broadcast.event;
+
+import com.google.common.base.Strings;
+import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.broadcast.event.config.AddBroadcastTableEvent;
+import org.apache.shardingsphere.broadcast.event.config.AlterBroadcastTableEvent;
+import org.apache.shardingsphere.broadcast.event.config.DeleteBroadcastTableEvent;
+import org.apache.shardingsphere.broadcast.metadata.converter.BroadcastNodeConverter;
+import org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration;
+import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
+import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
+import org.apache.shardingsphere.mode.event.DataChangedEvent;
+import org.apache.shardingsphere.mode.event.DataChangedEvent.Type;
+import org.apache.shardingsphere.mode.spi.RuleConfigurationEventBuilder;
+
+import java.util.Optional;
+
+/**
+ * Broadcast rule configuration event builder.
+ */
+public final class BroadcastRuleConfigurationEventBuilder implements RuleConfigurationEventBuilder {
+
+ @Override
+ public Optional<GovernanceEvent> build(final String databaseName, final DataChangedEvent event) {
+ if (!BroadcastNodeConverter.isBroadcastPath(event.getKey()) || Strings.isNullOrEmpty(event.getValue())) {
+ return Optional.empty();
+ }
+ if (BroadcastNodeConverter.isTablesPath(event.getKey()) && !Strings.isNullOrEmpty(event.getValue())) {
+ return createBroadcastConfigEvent(databaseName, event);
+ }
+ return Optional.empty();
+ }
+
+ private Optional<GovernanceEvent> createBroadcastConfigEvent(final String databaseName, final DataChangedEvent event) {
+ if (Type.ADDED == event.getType()) {
+ return Optional.of(new AddBroadcastTableEvent(databaseName, swapBroadcastTableRuleConfig(event.getValue())));
+ }
+ if (Type.UPDATED == event.getType()) {
+ return Optional.of(new AlterBroadcastTableEvent(databaseName, swapBroadcastTableRuleConfig(event.getValue())));
+ }
+ return Optional.of(new DeleteBroadcastTableEvent(databaseName));
+ }
+
+ private BroadcastRuleConfiguration swapBroadcastTableRuleConfig(final String yamlContext) {
+ YamlBroadcastRuleConfiguration yamlBroadcastRuleConfiguration = YamlEngine.unmarshal(yamlContext, YamlBroadcastRuleConfiguration.class);
+ return new BroadcastRuleConfiguration(yamlBroadcastRuleConfiguration.getTables());
+ }
+}
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/AddBroadcastTableEvent.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/AddBroadcastTableEvent.java
new file mode 100644
index 00000000000..54a6508fe81
--- /dev/null
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/AddBroadcastTableEvent.java
@@ -0,0 +1,35 @@
+/*
+ * 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.broadcast.event.config;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
+
+/**
+ * Add broadcast table event.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class AddBroadcastTableEvent implements GovernanceEvent {
+
+ private final String databaseName;
+
+ private final BroadcastRuleConfiguration config;
+}
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/AlterBroadcastTableEvent.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/AlterBroadcastTableEvent.java
new file mode 100644
index 00000000000..626c8749c48
--- /dev/null
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/AlterBroadcastTableEvent.java
@@ -0,0 +1,35 @@
+/*
+ * 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.broadcast.event.config;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
+
+/**
+ * Alter broadcast table event.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class AlterBroadcastTableEvent implements GovernanceEvent {
+
+ private final String databaseName;
+
+ private final BroadcastRuleConfiguration config;
+}
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/DeleteBroadcastTableEvent.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/DeleteBroadcastTableEvent.java
new file mode 100644
index 00000000000..bd624005d20
--- /dev/null
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/event/config/DeleteBroadcastTableEvent.java
@@ -0,0 +1,32 @@
+/*
+ * 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.broadcast.event.config;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.rule.event.GovernanceEvent;
+
+/**
+ * Delete broadcast table event.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class DeleteBroadcastTableEvent implements GovernanceEvent {
+
+ private final String databaseName;
+}
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/metadata/converter/BroadcastNodeConverter.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/metadata/converter/BroadcastNodeConverter.java
new file mode 100644
index 00000000000..9378c59f6c2
--- /dev/null
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/metadata/converter/BroadcastNodeConverter.java
@@ -0,0 +1,72 @@
+/*
+ * 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.broadcast.metadata.converter;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Broadcast node converter.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class BroadcastNodeConverter {
+
+ private static final String ROOT_NODE = "broadcast";
+
+ private static final String TABLES_NODE = "tables";
+
+ private static final String RULES_NODE_PREFIX = "/([\\w\\-]+)/([\\w\\-]+)/rules/";
+
+ private static final String VERSION_PATTERN = "/versions/[0-9]+";
+
+ /**
+ * Get table name path.
+ *
+ * @return table name path
+ */
+ public static String getTablesPath() {
+ return TABLES_NODE;
+ }
+
+ /**
+ * Is broadcast path.
+ *
+ * @param rulePath rule path
+ * @return true or false
+ */
+ public static boolean isBroadcastPath(final String rulePath) {
+ Pattern pattern = Pattern.compile(RULES_NODE_PREFIX + ROOT_NODE + "\\.*", Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(rulePath);
+ return matcher.find();
+ }
+
+ /**
+ * Is broadcast tables path.
+ *
+ * @param rulePath rule path
+ * @return true or false
+ */
+ public static boolean isTablesPath(final String rulePath) {
+ Pattern pattern = Pattern.compile(RULES_NODE_PREFIX + ROOT_NODE + "/" + TABLES_NODE + VERSION_PATTERN, Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(rulePath);
+ return matcher.find();
+ }
+}
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastConfigurationSubscriber.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastConfigurationSubscriber.java
new file mode 100644
index 00000000000..b5789233479
--- /dev/null
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/subscriber/BroadcastConfigurationSubscriber.java
@@ -0,0 +1,101 @@
+/*
+ * 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.broadcast.subscriber;
+
+import com.google.common.eventbus.Subscribe;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.broadcast.event.config.AddBroadcastTableEvent;
+import org.apache.shardingsphere.broadcast.event.config.AlterBroadcastTableEvent;
+import org.apache.shardingsphere.broadcast.event.config.DeleteBroadcastTableEvent;
+import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.rule.RuleConfigurationSubscribeCoordinator;
+import org.apache.shardingsphere.mode.event.config.DatabaseRuleConfigurationChangedEvent;
+
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Broadcast configuration subscriber.
+ */
+@SuppressWarnings("UnstableApiUsage")
+@RequiredArgsConstructor
+public final class BroadcastConfigurationSubscriber implements RuleConfigurationSubscribeCoordinator {
+
+ private Map<String, ShardingSphereDatabase> databases;
+
+ private InstanceContext instanceContext;
+
+ @Override
+ public void registerRuleConfigurationSubscriber(final Map<String, ShardingSphereDatabase> databases, final InstanceContext instanceContext) {
+ this.databases = databases;
+ this.instanceContext = instanceContext;
+ instanceContext.getEventBusContext().register(this);
+ }
+
+ /**
+ * Renew with add broadcast configuration.
+ *
+ * @param event add broadcast configuration event
+ */
+ @Subscribe
+ public synchronized void renew(final AddBroadcastTableEvent event) {
+ ShardingSphereDatabase database = databases.get(event.getDatabaseName());
+ BroadcastRuleConfiguration needToAddedConfig = event.getConfig();
+ Optional<BroadcastRule> rule = database.getRuleMetaData().findSingleRule(BroadcastRule.class);
+ BroadcastRuleConfiguration config;
+ if (rule.isPresent()) {
+ config = rule.get().getConfiguration();
+ config.getTables().clear();
+ config.getTables().addAll(needToAddedConfig.getTables());
+ } else {
+ config = new BroadcastRuleConfiguration(needToAddedConfig.getTables());
+ }
+ instanceContext.getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
+ }
+
+ /**
+ * Renew with alter broadcast configuration.
+ *
+ * @param event alter broadcast configuration event
+ */
+ @Subscribe
+ public synchronized void renew(final AlterBroadcastTableEvent event) {
+ ShardingSphereDatabase database = databases.get(event.getDatabaseName());
+ BroadcastRuleConfiguration needToAlteredConfig = event.getConfig();
+ BroadcastRuleConfiguration config = database.getRuleMetaData().getSingleRule(BroadcastRule.class).getConfiguration();
+ config.getTables().clear();
+ config.getTables().addAll(needToAlteredConfig.getTables());
+ instanceContext.getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
+ }
+
+ /**
+ * Renew with delete broadcast configuration.
+ *
+ * @param event delete broadcast configuration event
+ */
+ @Subscribe
+ public synchronized void renew(final DeleteBroadcastTableEvent event) {
+ ShardingSphereDatabase database = databases.get(event.getDatabaseName());
+ BroadcastRuleConfiguration config = database.getRuleMetaData().getSingleRule(BroadcastRule.class).getConfiguration();
+ config.getTables().clear();
+ instanceContext.getEventBusContext().post(new DatabaseRuleConfigurationChangedEvent(event.getDatabaseName(), config));
+ }
+}
diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/NewYamlBroadcastRuleConfigurationSwapper.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/NewYamlBroadcastRuleConfigurationSwapper.java
new file mode 100644
index 00000000000..4dc963663e1
--- /dev/null
+++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/yaml/swapper/NewYamlBroadcastRuleConfigurationSwapper.java
@@ -0,0 +1,70 @@
+/*
+ * 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.broadcast.yaml.swapper;
+
+import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.broadcast.constant.BroadcastOrder;
+import org.apache.shardingsphere.broadcast.metadata.converter.BroadcastNodeConverter;
+import org.apache.shardingsphere.broadcast.yaml.config.YamlBroadcastRuleConfiguration;
+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.NewYamlRuleConfigurationSwapper;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * TODO Rename to YamlBroadcastRuleConfigurationSwapper when metadata structure adjustment completed.
+ * New YAML broadcast rule configuration swapper.
+ */
+public final class NewYamlBroadcastRuleConfigurationSwapper implements NewYamlRuleConfigurationSwapper<BroadcastRuleConfiguration> {
+
+ @Override
+ public Collection<YamlDataNode> swapToDataNodes(final BroadcastRuleConfiguration data) {
+ if (data.getTables().isEmpty()) {
+ return Collections.emptyList();
+ }
+ YamlBroadcastRuleConfiguration yamlBroadcastRuleConfiguration = new YamlBroadcastRuleConfiguration();
+ yamlBroadcastRuleConfiguration.getTables().addAll(data.getTables());
+ return Collections.singleton(new YamlDataNode(BroadcastNodeConverter.getTablesPath(), YamlEngine.marshal(yamlBroadcastRuleConfiguration)));
+ }
+
+ @Override
+ public BroadcastRuleConfiguration swapToObject(final Collection<YamlDataNode> dataNodes) {
+ if (!dataNodes.isEmpty()) {
+ YamlBroadcastRuleConfiguration yamlBroadcastRuleConfiguration = YamlEngine.unmarshal(dataNodes.iterator().next().getValue(), YamlBroadcastRuleConfiguration.class);
+ return new BroadcastRuleConfiguration(yamlBroadcastRuleConfiguration.getTables());
+ }
+ return new BroadcastRuleConfiguration(Collections.emptyList());
+ }
+
+ @Override
+ public Class<BroadcastRuleConfiguration> getTypeClass() {
+ return BroadcastRuleConfiguration.class;
+ }
+
+ @Override
+ public int getOrder() {
+ return BroadcastOrder.ORDER;
+ }
+
+ @Override
+ public String getRuleTagName() {
+ return "BROADCAST";
+ }
+}
diff --git a/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.RuleConfigurationSubscribeCoordinator b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.RuleConfigurationSubscribeCoordinator
new file mode 100644
index 00000000000..ad852730c4a
--- /dev/null
+++ b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.rule.RuleConfigurationSubscribeCoordinator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.broadcast.subscriber.BroadcastConfigurationSubscriber
diff --git a/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper
new file mode 100644
index 00000000000..aa6db32a11b
--- /dev/null
+++ b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.yaml.config.swapper.rule.NewYamlRuleConfigurationSwapper
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.broadcast.yaml.swapper.NewYamlBroadcastRuleConfigurationSwapper
diff --git a/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.RuleConfigurationEventBuilder b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.RuleConfigurationEventBuilder
new file mode 100644
index 00000000000..cc2699147ef
--- /dev/null
+++ b/features/broadcast/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.spi.RuleConfigurationEventBuilder
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.broadcast.event.BroadcastRuleConfigurationEventBuilder
diff --git a/features/broadcast/core/src/main/test/org/apache/shardingsphere/broadcast/metadata/convert/BroadcastNodeConverterTest.java b/features/broadcast/core/src/main/test/org/apache/shardingsphere/broadcast/metadata/convert/BroadcastNodeConverterTest.java
new file mode 100644
index 00000000000..75ddee86d77
--- /dev/null
+++ b/features/broadcast/core/src/main/test/org/apache/shardingsphere/broadcast/metadata/convert/BroadcastNodeConverterTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.broadcast.metadata.convert;
+
+import org.apache.shardingsphere.broadcast.metadata.converter.BroadcastNodeConverter;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class BroadcastNodeConverterTest {
+
+ @Test
+ void assertGetTableNamePath() {
+ assertThat(BroadcastNodeConverter.getTablesPath(), is("tables"));
+ }
+
+ @Test
+ void assertCheckIsTargetRuleByRulePath() {
+ assertTrue(BroadcastNodeConverter.isBroadcastPath("/metadata/foo_db/rules/broadcast/tables"));
+ assertFalse(BroadcastNodeConverter.isBroadcastPath("/metadata/foo_db/rules/foo/tables/foo_table"));
+ assertTrue(BroadcastNodeConverter.isTablesPath("/metadata/foo_db/rules/broadcast/tables/versions/0"));
+ assertFalse(BroadcastNodeConverter.isTablesPath("/metadata/foo_db/rules/broadcast/tables/MD5"));
+ }
+}
diff --git a/features/broadcast/core/src/main/test/org/apache/shardingsphere/broadcast/yaml/swapper/NewYamlBroadcastRuleConfigurationSwapperTest.java b/features/broadcast/core/src/main/test/org/apache/shardingsphere/broadcast/yaml/swapper/NewYamlBroadcastRuleConfigurationSwapperTest.java
new file mode 100644
index 00000000000..cc07f188caa
--- /dev/null
+++ b/features/broadcast/core/src/main/test/org/apache/shardingsphere/broadcast/yaml/swapper/NewYamlBroadcastRuleConfigurationSwapperTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.broadcast.yaml.swapper;
+
+import org.apache.shardingsphere.broadcast.api.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.infra.util.yaml.datanode.YamlDataNode;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class NewYamlBroadcastRuleConfigurationSwapperTest {
+
+ private final NewYamlBroadcastRuleConfigurationSwapper swapper = new NewYamlBroadcastRuleConfigurationSwapper();
+
+ @Test
+ void assertSwapEmptyConfigToDataNodes() {
+ BroadcastRuleConfiguration config = new BroadcastRuleConfiguration();
+ Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
+ assertThat(result.size(), is(0));
+ }
+
+ @Test
+ void assertSwapFullConfigToDataNodes() {
+ BroadcastRuleConfiguration config = createMaximumBroadcastRule();
+ Collection<YamlDataNode> result = swapper.swapToDataNodes(config);
+ assertThat(result.size(), is(1));
+ Iterator<YamlDataNode> iterator = result.iterator();
+ assertThat(iterator.next().getKey(), is("tables"));
+ }
+
+ private BroadcastRuleConfiguration createMaximumBroadcastRule() {
+ Collection<String> tables = new LinkedList<>();
+ tables.add(("foo_table"));
+ tables.add(("foo_table2"));
+ BroadcastRuleConfiguration result = new BroadcastRuleConfiguration();
+ result.setTables(tables);
+ return result;
+ }
+
+ @Test
+ void assertSwapToObjectEmpty() {
+ Collection<YamlDataNode> config = new LinkedList<>();
+ BroadcastRuleConfiguration result = swapper.swapToObject(config);
+ assertThat(result.getTables().size(), is(0));
+ }
+
+ @Test
+ void assertSwapToObject() {
+ Collection<YamlDataNode> config = new LinkedList<>();
+ config.add(new YamlDataNode("/metadata/foo_db/rules/broadcast/tables", "tables:\n" +
+ "- foo_table\n" +
+ "- foo_table2\n"));
+ BroadcastRuleConfiguration result = swapper.swapToObject(config);
+ assertThat(result.getTables().size(), is(2));
+ Iterator<String> iterator = result.getTables().iterator();
+ assertThat(iterator.next(), is("foo_table"));
+ assertThat(iterator.next(), is("foo_table2"));
+ }
+}
diff --git a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleStatementUpdater.java b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleStatementUpdater.java
index 0fc0070fecd..df4b136671d 100644
--- a/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleStatementUpdater.java
+++ b/features/broadcast/distsql/handler/src/main/java/org/apache/shardingsphere/broadcast/distsql/handler/update/DropBroadcastTableRuleStatementUpdater.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import java.util.Collection;
+import java.util.HashSet;
import java.util.stream.Collectors;
/**
@@ -65,6 +66,13 @@ public final class DropBroadcastTableRuleStatementUpdater implements RuleDefinit
return isExistRuleConfig(currentRuleConfig) && !getIdenticalData(currentRuleConfig.getTables(), sqlStatement.getTables()).isEmpty();
}
+ @Override
+ public BroadcastRuleConfiguration buildToBeAlteredRuleConfiguration(final BroadcastRuleConfiguration currentRuleConfig, final DropBroadcastTableRuleStatement sqlStatement) {
+ BroadcastRuleConfiguration result = new BroadcastRuleConfiguration(new HashSet<>(currentRuleConfig.getTables()));
+ result.getTables().removeIf(each -> containsIgnoreCase(sqlStatement.getTables(), each));
+ return result;
+ }
+
@Override
public boolean updateCurrentRuleConfiguration(final DropBroadcastTableRuleStatement sqlStatement, final BroadcastRuleConfiguration currentRuleConfig) {
currentRuleConfig.getTables().removeIf(each -> containsIgnoreCase(sqlStatement.getTables(), each));