diff --git a/docs/community/content/powered-by/_index.cn.md b/docs/community/content/powered-by/_index.cn.md
index 28d37bfee59a1..d86b3197ca85b 100644
--- a/docs/community/content/powered-by/_index.cn.md
+++ b/docs/community/content/powered-by/_index.cn.md
@@ -13,7 +13,7 @@ chapter = true
## 谁在使用 ShardingSphere?
-共计 203 家公司。
+共计 206 家公司。
### 基础软件
### 出行
@@ -299,6 +300,8 @@ chapter = true
未来医生
思派网络
朝前科技
+ 绿葆
+ 伊丽汇
### 招聘
diff --git a/docs/community/content/powered-by/_index.en.md b/docs/community/content/powered-by/_index.en.md
index 96911c175e5dd..dc61ab3a4414e 100644
--- a/docs/community/content/powered-by/_index.en.md
+++ b/docs/community/content/powered-by/_index.en.md
@@ -13,7 +13,7 @@ Please register [here](https://github.com/apache/shardingsphere/discussions/1225
## Who is Using ShardingSphere?
-Total: 203 companies.
+Total: 206 companies.
### Infra Software
### Transportation
@@ -222,7 +223,7 @@ Total: 203 companies.
### Public Utilities
### Recruitment
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java
index a00f501202401..55d59f1b18c8b 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollector.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.agent.metrics.api.util.MetricsUtil;
import org.apache.shardingsphere.agent.metrics.prometheus.wrapper.PrometheusWrapperFactory;
import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesCreator;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -65,21 +65,21 @@ public List collect() {
private void collectProxy(final GaugeMetricFamily metricFamily) {
MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts();
- metricFamily.addMetric(Collections.singletonList(LOGIC_DB_COUNT), metaDataContexts.getMetaDataMap().size());
+ metricFamily.addMetric(Collections.singletonList(LOGIC_DB_COUNT), metaDataContexts.getDatabaseMetaDataMap().size());
metricFamily.addMetric(Collections.singletonList(ACTUAL_DB_COUNT), getDatabaseNames(metaDataContexts).size());
}
private Collection getDatabaseNames(final MetaDataContexts metaDataContexts) {
Collection result = new HashSet<>();
- for (ShardingSphereMetaData each : metaDataContexts.getMetaDataMap().values()) {
+ for (ShardingSphereDatabaseMetaData each : metaDataContexts.getDatabaseMetaDataMap().values()) {
result.addAll(getDatabaseNames(each));
}
return result;
}
- private Collection getDatabaseNames(final ShardingSphereMetaData metaData) {
+ private Collection getDatabaseNames(final ShardingSphereDatabaseMetaData databaseMetaData) {
Collection result = new HashSet<>();
- for (DataSource each : metaData.getResource().getDataSources().values()) {
+ for (DataSource each : databaseMetaData.getResource().getDataSources().values()) {
getDatabaseName(each).ifPresent(result::add);
}
return result;
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/ProxyContextRestorer.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/ProxyContextRestorer.java
new file mode 100644
index 0000000000000..ad1ef1c442a2c
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/ProxyContextRestorer.java
@@ -0,0 +1,38 @@
+/*
+ * 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.agent.metrics.prometheus;
+
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.junit.After;
+import org.junit.Before;
+
+public abstract class ProxyContextRestorer {
+
+ private ContextManager currentContextManager;
+
+ @Before
+ public void recordCurrentContextManager() {
+ currentContextManager = ProxyContext.getInstance().getContextManager();
+ }
+
+ @After
+ public void restorePreviousContextManager() {
+ ProxyContext.init(currentContextManager);
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java
index 86dd9ca447deb..8e611f177b81a 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/MetaDataInfoCollectorTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.collector;
+import org.apache.shardingsphere.agent.metrics.prometheus.ProxyContextRestorer;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.junit.Test;
@@ -25,7 +26,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
-public final class MetaDataInfoCollectorTest {
+public final class MetaDataInfoCollectorTest extends ProxyContextRestorer {
@Test
public void assertCollect() {
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
index cc2789bb838d3..1585eb945348e 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollectorTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.collector;
+import org.apache.shardingsphere.agent.metrics.prometheus.ProxyContextRestorer;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -25,6 +26,7 @@
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.memory.workerid.generator.MemoryWorkerIdGenerator;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Test;
@@ -32,13 +34,13 @@
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
-public final class ProxyInfoCollectorTest {
+public final class ProxyInfoCollectorTest extends ProxyContextRestorer {
@Test
public void assertCollect() {
- ContextManager contextManager = new ContextManager(mock(MetaDataContexts.class), mock(TransactionContexts.class), new InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)),
- new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class)));
- ProxyContext.init(contextManager);
+ InstanceContext instanceContext = new InstanceContext(
+ new ComputeNodeInstance(mock(InstanceDefinition.class)), new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class));
+ ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class)), mock(TransactionContexts.class), instanceContext));
assertFalse(new ProxyInfoCollector().collect().isEmpty());
}
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
index dac2e0fa93458..3e16c9cbb4392 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/test/java/org/apache/shardingsphere/agent/metrics/prometheus/service/PrometheusPluginBootServiceTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.agent.metrics.prometheus.service;
import org.apache.shardingsphere.agent.config.PluginConfiguration;
+import org.apache.shardingsphere.agent.metrics.prometheus.ProxyContextRestorer;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
import org.apache.shardingsphere.infra.instance.InstanceContext;
@@ -26,6 +27,7 @@
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.manager.memory.workerid.generator.MemoryWorkerIdGenerator;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.AfterClass;
@@ -38,7 +40,7 @@
import static org.mockito.Mockito.mock;
-public final class PrometheusPluginBootServiceTest {
+public final class PrometheusPluginBootServiceTest extends ProxyContextRestorer {
private static final PrometheusPluginBootService PROMETHEUS_PLUGIN_BOOT_SERVICE = new PrometheusPluginBootService();
@@ -49,9 +51,9 @@ public static void close() {
@Test
public void assertStart() throws IOException {
- ContextManager contextManager = new ContextManager(mock(MetaDataContexts.class), mock(TransactionContexts.class), new InstanceContext(new ComputeNodeInstance(mock(InstanceDefinition.class)),
- new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class)));
- ProxyContext.init(contextManager);
+ InstanceContext instanceContext = new InstanceContext(
+ new ComputeNodeInstance(mock(InstanceDefinition.class)), new MemoryWorkerIdGenerator(), new ModeConfiguration("Memory", null, false), mock(LockContext.class));
+ ProxyContext.init(new ContextManager(new MetaDataContexts(mock(MetaDataPersistService.class)), mock(TransactionContexts.class), instanceContext));
PROMETHEUS_PLUGIN_BOOT_SERVICE.start(new PluginConfiguration("localhost", 8090, "", createProperties()));
new Socket().connect(new InetSocketAddress("localhost", 8090));
}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java
new file mode 100644
index 0000000000000..fe5e04c8c3188
--- /dev/null
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/ProxyContextRestorer.java
@@ -0,0 +1,38 @@
+/*
+ * 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.agent.plugin.tracing;
+
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.junit.After;
+import org.junit.Before;
+
+public abstract class ProxyContextRestorer {
+
+ private ContextManager currentContextManager;
+
+ @Before
+ public void recordCurrentContextManager() {
+ currentContextManager = ProxyContext.getInstance().getContextManager();
+ }
+
+ @After
+ public void restorePreviousContextManager() {
+ ProxyContext.init(currentContextManager);
+ }
+}
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
index bf504f3981307..639f35d351364 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractCommandExecutorTaskAdviceTest.java
@@ -21,6 +21,7 @@
import lombok.Getter;
import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject;
import org.apache.shardingsphere.agent.plugin.tracing.AgentRunner;
+import org.apache.shardingsphere.agent.plugin.tracing.ProxyContextRestorer;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -33,7 +34,7 @@
import static org.mockito.Mockito.mock;
@RunWith(AgentRunner.class)
-public abstract class AbstractCommandExecutorTaskAdviceTest implements AdviceTestBase {
+public abstract class AbstractCommandExecutorTaskAdviceTest extends ProxyContextRestorer implements AdviceTestBase {
@Getter
private AdviceTargetObject targetObject;
diff --git a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java
index bf6eb134da587..e1a947ff4d8f3 100644
--- a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-tracing/shardingsphere-agent-tracing-test/src/main/java/org/apache/shardingsphere/agent/plugin/tracing/advice/AbstractJDBCExecutorCallbackAdviceTest.java
@@ -61,9 +61,9 @@ public void prepare() {
extraMap = new HashMap<>();
Statement statement = mock(Statement.class);
Connection connection = mock(Connection.class);
- DatabaseMetaData metaData = mock(DatabaseMetaData.class);
- when(metaData.getURL()).thenReturn("mock_url");
- when(connection.getMetaData()).thenReturn(metaData);
+ DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
+ when(databaseMetaData.getURL()).thenReturn("mock_url");
+ when(connection.getMetaData()).thenReturn(databaseMetaData);
when(statement.getConnection()).thenReturn(connection);
executionUnit = new JDBCExecutionUnit(new ExecutionUnit("mock.db", new SQLUnit("select 1", Collections.emptyList())), null, statement);
JDBCExecutorCallback mock = mock(JDBCExecutorCallback.class, invocation -> {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
index f63b8b43f5fae..4b2dcd29f45f2 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/route/DatabaseDiscoverySQLRouter.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.infra.binder.LogicSQL;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.infra.route.SQLRouter;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
@@ -41,7 +41,7 @@
public final class DatabaseDiscoverySQLRouter implements SQLRouter {
@Override
- public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) {
+ public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) {
RouteContext result = new RouteContext();
String dataSourceName = new DatabaseDiscoveryDataSourceRouter(rule.getSingleDataSourceRule()).route();
result.getRouteUnits().add(new RouteUnit(new RouteMapper(DefaultDatabase.LOGIC_NAME, dataSourceName), Collections.emptyList()));
@@ -50,7 +50,7 @@ public RouteContext createRouteContext(final LogicSQL logicSQL, final ShardingSp
@Override
public void decorateRouteContext(final RouteContext routeContext,
- final LogicSQL logicSQL, final ShardingSphereMetaData metaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) {
+ final LogicSQL logicSQL, final ShardingSphereDatabaseMetaData databaseMetaData, final DatabaseDiscoveryRule rule, final ConfigurationProperties props) {
Collection toBeRemoved = new LinkedList<>();
Collection toBeAdded = new LinkedList<>();
for (RouteUnit each : routeContext.getRouteUnits()) {
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
index 6e8eb1f760e72..ec3b20412b335 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/src/main/java/org/apache/shardingsphere/dbdiscovery/rule/DatabaseDiscoveryRule.java
@@ -31,10 +31,12 @@
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
+import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.rule.event.DataSourceStatusChangedEvent;
import org.apache.shardingsphere.infra.rule.identifier.scope.SchemaRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule;
+import org.apache.shardingsphere.infra.rule.identifier.type.InstanceAwareRule;
import org.apache.shardingsphere.infra.rule.identifier.type.StatusContainedRule;
import org.apache.shardingsphere.mode.metadata.storage.event.DataSourceNameDisabledEvent;
import org.apache.shardingsphere.mode.metadata.storage.event.PrimaryDataSourceChangedEvent;
@@ -58,13 +60,17 @@
/**
* Database discovery rule.
*/
-public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContainedRule, StatusContainedRule, ExportableRule {
+public final class DatabaseDiscoveryRule implements SchemaRule, DataSourceContainedRule, StatusContainedRule, ExportableRule, InstanceAwareRule {
private final Map discoveryTypes;
@Getter
private final Map dataSourceRules;
+ private final String databaseName;
+
+ private final Map dataSourceMap;
+
public DatabaseDiscoveryRule(final String databaseName, final Map dataSourceMap, final DatabaseDiscoveryRuleConfiguration config) {
this(databaseName, dataSourceMap, config.getDataSources(), config.getDiscoveryHeartbeats(), getDiscoveryProviderAlgorithms(config.getDiscoveryTypes()));
}
@@ -76,10 +82,11 @@ public DatabaseDiscoveryRule(final String databaseName, final Map dataSourceMap, final Collection dataSourceRuleConfigs,
final Map heartBeatConfig, final Map discoveryTypes) {
this.discoveryTypes = discoveryTypes;
+ this.databaseName = databaseName;
+ this.dataSourceMap = dataSourceMap;
dataSourceRules = getDataSourceRules(dataSourceRuleConfigs, heartBeatConfig);
findMasterSlaveRelation(databaseName, dataSourceMap);
initAware();
- initHeartBeatJobs(databaseName, dataSourceMap);
}
private static Map getDiscoveryProviderAlgorithms(final Map discoveryTypesConfig) {
@@ -178,8 +185,8 @@ private Map exportPrimaryDataSourceMap() {
return result;
}
- private void initHeartBeatJobs(final String databaseName, final Map dataSourceMap) {
- Optional modeScheduleContext = ModeScheduleContextFactory.getInstance().get();
+ private void initHeartBeatJobs(final InstanceContext instanceContext) {
+ Optional modeScheduleContext = ModeScheduleContextFactory.getInstance().get(instanceContext.getInstance().getInstanceDefinition().getInstanceId().getId());
if (modeScheduleContext.isPresent()) {
for (Entry entry : dataSourceRules.entrySet()) {
DatabaseDiscoveryDataSourceRule rule = entry.getValue();
@@ -197,4 +204,9 @@ private void initHeartBeatJobs(final String databaseName, final Map routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
}
@@ -94,9 +94,9 @@ public void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
public void assertDecorateRouteContextToPrimaryDataSource() {
RouteContext actual = mockRouteContext();
LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", Collections.emptyList());
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
+ ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap()));
- sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
+ sqlRouter.decorateRouteContext(actual, logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties()));
Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATA_SOURCE_NAME));
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
@@ -105,9 +105,9 @@ public void assertDecorateRouteContextToPrimaryDataSource() {
@Test
public void assertCreateRouteContextToPrimaryDataSourceWithLock() {
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
+ ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap()));
- RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
+ RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties()));
Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
}
@@ -116,9 +116,9 @@ public void assertCreateRouteContextToPrimaryDataSourceWithLock() {
public void assertDecorateRouteContextToPrimaryDataSourceWithLock() {
RouteContext actual = mockRouteContext();
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
+ ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap()));
- sqlRouter.decorateRouteContext(actual, logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
+ sqlRouter.decorateRouteContext(actual, logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties()));
Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(NONE_DB_DISCOVERY_DATA_SOURCE_NAME));
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
@@ -127,9 +127,9 @@ public void assertDecorateRouteContextToPrimaryDataSourceWithLock() {
@Test
public void assertCreateRouteContextToPrimaryDataSource() {
LogicSQL logicSQL = new LogicSQL(sqlStatementContext, "", Collections.emptyList());
- ShardingSphereMetaData metaData = new ShardingSphereMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
+ ShardingSphereDatabaseMetaData databaseMetaData = new ShardingSphereDatabaseMetaData(mock(DatabaseType.class), mock(ShardingSphereResource.class, RETURNS_DEEP_STUBS),
new ShardingSphereRuleMetaData(Collections.emptyList(), Collections.singleton(rule)), new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, Collections.emptyMap()));
- RouteContext actual = sqlRouter.createRouteContext(logicSQL, metaData, rule, new ConfigurationProperties(new Properties()));
+ RouteContext actual = sqlRouter.createRouteContext(logicSQL, databaseMetaData, rule, new ConfigurationProperties(new Properties()));
Iterator routedDataSourceNames = actual.getActualDataSourceNames().iterator();
assertThat(routedDataSourceNames.next(), is(PRIMARY_DATA_SOURCE));
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java
index e4adf5d34683f..5ed25005ee922 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSet.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryHeartBeatConfiguration;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryHeartbeatsStatement;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.util.Arrays;
@@ -39,8 +39,8 @@ public final class DatabaseDiscoveryHeartbeatQueryResultSet implements DistSQLRe
private Iterator> data = Collections.emptyIterator();
@Override
- public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
- Collection ruleConfig = metaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class);
+ public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) {
+ Collection ruleConfig = databaseMetaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class);
data = ruleConfig.stream().map(DatabaseDiscoveryRuleConfiguration::getDiscoveryHeartbeats)
.flatMap(each -> each.entrySet().stream()).collect(Collectors.toMap(Entry::getKey, Entry::getValue)).entrySet().iterator();
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java
index bc9fb39698be3..cce43ac52bc8a 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryRuleQueryResultSet.java
@@ -25,7 +25,7 @@
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.distsql.constant.ExportableConstants;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -64,13 +64,13 @@ public final class DatabaseDiscoveryRuleQueryResultSet implements DistSQLResultS
@SuppressWarnings("unchecked")
@Override
- public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
- Optional ruleConfig = metaData.getRuleMetaData().getConfigurations()
+ public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) {
+ Optional ruleConfig = databaseMetaData.getRuleMetaData().getConfigurations()
.stream().filter(each -> each instanceof DatabaseDiscoveryRuleConfiguration).map(each -> (DatabaseDiscoveryRuleConfiguration) each).findAny();
data = ruleConfig.map(optional -> optional.getDataSources().iterator()).orElseGet(Collections::emptyIterator);
discoveryTypes = ruleConfig.map(DatabaseDiscoveryRuleConfiguration::getDiscoveryTypes).orElseGet(Collections::emptyMap);
discoveryHeartbeats = ruleConfig.map(DatabaseDiscoveryRuleConfiguration::getDiscoveryHeartbeats).orElseGet(Collections::emptyMap);
- Optional exportableRule = metaData.getRuleMetaData().getRules()
+ Optional exportableRule = databaseMetaData.getRuleMetaData().getRules()
.stream().filter(each -> each instanceof ExportableRule)
.filter(each -> ((ExportableRule) each).containExportableKey(Collections.singleton(ExportableConstants.EXPORTABLE_KEY_PRIMARY_DATA_SOURCE)))
.map(each -> (ExportableRule) each).findAny();
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java
index 98b7d68d44c74..0dda1dd4ab222 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryTypeQueryResultSet.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import java.util.Arrays;
@@ -39,8 +39,8 @@ public final class DatabaseDiscoveryTypeQueryResultSet implements DistSQLResultS
private Iterator> data = Collections.emptyIterator();
@Override
- public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
- Collection ruleConfig = metaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class);
+ public void init(final ShardingSphereDatabaseMetaData databaseMetaData, final SQLStatement sqlStatement) {
+ Collection ruleConfig = databaseMetaData.getRuleMetaData().findRuleConfiguration(DatabaseDiscoveryRuleConfiguration.class);
data = ruleConfig.stream().map(DatabaseDiscoveryRuleConfiguration::getDiscoveryTypes)
.flatMap(each -> each.entrySet().stream()).collect(Collectors.toMap(Entry::getKey, Entry::getValue)).entrySet().iterator();
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java
index 42a4d038c3d7d..f39aa289e2afc 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryHeartbeatStatementUpdater.java
@@ -25,7 +25,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import java.util.Collection;
import java.util.Map.Entry;
@@ -48,9 +48,9 @@ public void updateCurrentRuleConfiguration(final DatabaseDiscoveryRuleConfigurat
}
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterDatabaseDiscoveryHeartbeatStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterDatabaseDiscoveryHeartbeatStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkCurrentConfiguration(databaseName, currentRuleConfig);
checkDuplicateHeartbeat(databaseName, sqlStatement);
checkNotExistHeartbeat(databaseName, sqlStatement, currentRuleConfig);
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
index a26932e5ed099..349c8adc02524 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryRuleStatementUpdater.java
@@ -33,7 +33,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import java.util.Collection;
@@ -50,12 +50,12 @@
public final class AlterDatabaseDiscoveryRuleStatementUpdater implements RuleDefinitionAlterUpdater {
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterDatabaseDiscoveryRuleStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkCurrentRuleConfiguration(databaseName, currentRuleConfig);
checkToBeAlteredRules(databaseName, sqlStatement, currentRuleConfig);
- checkToBeAlteredResources(databaseName, sqlStatement, shardingSphereMetaData.getResource());
+ checkToBeAlteredResources(databaseName, sqlStatement, databaseMetaData.getResource());
checkDiscoverTypeAndHeartbeat(sqlStatement, currentRuleConfig);
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java
index cadbf196ac6d3..bc2266dfb28e3 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/AlterDatabaseDiscoveryTypeStatementUpdater.java
@@ -28,7 +28,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionAlterUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import java.util.Collection;
import java.util.Map.Entry;
@@ -42,9 +42,9 @@ public final class AlterDatabaseDiscoveryTypeStatementUpdater implements RuleDef
private static final String RULE_TYPE = "database discovery";
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final AlterDatabaseDiscoveryTypeStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final AlterDatabaseDiscoveryTypeStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkCurrentRuleConfiguration(databaseName, currentRuleConfig);
checkDuplicateDiscoveryType(databaseName, sqlStatement);
checkNotExistDiscoveryType(databaseName, sqlStatement, currentRuleConfig);
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java
index 461785e8fbffa..f3948affbab98 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryHeartbeatStatementUpdater.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import java.util.Collection;
import java.util.Map.Entry;
@@ -47,9 +47,9 @@ public void updateCurrentRuleConfiguration(final DatabaseDiscoveryRuleConfigurat
}
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateDatabaseDiscoveryHeartbeatStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDatabaseDiscoveryHeartbeatStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkDuplicateHeartbeat(databaseName, sqlStatement, currentRuleConfig);
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
index 568535cf5ea2e..6a91d05ec26bf 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryRuleStatementUpdater.java
@@ -31,7 +31,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import java.util.Collection;
@@ -50,11 +50,11 @@ public final class CreateDatabaseDiscoveryRuleStatementUpdater implements RuleDe
private static final String RULE_TYPE = "Database discovery";
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateDatabaseDiscoveryRuleStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDatabaseDiscoveryRuleStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkDuplicateRuleNames(databaseName, sqlStatement, currentRuleConfig);
- checkResources(databaseName, sqlStatement, shardingSphereMetaData.getResource());
+ checkResources(databaseName, sqlStatement, databaseMetaData.getResource());
checkDiscoverTypeAndHeartbeat(databaseName, sqlStatement, currentRuleConfig);
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
index 5f2a8c9a5f84b..1186de9619f0d 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/CreateDatabaseDiscoveryTypeStatementUpdater.java
@@ -27,7 +27,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
import org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionCreateUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import java.util.Collection;
import java.util.Map.Entry;
@@ -41,9 +41,9 @@ public final class CreateDatabaseDiscoveryTypeStatementUpdater implements RuleDe
private static final String RULE_TYPE = "database discovery";
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final CreateDatabaseDiscoveryTypeStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final CreateDatabaseDiscoveryTypeStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkDuplicateDiscoveryType(databaseName, sqlStatement, currentRuleConfig);
checkInvalidDiscoverType(sqlStatement);
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java
index 29bd37524c25c..afd7382d453a7 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryHeartbeatStatementUpdater.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -37,9 +37,9 @@ public final class DropDatabaseDiscoveryHeartbeatStatementUpdater implements Rul
private static final String RULE_TYPE = "Database discovery";
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDatabaseDiscoveryHeartbeatStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig);
checkIsInUse(databaseName, sqlStatement, currentRuleConfig);
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java
index a3b617929e87c..335c82604544d 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryRuleStatementUpdater.java
@@ -25,7 +25,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.apache.shardingsphere.infra.rule.identifier.type.ExportableRule;
import java.util.Collection;
@@ -41,11 +41,11 @@ public final class DropDatabaseDiscoveryRuleStatementUpdater implements RuleDefi
private static final String RULE_TYPE = "Database discovery";
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropDatabaseDiscoveryRuleStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDatabaseDiscoveryRuleStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig);
- checkIsInUse(databaseName, sqlStatement, shardingSphereMetaData);
+ checkIsInUse(databaseName, sqlStatement, databaseMetaData);
}
private void checkCurrentRuleConfiguration(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement,
@@ -64,8 +64,8 @@ private void checkIsExist(final String databaseName, final DropDatabaseDiscovery
DistSQLException.predictionThrow(notExistedRuleNames.isEmpty(), () -> new RequiredRuleMissedException(RULE_TYPE, databaseName));
}
- private void checkIsInUse(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereMetaData shardingSphereMetaData) throws DistSQLException {
- Collection rulesInUse = shardingSphereMetaData.getRuleMetaData().findRules(ExportableRule.class).stream()
+ private void checkIsInUse(final String databaseName, final DropDatabaseDiscoveryRuleStatement sqlStatement, final ShardingSphereDatabaseMetaData databaseMetaData) throws DistSQLException {
+ Collection rulesInUse = databaseMetaData.getRuleMetaData().findRules(ExportableRule.class).stream()
.filter(each -> each.containExportableKey(Collections.singletonList(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE_NAME)))
.map(each -> each.export(ExportableConstants.EXPORTABLE_KEY_AUTO_AWARE_DATA_SOURCE_NAME)).filter(Optional::isPresent)
.map(each -> (Collection) each.get()).flatMap(Collection::stream).collect(Collectors.toSet());
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java
index 7916db4271350..0c03bf5c2ed16 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/update/DropDatabaseDiscoveryTypeStatementUpdater.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.exception.rule.RuleInUsedException;
import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import java.util.Collection;
import java.util.stream.Collectors;
@@ -37,9 +37,9 @@ public final class DropDatabaseDiscoveryTypeStatementUpdater implements RuleDefi
private static final String RULE_TYPE = "Database discovery";
@Override
- public void checkSQLStatement(final ShardingSphereMetaData shardingSphereMetaData, final DropDatabaseDiscoveryTypeStatement sqlStatement,
+ public void checkSQLStatement(final ShardingSphereDatabaseMetaData databaseMetaData, final DropDatabaseDiscoveryTypeStatement sqlStatement,
final DatabaseDiscoveryRuleConfiguration currentRuleConfig) throws DistSQLException {
- String databaseName = shardingSphereMetaData.getDatabase().getName();
+ String databaseName = databaseMetaData.getDatabase().getName();
checkCurrentRuleConfiguration(databaseName, sqlStatement, currentRuleConfig);
checkIsInUse(databaseName, sqlStatement, currentRuleConfig);
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java
index 14853ce2d7115..6566a4f41516b 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-handler/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/handler/query/DatabaseDiscoveryHeartbeatQueryResultSetTest.java
@@ -23,7 +23,7 @@
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryRulesStatement;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereDatabaseMetaData;
import org.junit.Test;
import java.util.ArrayList;
@@ -45,10 +45,10 @@ public final class DatabaseDiscoveryHeartbeatQueryResultSetTest {
@Test
public void assertGetRowData() {
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
- when(metaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration()));
+ ShardingSphereDatabaseMetaData databaseMetaData = mock(ShardingSphereDatabaseMetaData.class, RETURNS_DEEP_STUBS);
+ when(databaseMetaData.getRuleMetaData().findRuleConfiguration(any())).thenReturn(Collections.singleton(createRuleConfiguration()));
DistSQLResultSet resultSet = new DatabaseDiscoveryHeartbeatQueryResultSet();
- resultSet.init(metaData, mock(ShowDatabaseDiscoveryRulesStatement.class));
+ resultSet.init(databaseMetaData, mock(ShowDatabaseDiscoveryRulesStatement.class));
Collection columnNames = resultSet.getColumnNames();
List