Skip to content

Commit

Permalink
fix the bug that old uuid may be generated sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Sep 16, 2023
1 parent 1653778 commit 04ec749
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/uuid/internal_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ func (u *InternalUuidGenerator) GenerateUuids(idType UuidType, count uint8) []in
for {
unixTime = uint64(time.Now().Unix())
newLastSeqId = u.uuidSeqNumbers[uuidType].Add(uint64(count))
newSeqUnixTime := newLastSeqId >> seqNumberIdBits

if newLastSeqId>>seqNumberIdBits == unixTime {
if unixTime == newSeqUnixTime {
newFirstSeqId = newLastSeqId - uint64(count-1)
break
} else if unixTime < newSeqUnixTime {
continue
}

currentSeqId := newLastSeqId
Expand Down

0 comments on commit 04ec749

Please sign in to comment.