Skip to content

Commit

Permalink
Merge branch '2.x' into incr_spring_autoconfigure_unit_test
Browse files Browse the repository at this point in the history
  • Loading branch information
l81893521 authored Aug 17, 2024
2 parents bad4ec0 + f7c3866 commit d6afc9a
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 133 deletions.
3 changes: 3 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#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

### bugfix:
- [[#6592](https://github.com/apache/incubator-seata/pull/6592)] fix @Async annotation not working in ClusterWatcherManager
- [[#6624](https://github.com/apache/incubator-seata/pull/6624)] fix Alibaba Dubbo convert error
Expand All @@ -22,6 +23,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6711](https://github.com/apache/incubator-seata/pull/6711)] fix dameng rollback info un compress fail
- [[#6714](https://github.com/apache/incubator-seata/pull/6714)] fix dameng delete undo fail
- [[#6701](https://github.com/apache/incubator-seata/pull/6728)] fix support serialization for dm.jdbc.driver.DmdbTimestamp
- [[#6757](https://github.com/apache/incubator-seata/pull/6757)] the bug where multiple nodes cannot be retrieved from the naming server


### optimize:
Expand Down Expand Up @@ -54,6 +56,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6745](https://github.com/apache/incubator-seata/pull/6745)] fix node-gyp build error on arm64 and macos
- [[#6748](https://github.com/apache/incubator-seata/pull/6748)] optimize ConsistentHashLoadBalance Algorithm
- [[#6747](https://github.com/apache/incubator-seata/pull/6747)] optimize fastjson deserialization
- [[#6755](https://github.com/apache/incubator-seata/pull/6755)] optimize namingserver code logic


### refactor:
Expand Down
4 changes: 3 additions & 1 deletion changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- [[#6711](https://github.com/apache/incubator-seata/pull/6711)] 修复达梦数据库的getRollbackInfo没有解压缩的问题
- [[#6714](https://github.com/apache/incubator-seata/pull/6714)] 修复达梦数据库的delete sql回滚失败的问题
- [[#6701](https://github.com/apache/incubator-seata/pull/6728)] 修复达梦数据库的对dm.jdbc.driver.DmdbTimestamp的支持
- [[#6757](https://github.com/apache/incubator-seata/pull/6757)] 修复client通过namingserver只能获取到一个tc节点的bug


### optimize:
- [[#6499](https://github.com/apache/incubator-seata/pull/6499)] 拆分 committing 和 rollbacking 状态的任务线程池
Expand Down Expand Up @@ -55,7 +57,7 @@
- [[#6745](https://github.com/apache/incubator-seata/pull/6745)] 修复 node-gyp 在 arm64 和 macos 构建失败问题
- [[#6748](https://github.com/apache/incubator-seata/pull/6748)] 优化 ConsistentHashLoadBalance 算法
- [[#6747](https://github.com/apache/incubator-seata/pull/6747)] 优化 fastjson 反序列化

- [[#6755](https://github.com/apache/incubator-seata/pull/6755)] 优化namingserver代码逻辑


### refactor:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,9 @@ public interface ConfigurationKeys {
String REGISTRY_NAMINGSERVER_CLUSTER = NAMINGSERVER_REGISTRY_PREFIX + "cluster";

/**
* The constant MAPPING_TABLE_NAME
* The constant VGROUP_TABLE_NAME
*/
String MAPPING_TABLE_NAME = STORE_DB_PREFIX + "mapping-table";
String VGROUP_TABLE_NAME = STORE_DB_PREFIX + FILE_CONFIG_SPLIT_CHAR + "vgroup-table";

/**
* The constant NAMESPACE_KEY
Expand Down
13 changes: 11 additions & 2 deletions common/src/main/java/org/apache/seata/common/metadata/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
*/
package org.apache.seata.common.metadata;

import org.apache.seata.common.metadata.namingserver.Unit;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.apache.seata.common.metadata.namingserver.Unit;

public class Cluster {
private String clusterName;
private String clusterType;
Expand Down Expand Up @@ -54,6 +55,14 @@ public void setUnitData(List<Unit> unitData) {
this.unitData = unitData;
}

public void appendUnits(Collection<Unit> unitData) {
this.unitData.addAll(unitData);
}

public void appendUnit(Unit unitData) {
this.unitData.add(unitData);
}


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ static NamingserverRegistryServiceImpl getInstance() {

@Override
public void register(InetSocketAddress address) throws Exception {
unregister(address);
NetUtil.validAddress(address);
Instance instance = Instance.getInstance();
instance.setTransaction(new Node.Endpoint(address.getAddress().getHostAddress(), address.getPort(), "netty"));
Expand Down Expand Up @@ -207,7 +206,7 @@ public void doRegister(Instance instance, List<String> urlList) {
}

public boolean doHealthCheck(String url) {
url = HTTP_PREFIX + url + "/naming/v1/health";
url = HTTP_PREFIX + url + "/health";
Map<String, String> header = new HashMap<>();
header.put(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
try (CloseableHttpResponse response = HttpClientUtil.doGet(url, null, header, 3000)) {
Expand All @@ -233,6 +232,8 @@ public void unregister(InetSocketAddress address) {
String unit = instance.getUnit();
String jsonBody = instance.toJsonString();
String params = "unit=" + unit;
params = params + "&cluster=" + instance.getClusterName();
params = params + "&namespace=" + instance.getNamespace();
url += params;
Map<String, String> header = new HashMap<>();
header.put(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public Result<String> registerInstance(@RequestParam String namespace,
}

@PostMapping("/unregister")
public Result<String> unregisterInstance(@RequestParam String unit,
@RequestBody NamingServerNode registerBody) {
public Result<String> unregisterInstance(@RequestParam String namespace, @RequestParam String clusterName,
@RequestParam String unit, @RequestBody NamingServerNode registerBody) {
Result<String> result = new Result<>();
boolean isSuccess = namingManager.unregisterInstance(unit, registerBody);
boolean isSuccess = namingManager.unregisterInstance(namespace, clusterName, unit, registerBody);
if (isSuccess) {
result.setMessage("node has unregistered successfully!");
} else {
Expand All @@ -95,22 +95,29 @@ public MetaResponse discovery(@RequestParam String vGroup, @RequestParam String
clusterWatcherManager.getTermByvGroup(vGroup));
}

@PostMapping("/addGroup")
public Result<String> addGroup(@RequestParam String namespace,
@RequestParam String clusterName,
@RequestParam String unitName,
@RequestParam String vGroup) {

Result<String> addGroupResult = namingManager.createGroup(namespace, vGroup, clusterName, unitName);
if (!addGroupResult.isSuccess()) {
return addGroupResult;
}
return new Result<>("200", "change vGroup " + vGroup + "to cluster " + clusterName + " successfully!");
}

@PostMapping("/changeGroup")
public Result<String> changeGroup(@RequestParam String namespace,
@RequestParam String clusterName,
@RequestParam String unitName,
@RequestParam String vGroup) {

Result<String> addGroupResult = namingManager.addGroup(namespace, vGroup, clusterName, unitName);
Result<String> addGroupResult = namingManager.changeGroup(namespace, vGroup, clusterName, unitName);
if (!addGroupResult.isSuccess()) {
return addGroupResult;
}
// remove vGroup in old cluster
Result<String> removeGroupResult = namingManager.removeGroup(namespace, vGroup, unitName);
if (!removeGroupResult.isSuccess()) {
return removeGroupResult;
}
namingManager.changeGroup(namespace, clusterName, unitName, vGroup);
return new Result<>("200", "change vGroup " + vGroup + "to cluster " + clusterName + " successfully!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.Lock;
Expand All @@ -34,7 +35,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

public class ClusterData {
private static final Logger LOGGER = LoggerFactory.getLogger(ClusterData.class);
Expand Down Expand Up @@ -107,16 +107,18 @@ public List<Node> getInstanceList() {
}


public Cluster getClusterByUnit(String unitName) {
public Cluster getClusterByUnits(Set<String> unitNames) {
Cluster clusterResponse = new Cluster();
clusterResponse.setClusterName(clusterName);
clusterResponse.setClusterType(clusterType);
if (!StringUtils.hasLength(unitName)) {
clusterResponse.setUnitData(new ArrayList<>(unitData.values()));
if (CollectionUtils.isEmpty(unitNames)) {
clusterResponse.appendUnits(unitData.values());
} else {
List<Unit> unitList = new ArrayList<>();
Optional.ofNullable(unitData.get(unitName)).ifPresent(unitList::add);
clusterResponse.setUnitData(unitList);
for (String unitName : unitNames) {
List<Unit> unitList = new ArrayList<>();
Optional.ofNullable(unitData.get(unitName)).ifPresent(unitList::add);
clusterResponse.appendUnits(unitList);
}
}

return clusterResponse;
Expand Down
Loading

0 comments on commit d6afc9a

Please sign in to comment.