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 2020/08/20 03:31:32 UTC

[GitHub] [shardingsphere] RafaelGuo opened a new issue #6948: PreciseShardingAlgorithm does not work

RafaelGuo opened a new issue #6948:
URL: https://github.com/apache/shardingsphere/issues/6948


   I implements PreciseShardingAlgorithm interface, but it does not work, who can give me a help?


----------------------------------------------------------------
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] jacksparrow414 commented on issue #6948: PreciseShardingAlgorithm does not work

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


   @RafaelGuo could give more details ? 


----------------------------------------------------------------
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] RafaelGuo commented on issue #6948: PreciseShardingAlgorithm does not work

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


   > @tristaZero Grow with the community 😄
   
   @jacksparrow414 
   I find the reason why it is not work, because my configuration is wrong.
   my config is: spring.shardingsphere.rules.sharding.tables.sns_resource_cache.database-strategy.standard.sharding-column=res_id.
   It should be spring.shardingsphere.sharding.tables.sns_resource_essay.database-strategy.standard.sharding-column=res_id,


----------------------------------------------------------------
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] RafaelGuo commented on issue #6948: PreciseShardingAlgorithm does not work

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


   > @RafaelGuo hi, I use your config ,use you code, use the same res_id,data inserted to the same database.
   > ![Xnip2020-08-20_20-23-33](https://user-images.githubusercontent.com/33389378/90769674-3160a800-e323-11ea-88bd-0b4708532e8d.jpg)
   
   I find the reason why it is not work, because my configuration is wrong.
   my config is: spring.shardingsphere.rules.sharding.tables.sns_resource_cache.database-strategy.standard.sharding-column=res_id.
   It should be spring.shardingsphere.sharding.tables.sns_resource_essay.database-strategy.standard.sharding-column=res_id,
   ![image](https://user-images.githubusercontent.com/28351792/90867514-13994e80-e3c8-11ea-9a8d-3c78f713097d.png)
   


----------------------------------------------------------------
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] RafaelGuo commented on issue #6948: PreciseShardingAlgorithm does not work

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


   > @RafaelGuo hi, I use your config ,use you code, use the same res_id,data inserted to the same database.
   > ![Xnip2020-08-20_20-23-33](https://user-images.githubusercontent.com/33389378/90769674-3160a800-e323-11ea-88bd-0b4708532e8d.jpg)
   really? could you send your code to me? my email: 1412760381@qq.com 


----------------------------------------------------------------
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] RafaelGuo commented on issue #6948: PreciseShardingAlgorithm does not work

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


   > @RafaelGuo could you show more details ?
   now, I have three tables: sns_resource_basic, sns_resource_cache, sns_resource_essay. When i insert data to these tables, data should be inserted to a same database, sharding0 or sharding1, but In fact,data is insert to two deffierent databases. Please help me to check it.
   
   1. my class
   `public class CustomPreciseShardingAlgorithm implements PreciseShardingAlgorithm<String> {
   
       private static final Logger logger = LoggerFactory.getLogger(CustomPreciseShardingAlgorithm.class);
   
       public CustomPreciseShardingAlgorithm() {
           logger.info("CustomPreciseShardingAlgorithm 初始化");
       }
   
       @Override
       public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
           int hashedKey = Math.abs(preciseShardingValue.getValue().hashCode());
   
           for (Object dbName : collection) {
               String dbNameStr = (String) dbName;
   
               String dbRange = dbNameStr.substring(dbNameStr.indexOf("-") + 1);
               String[] dbRangeArr = dbRange.split("-");
               Integer begin = Integer.valueOf(dbRangeArr[0]);
               Integer end = Integer.valueOf(dbRangeArr[1]);
   
               if (hashedKey >= begin && hashedKey <= end) {
                   return dbNameStr;
               }
           }
           return null;
       }
   }`
   
   2. my configuration
   `spring.shardingsphere.datasource.names=sharding0,sharding1
   
   spring.shardingsphere.datasource.sharding0.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.sharding0.driver-class-name=com.mysql.cj.jdbc.Driver
   spring.shardingsphere.datasource.sharding0.url=jdbc:mysql://127.0.0.1:3306/sharding0?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.sharding0.username=root
   spring.shardingsphere.datasource.sharding0.password=123456
   
   spring.shardingsphere.datasource.sharding1.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.sharding1.driver-class-name=com.mysql.cj.jdbc.Driver
   spring.shardingsphere.datasource.sharding1.url=jdbc:mysql://127.0.0.1:3306/sharding1?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.sharding1.username=root
   spring.shardingsphere.datasource.sharding1.password=123456
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_basic.actual-data-nodes=sharding0.sns_resource_basic,sharding1.sns_resource_basic
   spring.shardingsphere.rules.sharding.tables.sns_resource_essay.actual-data-nodes=sharding0.sns_resource_essay,sharding1.sns_resource_essay
   spring.shardingsphere.rules.sharding.tables.sns_resource_cache.actual-data-nodes=sharding0.sns_resource_cache,sharding1.sns_resource_cache
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_basic.database-strategy.inline.sharding-column=res_id
   spring.shardingsphere.rules.sharding.tables.sns_resource_basic.database-strategy.inline.algorithm-expression=sharding$->{Math.abs(res_id.hashCode())%2}
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_essay.database-strategy.inline.sharding-column=res_id
   spring.shardingsphere.rules.sharding.tables.sns_resource_essay.database-strategy.inline.algorithm-expression=sharding$->{Math.abs(res_id.hashCode())%2}
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_cache.database-strategy.inline.sharding-column=res_id
   spring.shardingsphere.rules.sharding.tables.sns_resource_cache.database-strategy.inline.algorithm-expression=sharding$->{Math.abs(res_id.hashCode())%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



[GitHub] [shardingsphere] jacksparrow414 commented on issue #6948: PreciseShardingAlgorithm does not work

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


   @RafaelGuo :thumbsup:  as other configuartion,you could refer to official documents or the code I sent you


----------------------------------------------------------------
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] jacksparrow414 commented on issue #6948: PreciseShardingAlgorithm does not work

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


   @tristaZero Grow with the community  :smile: 


----------------------------------------------------------------
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] kimmking closed issue #6948: PreciseShardingAlgorithm does not work

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


   


----------------------------------------------------------------
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] jacksparrow414 edited a comment on issue #6948: PreciseShardingAlgorithm does not work

Posted by GitBox <gi...@apache.org>.
jacksparrow414 edited a comment on issue #6948:
URL: https://github.com/apache/shardingsphere/issues/6948#issuecomment-677252878


   @RafaelGuo could you show more details ? 


----------------------------------------------------------------
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] RafaelGuo removed a comment on issue #6948: PreciseShardingAlgorithm does not work

Posted by GitBox <gi...@apache.org>.
RafaelGuo removed a comment on issue #6948:
URL: https://github.com/apache/shardingsphere/issues/6948#issuecomment-677638806


   > @RafaelGuo hi, I use your config ,use you code, use the same res_id,data inserted to the same database.
   > ![Xnip2020-08-20_20-23-33](https://user-images.githubusercontent.com/33389378/90769674-3160a800-e323-11ea-88bd-0b4708532e8d.jpg)
   really? could you send your code to me? my email: 1412760381@qq.com 


----------------------------------------------------------------
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] RafaelGuo edited a comment on issue #6948: PreciseShardingAlgorithm does not work

Posted by GitBox <gi...@apache.org>.
RafaelGuo edited a comment on issue #6948:
URL: https://github.com/apache/shardingsphere/issues/6948#issuecomment-677402250


   > @RafaelGuo could you show more details ?
   now, I have three tables: sns_resource_basic, sns_resource_cache, sns_resource_essay. When i insert data to these tables, data should be inserted to a same database, sharding0 or sharding1, but In fact,data is insert to two deffierent databases. Please help me to check it.
   
   1. my class
   `public class CustomPreciseShardingAlgorithm implements PreciseShardingAlgorithm<String> {
   
       private static final Logger logger = LoggerFactory.getLogger(CustomPreciseShardingAlgorithm.class);
   
       public CustomPreciseShardingAlgorithm() {
           logger.info("CustomPreciseShardingAlgorithm 初始化");
       }
   
       @Override
       public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
           int hashedKey = Math.abs(preciseShardingValue.getValue().hashCode());
   
           for (Object dbName : collection) {
               String dbNameStr = (String) dbName;
   
               String dbRange = dbNameStr.substring(dbNameStr.indexOf("-") + 1);
               String[] dbRangeArr = dbRange.split("-");
               Integer begin = Integer.valueOf(dbRangeArr[0]);
               Integer end = Integer.valueOf(dbRangeArr[1]);
   
               if (hashedKey >= begin && hashedKey <= end) {
                   return dbNameStr;
               }
           }
           return null;
       }
   }`
   
   2. my configuration
   `spring.shardingsphere.datasource.names=ds-0-1073741823,ds-1073741824-2147483647
   
   spring.shardingsphere.datasource.ds-0-1073741823.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.ds-0-1073741823.driver-class-name=com.mysql.cj.jdbc.Driver
   spring.shardingsphere.datasource.ds-0-1073741823.url=jdbc:mysql://127.0.0.1:3306/sharding0?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.ds-0-1073741823.username=root
   spring.shardingsphere.datasource.ds-0-1073741823.password=123456
   spring.shardingsphere.datasource.ds-0-1073741823.initial-size=5
   spring.shardingsphere.datasource.ds-0-1073741823.max-active=20
   spring.shardingsphere.datasource.ds-0-1073741823.min-idle=5
   spring.shardingsphere.datasource.ds-0-1073741823.max-wait=60000
   
   spring.shardingsphere.datasource.ds-1073741824-2147483647.type=com.alibaba.druid.pool.DruidDataSource
   spring.shardingsphere.datasource.ds-1073741824-2147483647.driver-class-name=com.mysql.cj.jdbc.Driver
   spring.shardingsphere.datasource.ds-1073741824-2147483647.url=jdbc:mysql://127.0.0.1:3306/sharding1?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
   spring.shardingsphere.datasource.ds-1073741824-2147483647.username=root
   spring.shardingsphere.datasource.ds-1073741824-2147483647.password=123456
   spring.shardingsphere.datasource.ds-1073741824-2147483647.initial-size=5
   spring.shardingsphere.datasource.ds-1073741824-2147483647.max-active=20
   spring.shardingsphere.datasource.ds-1073741824-2147483647.min-idle=5
   spring.shardingsphere.datasource.ds-1073741824-2147483647.max-wait=60000
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_basic.actual-data-nodes=ds-0-1073741823.sns_resource_basic,ds-1073741824-2147483647.sns_resource_basic
   spring.shardingsphere.rules.sharding.tables.sns_resource_essay.actual-data-nodes=ds-0-1073741823.sns_resource_essay,ds-1073741824-2147483647.sns_resource_essay
   spring.shardingsphere.rules.sharding.tables.sns_resource_cache.actual-data-nodes=ds-0-1073741823.sns_resource_cache,ds-1073741824-2147483647.sns_resource_cache
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_basic.database-strategy.standard.sharding-column=res_id
   spring.shardingsphere.rules.sharding.tables.sns_resource_basic.database-strategy.standard.precise-algorithm-class-name=com.tdx.sharding.configration.CustomPreciseShardingAlgorithm
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_essay.database-strategy.standard.sharding-column=res_id
   spring.shardingsphere.rules.sharding.tables.sns_resource_essay.database-strategy.standard.precise-algorithm-class-name=com.tdx.sharding.configration.CustomPreciseShardingAlgorithm
   
   spring.shardingsphere.rules.sharding.tables.sns_resource_cache.database-strategy.standard.sharding-column=res_id
   spring.shardingsphere.rules.sharding.tables.sns_resource_cache.database-strategy.standard.precise-algorithm-class-name=com.tdx.sharding.configration.CustomPreciseShardingAlgorithm`


----------------------------------------------------------------
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] jacksparrow414 commented on issue #6948: PreciseShardingAlgorithm does not work

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


   @RafaelGuo hi, I use your config ,use you code, use the same res_id,data inserted to the same database.
   ![Xnip2020-08-20_20-23-33](https://user-images.githubusercontent.com/33389378/90769674-3160a800-e323-11ea-88bd-0b4708532e8d.jpg)
   


----------------------------------------------------------------
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] RafaelGuo removed a comment on issue #6948: PreciseShardingAlgorithm does not work

Posted by GitBox <gi...@apache.org>.
RafaelGuo removed a comment on issue #6948:
URL: https://github.com/apache/shardingsphere/issues/6948#issuecomment-678105104


   > @RafaelGuo hi, I use your config ,use you code, use the same res_id,data inserted to the same database.
   > ![Xnip2020-08-20_20-23-33](https://user-images.githubusercontent.com/33389378/90769674-3160a800-e323-11ea-88bd-0b4708532e8d.jpg)
   
   I find the reason why it is not work, because my configuration is wrong.
   my config is: spring.shardingsphere.rules.sharding.tables.sns_resource_cache.database-strategy.standard.sharding-column=res_id.
   It should be spring.shardingsphere.sharding.tables.sns_resource_essay.database-strategy.standard.sharding-column=res_id,
   ![image](https://user-images.githubusercontent.com/28351792/90867514-13994e80-e3c8-11ea-9a8d-3c78f713097d.png)
   


----------------------------------------------------------------
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] RafaelGuo commented on issue #6948: PreciseShardingAlgorithm does not work

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


   > @RafaelGuo hi, I use your config ,use you code, use the same res_id,data inserted to the same database.
   > ![Xnip2020-08-20_20-23-33](https://user-images.githubusercontent.com/33389378/90769674-3160a800-e323-11ea-88bd-0b4708532e8d.jpg)
   
   @jacksparrow414 really? could you send your code to me? my email: 1412760381@qq.com


----------------------------------------------------------------
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 #6948: PreciseShardingAlgorithm does not work

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


   @jacksparrow414 Very appreciated your time to answer questions, nice job. :-)
   Your work will benefit `OUR` community. 
   
   Thanks,
   Trista


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