-
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: support instance registration to the registry center #7089
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1d45946
optimize: support instance registration to the registry center
funky-eyes dd8eefe
optimize: support instance registration to the registry center
funky-eyes 3c6dc2e
optimize: support instance registration to the registry center
funky-eyes 03ed958
code format
funky-eyes 91c70d9
ut fix
funky-eyes acc5b38
ut fix
funky-eyes 6b7adaa
ut fix
funky-eyes 9fd9596
ut fix
funky-eyes 3b7edb4
ut fix
funky-eyes faccd63
ut fix
funky-eyes 900eb05
ut fix
funky-eyes 46c53c6
ut fix
funky-eyes 3de47f7
ut fix
funky-eyes 8f3bc1e
Merge branch '2.x' into 20250102
xingfudeshi e543a43
Merge branch '2.x' into 20250102
xingfudeshi cf62571
opt
funky-eyes f8c1a0e
Merge branch '20250102' of github.cot m:funky-eyes/seata into 20250102
funky-eyes a646185
Merge branch '2.x' into 20250102
funky-eyes 32d4523
Merge branch '2.x' into 20250102
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ | |
import io.netty.handler.timeout.IdleStateHandler; | ||
import org.apache.seata.common.ConfigurationKeys; | ||
import org.apache.seata.common.XID; | ||
import org.apache.seata.common.metadata.Instance; | ||
import org.apache.seata.common.metadata.Node; | ||
import org.apache.seata.common.thread.NamedThreadFactory; | ||
import org.apache.seata.config.ConfigurationFactory; | ||
import org.apache.seata.core.rpc.RemotingBootstrap; | ||
|
@@ -170,9 +172,13 @@ public void initChannel(SocketChannel ch) { | |
try { | ||
this.serverBootstrap.bind(port).sync(); | ||
LOGGER.info("Server started, service listen port: {}", getListenPort()); | ||
InetSocketAddress address = new InetSocketAddress(XID.getIpAddress(), XID.getPort()); | ||
Instance instance = Instance.getInstance(); | ||
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. I don't think it makes sense for |
||
// Lines 177-180 are just for compatibility with test cases | ||
if (instance.getTransaction() == null) { | ||
Instance.getInstance().setTransaction(new Node.Endpoint(XID.getIpAddress(), XID.getPort(), "netty")); | ||
} | ||
for (RegistryService<?> registryService : MultiRegistryFactory.getInstances()) { | ||
registryService.register(address); | ||
registryService.register(Instance.getInstance()); | ||
} | ||
initialized.set(true); | ||
} catch (SocketException se) { | ||
|
@@ -189,9 +195,8 @@ public void shutdown() { | |
LOGGER.info("Shutting server down, the listen port: {}", XID.getPort()); | ||
} | ||
if (initialized.get()) { | ||
InetSocketAddress address = new InetSocketAddress(XID.getIpAddress(), XID.getPort()); | ||
for (RegistryService registryService : MultiRegistryFactory.getInstances()) { | ||
registryService.unregister(address); | ||
registryService.unregister(Instance.getInstance()); | ||
registryService.close(); | ||
} | ||
//wait a few seconds for server transport | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,7 @@ | |
import org.apache.http.entity.ContentType; | ||
import org.apache.http.protocol.HTTP; | ||
import org.apache.http.util.EntityUtils; | ||
import org.apache.seata.common.metadata.Node; | ||
import org.apache.seata.common.metadata.namingserver.Instance; | ||
import org.apache.seata.common.metadata.Instance; | ||
import org.apache.seata.common.metadata.namingserver.MetaResponse; | ||
import org.apache.seata.common.thread.NamedThreadFactory; | ||
import org.apache.seata.common.util.CollectionUtils; | ||
|
@@ -148,9 +147,11 @@ static NamingserverRegistryServiceImpl getInstance() { | |
|
||
@Override | ||
public void register(InetSocketAddress address) throws Exception { | ||
NetUtil.validAddress(address); | ||
Instance instance = Instance.getInstance(); | ||
instance.setTransaction(new Node.Endpoint(address.getAddress().getHostAddress(), address.getPort(), "netty")); | ||
register(Instance.getInstance()); | ||
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 IP address should be checked to ensure that it is not a loopback address. |
||
} | ||
|
||
@Override | ||
public void register(Instance instance) throws Exception { | ||
instance.setTimestamp(System.currentTimeMillis()); | ||
doRegister(instance, getNamingAddrs()); | ||
} | ||
|
@@ -198,11 +199,15 @@ public boolean doHealthCheck(String url) { | |
} | ||
} | ||
|
||
|
||
|
||
@Override | ||
public void unregister(InetSocketAddress inetSocketAddress) { | ||
unregister(Instance.getInstance()); | ||
} | ||
|
||
@Override | ||
public void unregister(InetSocketAddress address) { | ||
NetUtil.validAddress(address); | ||
Instance instance = Instance.getInstance(); | ||
instance.setTransaction(new Node.Endpoint(address.getAddress().getHostAddress(), address.getPort(), "netty")); | ||
public void unregister(Instance instance) { | ||
for (String urlSuffix : getNamingAddrs()) { | ||
String url = HTTP_PREFIX + urlSuffix + "/naming/v1/unregister?"; | ||
String unit = instance.getUnit(); | ||
|
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
What is the specific meaning of
Node.Endpoint control
?