-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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: Modify workerid generation method #2787
Conversation
release 0.5.2
Release 0.6.1
release 0.7.1
release 0.8.0
[release] release 1.0.0
release 1.2.0
the title prefix optimize: |
} | ||
byte[] ipAddressByteArray = address.getAddress(); | ||
long workerId = (((ipAddressByteArray[ipAddressByteArray.length - 2] & 0B11) << Byte.SIZE) + (ipAddressByteArray[ipAddressByteArray.length - 1] & 0xFF)); | ||
Preconditions.checkArgument(workerId >= 0L && workerId < 1024L); |
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 according to the current practice, will the id be greater than 1023? if yes, it is not advisable to simply throw an exception
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.
No more than 1023, because according to the snowflake algorithm, the maximum 1111111111 is 1023
Codecov Report
@@ Coverage Diff @@
## develop #2787 +/- ##
=============================================
- Coverage 50.22% 50.18% -0.04%
+ Complexity 2954 2952 -2
=============================================
Files 588 588
Lines 18929 18938 +9
Branches 2286 2287 +1
=============================================
- Hits 9507 9504 -3
- Misses 8480 8489 +9
- Partials 942 945 +3
|
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.
restore the unchanged code format
integration/http/src/test/java/io/seata/integration/http/HttpTest.java
Outdated
Show resolved
Hide resolved
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
try { | ||
address = InetAddress.getLocalHost(); | ||
} catch (final UnknownHostException e) { | ||
throw new IllegalStateException("Cannot get LocalHost InetAddress, please check your network!"); |
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.
the exception information should contain e.
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
} | ||
} | ||
} | ||
return idWorker; | ||
} | ||
|
||
public static long initWorkerId() { |
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.
I think it will always return 8 bytes, is it too big for long?
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.
Indeed, it will be dealt with next time
…into seata_workerid
The same machine, multiple servers, how to solve? |
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
Modify workerid generation method
Ⅱ. Does this pull request fix one issue?
fix #2785
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews