-
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
feature: Raft cluster mode supports address translation #7069
Conversation
|
||
private static InetSocketAddress selectEndpoint(String type, Node node) { | ||
if (StringUtils.isBlank(PREFERRED_NETWORKS)) { | ||
// 采取默认的方式,直接使用node.control node.transaction |
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.
// 采取默认的方式,直接使用node.control node.transaction | |
// Use the default method, directly using node.control and node.transaction |
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.
done
@@ -366,7 +366,7 @@ public RaftClusterMetadata changeOrInitRaftClusterMetadata() { | |||
Integer.parseInt( | |||
((Environment)ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT)) | |||
.getProperty("server.port", String.valueOf(7091))), | |||
group, Collections.emptyMap()); | |||
group, new HashMap<>()); |
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.
Why change to new HashMap < > ()
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.
因为Collections.emptyMap()返回的集合使用了final修饰,导致我进行put操作时,报错,unsupoort...
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.
不要直接put,而是构建一个新的map替换它,copyonwrite
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.
不要直接put,而是构建一个新的map替换它,copyonwrite
done
@@ -406,7 +406,7 @@ private void syncCurrentNodeInfo(PeerId leaderPeerId) { | |||
Integer.parseInt( | |||
((Environment)ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT)) | |||
.getProperty("server.port", String.valueOf(7091))), | |||
group, Collections.emptyMap()); | |||
group, new HashMap<>()); |
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.
ditto
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.
same
@@ -55,6 +58,10 @@ public Node createNode(String host, int txPort, int internalPort, int controlPor | |||
node.setGroup(group); | |||
node.setVersion(Version.getCurrent()); | |||
node.setInternal(node.createEndpoint(host, internalPort, "raft")); | |||
String serverRegistryMetadataExternalValue = System.getProperty("SERVER_REGISTRY_METADATA_EXTERNAL_VALUE"); |
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.
不应该这样读取,如果有用户直接使用properties配置文件去配置怎么办?应该通过下面这样的方式读取
It should not be read like this. What if a user directly uses the properties configuration file to configure it? It should be read in the following way
ConfigurableEnvironment environment=ObjectHolder.INSTANCE.getObject(OBJECT_KEY_SPRING_CONFIGURABLE_ENVIRONMENT);
environment.resolvePlaceholders("${seata.registry.metadata.external:${registry.metadata.external:}}")
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.
done
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.
done
不要直接put,而是构建一个新的map替换它,copyonwrite
...ery-raft/src/main/java/org/apache/seata/discovery/registry/raft/RaftRegistryServiceImpl.java
Outdated
Show resolved
Hide resolved
throw new ParseEndpointException("Node metadata is empty."); | ||
} | ||
|
||
Object external = metadata.get("external"); |
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.
这里要判空,高版本客户端对接低版本server是不会有这个字段的
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.
changes/zh-cn/2.x.md
Outdated
@@ -4,7 +4,7 @@ | |||
|
|||
### feature: | |||
|
|||
- [[#PR_NO](https://github.com/seata/seata/pull/PR_NO)] 支持XXX | |||
- [[#7069](https://github.com/apache/incubator-seata/pull/7069)] Raft模式支持集群外访问 |
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.
应该是 raft集群模式支持地址转换
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.
done
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
现有raft sdk如果在k8s环境下,客户端集群外访问,无法通过域名方式链接raft node,造成无法通信。
支持外部访问的方案:
server: 在元数据Node中添加一个metadata.external数组,在部署时,传入SEATA_REGISTRY_METADATA_EXTERNAL变量,创建节点时解析设置,同步至主节点。
client:
通过api获取集群元数据,然后解析并选择通信的IP及地址。如果客户端配置了preferredNetworks,那么将从元数据Node.metadata.external中正则匹配选择,否则就按照原来方案,使用Node.control及Node.transaction。
客户端配置:
部署文件:
这里之所以取名这么简单是测试的时候,发现service过长,会出现 #7082 的错误
元数据:
测试:
Ⅱ. Does this pull request fix one issue?
Ⅲ. Why don't you add test cases (unit test/integration test)?
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews