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: changed xid generation strategy to snowflake #2412

Merged
merged 45 commits into from
May 4, 2020

Conversation

funky-eyes
Copy link
Contributor

@funky-eyes funky-eyes commented Mar 17, 2020

Ⅰ. Describe what this PR did

optimize xid generation strategy

Ⅱ. Does this pull request fix one issue?

#2416

Ⅲ. Why don't you add test cases (unit test/integration test)?

Ⅳ. Describe how to verify it

Ⅴ. Special notes for reviews

@codecov-io
Copy link

codecov-io commented Mar 17, 2020

Codecov Report

Merging #2412 into develop will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop    #2412   +/-   ##
==========================================
  Coverage      50.93%   50.93%           
  Complexity      2813     2813           
==========================================
  Files            557      557           
  Lines          17823    17823           
  Branches        2076     2076           
==========================================
  Hits            9079     9079           
  Misses          7858     7858           
  Partials         886      886           

@zjinlei zjinlei added the status: merge-conflict Category prs with merge conflict. label Mar 22, 2020
@zjinlei zjinlei removed the status: merge-conflict Category prs with merge conflict. label Mar 24, 2020
@zjinlei zjinlei modified the milestones: 1.2.0, 1.3.0 Apr 10, 2020
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.

And Now. IdWorker would expired at

2088-09-06 15:47:35

If change the twepoch to 2020, IdWorker would expired at about 2093.
I think give 41 bit for time is a little bit long. 5-10 year maybe enough, because we can change the twepoch at 5-10 years later.

@funky-eyes
Copy link
Contributor Author

And Now. IdWorker would expired at

2088-09-06 15:47:35

If change the twepoch to 2020, IdWorker would expired at about 2093.
I think give 41 bit for time is a little bit long. 5-10 year maybe enough, because we can change the twepoch at 5-10 years later.

ok

@funky-eyes funky-eyes closed this May 3, 2020
@funky-eyes funky-eyes reopened this May 3, 2020
@funky-eyes funky-eyes changed the title optimize: xid generation strategy optimize: changed xid generation strategy to snowflake May 3, 2020
@funky-eyes funky-eyes requested a review from zjinlei May 3, 2020 14:49
Copy link
Contributor

@zjinlei zjinlei left a comment

Choose a reason for hiding this comment

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

LGTM

core/src/main/java/io/seata/core/util/IdWorker.java Outdated Show resolved Hide resolved
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
if (sequence == 0) {
timestamp = tilNextMillis(lastTimestamp);
Copy link
Member

Choose a reason for hiding this comment

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

need some output shows that the sequence is not enough to use?

}
lastTimestamp = timestamp;
}
return ((timestamp - twepoch) << timestampLeftShift) | (workerId << workerIdShift) | sequence;
Copy link
Member

Choose a reason for hiding this comment

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

How do you ensure order when timestamp-twepoch is greater than 2^22?

Copy link
Member

@slievrly slievrly May 4, 2020

Choose a reason for hiding this comment

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

2^42

Copy link
Member

@slievrly slievrly left a comment

Choose a reason for hiding this comment

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

LGTM

@funky-eyes
Copy link
Contributor Author

@long187 will this pr have any effect on the field length of saga

@funky-eyes funky-eyes closed this May 4, 2020
@funky-eyes funky-eyes reopened this May 4, 2020
@zjinlei zjinlei merged commit 2dccac4 into apache:develop May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants