You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/16 03:52:58 UTC

[GitHub] [shardingsphere] jmbkeyes opened a new issue #12475: HOW to use customized sharding algorithm?

jmbkeyes opened a new issue #12475:
URL: https://github.com/apache/shardingsphere/issues/12475


   ## Question
   
   **For English only**, other languages will not accept.
   I do test customized sharding algorithm, but without success. 
   Steps:
   1. implement the algorithm
   2. config the configurations
   3. put a breakpoint at doSharding method of algorithm, and then start the application in debug mode.
   4. do save test data.
   results:
   doSharding isn't invoked.
   
   
   Spring boot config file as below.
   server:
     port: 9090
   spring:
     jpa:
       hibernate:
         naming:
           physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
     shardingsphere:
       datasource:
         common:
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.jdbc.Driver
           username: root
           password: jmbkeyes
         names: bocaicheckin${2018..2020}
         bocaicheckin2018:
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.jdbc.Driver
           jdbc-url: jdbc:mysql://10.0.0.5:3306/bocai_checkin2019
           username: root
           password: jmbkeyes
         bocaicheckin2019:
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.jdbc.Driver
           jdbc-url: jdbc:mysql://10.0.0.5:3306/bocai_checkin2019
           username: root
           password: jmbkeyes
         bocaicheckin2020:
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.jdbc.Driver
           jdbc-url: jdbc:mysql://10.0.0.5:3306/bocai_checkin2020
           username: root
           password: jmbkeyes
   
       sharding:
         tables:
           trainee_center_info:
             actual-data-nodes: bocaicheckin${2018..2020}.trainee_center_info
             table-strategy:
               none:
             database-strategy:
               standard:
                 sharding-column: centerId
                 precise-algorithm-class-name: com.forzadata.bodytrack.shardingstrategy.database.CenterIdPrecisionShardingAlgorithm
       props:
         sql.show: true
   
   and shardingalgorithm code as below.
   `
   package com.forzadata.bodytrack.shardingstrategy.database;
   
   import com.forzadata.bodytrack.consts.Consts;
   import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
   import org.apache.shardingsphere.sharding.api.sharding.standard.RangeShardingValue;
   import org.apache.shardingsphere.sharding.api.sharding.standard.StandardShardingAlgorithm;
   
   import java.util.Collection;
   import java.util.Properties;
   
   public class CenterIdPrecisionShardingAlgorithm implements StandardShardingAlgorithm<Long>{
       @Override
       public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> shardingValue) {
           String value = Consts.CENTERID_MAPPING.get(shardingValue.getValue());
           if(null == value){
               throw new UnsupportedOperationException();
           }
           return value;
       }
   
       @Override
       public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<Long> shardingValue) {
           return null;
       }
       @Override
       public void init() {
           System.out.println('a');
       }
   
       @Override
       public String getType() {
           return null;
       }
   
       @Override
       public Properties getProps() {
           return null;
       }
   
       @Override
       public void setProps(Properties props) {
   
       }
   }
   
   `
   
   Before asking a question, make sure you have:
   
   - Googled your question.
   - Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more details. 
   If no response anymore and we cannot reproduce it on current information, we will **close it**.
   


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



[GitHub] [shardingsphere] RaigorJiang commented on issue #12475: HOW to use customized sharding algorithm?

Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #12475:
URL: https://github.com/apache/shardingsphere/issues/12475#issuecomment-920617967


   Hi @jmbkeyes 
   Welcome to ShardingSphere community.
   Please refer to this example: 
   https://github.com/apache/shardingsphere/tree/master/examples/shardingsphere-jdbc-example/extension-example/custom-sharding-algortihm-example/class-based-sharding-algorithm-example


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



[GitHub] [shardingsphere] jmbkeyes closed issue #12475: HOW to use customized sharding algorithm?

Posted by GitBox <gi...@apache.org>.
jmbkeyes closed issue #12475:
URL: https://github.com/apache/shardingsphere/issues/12475


   


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