优化取模分片时不均匀的数据倾斜问题
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user