1
0
mirror of synced 2025-12-16 18:18:10 +08:00

限定TopOverCostCount范围

This commit is contained in:
yitter
2022-07-16 00:42:36 +08:00
parent 519206cdbf
commit b1b3d0cd6d
12 changed files with 165 additions and 84 deletions

View File

@@ -4,6 +4,7 @@
* 代码修订yitter
* 开源地址https://github.com/yitter/idgenerator
*/
package idgen
import (
@@ -64,6 +65,11 @@ func NewDefaultIdGenerator(options *IdGeneratorOptions) *DefaultIdGenerator {
panic("MinSeqNumber error. (range:[5, " + strconv.FormatUint(uint64(maxSeqNumber), 10) + "]")
}
// 7.TopOverCostCount
if options.TopOverCostCount < 0 || options.TopOverCostCount > 10000 {
panic("TopOverCostCount error. (range:[0, 10000]")
}
var snowWorker ISnowWorker
switch options.Method {
case 1:

View File

@@ -4,6 +4,7 @@
* 代码修订yitter
* 开源地址https://github.com/yitter/idgenerator
*/
package idgen
import (
@@ -13,13 +14,13 @@ import (
// SnowWorkerM1 .
type SnowWorkerM1 struct {
BaseTime int64 //基础时间
WorkerId uint16 //机器码
WorkerIdBitLength byte //机器码位长
SeqBitLength byte //自增序列数位长
MaxSeqNumber uint32 //最大序列数(含)
MinSeqNumber uint32 //最小序列数(含)
TopOverCostCount uint32 //最大漂移次数
BaseTime int64 // 基础时间
WorkerId uint16 // 机器码
WorkerIdBitLength byte // 机器码位长
SeqBitLength byte // 自增序列数位长
MaxSeqNumber uint32 // 最大序列数(含)
MinSeqNumber uint32 // 最小序列数(含)
TopOverCostCount uint32 // 最大漂移次数
_TimestampShift byte
_CurrentSeqNumber uint32
@@ -75,12 +76,13 @@ func NewSnowWorkerM1(options *IdGeneratorOptions) ISnowWorker {
// 6.MinSeqNumber
var minSeqNumber = options.MinSeqNumber
// 7.Others
// 7.TopOverCostCount
var topOverCostCount = options.TopOverCostCount
if topOverCostCount == 0 {
topOverCostCount = 2000
}
// if topOverCostCount == 0 {
// topOverCostCount = 2000
// }
// 8.Others
timestampShift := (byte)(workerIdBitLength + seqBitLength)
currentSeqNumber := minSeqNumber