提交 5bf1de3d 编写于 作者: zlt2000's avatar zlt2000

优化取模分片时不均匀的数据倾斜问题

上级 bbae7da2
......@@ -173,12 +173,13 @@ public class Sequence {
// 相同毫秒内,序列号自增
sequence = (sequence + 1) & sequenceMask;
if (sequence == 0) {
sequence = ThreadLocalRandom.current().nextLong(1, 101);
// 同一毫秒的序列数已经达到最大
timestamp = tilNextMillis(lastTimestamp);
}
} else {
// 不同毫秒内,序列号置为 1 - 3 随机数
sequence = ThreadLocalRandom.current().nextLong(1, 3);
// 不同毫秒内,序列号置为 1 - 100 随机数
sequence = ThreadLocalRandom.current().nextLong(1, 101);
}
lastTimestamp = timestamp;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册