coinicon72 opened a new issue, #24117:
URL: https://github.com/apache/shardingsphere/issues/24117

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   5.3.1
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   
   ### Expected behavior
   
   Changing of `datasource` settings in local `sharding-sphere.yml` should 
always applied.
   
   ### Actual behavior
   
   Always use persistent version instead of local one.
   
   ### Reason analyze (If you can)
   
   And I debug into the ShardingSphere, turns out ShardingSphere not update 
datasource props from local, instead it still use persistent version.
   
   I looked into the source code of ShardingSphere, and found  following 
function `mergeEffectiveDataSources` in 
`https://github.com/apache/shardingsphere/blob/master/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/MetaDataPersistService.java`:
   ```java
       private Map<String, DataSource> mergeEffectiveDataSources(final 
Map<String, DataSourceProperties> persistedDataSourcePropsMap, final 
Map<String, DataSource> localConfiguredDataSources) {
           Map<String, DataSource> result = new 
LinkedHashMap<>(persistedDataSourcePropsMap.size(), 1);
           for (Entry<String, DataSourceProperties> entry : 
persistedDataSourcePropsMap.entrySet()) {
               String dataSourceName = entry.getKey();
               DataSourceProperties persistedDataSourceProps = entry.getValue();
               DataSource localConfiguredDataSource = 
localConfiguredDataSources.get(dataSourceName);
               if (null == localConfiguredDataSource) {
                   result.put(dataSourceName, 
DataSourcePoolCreator.create(persistedDataSourceProps));
               } else if 
(DataSourcePropertiesCreator.create(localConfiguredDataSource).equals(persistedDataSourceProps))
 {
                   result.put(dataSourceName, localConfiguredDataSource);
               } else {
                   result.put(dataSourceName, 
DataSourcePoolCreator.create(persistedDataSourceProps));
                   new 
DataSourcePoolDestroyer(localConfiguredDataSource).asyncDestroy();
               }
           }
           return result;
       }
   ```
   
   I think following logic is not right: 
   ```
               } else if 
(DataSourcePropertiesCreator.create(localConfiguredDataSource).equals(persistedDataSourceProps))
 {
                   result.put(dataSourceName, localConfiguredDataSource);
   
   ```
   
   this will not apply local changings at all.
   
   should be (fixed by add `NOT` operator)
   ```
               } else if (! 
DataSourcePropertiesCreator.create(localConfiguredDataSource).equals(persistedDataSourceProps))
 {
                   result.put(dataSourceName, localConfiguredDataSource);
   ```
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   I followed official document and setup a spring boot project, used Nacos as 
cluster repository. 
   
   Those main configurations are following:
   
   application.yaml
   ```yaml
   spring:
     // others ommited
   
     datasource:
       driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
       url:  jdbc:shardingsphere:classpath:sharding-sphere.yml
   
     // others omitted
   ```
   
   sharding-sphere.yml (complete)
   ```yaml
   mode:
     type: Cluster
     repository:
       type: Nacos
       props:
         namespace: sharding-sphere
         server-lists: localhost:8848
   
   dataSources:
     ds_mysql:
       dataSourceClassName: com.zaxxer.hikari.HikariDataSource
       driverClassName: com.mysql.cj.jdbc.Driver
       jdbcUrl: 
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
       username: <xxx>
       password: <xxx>
   ```
   
   When I debug the project, I got an error said: " Public Key Retrieval is not 
allowed". Of couse this is caused by my `jdbcUrl`, so I changed the `jdbcUrl` 
in  `sharding-sphere.yml` to 
`jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true`,
 this is right solution for the error.
   
   But ShardingSphere still use old (persistent) version.
   
   ### Example codes for reproduce this issue (such as a github link).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to