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/10/12 06:54:54 UTC

[GitHub] [shardingsphere] shun634501730 opened a new issue #7750: The issue about DefaultKeyGenerator(3.1.0) or SnowflakeKeyGenerateAlgorithm(4.1.1)

shun634501730 opened a new issue #7750:
URL: https://github.com/apache/shardingsphere/issues/7750


   Hi, 
   
   I am using Sharing Jbdc 3.1.0 on my project.
   
   When the app using the expression '{id % 8}' to shadring the 't_order' table, the generated distributed id always inserted to the t_order_0 and t_order_1. For expression '{id % 16}' or '{id % 32}' or any expression '{id % x}' which the x is 2^n (n > 1), it also will be occur above issue.
   
   I write the below example code to reproduce the issue:
   ```
   import io.shardingsphere.core.keygen.DefaultKeyGenerator;
   import io.shardingsphere.core.keygen.KeyGenerator;
   import org.apache.commons.lang3.RandomUtils;
   
   import java.math.BigInteger;
   import java.util.Properties;
   
   public class TestKeyGenerator {
       public static void main(String[] args) throws InterruptedException {
   
           KeyGenerator keyGenerator = new DefaultKeyGenerator();
           DefaultKeyGenerator.setWorkerId(532L);
   
   //        SnowflakeKeyGenerateAlgorithm keyGenerator = new SnowflakeKeyGenerateAlgorithm();
   //        Properties properties = new Properties();
   //        properties.setProperty("worker-id", "532");
   //        keyGenerator.setProps(properties);
   //        keyGenerator.init();
   
           int i = 0;
           while (i++ < 100) {
               // sleep some ms to simulate the http request
               Thread.sleep(RandomUtils.nextInt(10, 1000));
   
               BigInteger bigInteger = new BigInteger(String.valueOf(keyGenerator.generateKey()));
               long currentTimeMs = System.currentTimeMillis();
   
               // to simulate the expression {id % 8}
               BigInteger[] result = bigInteger.divideAndRemainder(BigInteger.valueOf(8L));
   
               // the result[1] seems always be 0 or 1
               System.out.println(currentTimeMs + ":" + bigInteger + ":" + result[1]);
           }
       }
   }
   ```
   
   I am not sure the reason about this issue, so could you help to check and explain/fix this issue?
   


----------------------------------------------------------------
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 commented on issue #7750: The issue about DefaultKeyGenerator(3.1.0) or SnowflakeKeyGenerateAlgorithm(4.1.1)

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


   QPS is low and this is a normal case.
   
   ```
   private void vibrateSequenceOffset() {
           sequenceOffset = sequenceOffset >= maxVibrationOffset ? 0 : sequenceOffset + 1;
       }
   ```


----------------------------------------------------------------
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] yu199195 closed issue #7750: The issue about DefaultKeyGenerator(3.1.0) or SnowflakeKeyGenerateAlgorithm(4.1.1)

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


   


----------------------------------------------------------------
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 commented on issue #7750: The issue about DefaultKeyGenerator(3.1.0) or SnowflakeKeyGenerateAlgorithm(4.1.1)

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


   The version 3.1.0 is out of date now.
   Can you try 4.1.1 or master branch?


----------------------------------------------------------------
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 commented on issue #7750: The issue about DefaultKeyGenerator(3.1.0) or SnowflakeKeyGenerateAlgorithm(4.1.1)

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


   referred: http://qdcypf.com/article-2128.html


----------------------------------------------------------------
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] shun634501730 commented on issue #7750: The issue about DefaultKeyGenerator(3.1.0) or SnowflakeKeyGenerateAlgorithm(4.1.1)

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


   > 
   > 
   > The version 3.1.0 is out of date now.
   > Can you try 4.1.1 or master branch?
   
   For above example code, using the SnowflakeKeyGenerateAlgorithm (4.1.1) still have issue.
   
   
   
   
   


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