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

zhangliang 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 44201a5  BootstrapInitializer find backend data source from complete 
metadata (#12756)
44201a5 is described below

commit 44201a53ee0e09eff37363dab607b134f3900a79
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Wed Sep 29 23:37:53 2021 +0800

    BootstrapInitializer find backend data source from complete metadata 
(#12756)
---
 .../shardingsphere/proxy/initializer/BootstrapInitializer.java   | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
index 276526a..2407aaa 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/initializer/BootstrapInitializer.java
@@ -25,10 +25,12 @@ import 
org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmC
 import org.apache.shardingsphere.infra.config.datasource.DataSourceConverter;
 import org.apache.shardingsphere.infra.config.datasource.DataSourceParameter;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
 import 
org.apache.shardingsphere.infra.yaml.config.pojo.algorithm.YamlShardingSphereAlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.yaml.config.swapper.mode.ModeConfigurationYamlSwapper;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.mode.manager.ContextManagerBuilderFactory;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import org.apache.shardingsphere.proxy.config.ProxyConfiguration;
 import org.apache.shardingsphere.proxy.config.YamlProxyConfiguration;
@@ -103,10 +105,9 @@ public final class BootstrapInitializer {
     }
     
     private Optional<DataSource> findBackendDataSource() {
-        for (String each : ProxyContext.getInstance().getAllSchemaNames()) {
-            return 
ProxyContext.getInstance().getMetaData(each).getResource().getDataSources().values().stream().findFirst();
-        }
-        return Optional.empty();
+        MetaDataContexts metaDataContexts = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
+        Optional<ShardingSphereMetaData> metaDataOptional = 
metaDataContexts.getMetaDataMap().values().stream().filter(ShardingSphereMetaData::isComplete).findFirst();
+        return metaDataOptional.flatMap(shardingSphereMetaData -> 
shardingSphereMetaData.getResource().getDataSources().values().stream().findFirst());
     }
     
     private void initScaling(final YamlProxyConfiguration yamlConfig, final 
ModeConfiguration modeConfig) {

Reply via email to