-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement snowflake algorithm #659
Conversation
Codecov Report
@@ Coverage Diff @@
## main #659 +/- ##
==========================================
- Coverage 60.92% 60.78% -0.14%
==========================================
Files 120 121 +1
Lines 6377 6421 +44
==========================================
+ Hits 3885 3903 +18
- Misses 2120 2142 +22
- Partials 372 376 +4
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to implement GetSegment
) | ||
|
||
var ( | ||
machineRoomIdBits = 5 // 机房id 五位数 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need english comments
@seeflood |
@ZLBer Agreed. We should follow the rules and make it fair. |
解决两个问题:
1.时钟回拨,没有采用redis的方式,而是本地保存当前最大timestart,每次启动时就找到这台机器上面的max_time自增就好了,保持逻辑时钟
2.跨毫秒起始值起始每次默认都是0,这会导致末尾是偶数不方便取余,所以采用random的方式选取1~3的随机数