SDSmalin commented on issue #16725:
URL: 
https://github.com/apache/shardingsphere/issues/16725#issuecomment-1556578604

   I found a simpler code
   
   ``` yaml
   actual-data-nodes: 
ds0.$->{com.lingh.LocalShardingDatabasesAndTablesUtil.getActualDataNodes()}
   ```
   
   ``` JAVA
   public class LocalShardingDatabasesAndTablesUtil { 
        public static List<String> getActualDataNodes() { 
            LocalDate startTime = LocalDate.now().minusDays(10); 
            LocalDate endTime = LocalDate.now(); 
            return LongStream.range(0, ChronoUnit.DAYS.between(startTime, 
endTime)) 
                    .mapToObj(startTime::plusDays) 
                    .map(localDate -> "table_name_" + 
localDate.format(DateTimeFormatter.ofPattern("yyyyMMdd"))) 
                    .collect(Collectors.toList()); 
        }
   }
   ```
   ``` JAVA
   public class InitActualDataNodesAO {
       @Resource
       private ShardingSphereDataSource shardingSphereDataSource;
       private final String schemaNameForTOrder = "sharding_db";
   
       public void testSharding() {
           this.reloadShardRuleActualDataNodes(shardingSphereDataSource, 
schemaNameForTOrder);
       }
   
       private void reloadShardRuleActualDataNodes(ShardingSphereDataSource 
dataSource, String schemaName) {
           // Context manager.
           org.apache.shardingsphere.mode.manager.ContextManager contextManager 
= dataSource.getContextManager();
   
           // Rule configuration.
           Collection<RuleConfiguration> ruleConfigList = 
dataSource.getContextManager()
                   .getMetaDataContexts()
                   .getMetaData(schemaName)
                   .getRuleMetaData()
                   .getConfigurations();
           // update context
           contextManager.alterRuleConfiguration(schemaName, ruleConfigList);
       }
   }
   ```
   It's just need to execute `contextManager.alterRuleConfiguration()` to 
reload `actual-data-nodes`


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