Skip to content

Commit

Permalink
fix: uuid v7 monotonicity in rare case
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Oct 26, 2024
1 parent 0e97ed3 commit 6d5272f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions version7.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ func getV7Time() (milli, seq int64) {
seq = (nano - milli*nanoPerMilli) >> 8
now := milli<<12 + seq
if now <= lastV7time {
now = lastV7time + 1
milli = now >> 12
seq = now & 0xfff
// uuid ver bits may eat seq carry
if seq == 0xfff {
milli = milli + 1
seq = 0
now = milli<<12 + seq
} else {
now = lastV7time + 1
milli = now >> 12
seq = now & 0xfff
}
}
lastV7time = now
return milli, seq
Expand Down

0 comments on commit 6d5272f

Please sign in to comment.