-
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e9e7255
release 0.5.1
slievrly f017c6b
release 0.5.2
slievrly 7ca3332
Release 0.6.0 (#1106)
zhangthen dc088cb
Revert "Release 0.6.0 (#1106)" (#1107)
slievrly da96029
re-merging 0.6.0
slievrly ca567ef
Release 0.6.1
zhangthen 1b90f93
release 0.7.0
slievrly 39e4d89
release 0.7.1
slievrly 0945681
release 0.8.0
slievrly 9ffa290
release 0.8.1
slievrly a174ed5
release 0.9.0
slievrly 5bdbc44
[release] release 1.0.0
slievrly f990a57
release: release 1.1.0
slievrly 04d0568
Merge pull request #2582 from seata/1.2.0
slievrly 952248d
修改workid生成方式
ab55797
modify workerid generation method
lj2018110133 6693048
modify workerid generation method 2th
lj2018110133 f99be7f
modify workerid generation method 3th
lj2018110133 53b721b
modify workerid generation method 4th
lj2018110133 1fade38
Merge branch 'develop' into seata_workerid
slievrly 61d1188
modify workerid generation method 5th
lj2018110133 b148f7d
Merge branch 'seata_workerid' of https://github.com/lj2018110133/seat…
lj2018110133 47456e4
contain exception information
lj2018110133 08d2a8a
Merge branch 'develop' into seata_workerid
slievrly 1ea747c
Merge branch 'master' of https://github.com/lj2018110133/seata into s…
lj2018110133 15a44aa
Handling conflicts
lj2018110133 160d41a
Merge branch 'seata_workerid' of https://github.com/lj2018110133/seat…
lj2018110133 f1a4067
Handling conflicts
lj2018110133 aa6c17e
Merge branch 'develop' into seata_workerid
l81893521 af4176a
Merge branch 'develop' into seata_workerid
jsbxyyx f0d3e8a
Merge branch 'develop' into seata_workerid
funky-eyes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,8 @@ | |
* limitations under the License. | ||
*/ | ||
package io.seata.common.util; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
/** | ||
* @author funkye | ||
|
@@ -144,13 +144,24 @@ public static IdWorker getInstance() { | |
if (idWorker == null) { | ||
synchronized (IdWorker.class) { | ||
if (idWorker == null) { | ||
init(ThreadLocalRandom.current().nextLong(1024)); | ||
init(initWorkerId()); | ||
} | ||
} | ||
} | ||
return idWorker; | ||
} | ||
|
||
public static long initWorkerId() { | ||
InetAddress address; | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. the exception information should contain e. |
||
} | ||
byte[] ipAddressByteArray = address.getAddress(); | ||
return ((ipAddressByteArray[ipAddressByteArray.length - 2] & 0B11) << Byte.SIZE) + (ipAddressByteArray[ipAddressByteArray.length - 1] & 0xFF); | ||
slievrly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public static void init(Long serverNodeId) { | ||
if (idWorker == null) { | ||
synchronized (IdWorker.class) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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