Skip to content
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: init namingserver client #6536

Merged
merged 40 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
50c77dc
add signature
ggbocoder Jan 2, 2024
b36f5b2
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Jan 20, 2024
e15537d
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Jan 25, 2024
85398ec
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Jan 31, 2024
e049125
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Mar 7, 2024
2939f59
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder May 12, 2024
0d9d18f
init namingserver-client
ggbocoder May 12, 2024
b5a2847
fix ci
ggbocoder May 13, 2024
e07f2fc
fix ci
ggbocoder May 13, 2024
a62f801
fix ci
ggbocoder May 13, 2024
7909e80
fix ci
ggbocoder May 13, 2024
731b008
register
ggbocoder Jul 4, 2024
5197420
Merge branch '2.x' into namingserver-client
xingfudeshi Jul 8, 2024
de36f55
Merge branch '2.x' into namingserver-client
funky-eyes Jul 29, 2024
b1aadc5
Merge remote-tracking branch 'upstream/2.x' into namingserver-client
ggbocoder Aug 3, 2024
e5e3f8f
解决冲突
ggbocoder Aug 3, 2024
2fbca4d
解决冲突
ggbocoder Aug 3, 2024
05542c8
Merge remote-tracking branch 'origin/namingserver-client' into naming…
ggbocoder Aug 3, 2024
73bd66f
fix header
ggbocoder Aug 3, 2024
0a97105
fix
ggbocoder Aug 10, 2024
39e7250
fix style
ggbocoder Aug 10, 2024
70fa46c
fix style
ggbocoder Aug 10, 2024
8f4e1a1
fix style
ggbocoder Aug 10, 2024
26d0e16
fix style
ggbocoder Aug 10, 2024
5abdb10
fix
ggbocoder Aug 12, 2024
5c2f827
pass ci
ggbocoder Aug 12, 2024
17bf79a
pass ci
ggbocoder Aug 12, 2024
365fe08
Merge branch '2.x' into namingserver-client
ggbocoder Aug 12, 2024
a7edf2c
pass ci
ggbocoder Aug 12, 2024
bb6b611
Merge remote-tracking branch 'origin/namingserver-client' into naming…
ggbocoder Aug 12, 2024
03bc580
fix
ggbocoder Aug 12, 2024
2b66dc4
fix
ggbocoder Aug 12, 2024
b4751b4
Update changes/en-us/2.x.md
funky-eyes Aug 13, 2024
ec44a84
Update changes/zh-cn/2.x.md
funky-eyes Aug 13, 2024
12e0fc1
Update discovery/seata-discovery-namingserver/src/main/java/org/apach…
funky-eyes Aug 13, 2024
53ed7fa
Update discovery/seata-discovery-namingserver/src/main/java/org/apach…
funky-eyes Aug 13, 2024
401627c
Merge branch '2.x' into namingserver-client
funky-eyes Aug 13, 2024
43f68e8
Update discovery/seata-discovery-namingserver/src/test/java/org/apach…
funky-eyes Aug 13, 2024
b0051bb
Update discovery/seata-discovery-namingserver/src/test/java/org/apach…
funky-eyes Aug 13, 2024
18d3db4
Merge branch '2.x' into namingserver-client
funky-eyes Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
<artifactId>seata-discovery-etcd3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-discovery-namingserver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-brpc</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@
<artifactId>seata-discovery-zk</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-discovery-namingserver</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seata</groupId>
<artifactId>seata-discovery-redis</artifactId>
Expand Down
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Add changes here for all PR submitted to the 2.x branch.
<!-- Please add the `changes` to the following location(feature/bugfix/optimize/test) based on the type of PR -->

### feature:
- [[#6536](https://github.com/apache/incubator-seata/pull/6536)] support naming server client
- [[#6226](https://github.com/apache/incubator-seata/pull/6226)] multi-version seata protocol support
- [[#6537](https://github.com/apache/incubator-seata/pull/6537)] support Namingserver
- [[#6538](https://github.com/apache/incubator-seata/pull/6538)] Integration of naming server on the Seata server side
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- 请根据PR的类型添加 `变更记录` 到以下对应位置(feature/bugfix/optimize/test) 下 -->

### feature:
- [[#6536](https://github.com/apache/incubator-seata/pull/6536)] 支持 naming server客户端
- [[#6226](https://github.com/apache/incubator-seata/pull/6226)] 支持seata私有协议多版本兼容
- [[#6537](https://github.com/apache/incubator-seata/pull/6537)] 支持 Namingserver
- [[#6538](https://github.com/apache/incubator-seata/pull/6538)] seata server端集成naming server
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/org/apache/seata/common/XID.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.apache.seata.common.Constants.IP_PORT_SPLIT_CHAR;


/**
* The type Xid.
*
Expand Down
67 changes: 67 additions & 0 deletions common/src/main/java/org/apache/seata/common/metadata/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


public class Node {
Expand All @@ -28,6 +29,10 @@ public class Node {

private Endpoint internal;

private double weight = 1.0;
private boolean healthy = true;
private long timeStamp;

private String group;
private ClusterRole role = ClusterRole.MEMBER;

Expand Down Expand Up @@ -97,6 +102,49 @@ public void setInternal(Endpoint internal) {
this.internal = internal;
}

@Override
public int hashCode() {
return Objects.hash(control, transaction);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Node node = (Node) o;
return Objects.equals(control, node.control) && Objects.equals(transaction, node.transaction);
}


// convert to String
public String toJsonString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("\"controlEndpoint\": ").append(control.toString()).append(", ");
sb.append("\"transactionEndpoint\": ").append(transaction.toString()).append(", ");
sb.append("\"weight\": ").append(weight).append(", ");
sb.append("\"healthy\": ").append(healthy).append(", ");
sb.append("\"timeStamp\": ").append(timeStamp).append(", ");
sb.append("\"metadata\": {");

// handle metadata k-v map
int i = 0;
for (Map.Entry<String, Object> entry : metadata.entrySet()) {
if (i > 0) {
sb.append(", ");
}
sb.append("\"").append(entry.getKey()).append("\": \"").append(entry.getValue()).append("\"");
i++;
}

sb.append("}}");
return sb.toString();
}

public static class Endpoint {

private String host;
Expand Down Expand Up @@ -136,6 +184,25 @@ public String createAddress() {
return host + ":" + port;
}

@Override
public int hashCode() {
return Objects.hash(host,port,protocol);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Endpoint endpoint = (Endpoint) o;
return Objects.equals(endpoint.host,this.host)
&& Objects.equals(endpoint.port,this.port)
&& Objects.equals(endpoint.protocol,this.protocol);
}

@Override
public String toString() {
return "Endpoint{" + "host='" + host + '\'' + ", port=" + port + '}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public class Instance {
private String namespace;
private String clusterName;
private String unit;
private Node.Endpoint controlEndpoint = new Node.Endpoint();
private Node.Endpoint transactionEndpoint = new Node.Endpoint();
private Node.Endpoint control = new Node.Endpoint();
private Node.Endpoint transaction = new Node.Endpoint();
private double weight = 1.0;
private boolean healthy = true;
private long term;
private long timestamp;
private ClusterRole role = ClusterRole.MEMBER;
private Map<String, Object> metadata = new HashMap<>();

Expand Down Expand Up @@ -83,20 +84,20 @@ public void setRole(ClusterRole role) {
this.role = role;
}

public Node.Endpoint getControlEndpoint() {
return controlEndpoint;
public Node.Endpoint getControl() {
return control;
}

public void setControlEndpoint(Node.Endpoint controlEndpoint) {
this.controlEndpoint = controlEndpoint;
public void setControl(Node.Endpoint control) {
this.control = control;
}

public Node.Endpoint getTransactionEndpoint() {
return transactionEndpoint;
public Node.Endpoint getTransaction() {
return transaction;
}

public void setTransactionEndpoint(Node.Endpoint transactionEndpoint) {
this.transactionEndpoint = transactionEndpoint;
public void setTransaction(Node.Endpoint transaction) {
this.transaction = transaction;
}

public double getWeight() {
Expand Down Expand Up @@ -124,6 +125,14 @@ public void setTerm(long term) {
this.term = term;
}

public long getTimestamp() {
return timestamp;
}

public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}

public void addMetadata(String key, Object value) {
this.metadata.put(key, value);
}
Expand All @@ -134,7 +143,7 @@ public void setMetadata(Map<String, Object> metadata) {

@Override
public int hashCode() {
return Objects.hash(controlEndpoint, transactionEndpoint);
return Objects.hash(control, transaction);
}

@Override
Expand All @@ -146,7 +155,7 @@ public boolean equals(Object o) {
return false;
}
Instance instance = (Instance) o;
return Objects.equals(controlEndpoint, instance.controlEndpoint) && Objects.equals(transactionEndpoint, instance.transactionEndpoint);
return Objects.equals(control, instance.control) && Objects.equals(transaction, instance.transaction);
}


Expand All @@ -168,11 +177,12 @@ public Map<String, String> toMap() {
resultMap.put("namespace", namespace);
resultMap.put("clusterName", clusterName);
resultMap.put("unit", unit);
resultMap.put("controlEndpoint", controlEndpoint.toString());
resultMap.put("transactionEndpoint", transactionEndpoint.toString());
resultMap.put("control", control.toString());
resultMap.put("transaction", transaction.toString());
resultMap.put("weight", String.valueOf(weight));
resultMap.put("healthy", String.valueOf(healthy));
resultMap.put("term", String.valueOf(term));
resultMap.put("timestamp",String.valueOf(timestamp));
resultMap.put("metadata", mapToJsonString(metadata));

return resultMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ public class NamingServerNode extends Node {
private boolean healthy = true;
private long term;

public double getWeight() {
return weight;
}

public boolean isHealthy() {
return healthy;
}

public void setHealthy(boolean healthy) {
this.healthy = healthy;
}

public long getTerm() {
return term;
}

public void setTerm(long term) {
this.term = term;
}

@Override
public int hashCode() {
return Objects.hash(getControl(), getTransaction());
Expand All @@ -45,25 +65,15 @@ public boolean equals(Object o) {
return Objects.equals(getControl(), node.getControl()) && Objects.equals(getTransaction(), node.getTransaction());
}

public boolean isTotalEqual(Object obj) {
if (this == obj) {
return true;
}

if (obj == null || getClass() != obj.getClass()) {
public boolean isChanged(Object obj) {
if (Objects.isNull(obj)) {
return false;
}

NamingServerNode otherNode = (NamingServerNode) obj;

// check each member variable
return Objects.equals(getControl(), otherNode.getControl()) &&
Objects.equals(getTransaction(), otherNode.getTransaction()) &&
Double.compare(otherNode.weight, weight) == 0 &&
healthy == otherNode.healthy &&
Objects.equals(getRole(), otherNode.getRole()) &&
term == otherNode.term &&
Objects.equals(getMetadata(), otherNode.getMetadata());
// other node is newer than me
return otherNode.term > term;
}

// convert to String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Unit {

private String unitName;

private List<Node> nodeList;
private List<NamingServerNode> nodeList;

public String getUnitName() {
return unitName;
Expand All @@ -34,11 +34,11 @@ public void setUnitName(String unitName) {
this.unitName = unitName;
}

public List<Node> getNamingInstanceList() {
public List<NamingServerNode> getNamingInstanceList() {
return nodeList;
}

public void setNamingInstanceList(List<Node> nodeList) {
public void setNamingInstanceList(List<NamingServerNode> nodeList) {
this.nodeList = nodeList;
}

Expand All @@ -51,16 +51,17 @@ public void removeInstance(Node node) {
/**
* @param node node
*/
public void addInstance(NamingServerNode node) {
public boolean addInstance(NamingServerNode node) {
if (nodeList.contains(node)) {
Node node1 = nodeList.get(nodeList.indexOf(node));
if (node.isTotalEqual(node1)) {
return;
} else {
NamingServerNode node1 = nodeList.get(nodeList.indexOf(node));
if (node1.isChanged(node)) {
nodeList.remove(node1);
} else {
return false;
}
}
nodeList.add(node);
return true;

}

Expand Down
Loading
Loading