Skip to content
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

Merged
merged 15 commits into from
Dec 15, 2020

Conversation

selfishlover
Copy link
Contributor

Ⅰ. 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.

@codecov-io
Copy link

codecov-io commented Oct 10, 2020

Codecov Report

Merging #3175 (c642166) into develop (23a407e) will increase coverage by 0.01%.
The diff coverage is 82.35%.

Impacted file tree graph

@@              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              
Impacted Files Coverage Δ Complexity Δ
...src/main/java/io/seata/server/ParameterParser.java 45.71% <ø> (-0.24%) 8.00 <0.00> (ø)
...n/src/main/java/io/seata/common/util/IdWorker.java 83.33% <81.81%> (+83.33%) 12.00 <11.00> (+12.00)
...r/src/main/java/io/seata/server/UUIDGenerator.java 77.77% <85.71%> (+2.77%) 3.00 <3.00> (+1.00)
.../src/main/java/io/seata/core/rpc/ShutdownHook.java 0.00% <0.00%> (-82.86%) 0.00% <0.00%> (-8.00%)
...in/java/io/seata/server/session/GlobalSession.java 82.72% <0.00%> (-0.91%) 70.00% <0.00%> (-1.00%)
.../java/io/seata/server/coordinator/DefaultCore.java 49.39% <0.00%> (+1.82%) 23.00% <0.00%> (-1.00%) ⬆️

@funky-eyes funky-eyes added first-time contributor first-time contributor module/common common module labels Oct 12, 2020
@funky-eyes funky-eyes removed the first-time contributor first-time contributor label Oct 12, 2020
@l81893521 l81893521 added this to the 1.4.0 milestone Oct 19, 2020
@slievrly slievrly modified the milestones: 1.4.0, 1.5.0 Oct 28, 2020
Copy link
Contributor

@funky-eyes funky-eyes left a 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;
Copy link
Contributor

@l81893521 l81893521 Dec 5, 2020

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@l81893521 l81893521 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@l81893521 l81893521 added the module/server server module label Dec 9, 2020
@l81893521 l81893521 merged commit 0944fe5 into apache:develop Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

seata更改服务器时间后增删改报错回滚
7 participants