Skip to content

Commit 0d4ffd5

Browse files
Release 650 (#351)
* 提供API查询session链接数 * fix node forbidden bug * support top sub/pub query api * interface app cleaner * sessionNode renew add weight * default push opened * connection load balance support p2c * update version & fix & add ut * fix ut & git uint test add dump * set unit test timeout * registry-client compatible old version server * fix p2c client bug * fix log & update version
1 parent 3d8297a commit 0d4ffd5

File tree

70 files changed

+622
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+622
-88
lines changed

.github/workflows/unit-test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
build:
1414

1515
runs-on: ubuntu-latest
16+
timeout-minutes: 15
1617

1718
steps:
1819
- uses: actions/checkout@v2
@@ -23,6 +24,12 @@ jobs:
2324
- name: Unit Testt
2425
run: mvn compile -B
2526
&& mvn clean test -DisSkipIntegrationTest=true "-Dtest.logging.level=ERROR" --fail-at-end --batch-mode
27+
- name: Upload heap dump
28+
if: always()
29+
uses: actions/upload-artifact@v2
30+
with:
31+
name: heap-dump
32+
path: /tmp/*.hprof
2633
- name: Publish Test Report
2734
if: ${{ always() }}
2835
uses: ScaCap/action-surefire-report@v1

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.4.0
1+
6.5.1

client/all/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.alipay.sofa</groupId>
88
<artifactId>registry-client-all</artifactId>
9-
<version>6.4.0</version>
9+
<version>6.5.1</version>
1010

1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<url>http://github.com/alipay/sofa-registry</url>

client/api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-client-parent</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

client/impl/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-client-parent</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

client/impl/src/main/java/com/alipay/sofa/registry/client/provider/DefaultServerManager.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public ServerNode random() {
9090
private void syncServerList() {
9191
String url =
9292
String.format(
93-
"http://%s:%d/api/servers/query",
93+
"http://%s:%d/api/servers/queryWithWeight",
9494
config.getRegistryEndpoint(), config.getRegistryEndpointPort());
9595
Map<String, String> params = new HashMap<String, String>();
9696
params.put("env", config.getEnv());
@@ -100,6 +100,14 @@ private void syncServerList() {
100100
params.put("instanceId", config.getInstanceId());
101101
try {
102102
String result = HttpClientUtils.get(url, params, config);
103+
if (null == result) {
104+
// when registry not support query with weight , go back
105+
url =
106+
String.format(
107+
"http://%s:%d/api/servers/query",
108+
config.getRegistryEndpoint(), config.getRegistryEndpointPort());
109+
result = HttpClientUtils.get(url, params, config);
110+
}
103111
if (null != result) {
104112
String[] servers = result.split(";");
105113
Set<ServerNode> tempNodes = new HashSet<ServerNode>();

client/impl/src/main/java/com/alipay/sofa/registry/client/provider/DefaultServerNode.java

+19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.alipay.sofa.registry.client.provider;
1818

1919
import com.alipay.sofa.registry.client.remoting.ServerNode;
20+
import com.alipay.sofa.registry.client.util.StringUtils;
2021
import java.util.Properties;
2122

2223
/**
@@ -35,6 +36,8 @@ public class DefaultServerNode implements ServerNode {
3536

3637
private Properties properties;
3738

39+
private static final String WEIGHT_KEY = "weight";
40+
3841
/**
3942
* Instantiates a new Default server node.
4043
*
@@ -80,6 +83,22 @@ public String getUrl() {
8083
return url;
8184
}
8285

86+
@Override
87+
public int getWeight() {
88+
if (null == getProperties()) {
89+
return 0;
90+
}
91+
String weightStr = getProperties().getProperty(WEIGHT_KEY);
92+
if (StringUtils.isBlank(weightStr)) {
93+
return 0;
94+
}
95+
try {
96+
return Integer.parseInt(weightStr);
97+
} catch (NumberFormatException e) {
98+
return 0;
99+
}
100+
}
101+
83102
/**
84103
* Gets properties.
85104
*

client/impl/src/main/java/com/alipay/sofa/registry/client/remoting/ClientConnection.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,29 @@ private boolean connect() {
125125
List<ServerNode> serverNodes = new ArrayList<ServerNode>(serverManager.getServerList());
126126
// shuffle server list to make server connections as discrete as possible
127127
Collections.shuffle(serverNodes);
128-
for (ServerNode serverNode : serverNodes) {
128+
int choosed = 0;
129+
for (int i = 0; i < serverNodes.size(); i++) {
129130
try {
130-
connection = connect(serverNode);
131+
// Power of Two Choices
132+
if (serverNodes.size() > 1) {
133+
choosed =
134+
serverNodes.get(i).getWeight()
135+
> serverNodes.get((i + 1) % serverNodes.size()).getWeight()
136+
? (i + 1) % serverNodes.size()
137+
: i;
138+
}
139+
connection = connect(serverNodes.get(choosed));
131140
if (null != connection && connection.isFine()) {
132141
resetRegister();
133-
LOGGER.info("[Connect] Successfully connected to server: {}", serverNode);
142+
LOGGER.info("[Connect] Successfully connected to server: {}", serverNodes.get(choosed));
134143
break;
135144
} else {
136145
recycle(connection);
137146
}
138147

139148
Thread.sleep(random.nextInt(RECONNECTING_DELAY));
140149
} catch (Exception e) {
141-
LOGGER.error("[Connect] Failed trying connect to {}", serverNode, e);
150+
LOGGER.error("[Connect] Failed trying connect to {}", serverNodes.get(choosed), e);
142151
}
143152
}
144153

client/impl/src/main/java/com/alipay/sofa/registry/client/remoting/ServerNode.java

+7
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,11 @@ public interface ServerNode {
5353
* @return the url
5454
*/
5555
String getUrl();
56+
57+
/**
58+
* Gets Weight
59+
*
60+
* @return the weight
61+
*/
62+
int getWeight();
5663
}

client/impl/src/test/java/com/alipay/sofa/registry/client/provider/DefaultServerManagerTest.java

+33-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
package com.alipay.sofa.registry.client.provider;
1818

1919
import static org.junit.Assert.assertNotNull;
20-
import static org.mockito.Matchers.any;
21-
import static org.mockito.Matchers.anyMapOf;
22-
import static org.mockito.Matchers.anyString;
20+
import static org.mockito.Matchers.*;
2321
import static org.mockito.Mockito.mock;
2422
import static org.mockito.Mockito.times;
2523
import static org.mockito.Mockito.when;
@@ -67,4 +65,36 @@ public void initServerList() throws Exception {
6765
// verify
6866
PowerMockito.verifyStatic(times(4));
6967
}
68+
69+
@Test
70+
public void initServerListCompatible() throws Exception {
71+
// given
72+
PowerMockito.mockStatic(HttpClientUtils.class);
73+
RegistryClientConfig config = mock(RegistryClientConfig.class);
74+
75+
// when
76+
when(config.getSyncConfigRetryInterval()).thenReturn(100);
77+
when(HttpClientUtils.get(
78+
eq("http://null:0/api/servers/queryWithWeight"),
79+
anyMapOf(String.class, String.class),
80+
any(RegistryClientConfig.class)))
81+
.thenReturn(null);
82+
when(HttpClientUtils.get(
83+
eq("http://null:0/api/servers/query"),
84+
anyMapOf(String.class, String.class),
85+
any(RegistryClientConfig.class)))
86+
.thenReturn("127.0.0.1:9600;127.0.0.2:9600");
87+
88+
// then
89+
ServerManager serverManager = new DefaultServerManager(config);
90+
91+
List<ServerNode> serverList = serverManager.getServerList();
92+
93+
assertNotNull(serverList);
94+
95+
Thread.sleep(450);
96+
97+
// verify
98+
PowerMockito.verifyStatic(times(4));
99+
}
70100
}

client/log/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-client-parent</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

client/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.alipay.sofa</groupId>
99
<artifactId>registry-parent</artifactId>
10-
<version>6.4.0</version>
10+
<version>6.5.1</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-parent</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.alipay.sofa</groupId>
88
<artifactId>registry-parent</artifactId>
9-
<version>6.4.0</version>
9+
<version>6.5.1</version>
1010

1111
<packaging>pom</packaging>
1212

server/common/model/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-common</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

server/common/model/src/main/java/com/alipay/sofa/registry/common/model/constants/ValueConstants.java

+6
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ public class ValueConstants {
138138
"app_revision.cleaner.enabled",
139139
SESSION_PROVIDE_DATA_INSTANCE_ID,
140140
SESSION_PROVIDE_DATA_GROUP);
141+
142+
public static final String INTERFACE_APP_CLEANER_ENABLED_DATA_ID =
143+
DataInfo.toDataInfoId(
144+
"interface_app.cleaner.enabled",
145+
SESSION_PROVIDE_DATA_INSTANCE_ID,
146+
SESSION_PROVIDE_DATA_GROUP);
141147
public static final String COMPRESS_PUSH_SWITCH_DATA_ID =
142148
DataInfo.toDataInfoId(
143149
"compress.push.switch", SESSION_PROVIDE_DATA_INSTANCE_ID, SESSION_PROVIDE_DATA_GROUP);

server/common/model/src/main/java/com/alipay/sofa/registry/common/model/metaserver/nodes/SessionNode.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@ public class SessionNode extends AbstractNode {
2727

2828
private final ProcessId processId;
2929

30+
// session weight for client conn load balance
31+
private int weight;
32+
3033
/**
3134
* constructor
3235
*
3336
* @param nodeUrl nodeUrl
3437
* @param regionId regionId
3538
* @param processId processId
3639
*/
37-
public SessionNode(URL nodeUrl, String regionId, ProcessId processId) {
40+
public SessionNode(URL nodeUrl, String regionId, ProcessId processId, int weight) {
3841
super(null, nodeUrl, regionId);
3942
this.processId = processId;
43+
this.weight = weight;
4044
}
4145

4246
@Override
@@ -61,6 +65,10 @@ public ProcessId getProcessId() {
6165
return processId;
6266
}
6367

68+
public int getWeight() {
69+
return weight;
70+
}
71+
6472
/**
6573
* Hash code int.
6674
*

server/common/model/src/test/java/com/alipay/sofa/registry/common/model/metaserver/nodes/NodeTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public void testDataNode() {
5151
public void testSessionNode() {
5252
ProcessId processId1 = new ProcessId("test", 1, 2, 3);
5353
ProcessId processId2 = new ProcessId("test1", 1, 2, 3);
54-
SessionNode node1 = new SessionNode(url1, region, processId1);
55-
SessionNode node2 = new SessionNode(url2, region, processId2);
56-
SessionNode node3 = new SessionNode(url1, region, processId2);
54+
SessionNode node1 = new SessionNode(url1, region, processId1, 0);
55+
SessionNode node2 = new SessionNode(url2, region, processId2, 0);
56+
SessionNode node3 = new SessionNode(url1, region, processId2, 0);
5757
Assert.assertEquals(node1, node3);
5858
Assert.assertEquals(node1.hashCode(), node3.hashCode());
5959
Assert.assertEquals(node1.toString(), node3.toString());

server/common/model/src/test/java/com/alipay/sofa/registry/common/model/metaserver/rpc/DataCenterNodesTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public void test() {
3131
ProcessId processId1 = new ProcessId("test", 1, 2, 3);
3232
final String dataId = "testDataId";
3333
DataCenterNodes request = new DataCenterNodes(Node.NodeType.CLIENT, 10, dataId);
34-
SessionNode sessionNode = new SessionNode(new URL("192.168.1.1", 8888), "testZone", processId1);
34+
SessionNode sessionNode =
35+
new SessionNode(new URL("192.168.1.1", 8888), "testZone", processId1, 0);
3536
request.setNodes(Collections.singletonMap("testKey", sessionNode));
3637
Assert.assertEquals(request.getDataCenterId(), dataId);
3738
Assert.assertEquals(request.getVersion(), 10);

server/common/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-server-parent</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

server/common/util/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-common</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

server/distribution/all/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-distribution</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

server/distribution/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.alipay.sofa</groupId>
88
<artifactId>registry-server-parent</artifactId>
9-
<version>6.4.0</version>
9+
<version>6.5.1</version>
1010
<relativePath>../pom.xml</relativePath>
1111
</parent>
1212
<modelVersion>4.0.0</modelVersion>

server/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.alipay.sofa</groupId>
99
<artifactId>registry-parent</artifactId>
10-
<version>6.4.0</version>
10+
<version>6.5.1</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

server/remoting/api/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-remoting</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

server/remoting/bolt/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-remoting</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

server/remoting/http/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.alipay.sofa</groupId>
77
<artifactId>registry-remoting</artifactId>
8-
<version>6.4.0</version>
8+
<version>6.5.1</version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

0 commit comments

Comments
 (0)