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

   ## Question
   
   ### Which version of ShardingSphere did you use?
   V5.2.0
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC Standalone mode
   
   ### question
   refer to [how to config actual-data-nodes while my actual-data-nodes tables 
is dynamic](https://github.com/apache/shardingsphere/issues/16725) 
   When configuring a dynamic node, it cannot be routed normally. After 
debugging, I found that the new schema is empty
   
   The code is as follow:
   ```
   ContextManager contextManager = getContextManager(dataSource);
   Collection<RuleConfiguration> configurations 
=contextManager.getMetaDataContexts().getMetaData().getDatabases().get(dataSourceName).getRuleMetaData().getConfigurations();
   contextManager.alterRuleConfiguration(dataSourceName,configurations);
   ```
   
   The calling method in ContextManager is as follows
   ```
   public synchronized void alterRuleConfiguration(final String databaseName, 
final Collection<RuleConfiguration> ruleConfigs) {
   try {
      Collection<ResourceHeldRule> staleResourceHeldRules = 
getStaleResourceHeldRules(databaseName);
      staleResourceHeldRules.forEach(ResourceHeldRule::closeStaleResource);
      metaDataContexts = createMetaDataContexts(databaseName, null, 
ruleConfigs);
   
metaDataContexts.getMetaData().getDatabases().putAll(newShardingSphereDatabase(metaDataContexts.getMetaData().getDatabase(databaseName)));
   } catch (final SQLException ex) {
      log.error("Alter database: {} rule configurations failed", databaseName, 
ex);
   }
   }
   
   
   private Map<String, ShardingSphereDatabase> newShardingSphereDatabase(final 
ShardingSphereDatabase originalDatabase) {
      Map<String, ShardingSphereDatabase> result = new LinkedHashMap<>(1, 1);
      result.put(originalDatabase.getName().toLowerCase(), new 
ShardingSphereDatabase(originalDatabase.getName(),
      originalDatabase.getProtocolType(), 
originalDatabase.getResourceMetaData(), originalDatabase.getRuleMetaData(),
      
metaDataContexts.getPersistService().getDatabaseMetaDataService().loadSchemas(originalDatabase.getName())));
      return result;
   }
   ```
   
   The following code obtains null schema from H2 database
   ```
   
metaDataContexts.getPersistService().getDatabaseMetaDataService().loadSchemas(originalDatabase.getName())
   ```
   
   It can operate normally after changing it to the following code
   
   ```
   result.put(originalDatabase.getName().toLowerCase(), new 
ShardingSphereDatabase(originalDatabase.getName(),
   originalDatabase.getProtocolType(), originalDatabase.getResource(), 
originalDatabase.getRuleMetaData(),
   originalDatabase.getSchemas()));
   ```
   
   Is there a problem with my configuration or with the framework itself?
   


-- 
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