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/02/05 10:35:44 UTC

[GitHub] [shardingsphere] sunday20111107 opened a new issue #9353: 5.0.0-alpha HashModShardingAlgorithm getShardingCount method is wrong

sunday20111107 opened a new issue #9353:
URL: https://github.com/apache/shardingsphere/issues/9353


   ## Bug Report
   
   Exception in thread "main" java.lang.NumberFormatException: null
   	at java.lang.Integer.parseInt(Integer.java:542)
   	at java.lang.Integer.parseInt(Integer.java:615)
   	at org.apache.shardingsphere.sharding.algorithm.sharding.mod.HashModShardingAlgorithm.getShardingCount(HashModShardingAlgorithm.java:52)
   	at org.apache.shardingsphere.sharding.algorithm.sharding.mod.HashModShardingAlgorithm.init(HashModShardingAlgorithm.java:47)
   	at org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmFactory.createAlgorithm(ShardingSphereAlgorithmFactory.java:43)
   	at org.apache.shardingsphere.sharding.rule.ShardingRule.lambda$new$0(ShardingRule.java:89)
   
   ### Which version of ShardingSphere did you use?
   5.0.0-alpha
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   ### Expected behavior
   
   ### Actual behavior
   Exception in thread "main" java.lang.NumberFormatException: null
   ### Reason analyze (If you can)
   
   i use HASH_MOD shardingAlgorithms,YAML config as follows
   shardingAlgorithms:
       myDatabasePreciseShardingAlgorithm:
         type: HASH_MOD
         props:
           sharding-count: 2
     
   HashModShardingAlgorithm.getShardingCount will call Properties.getProperty,  sharding-count will be load to Properties as Integer,but Properties.getProperty is only return string,so getProperty(“sharding-count”) will return null.  
   
   HashModShardingAlgorithm should reference ModShardingAlgorithm implements
     
   
     private int getShardingCount() {
           Preconditions.checkArgument(props.containsKey(SHARDING_COUNT_KEY), "Sharding count cannot be null.");
           return Integer.parseInt(props.getProperty(SHARDING_COUNT_KEY));
       }
       
       
     public String getProperty(String key) {
           Object oval = super.get(key);
           String sval = (oval instanceof String) ? (String)oval : null;
           return ((sval == null) && (defaults != null)) ? defaults.getProperty(key) : sval;
       }
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   ### 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.

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



[GitHub] [shardingsphere] tuohai666 closed issue #9353: 5.0.0-alpha HashModShardingAlgorithm getShardingCount method is wrong

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


   


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

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



[GitHub] [shardingsphere] tristaZero commented on issue #9353: 5.0.0-alpha HashModShardingAlgorithm getShardingCount method is wrong

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


   @sunday20111107 
   
   Thanks for explanation.
   `sharding-count: '2'` could avoid exception though, I still wonder why the `integer` value is put into `properties`. Maybe we can get something from `Yaml converter`.
   


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

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



[GitHub] [shardingsphere] sunday20111107 commented on issue #9353: 5.0.0-alpha HashModShardingAlgorithm getShardingCount method is wrong

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


   tks all.


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

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



[GitHub] [shardingsphere] tuohai666 commented on issue #9353: 5.0.0-alpha HashModShardingAlgorithm getShardingCount method is wrong

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


   Please try sharding-count: '2'


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

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