-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
optimize: improve UUIDGenerator using "history time" version of snowflake algorithm #3175
optimize: improve UUIDGenerator using "history time" version of snowflake algorithm #3175
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #3175 +/- ##
=============================================
+ Coverage 51.11% 51.12% +0.01%
- Complexity 3297 3300 +3
=============================================
Files 614 614
Lines 20125 20149 +24
Branches 2514 2519 +5
=============================================
+ Hits 10287 10302 +15
- Misses 8806 8815 +9
Partials 1032 1032
|
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.
LGTM
timestamp = timeGen(); | ||
private void waitIfNecessary() { | ||
long currentWithSequence = timestampAndSequence.get(); | ||
long current = currentWithSequence >>> sequenceBits; |
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.
if currentWithSequence will never be negative number, I think use
>>
is enought.
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.
currentWithSequence could be a negative number(though it would be a long long time to reach this~). What ever, >>> and >> have the same speed for cpu.
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.
LGTM
Ⅰ. Describe what this PR did
Improve UUIDGenerator base on an improved snowflake algorithm which use "history time" instead of current timestamp.
algorithm doc
So that seata-server can support system time move backward during run time.
Beside, implement is base on CAS instead of Lock, so it would be faster~
Ⅱ. Does this pull request fix one issue?
fixes #3126
Ⅳ. Describe how to verify it
run seata-server in a server, then change machine's system time to a previous time, if seata-server can still generate normal UUID, then it proved worked.