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:
[email protected]