You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by ji...@apache.org on 2024/09/06 07:21:42 UTC
(incubator-seata) branch 2.x updated: bugfix: fix namingserver changVgroup failed (#6817)
This is an automated email from the ASF dual-hosted git repository.
jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push:
new 145b33c0c1 bugfix: fix namingserver changVgroup failed (#6817)
145b33c0c1 is described below
commit 145b33c0c1334d8e69807a218cb9e156a3e96424
Author: ggbocoder <11...@users.noreply.github.com>
AuthorDate: Fri Sep 6 15:21:38 2024 +0800
bugfix: fix namingserver changVgroup failed (#6817)
---
changes/en-us/2.x.md | 3 ++-
changes/zh-cn/2.x.md | 1 +
.../seata/namingserver/entity/bo/NamespaceBO.java | 7 ++++++-
.../seata/namingserver/manager/NamingManager.java | 22 ++++++++++++----------
.../server/controller/VGroupMappingController.java | 4 ----
5 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index a09f52ad97..9093aed1db 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -33,7 +33,8 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6797](https://github.com/apache/incubator-seata/pull/6797)] fall back to any of available cluster address when query cluster address is empty
- [[#6800](https://github.com/apache/incubator-seata/pull/6800)] make exception message generic for all database drivers
- [[#6759](https://github.com/apache/incubator-seata/pull/6759)] fix the error of active refresh failure of cross-database table metadata
-- [[#6812](https://github.com/apache/incubator-seata/pull/6812)] change group and node offline status are not pushed in real time
+- [[#6812](https://github.com/apache/incubator-seata/pull/6812)] bugfix: change group and node offline status are not pushed in real time
+- [[#6817](https://github.com/apache/incubator-seata/pull/6817)] bugfix: fix namingserver changVgroup failed
- [[#6820](https://github.com/apache/incubator-seata/pull/6820)] Fix file path error in the Dockerfile
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index ab20393b22..850f1d7ea7 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -35,6 +35,7 @@
- [[#6800](https://github.com/apache/incubator-seata/pull/6800)] 使异常消息对所有数据库驱动程序通用
- [[#6812](https://github.com/apache/incubator-seata/pull/6812)] 修复切换事务分组和节点下线时namingserver没有实时感知和推送的bug
- [[#6759](https://github.com/apache/incubator-seata/pull/6759)] 修复跨库表主动刷新`tableMeta`的异常问题
+- [[#6817](https://github.com/apache/incubator-seata/pull/6817)] 修复namingserver切换事务分组失效的问题
- [[#6820](https://github.com/apache/incubator-seata/pull/6820)] 修复Dockerfile得文件结构错误
-
### optimize:
diff --git a/namingserver/src/main/java/org/apache/seata/namingserver/entity/bo/NamespaceBO.java b/namingserver/src/main/java/org/apache/seata/namingserver/entity/bo/NamespaceBO.java
index 74749d8aac..e5694b0240 100644
--- a/namingserver/src/main/java/org/apache/seata/namingserver/entity/bo/NamespaceBO.java
+++ b/namingserver/src/main/java/org/apache/seata/namingserver/entity/bo/NamespaceBO.java
@@ -19,6 +19,7 @@ package org.apache.seata.namingserver.entity.bo;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.seata.common.metadata.Cluster;
@@ -56,7 +57,11 @@ public class NamespaceBO {
}
public void removeOldCluster(String clusterName) {
- clusterMap.keySet().forEach(currentClusterName -> {
+ Set<String> clusterSet = clusterMap.keySet();
+ if (clusterSet.size() <= 1) {
+ return;
+ }
+ clusterSet.forEach(currentClusterName -> {
if (!StringUtils.equals(currentClusterName, clusterName)) {
clusterMap.remove(currentClusterName);
}
diff --git a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
index 20e2d3dc04..9a6b790220 100644
--- a/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
+++ b/namingserver/src/main/java/org/apache/seata/namingserver/manager/NamingManager.java
@@ -205,28 +205,29 @@ public class NamingManager {
return new Result<>("200", "remove group in old cluster successfully!");
}
- public void addGroup(String namespace, String clusterName, String unitName, String vGroup) {
+ public boolean addGroup(String namespace, String clusterName, String unitName, String vGroup) {
try {
ClusterBO clusterBO = vGroupMap.get(vGroup, k -> new ConcurrentHashMap<>())
.computeIfAbsent(namespace, k -> new NamespaceBO()).getCluster(clusterName);
- if (clusterBO != null && !clusterBO.getUnitNames().contains(unitName)) {
- clusterBO.addUnit(unitName);
+ if (clusterBO != null /**&& !clusterBO.getUnitNames().contains(unitName)**/) {
+ boolean needNotify = !clusterBO.getUnitNames().contains(unitName);
NamespaceBO namespaceBO = vGroupMap.getIfPresent(vGroup).get(namespace);
namespaceBO.removeOldCluster(clusterName);
- applicationContext.publishEvent(new ClusterChangeEvent(this, vGroup, System.currentTimeMillis()));
+ if (needNotify) {
+ clusterBO.addUnit(unitName);
+ }
+ return needNotify;
}
} catch (Exception e) {
LOGGER.error("change vGroup mapping failed:{}", vGroup, e);
}
+ return false;
}
public void notifyClusterChange(String vGroup, String namespace, String clusterName, String unitName, long term) {
Optional.ofNullable(vGroupMap.asMap().get(vGroup)).flatMap(map -> Optional.ofNullable(map.get(namespace)).flatMap(namespaceBO -> Optional.ofNullable(namespaceBO.getCluster(clusterName)))).ifPresent(clusterBO -> {
-// Set<String> units = clusterBO.getUnitNames();
-// if (!CollectionUtils.isEmpty(units)) {
applicationContext.publishEvent(new ClusterChangeEvent(this, vGroup, term));
-// }
});
}
@@ -248,8 +249,8 @@ public class NamingManager {
vGroups.forEach((k, v) -> {
// In non-raft mode, a unit is one-to-one with a node, and the unitName is stored on the node.
// In raft mode, the unitName is equal to the raft-group, so the node's unitName cannot be used.
- addGroup(namespace, clusterName, StringUtils.isBlank(v) ? unitName : v, k);
- if (hasChanged) {
+ boolean changed = addGroup(namespace, clusterName, StringUtils.isBlank(v) ? unitName : v, k);
+ if (hasChanged || changed) {
notifyClusterChange(k, namespace, clusterName, unitName, node.getTerm());
}
});
@@ -360,6 +361,7 @@ public class NamingManager {
}
public Result<String> changeGroup(String namespace, String vGroup, String clusterName, String unitName) {
+ long changeTime = System.currentTimeMillis();
ConcurrentMap<String, NamespaceBO> namespaceMap = new ConcurrentHashMap<>(vGroupMap.get(vGroup));
Set<String> currentNamespaces = namespaceMap.keySet();
Map<String, Set<String>> namespaceClusters = new HashMap<>();
@@ -384,7 +386,7 @@ public class NamingManager {
String unit = optionalEntry.get().getKey();
Unit unitData = optionalEntry.get().getValue();
result.set(removeGroup(unitData, vGroup, cluster, oldNamespace, unitName));
- notifyClusterChange(vGroup, namespace, cluster, unit, -1);
+ notifyClusterChange(vGroup, namespace, cluster, unit, changeTime);
}
}
});
diff --git a/server/src/main/java/org/apache/seata/server/controller/VGroupMappingController.java b/server/src/main/java/org/apache/seata/server/controller/VGroupMappingController.java
index ae80858ff1..348a750283 100644
--- a/server/src/main/java/org/apache/seata/server/controller/VGroupMappingController.java
+++ b/server/src/main/java/org/apache/seata/server/controller/VGroupMappingController.java
@@ -73,8 +73,6 @@ public class VGroupMappingController {
result.setCode("500");
result.setMessage("add vGroup failed!");
}
- // push the newest mapping relationship
- vGroupMappingStoreManager.notifyMapping();
return result;
}
@@ -93,8 +91,6 @@ public class VGroupMappingController {
result.setCode("500");
result.setMessage("remove vGroup failed!");
}
- // push the newest mapping relationship
- vGroupMappingStoreManager.notifyMapping();
return result;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org