You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "StarHuzy (via GitHub)" <gi...@apache.org> on 2023/10/09 03:41:16 UTC

Re: [I] how to config actual-data-nodes while my actual-data-nodes tables is dynamic。 [shardingsphere]

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

   > There is also some experiment in ShardingSphere 4.x to implement `SPI` in the registry to dynamically modify `actualDatanodes`, this process becomes more complex in `5.x` as the data distribution changes and the `ShardingRule` is rebuilt, I wonder if anyone's willing to do that. If you dispense with `ShardingSphere` data sources altogether, you can use its algorithm classes to encapsulate util yourself, bypassing the problems `actualDatanodes` needs to find.
   
   hello  , i Use custom table splitting strategy ,Successfully dynamically adding nodes
   There will be no issues in the SQL execution of a single tables,But if there are node configuration issues in cascading queries with `join query`
   
   ![image](https://github.com/apache/shardingsphere/assets/42610282/49a8b4b3-006a-49fc-950f-d9677252a6dc)
   
   
   ```
   @Component
   @Slf4j
   public class DataShardingAlgorithm implements StandardShardingAlgorithm<Long> {
   
   
       @Override
       public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Long> rangeShardingValue) {
           System.out.println("demo = " + collection);
           return collection;
       }
   
       @Override
       public String doSharding(Collection<String> collection, PreciseShardingValue<Long> preciseShardingValue) {
           StringBuilder resultTableName = new StringBuilder();
           String logicTableName = preciseShardingValue.getLogicTableName();
           // 拼接的tenantId,格式为 表名_{tenant_id}
           resultTableName.append(logicTableName).append("_").append(preciseShardingValue.getValue());
           String newTableName = resultTableName.toString().toLowerCase();
           if (!collection.contains(newTableName)) {
               // 动态新增节点
               ShardingAlgorithmTool.copyTable(logicTableName,newTableName);
               collection.add(newTableName);
           }
           System.out.println("collection = " + collection);
           return newTableName;
       }
       @Override
       public String getType() {
           return null;
       }
       @Override
       public void init(Properties properties) {
   
       }
   
   }
   ```


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org