Skip to content

Commit

Permalink
Release 650 (#351)
Browse files Browse the repository at this point in the history
* 提供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
  • Loading branch information
huanglongchao authored May 22, 2024
1 parent 3d8297a commit 0d4ffd5
Show file tree
Hide file tree
Showing 70 changed files with 622 additions and 88 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- uses: actions/checkout@v2
Expand All @@ -23,6 +24,12 @@ jobs:
- name: Unit Testt
run: mvn compile -B
&& mvn clean test -DisSkipIntegrationTest=true "-Dtest.logging.level=ERROR" --fail-at-end --batch-mode
- name: Upload heap dump
if: always()
uses: actions/upload-artifact@v2
with:
name: heap-dump
path: /tmp/*.hprof
- name: Publish Test Report
if: ${{ always() }}
uses: ScaCap/action-surefire-report@v1
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.0
6.5.1
2 changes: 1 addition & 1 deletion client/all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-all</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>

<name>${project.groupId}:${project.artifactId}</name>
<url>http://github.com/alipay/sofa-registry</url>
Expand Down
2 changes: 1 addition & 1 deletion client/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion client/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ServerNode random() {
private void syncServerList() {
String url =
String.format(
"http://%s:%d/api/servers/query",
"http://%s:%d/api/servers/queryWithWeight",
config.getRegistryEndpoint(), config.getRegistryEndpointPort());
Map<String, String> params = new HashMap<String, String>();
params.put("env", config.getEnv());
Expand All @@ -100,6 +100,14 @@ private void syncServerList() {
params.put("instanceId", config.getInstanceId());
try {
String result = HttpClientUtils.get(url, params, config);
if (null == result) {
// when registry not support query with weight , go back
url =
String.format(
"http://%s:%d/api/servers/query",
config.getRegistryEndpoint(), config.getRegistryEndpointPort());
result = HttpClientUtils.get(url, params, config);
}
if (null != result) {
String[] servers = result.split(";");
Set<ServerNode> tempNodes = new HashSet<ServerNode>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alipay.sofa.registry.client.provider;

import com.alipay.sofa.registry.client.remoting.ServerNode;
import com.alipay.sofa.registry.client.util.StringUtils;
import java.util.Properties;

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

private Properties properties;

private static final String WEIGHT_KEY = "weight";

/**
* Instantiates a new Default server node.
*
Expand Down Expand Up @@ -80,6 +83,22 @@ public String getUrl() {
return url;
}

@Override
public int getWeight() {
if (null == getProperties()) {
return 0;
}
String weightStr = getProperties().getProperty(WEIGHT_KEY);
if (StringUtils.isBlank(weightStr)) {
return 0;
}
try {
return Integer.parseInt(weightStr);
} catch (NumberFormatException e) {
return 0;
}
}

/**
* Gets properties.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,29 @@ private boolean connect() {
List<ServerNode> serverNodes = new ArrayList<ServerNode>(serverManager.getServerList());
// shuffle server list to make server connections as discrete as possible
Collections.shuffle(serverNodes);
for (ServerNode serverNode : serverNodes) {
int choosed = 0;
for (int i = 0; i < serverNodes.size(); i++) {
try {
connection = connect(serverNode);
// Power of Two Choices
if (serverNodes.size() > 1) {
choosed =
serverNodes.get(i).getWeight()
> serverNodes.get((i + 1) % serverNodes.size()).getWeight()
? (i + 1) % serverNodes.size()
: i;
}
connection = connect(serverNodes.get(choosed));
if (null != connection && connection.isFine()) {
resetRegister();
LOGGER.info("[Connect] Successfully connected to server: {}", serverNode);
LOGGER.info("[Connect] Successfully connected to server: {}", serverNodes.get(choosed));
break;
} else {
recycle(connection);
}

Thread.sleep(random.nextInt(RECONNECTING_DELAY));
} catch (Exception e) {
LOGGER.error("[Connect] Failed trying connect to {}", serverNode, e);
LOGGER.error("[Connect] Failed trying connect to {}", serverNodes.get(choosed), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public interface ServerNode {
* @return the url
*/
String getUrl();

/**
* Gets Weight
*
* @return the weight
*/
int getWeight();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
package com.alipay.sofa.registry.client.provider;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMapOf;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -67,4 +65,36 @@ public void initServerList() throws Exception {
// verify
PowerMockito.verifyStatic(times(4));
}

@Test
public void initServerListCompatible() throws Exception {
// given
PowerMockito.mockStatic(HttpClientUtils.class);
RegistryClientConfig config = mock(RegistryClientConfig.class);

// when
when(config.getSyncConfigRetryInterval()).thenReturn(100);
when(HttpClientUtils.get(
eq("http://null:0/api/servers/queryWithWeight"),
anyMapOf(String.class, String.class),
any(RegistryClientConfig.class)))
.thenReturn(null);
when(HttpClientUtils.get(
eq("http://null:0/api/servers/query"),
anyMapOf(String.class, String.class),
any(RegistryClientConfig.class)))
.thenReturn("127.0.0.1:9600;127.0.0.2:9600");

// then
ServerManager serverManager = new DefaultServerManager(config);

List<ServerNode> serverList = serverManager.getServerList();

assertNotNull(serverList);

Thread.sleep(450);

// verify
PowerMockito.verifyStatic(times(4));
}
}
2 changes: 1 addition & 1 deletion client/log/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-client-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>

<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion server/common/model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-common</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public class ValueConstants {
"app_revision.cleaner.enabled",
SESSION_PROVIDE_DATA_INSTANCE_ID,
SESSION_PROVIDE_DATA_GROUP);

public static final String INTERFACE_APP_CLEANER_ENABLED_DATA_ID =
DataInfo.toDataInfoId(
"interface_app.cleaner.enabled",
SESSION_PROVIDE_DATA_INSTANCE_ID,
SESSION_PROVIDE_DATA_GROUP);
public static final String COMPRESS_PUSH_SWITCH_DATA_ID =
DataInfo.toDataInfoId(
"compress.push.switch", SESSION_PROVIDE_DATA_INSTANCE_ID, SESSION_PROVIDE_DATA_GROUP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ public class SessionNode extends AbstractNode {

private final ProcessId processId;

// session weight for client conn load balance
private int weight;

/**
* constructor
*
* @param nodeUrl nodeUrl
* @param regionId regionId
* @param processId processId
*/
public SessionNode(URL nodeUrl, String regionId, ProcessId processId) {
public SessionNode(URL nodeUrl, String regionId, ProcessId processId, int weight) {
super(null, nodeUrl, regionId);
this.processId = processId;
this.weight = weight;
}

@Override
Expand All @@ -61,6 +65,10 @@ public ProcessId getProcessId() {
return processId;
}

public int getWeight() {
return weight;
}

/**
* Hash code int.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public void testDataNode() {
public void testSessionNode() {
ProcessId processId1 = new ProcessId("test", 1, 2, 3);
ProcessId processId2 = new ProcessId("test1", 1, 2, 3);
SessionNode node1 = new SessionNode(url1, region, processId1);
SessionNode node2 = new SessionNode(url2, region, processId2);
SessionNode node3 = new SessionNode(url1, region, processId2);
SessionNode node1 = new SessionNode(url1, region, processId1, 0);
SessionNode node2 = new SessionNode(url2, region, processId2, 0);
SessionNode node3 = new SessionNode(url1, region, processId2, 0);
Assert.assertEquals(node1, node3);
Assert.assertEquals(node1.hashCode(), node3.hashCode());
Assert.assertEquals(node1.toString(), node3.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public void test() {
ProcessId processId1 = new ProcessId("test", 1, 2, 3);
final String dataId = "testDataId";
DataCenterNodes request = new DataCenterNodes(Node.NodeType.CLIENT, 10, dataId);
SessionNode sessionNode = new SessionNode(new URL("192.168.1.1", 8888), "testZone", processId1);
SessionNode sessionNode =
new SessionNode(new URL("192.168.1.1", 8888), "testZone", processId1, 0);
request.setNodes(Collections.singletonMap("testKey", sessionNode));
Assert.assertEquals(request.getDataCenterId(), dataId);
Assert.assertEquals(request.getVersion(), 10);
Expand Down
2 changes: 1 addition & 1 deletion server/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/common/util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-common</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/distribution/all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-distribution</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-server-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-parent</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion server/remoting/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-remoting</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/remoting/bolt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-remoting</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion server/remoting/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>registry-remoting</artifactId>
<version>6.4.0</version>
<version>6.5.1</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Loading

0 comments on commit 0d4ffd5

Please sign in to comment.