You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/03/22 09:06:20 UTC

[shardingsphere] branch master updated: Fix get data node empty for broadcast. (#24740)

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

duanzhengqiang 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 f2a167c4f45 Fix get data node empty for broadcast. (#24740)
f2a167c4f45 is described below

commit f2a167c4f45c5a86a39d6aa5b6cc12628367a1c7
Author: Chuxin Chen <ch...@qq.com>
AuthorDate: Wed Mar 22 17:06:06 2023 +0800

    Fix get data node empty for broadcast. (#24740)
---
 .../org/apache/shardingsphere/sharding/rule/ShardingRule.java  |  3 +++
 .../apache/shardingsphere/sharding/rule/ShardingRuleTest.java  | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
index f613857061f..96f2fb21571 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
@@ -662,6 +662,9 @@ public final class ShardingRule implements DatabaseRule, DataNodeContainedRule,
     
     @Override
     public Collection<DataNode> getDataNodesByTableName(final String tableName) {
+        if (isBroadcastTable(tableName)) {
+            return new TableRule(dataSourceNames, tableName).getActualDataNodes();
+        }
         return shardingTableDataNodes.getOrDefault(tableName.toLowerCase(), Collections.emptyList());
     }
     
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
index f8765485176..f7684ab9a25 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java
@@ -779,4 +779,14 @@ public final class ShardingRuleTest {
         assertFalse(createMaximumShardingRule().isSupportAutoIncrement("logic_table"));
         assertTrue(createMaximumShardingRule().isSupportAutoIncrement("sub_logic_table"));
     }
+    
+    @Test
+    public void assertGetDataNodesByTableNameForBroadcastTable() {
+        ShardingRule actual = createMaximumShardingRule();
+        Collection<DataNode> actualDataNodes = actual.getDataNodesByTableName("broadcast_table");
+        assertThat(actualDataNodes.size(), is(2));
+        Iterator<DataNode> actualDataNode = actualDataNodes.iterator();
+        assertThat(actualDataNode.next().getDataSourceName(), is("ds_0"));
+        assertThat(actualDataNode.next().getDataSourceName(), is("ds_1"));
+    }
 }