funky-eyes commented on code in PR #7069:
URL: https://github.com/apache/incubator-seata/pull/7069#discussion_r1899233749
##########
discovery/seata-discovery-raft/src/main/java/org/apache/seata/discovery/registry/raft/RaftRegistryServiceImpl.java:
##########
@@ -276,9 +295,85 @@ private static boolean isTokenExpired() {
return System.currentTimeMillis() >= tokenExpiredTime;
}
- private InetSocketAddress convertInetSocketAddress(Node node) {
- Node.Endpoint endpoint = node.getTransaction();
- return new InetSocketAddress(endpoint.getHost(), endpoint.getPort());
+ private static String selectControlEndpointStr(Node node) {
+ InetSocketAddress control = selectControlEndpoint(node);
+ return NetUtil.toStringAddress(control);
+ }
+
+ private static String selectTransactionEndpointStr(Node node) {
+ InetSocketAddress transaction = selectTransactionEndpoint(node);
+ return NetUtil.toStringAddress(transaction);
+ }
+
+ private static InetSocketAddress selectControlEndpoint(Node node) {
+ return selectEndpoint("control", node);
+ }
+
+ private static InetSocketAddress selectTransactionEndpoint(Node node) {
+ return selectEndpoint("transaction", node);
+ }
+
+ private static InetSocketAddress selectEndpoint(String type, Node node) {
+ if (StringUtils.isBlank(PREFERRED_NETWORKS)) {
+ // Use the default method, directly using node.control and
node.transaction
+ switch (type) {
+ case "control":
+ return new InetSocketAddress(node.getControl().getHost(),
node.getControl().getPort());
+ case "transaction":
+ return new
InetSocketAddress(node.getTransaction().getHost(),
node.getTransaction().getPort());
+ default:
+ throw new NotSupportYetException("SelectEndpoint is not
support type: " + type);
+ }
+ }
+ Node.ExternalEndpoint externalEndpoint = selectExternalEndpoint(node,
PREFERRED_NETWORKS.split(";"));
+ switch (type) {
+ case "control":
+ return new InetSocketAddress(externalEndpoint.getHost(),
externalEndpoint.getControlPort());
+ case "transaction":
+ return new InetSocketAddress(externalEndpoint.getHost(),
externalEndpoint.getTransactionPort());
+ default:
+ throw new NotSupportYetException("SelectEndpoint is not
support type: " + type);
+ }
+ }
+
+ private static Node.ExternalEndpoint selectExternalEndpoint(Node node,
String[] preferredNetworks) {
+ Map<String, Object> metadata = node.getMetadata();
+ if (CollectionUtils.isEmpty(metadata)) {
+ throw new ParseEndpointException("Node metadata is empty.");
+ }
+
+ Object external = metadata.get("external");
Review Comment:
这里要判空,高版本客户端对接低版本server是不会有这个字段的
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]