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 d0ca45fd92e Modify ResourceContainedRule.getDataSourceMapper return
role info (#24609)
d0ca45fd92e is described below
commit d0ca45fd92e65f48d36ea35a4dec117cd203d79d
Author: ZhangCheng <[email protected]>
AuthorDate: Thu Mar 16 10:28:28 2023 +0800
Modify ResourceContainedRule.getDataSourceMapper return role info (#24609)
* Modify ResourceContainedRule.getDataSourceMapper return role info
* fix
* Remote dataSourceMapperInfo
* fix
---
.../rule/DatabaseDiscoveryDataSourceRule.java | 16 +++++++++----
.../dbdiscovery/rule/DatabaseDiscoveryRule.java | 5 ++--
.../rule/DatabaseDiscoveryDataSourceRuleTest.java | 8 +++++--
.../rule/DatabaseDiscoveryRuleTest.java | 9 +++++---
.../CountDatabaseDiscoveryRuleExecutorTest.java | 12 ++++++----
.../rule/ReadwriteSplittingRule.java | 5 ++--
.../strategy/ReadwriteSplittingStrategy.java | 4 +++-
.../type/DynamicReadwriteSplittingStrategy.java | 6 +++--
.../type/StaticReadwriteSplittingStrategy.java | 12 ++++++----
.../rule/ReadwriteSplittingRuleTest.java | 7 ++++--
.../DynamicReadwriteSplittingStrategyTest.java | 7 ++++--
...DropReadwriteSplittingRuleStatementUpdater.java | 9 ++++----
.../CountReadwriteSplittingRuleExecutorTest.java | 8 ++++++-
...ReadwriteSplittingRuleStatementUpdaterTest.java | 6 ++++-
.../shardingsphere/shadow/rule/ShadowRule.java | 14 ++++++-----
.../distsql/query/CountShadowRuleExecutorTest.java | 12 ++++++----
...reateShardingTableRuleStatementUpdaterTest.java | 5 ++--
.../infra/datanode/DataNodeUtil.java | 7 +++---
.../mapper/DataSourceRole.java} | 19 ++++-----------
.../mapper/DataSourceRoleInfo.java} | 27 +++++++++++-----------
.../identifier/type/DataSourceContainedRule.java | 3 ++-
.../type/StaticDataSourceContainedRule.java | 3 ++-
.../infra/datanode/DataNodeUtilTest.java | 15 +++++++-----
.../infra/datanode/DataNodesTest.java | 15 ++++++------
.../shardingsphere/infra/fixture/FixtureRule.java | 3 ++-
.../shardingsphere/single/rule/SingleRule.java | 9 ++++----
.../subscriber/ConfigurationChangedSubscriber.java | 3 ++-
.../unit/UnregisterStorageUnitBackendHandler.java | 9 ++++----
.../rql/storage/unit/ShowStorageUnitExecutor.java | 9 ++++----
.../fixture/FixtureDataSourceContainedRule.java | 9 ++++----
.../ImportDatabaseConfigurationUpdaterTest.java | 4 ++--
.../UnregisterStorageUnitBackendHandlerTest.java | 6 +++--
32 files changed, 166 insertions(+), 120 deletions(-)
diff --git
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
index 86ca026b617..cf32aa48388 100644
---
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
+++
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRule.java
@@ -24,6 +24,8 @@ import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDa
import
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDataSourceNamesConfigurationException;
import
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredGroupNameConfigurationException;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import javax.sql.DataSource;
@@ -129,14 +131,18 @@ public final class DatabaseDiscoveryDataSourceRule {
*
* @return data source mapper
*/
- public Map<String, Collection<String>> getDataSourceMapper() {
+ public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
return Collections.singletonMap(groupName, getActualDataSourceNames());
}
- private Collection<String> getActualDataSourceNames() {
- Collection<String> result = new LinkedHashSet<>();
- result.add(primaryDataSourceName);
- result.addAll(dataSourceNames);
+ private Collection<DataSourceRoleInfo> getActualDataSourceNames() {
+ Collection<DataSourceRoleInfo> result = new LinkedHashSet<>();
+ result.add(new DataSourceRoleInfo(primaryDataSourceName,
DataSourceRole.PRIMARY));
+ dataSourceNames.forEach(each -> {
+ if (!primaryDataSourceName.equals(each)) {
+ result.add(new DataSourceRoleInfo(each,
DataSourceRole.MEMBER));
+ }
+ });
return result;
}
}
diff --git
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 737392d0063..55842e0772f 100644
---
a/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++
b/features/db-discovery/core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -29,6 +29,7 @@ import
org.apache.shardingsphere.dbdiscovery.heartbeat.HeartbeatJob;
import org.apache.shardingsphere.dbdiscovery.spi.DatabaseDiscoveryProvider;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
@@ -151,8 +152,8 @@ public final class DatabaseDiscoveryRule implements
DatabaseRule, DataSourceCont
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new HashMap<>();
+ public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
+ Map<String, Collection<DataSourceRoleInfo>> result = new
LinkedHashMap<>();
for (Entry<String, DatabaseDiscoveryDataSourceRule> entry :
dataSourceRules.entrySet()) {
result.putAll(entry.getValue().getDataSourceMapper());
}
diff --git
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
index b74c04497de..1e1da1a4a6d 100644
---
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
+++
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryDataSourceRuleTest.java
@@ -20,11 +20,13 @@ package org.apache.shardingsphere.dbdiscovery.rule;
import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
import
org.apache.shardingsphere.dbdiscovery.exception.MissingRequiredDataSourceNamesConfigurationException;
import
org.apache.shardingsphere.dbdiscovery.mysql.type.MGRMySQLDatabaseDiscoveryProvider;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
@@ -66,6 +68,8 @@ public final class DatabaseDiscoveryDataSourceRuleTest {
@Test
public void assertGetDataSourceMapper() {
databaseDiscoveryDataSourceRule.changePrimaryDataSourceName("ds_1");
- assertThat(databaseDiscoveryDataSourceRule.getDataSourceMapper(),
is(Collections.singletonMap("test_pr", new HashSet<>(Arrays.asList("ds_1",
"ds_0")))));
+ assertThat(databaseDiscoveryDataSourceRule.getDataSourceMapper(),
+ is(Collections.singletonMap("test_pr",
+ new LinkedHashSet<>(Arrays.asList(new
DataSourceRoleInfo("ds_1", DataSourceRole.PRIMARY), new
DataSourceRoleInfo("ds_0", DataSourceRole.MEMBER))))));
}
}
diff --git
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
index f64d90b8a2d..41c83638657 100644
---
a/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
+++
b/features/db-discovery/core/src/test/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRuleTest.java
@@ -23,6 +23,8 @@ import
org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHe
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import
org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.rule.identifier.type.exportable.constant.ExportableConstants;
import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
@@ -34,7 +36,7 @@ import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
@@ -75,8 +77,9 @@ public final class DatabaseDiscoveryRuleTest {
@Test
public void assertGetDataSourceMapper() {
DatabaseDiscoveryRule databaseDiscoveryRule = createRule();
- Map<String, Collection<String>> actual =
databaseDiscoveryRule.getDataSourceMapper();
- assertThat(actual, is(Collections.singletonMap("replica_ds", new
HashSet<>(Arrays.asList("primary_ds", "replica_ds_0", "replica_ds_1")))));
+ Map<String, Collection<DataSourceRoleInfo>> actual =
databaseDiscoveryRule.getDataSourceMapper();
+ assertThat(actual, is(Collections.singletonMap("replica_ds", new
LinkedHashSet<>(Arrays.asList(new DataSourceRoleInfo("primary_ds",
DataSourceRole.PRIMARY),
+ new DataSourceRoleInfo("replica_ds_0", DataSourceRole.MEMBER),
new DataSourceRoleInfo("replica_ds_1", DataSourceRole.MEMBER))))));
}
@Test
diff --git
a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutorTest.java
b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutorTest.java
index 0dda96c4b26..8ab6cb02a68 100644
---
a/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutorTest.java
+++
b/features/db-discovery/distsql/handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/CountDatabaseDiscoveryRuleExecutorTest.java
@@ -20,6 +20,8 @@ package
org.apache.shardingsphere.dbdiscovery.distsql.handler.query;
import
org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CountDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.dbdiscovery.rule.DatabaseDiscoveryRule;
import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -27,8 +29,8 @@ import org.junit.jupiter.api.Test;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -72,10 +74,10 @@ public final class CountDatabaseDiscoveryRuleExecutorTest {
private DatabaseDiscoveryRule mockDatabaseDiscoveryRule() {
DatabaseDiscoveryRule result = mock(DatabaseDiscoveryRule.class);
- Map<String, Collection<String>> datasourceMapper = new HashMap<>(2, 1);
- datasourceMapper.put("ds_0", Collections.singletonList("ds_0"));
- datasourceMapper.put("ds_1", Collections.singletonList("ds_1"));
- when(result.getDataSourceMapper()).thenReturn(datasourceMapper);
+ Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper = new
LinkedHashMap<>();
+ dataSourceMapper.put("ds_0", Collections.singletonList(new
DataSourceRoleInfo("ds_0", DataSourceRole.PRIMARY)));
+ dataSourceMapper.put("ds_1", Collections.singletonList(new
DataSourceRoleInfo("ds_1", DataSourceRole.MEMBER)));
+ when(result.getDataSourceMapper()).thenReturn(dataSourceMapper);
return result;
}
}
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
index 582ddd8f4f0..2d0d82b7b42 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRule.java
@@ -21,6 +21,7 @@ import com.google.common.base.Preconditions;
import lombok.Getter;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
@@ -168,8 +169,8 @@ public final class ReadwriteSplittingRule implements
DatabaseRule, DataSourceCon
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new HashMap<>();
+ public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
+ Map<String, Collection<DataSourceRoleInfo>> result = new
LinkedHashMap<>();
for (Entry<String, ReadwriteSplittingDataSourceRule> entry :
dataSourceRules.entrySet()) {
result.put(entry.getValue().getName(),
entry.getValue().getReadwriteSplittingStrategy().getAllDataSources());
}
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/ReadwriteSplittingStrategy.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/ReadwriteSplittingStrategy.java
index f12e8826e13..2fd0dfc062a 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/ReadwriteSplittingStrategy.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/ReadwriteSplittingStrategy.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.readwritesplitting.strategy;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
+
import java.util.Collection;
import java.util.List;
@@ -43,5 +45,5 @@ public interface ReadwriteSplittingStrategy {
*
* @return all data sources
*/
- Collection<String> getAllDataSources();
+ Collection<DataSourceRoleInfo> getAllDataSources();
}
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
index 78f8d333c67..dba6c917493 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategy.java
@@ -20,6 +20,8 @@ package
org.apache.shardingsphere.readwritesplitting.strategy.type;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.readwritesplitting.strategy.ReadwriteSplittingStrategy;
import java.util.ArrayList;
@@ -49,7 +51,7 @@ public final class DynamicReadwriteSplittingStrategy
implements ReadwriteSplitti
}
@Override
- public Collection<String> getAllDataSources() {
- return Collections.singletonList(autoAwareDataSourceName);
+ public Collection<DataSourceRoleInfo> getAllDataSources() {
+ return Collections.singletonList(new
DataSourceRoleInfo(autoAwareDataSourceName, DataSourceRole.PRIMARY));
}
}
diff --git
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/StaticReadwriteSplittingStrategy.java
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/StaticReadwriteSplittingStrategy.java
index 0e530efaff7..d9bbcde626a 100644
---
a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/StaticReadwriteSplittingStrategy.java
+++
b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/strategy/type/StaticReadwriteSplittingStrategy.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.readwritesplitting.strategy.type;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.readwritesplitting.strategy.ReadwriteSplittingStrategy;
import java.util.Collection;
@@ -45,10 +47,12 @@ public final class StaticReadwriteSplittingStrategy
implements ReadwriteSplittin
}
@Override
- public Collection<String> getAllDataSources() {
- Collection<String> result = new LinkedList<>();
- result.add(writeDataSourceName);
- result.addAll(readDataSourceNames);
+ public Collection<DataSourceRoleInfo> getAllDataSources() {
+ Collection<DataSourceRoleInfo> result = new LinkedList<>();
+ result.add(new DataSourceRoleInfo(writeDataSourceName,
DataSourceRole.PRIMARY));
+ readDataSourceNames.forEach(each -> {
+ result.add(new DataSourceRoleInfo(each, DataSourceRole.MEMBER));
+ });
return result;
}
}
diff --git
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
index 539d877fd21..99b5b900eca 100644
---
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
+++
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/ReadwriteSplittingRuleTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.readwritesplitting.rule;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDatabase;
@@ -99,8 +101,9 @@ public final class ReadwriteSplittingRuleTest {
@Test
public void assertGetDataSourceMapper() {
ReadwriteSplittingRule readwriteSplittingRule =
createReadwriteSplittingRule();
- Map<String, Collection<String>> actual =
readwriteSplittingRule.getDataSourceMapper();
- Map<String, Collection<String>> expected =
Collections.singletonMap("readwrite", Arrays.asList("write_ds", "read_ds_0",
"read_ds_1"));
+ Map<String, Collection<DataSourceRoleInfo>> actual =
readwriteSplittingRule.getDataSourceMapper();
+ Map<String, Collection<DataSourceRoleInfo>> expected =
Collections.singletonMap("readwrite", Arrays.asList(new
DataSourceRoleInfo("write_ds", DataSourceRole.PRIMARY),
+ new DataSourceRoleInfo("read_ds_0", DataSourceRole.MEMBER),
new DataSourceRoleInfo("read_ds_1", DataSourceRole.MEMBER)));
assertThat(actual, is(expected));
}
}
diff --git
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategyTest.java
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategyTest.java
index adc28e6ff61..01fd49b71a3 100644
---
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategyTest.java
+++
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/strategy/type/DynamicReadwriteSplittingStrategyTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.readwritesplitting.strategy.type;
import
org.apache.shardingsphere.infra.rule.identifier.type.DynamicDataSourceContainedRule;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.junit.jupiter.api.Test;
import java.util.Collections;
@@ -30,7 +32,8 @@ public final class DynamicReadwriteSplittingStrategyTest {
@Test
public void assertGetDataSourceMapper() {
- DynamicReadwriteSplittingStrategy dynamicReadwriteSplittingStrategy =
new DynamicReadwriteSplittingStrategy("database_discovery_ds",
mock(DynamicDataSourceContainedRule.class));
- assertThat(dynamicReadwriteSplittingStrategy.getAllDataSources(),
is(Collections.singletonList("database_discovery_ds")));
+ DynamicReadwriteSplittingStrategy dynamicReadwriteSplittingStrategy =
new DynamicReadwriteSplittingStrategy("database_discovery_ds",
+ mock(DynamicDataSourceContainedRule.class));
+ assertThat(dynamicReadwriteSplittingStrategy.getAllDataSources(),
is(Collections.singletonList(new DataSourceRoleInfo("database_discovery_ds",
DataSourceRole.PRIMARY))));
}
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java
index 96ed336cd7f..49c27dab70a 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdater.java
@@ -17,11 +17,12 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.update;
-import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.distsql.handler.exception.rule.MissingRequiredRuleException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.RuleDefinitionViolationException;
import
org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
import
org.apache.shardingsphere.distsql.handler.update.RuleDefinitionDropUpdater;
+import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
@@ -34,6 +35,7 @@ import
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
import java.util.Collection;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -77,9 +79,8 @@ public final class DropReadwriteSplittingRuleStatementUpdater
implements RuleDef
if (each instanceof ReadwriteSplittingRule) {
continue;
}
- Collection<String> actualDataSources = new HashSet<>();
-
each.getDataSourceMapper().values().forEach(actualDataSources::addAll);
- result.addAll(actualDataSources);
+
result.addAll(each.getDataSourceMapper().values().stream().flatMap(Collection::stream)
+
.map(DataSourceRoleInfo::getName).collect(Collectors.toCollection(LinkedHashSet::new)));
}
for (DataNodeContainedRule each :
database.getRuleMetaData().findRules(DataNodeContainedRule.class)) {
Collection<DataNode> actualDataNodes = new HashSet<>();
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/CountReadwriteSplittingRuleExecutorTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/CountReadwriteSplittingRuleExecutorTest.java
index ac9cc04bd82..ed49040d29e 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/CountReadwriteSplittingRuleExecutorTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/CountReadwriteSplittingRuleExecutorTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.readwritesplitting.distsql.handler.query;
import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -29,6 +31,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -71,7 +74,10 @@ public final class CountReadwriteSplittingRuleExecutorTest {
private ReadwriteSplittingRule mockReadwriteSplittingRule() {
ReadwriteSplittingRule result = mock(ReadwriteSplittingRule.class);
-
when(result.getDataSourceMapper()).thenReturn(Collections.singletonMap("readwrite_splitting",
Arrays.asList("write_ds", "read_ds")));
+ Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper =
Collections.singletonMap("readwrite_splitting",
+ Arrays.asList(new DataSourceRoleInfo("write_ds",
DataSourceRole.PRIMARY),
+ new DataSourceRoleInfo("read_ds",
DataSourceRole.MEMBER)));
+ when(result.getDataSourceMapper()).thenReturn(dataSourceMapper);
return result;
}
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
index d5bc6208272..a9510237cd3 100644
---
a/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
+++
b/features/readwrite-splitting/distsql/handler/src/test/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/update/DropReadwriteSplittingRuleStatementUpdaterTest.java
@@ -22,6 +22,8 @@ import
org.apache.shardingsphere.distsql.handler.exception.rule.RuleDefinitionVi
import
org.apache.shardingsphere.distsql.handler.exception.rule.RuleInUsedException;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
@@ -36,6 +38,7 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
@@ -78,7 +81,8 @@ public final class
DropReadwriteSplittingRuleStatementUpdaterTest {
@Test
public void assertCheckSQLStatementWithInUsed() throws
RuleDefinitionViolationException {
DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
-
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("foo_ds",
Collections.singleton("readwrite_ds")));
+ Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper =
Collections.singletonMap("foo_ds", Collections.singleton(new
DataSourceRoleInfo("readwrite_ds", DataSourceRole.PRIMARY)));
+
when(dataSourceContainedRule.getDataSourceMapper()).thenReturn(dataSourceMapper);
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
DataNodeContainedRule dataNodeContainedRule =
mock(DataNodeContainedRule.class);
when(dataNodeContainedRule.getAllDataNodes()).thenReturn(Collections.singletonMap("foo_ds",
Collections.singleton(new DataNode("readwrite_ds.tbl"))));
diff --git
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
index 3717a86e333..a3013271f7f 100644
---
a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
+++
b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/rule/ShadowRule.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.shadow.rule;
import lombok.Getter;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPILoader;
@@ -236,16 +238,16 @@ public final class ShadowRule implements DatabaseRule,
DataSourceContainedRule {
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new LinkedHashMap<>();
+ public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
+ Map<String, Collection<DataSourceRoleInfo>> result = new
LinkedHashMap<>();
shadowDataSourceMappings.forEach((key, value) -> result.put(key,
createShadowDataSources(value)));
return result;
}
- private Collection<String> createShadowDataSources(final
ShadowDataSourceRule shadowDataSourceRule) {
- Collection<String> result = new LinkedList<>();
- result.add(shadowDataSourceRule.getProductionDataSource());
- result.add(shadowDataSourceRule.getShadowDataSource());
+ private Collection<DataSourceRoleInfo> createShadowDataSources(final
ShadowDataSourceRule shadowDataSourceRule) {
+ Collection<DataSourceRoleInfo> result = new LinkedList<>();
+ result.add(new
DataSourceRoleInfo(shadowDataSourceRule.getProductionDataSource(),
DataSourceRole.PRODUCTION));
+ result.add(new
DataSourceRoleInfo(shadowDataSourceRule.getShadowDataSource(),
DataSourceRole.SHADOW));
return result;
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleExecutorTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleExecutorTest.java
index 3c5f17e7d2c..e466481a2f9 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleExecutorTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/CountShadowRuleExecutorTest.java
@@ -18,6 +18,8 @@
package org.apache.shardingsphere.shadow.distsql.query;
import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -29,8 +31,8 @@ import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Map;
import static org.hamcrest.CoreMatchers.is;
@@ -73,11 +75,11 @@ public final class CountShadowRuleExecutorTest {
}
private ShadowRule mockShadowRule() {
- Map<String, Collection<String>> shadowDataSourceMappings = new
HashMap<>();
- shadowDataSourceMappings.put("shadow-data-source-0",
Arrays.asList("ds", "ds_shadow"));
- shadowDataSourceMappings.put("shadow-data-source-1",
Arrays.asList("ds1", "ds1_shadow"));
ShadowRule result = mock(ShadowRule.class);
-
when(result.getDataSourceMapper()).thenReturn(shadowDataSourceMappings);
+ Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper = new
LinkedHashMap<>();
+ dataSourceMapper.put("shadow-data-source-0", Arrays.asList(new
DataSourceRoleInfo("ds", DataSourceRole.PRODUCTION), new
DataSourceRoleInfo("ds_shadow", DataSourceRole.SHADOW)));
+ dataSourceMapper.put("shadow-data-source-1", Arrays.asList(new
DataSourceRoleInfo("ds1", DataSourceRole.PRODUCTION), new
DataSourceRoleInfo("ds1_shadow", DataSourceRole.SHADOW)));
+ when(result.getDataSourceMapper()).thenReturn(dataSourceMapper);
return result;
}
}
diff --git
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
index a9656f9f2c3..4548571241f 100644
---
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
+++
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.distsql.parser.statement.DistSQLStatement;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
@@ -258,8 +259,8 @@ public final class
CreateShardingTableRuleStatementUpdaterTest {
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- return Collections.singletonMap("logic_ds", null);
+ public Map<String, Collection<DataSourceRoleInfo>>
getDataSourceMapper() {
+ return Collections.singletonMap("logic_ds",
Collections.emptyList());
}
@Override
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeUtil.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeUtil.java
index 7b9b88722b4..860b65378c9 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeUtil.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNodeUtil.java
@@ -19,6 +19,7 @@ package org.apache.shardingsphere.infra.datanode;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import java.util.Collection;
import java.util.Collections;
@@ -59,13 +60,13 @@ public final class DataNodeUtil {
* @param dataSources dataSource map
* @return data node collection
*/
- public static Collection<DataNode> buildDataNode(final DataNode dataNode,
final Map<String, Collection<String>> dataSources) {
+ public static Collection<DataNode> buildDataNode(final DataNode dataNode,
final Map<String, Collection<DataSourceRoleInfo>> dataSources) {
if (!dataSources.containsKey(dataNode.getDataSourceName())) {
return Collections.singletonList(dataNode);
}
Collection<DataNode> result = new LinkedList<>();
- for (String each : dataSources.get(dataNode.getDataSourceName())) {
- result.add(new DataNode(each, dataNode.getTableName()));
+ for (DataSourceRoleInfo each :
dataSources.get(dataNode.getDataSourceName())) {
+ result.add(new DataNode(each.getName(), dataNode.getTableName()));
}
return result;
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/mapper/DataSourceRole.java
similarity index 64%
copy from
infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
copy to
infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/mapper/DataSourceRole.java
index ca5302c233d..606d63a2e63 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/mapper/DataSourceRole.java
@@ -15,22 +15,11 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.rule.identifier.type;
-
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-
-import java.util.Collection;
-import java.util.Map;
+package org.apache.shardingsphere.infra.datasource.mapper;
/**
- * ShardingSphere rule which contains data source.
+ * Data source role.
*/
-public interface DataSourceContainedRule extends ShardingSphereRule {
-
- /**
- * Get data source mapper.
- *
- * @return data source mapper
- */
- Map<String, Collection<String>> getDataSourceMapper();
+public enum DataSourceRole {
+ PRIMARY, MEMBER, PRODUCTION, SHADOW
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/mapper/DataSourceRoleInfo.java
similarity index 64%
copy from
infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
copy to
infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/mapper/DataSourceRoleInfo.java
index ca5302c233d..530f9f9eb6f 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/datasource/mapper/DataSourceRoleInfo.java
@@ -15,22 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.rule.identifier.type;
+package org.apache.shardingsphere.infra.datasource.mapper;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-
-import java.util.Collection;
-import java.util.Map;
+import lombok.AllArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
/**
- * ShardingSphere rule which contains data source.
+ * Data source role info.
*/
-public interface DataSourceContainedRule extends ShardingSphereRule {
+@Getter
+@Setter
+@EqualsAndHashCode
+@AllArgsConstructor
+public final class DataSourceRoleInfo {
+
+ private String name;
- /**
- * Get data source mapper.
- *
- * @return data source mapper
- */
- Map<String, Collection<String>> getDataSourceMapper();
+ private DataSourceRole role;
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
index ca5302c233d..99e403ab5ce 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/DataSourceContainedRule.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.rule.identifier.type;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import java.util.Collection;
@@ -32,5 +33,5 @@ public interface DataSourceContainedRule extends
ShardingSphereRule {
*
* @return data source mapper
*/
- Map<String, Collection<String>> getDataSourceMapper();
+ Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper();
}
diff --git
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/StaticDataSourceContainedRule.java
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/StaticDataSourceContainedRule.java
index 53111980ffd..a1b771c34bc 100644
---
a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/StaticDataSourceContainedRule.java
+++
b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/identifier/type/StaticDataSourceContainedRule.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.rule.identifier.type;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
@@ -33,7 +34,7 @@ public interface StaticDataSourceContainedRule extends
ShardingSphereRule {
*
* @return data source mapper
*/
- Map<String, Collection<String>> getDataSourceMapper();
+ Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper();
/**
* Update data source status.
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeUtilTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeUtilTest.java
index 710bbcc600f..df30d354510 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeUtilTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeUtilTest.java
@@ -17,10 +17,13 @@
package org.apache.shardingsphere.infra.datanode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
@@ -46,9 +49,9 @@ public final class DataNodeUtilTest {
@Test
public void assertBuildDataNodeWithSameDataSource() {
DataNode dataNode = new DataNode("readwrite_ds.t_order");
- Map<String, Collection<String>> dataSources = new LinkedHashMap<>();
- dataSources.put("readwrite_ds", Arrays.asList("ds_0", "shadow_ds_0"));
- Collection<DataNode> dataNodes = DataNodeUtil.buildDataNode(dataNode,
dataSources);
+ Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper =
Collections.singletonMap("readwrite_ds",
+ Arrays.asList(new DataSourceRoleInfo("ds_0",
DataSourceRole.PRIMARY), new DataSourceRoleInfo("shadow_ds_0",
DataSourceRole.MEMBER)));
+ Collection<DataNode> dataNodes = DataNodeUtil.buildDataNode(dataNode,
dataSourceMapper);
assertThat(dataNodes.size(), is(2));
Iterator<DataNode> iterator = dataNodes.iterator();
assertThat(iterator.next().getDataSourceName(), is("ds_0"));
@@ -58,9 +61,9 @@ public final class DataNodeUtilTest {
@Test
public void assertBuildDataNodeWithoutSameDataSource() {
DataNode dataNode = new DataNode("read_ds.t_order");
- Map<String, Collection<String>> dataSources = new LinkedHashMap<>();
- dataSources.put("readwrite_ds", Arrays.asList("ds_0", "shadow_ds_0"));
- Collection<DataNode> dataNodes = DataNodeUtil.buildDataNode(dataNode,
dataSources);
+ Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper =
Collections.singletonMap("readwrite_ds",
+ Arrays.asList(new DataSourceRoleInfo("ds_0",
DataSourceRole.PRIMARY), new DataSourceRoleInfo("shadow_ds_0",
DataSourceRole.MEMBER)));
+ Collection<DataNode> dataNodes = DataNodeUtil.buildDataNode(dataNode,
dataSourceMapper);
assertThat(dataNodes.size(), is(1));
assertThat(dataNodes.iterator().next().getDataSourceName(),
is("read_ds"));
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java
index 02d99e5075c..772a71a0d6f 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodesTest.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.infra.datanode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.fixture.FixtureRule;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
@@ -26,8 +28,8 @@ import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
@@ -38,12 +40,6 @@ import static org.mockito.Mockito.when;
public final class DataNodesTest {
- private static final Map<String, Collection<String>>
READ_WRITE_SPLITTING_DATASOURCE_MAP = new HashMap<>();
-
- static {
- READ_WRITE_SPLITTING_DATASOURCE_MAP.putIfAbsent("readwrite_ds",
Arrays.asList("primary_ds", "replica_ds_0", "replica_ds_1"));
- }
-
@Test
public void
assertGetDataNodesForShardingTableWithoutDataNodeContainedRule() {
DataNodes dataNodes = new
DataNodes(Collections.singletonList(mockDataSourceContainedRule()));
@@ -135,7 +131,10 @@ public final class DataNodesTest {
private ShardingSphereRule mockDataSourceContainedRule() {
DataSourceContainedRule result = mock(FixtureRule.class);
-
when(result.getDataSourceMapper()).thenReturn(READ_WRITE_SPLITTING_DATASOURCE_MAP);
+ Map<String, Collection<DataSourceRoleInfo>> dataSourceMapper = new
LinkedHashMap<>();
+ dataSourceMapper.put("readwrite_ds", Arrays.asList(new
DataSourceRoleInfo("primary_ds", DataSourceRole.PRIMARY),
+ new DataSourceRoleInfo("replica_ds_0", DataSourceRole.MEMBER),
new DataSourceRoleInfo("replica_ds_1", DataSourceRole.MEMBER)));
+ when(result.getDataSourceMapper()).thenReturn(dataSourceMapper);
return result;
}
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
index e50265e9287..0b27496fdfe 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
+++
b/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.fixture;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
@@ -35,7 +36,7 @@ public final class FixtureRule implements DatabaseRule,
DataSourceContainedRule
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
+ public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
return Collections.emptyMap();
}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
index 2307d7500ec..860c05c7f2a 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
@@ -21,6 +21,7 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.datasource.state.DataSourceStateManager;
import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
import org.apache.shardingsphere.infra.route.context.RouteContext;
@@ -91,10 +92,10 @@ public final class SingleRule implements DatabaseRule,
DataNodeContainedRule, Ta
private Map<String, DataSource> getAggregateDataSourceMap(final
Map<String, DataSource> dataSourceMap, final DataSourceContainedRule builtRule)
{
Map<String, DataSource> result = new LinkedHashMap<>();
- for (Entry<String, Collection<String>> entry :
builtRule.getDataSourceMapper().entrySet()) {
- for (String each : entry.getValue()) {
- if (dataSourceMap.containsKey(each)) {
- result.putIfAbsent(entry.getKey(),
dataSourceMap.remove(each));
+ for (Entry<String, Collection<DataSourceRoleInfo>> entry :
builtRule.getDataSourceMapper().entrySet()) {
+ for (DataSourceRoleInfo each : entry.getValue()) {
+ if (dataSourceMap.containsKey(each.getName())) {
+ result.putIfAbsent(entry.getKey(),
dataSourceMap.remove(each.getName()));
}
}
}
diff --git
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java
index 48e8ffdc20b..42dc5105407 100644
---
a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java
+++
b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/subscriber/ConfigurationChangedSubscriber.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.mode.manager.cluster.coordinator.subscriber;
import com.google.common.eventbus.Subscribe;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.datasource.state.DataSourceState;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -138,7 +139,7 @@ public final class ConfigurationChangedSubscriber {
}
private void disableDataSources(final StorageNodeDataSource
storageNodeDataSource, final StaticDataSourceContainedRule rule, final
QualifiedDatabase database) {
- for (Entry<String, Collection<String>> entry :
rule.getDataSourceMapper().entrySet()) {
+ for (Entry<String, Collection<DataSourceRoleInfo>> entry :
rule.getDataSourceMapper().entrySet()) {
if (!database.getGroupName().equals(entry.getKey())) {
continue;
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java
index f092af84448..69a5f2116ea 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandler.java
@@ -25,6 +25,7 @@ import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRe
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.StorageUnitInUsedException;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.UnregisterStorageUnitStatement;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataNodeContainedRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import
org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
@@ -40,6 +41,7 @@ import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.stream.Collectors;
@@ -105,11 +107,8 @@ public final class UnregisterStorageUnitBackendHandler
extends StorageUnitDefini
}
private Collection<String> getInUsedResourceNames(final
DataSourceContainedRule rule) {
- Collection<String> result = new HashSet<>();
- for (Collection<String> each : rule.getDataSourceMapper().values()) {
- result.addAll(each);
- }
- return result;
+ return
rule.getDataSourceMapper().values().stream().flatMap(Collection::stream)
+
.map(DataSourceRoleInfo::getName).collect(Collectors.toCollection(LinkedHashSet::new));
}
private Collection<String> getInUsedResourceNames(final
DataNodeContainedRule rule) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
index 942817a1b70..cbcec300668 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/storage/unit/ShowStorageUnitExecutor.java
@@ -24,6 +24,7 @@ import
org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
import
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowStorageUnitsStatement;
import org.apache.shardingsphere.infra.database.metadata.DataSourceMetaData;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import
org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
@@ -38,6 +39,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
@@ -118,11 +120,8 @@ public final class ShowStorageUnitExecutor implements
RQLExecutor<ShowStorageUni
}
private Collection<String> getInUsedResourceNames(final
DataSourceContainedRule rule) {
- Set<String> result = new HashSet<>();
- for (Collection<String> each : rule.getDataSourceMapper().values()) {
- result.addAll(each);
- }
- return result;
+ return
rule.getDataSourceMapper().values().stream().flatMap(Collection::stream)
+
.map(DataSourceRoleInfo::getName).collect(Collectors.toCollection(LinkedHashSet::new));
}
private Collection<String> getInUsedResourceNames(final
DataNodeContainedRule rule) {
diff --git
a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/fixture/FixtureDataSourceContainedRule.java
similarity index 77%
copy from
infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
copy to
proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/fixture/FixtureDataSourceContainedRule.java
index e50265e9287..9c4c7425bd8 100644
---
a/infra/common/src/test/java/org/apache/shardingsphere/infra/fixture/FixtureRule.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/fixture/FixtureDataSourceContainedRule.java
@@ -15,9 +15,10 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.fixture;
+package org.apache.shardingsphere.proxy.backend.handler.distsql.fixture;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.rule.identifier.scope.DatabaseRule;
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
@@ -27,7 +28,7 @@ import java.util.Map;
import static org.mockito.Mockito.mock;
-public final class FixtureRule implements DatabaseRule,
DataSourceContainedRule {
+public final class FixtureDataSourceContainedRule implements DatabaseRule,
DataSourceContainedRule {
@Override
public RuleConfiguration getConfiguration() {
@@ -35,12 +36,12 @@ public final class FixtureRule implements DatabaseRule,
DataSourceContainedRule
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
+ public Map<String, Collection<DataSourceRoleInfo>> getDataSourceMapper() {
return Collections.emptyMap();
}
@Override
public String getType() {
- return FixtureRule.class.getSimpleName();
+ return FixtureDataSourceContainedRule.class.getSimpleName();
}
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
index de98effa5a5..fd3f52ce574 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java
@@ -31,6 +31,7 @@ import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSp
import
org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import
org.apache.shardingsphere.proxy.backend.handler.distsql.fixture.FixtureDataSourceContainedRule;
import
org.apache.shardingsphere.proxy.backend.util.YamlDatabaseConfigurationImportExecutor;
import org.apache.shardingsphere.test.mock.AutoMockExtension;
import org.apache.shardingsphere.test.mock.StaticMockSettings;
@@ -132,8 +133,7 @@ public final class ImportDatabaseConfigurationUpdaterTest {
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(database.getSchema(DefaultDatabase.LOGIC_NAME)).thenReturn(schema);
- DataSourceContainedRule dataSourceContainedRule =
mock(DataSourceContainedRule.class);
-
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(dataSourceContainedRule));
+
when(database.getRuleMetaData().findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(new
FixtureDataSourceContainedRule()));
when(result.getMetaDataContexts().getMetaData().getDatabases()).thenReturn(Collections.singletonMap(databaseName,
database));
when(result.getMetaDataContexts().getMetaData().getDatabase(databaseName)).thenReturn(database);
when(result.getMetaDataContexts().getMetaData().getProps()).thenReturn(new
ConfigurationProperties(createProperties()));
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java
index 3099a90b6bb..a5f81391e50 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rdl/storage/unit/UnregisterStorageUnitBackendHandlerTest.java
@@ -22,6 +22,8 @@ import
org.apache.shardingsphere.distsql.handler.exception.storageunit.MissingRe
import
org.apache.shardingsphere.distsql.handler.exception.storageunit.StorageUnitInUsedException;
import
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.UnregisterStorageUnitStatement;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRole;
+import org.apache.shardingsphere.infra.datasource.mapper.DataSourceRoleInfo;
import org.apache.shardingsphere.infra.instance.mode.ModeContextManager;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.resource.ShardingSphereResourceMetaData;
@@ -128,7 +130,7 @@ public final class UnregisterStorageUnitBackendHandlerTest {
public void assertStorageUnitNameInUseExecute() {
when(ruleMetaData.findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(shadowRule));
when(shadowRule.getType()).thenReturn("ShadowRule");
-
when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton("foo_ds")));
+
when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton(new DataSourceRoleInfo("foo_ds",
DataSourceRole.PRIMARY))));
when(resourceMetaData.getDataSources()).thenReturn(Collections.singletonMap("foo_ds",
dataSource));
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
when(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database);
@@ -176,7 +178,7 @@ public final class UnregisterStorageUnitBackendHandlerTest {
public void assertStorageUnitNameInUseWithIfExists() {
when(ruleMetaData.findRules(DataSourceContainedRule.class)).thenReturn(Collections.singleton(shadowRule));
when(shadowRule.getType()).thenReturn("ShadowRule");
-
when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton("foo_ds")));
+
when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("",
Collections.singleton(new DataSourceRoleInfo("foo_ds",
DataSourceRole.PRIMARY))));
when(contextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db")).thenReturn(database);
UnregisterStorageUnitStatement unregisterStorageUnitStatement = new
UnregisterStorageUnitStatement(true, Collections.singleton("foo_ds"), true);
assertThrows(DistSQLException.class, () -> handler.execute("foo_db",
unregisterStorageUnitStatement));