Skip to content

bugfix: fix namingserver changVgroup failed #6817

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

Merged
merged 28 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
ebeda3a
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Jul 5, 2024
f2f9509
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Jul 7, 2024
eed8785
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Jul 15, 2024
5147f84
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Jul 28, 2024
f6f4293
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Aug 3, 2024
858aabd
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Aug 14, 2024
f90f421
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Aug 17, 2024
64a1040
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Aug 19, 2024
892d030
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Aug 23, 2024
9422ddd
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Aug 24, 2024
aa805d3
Merge branch '2.x' of https://github.com/seata/seata into 2.x
ggbocoder Aug 28, 2024
95591cc
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Aug 31, 2024
6876f1c
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Sep 3, 2024
d14deb1
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Sep 4, 2024
33d276c
Merge remote-tracking branch 'upstream/2.x' into 2.x
ggbocoder Sep 4, 2024
ab8ea95
fix
ggbocoder Sep 5, 2024
861590f
Merge branch '2.x' into fix/fix_changVgroup_fail
funky-eyes Sep 5, 2024
c8dfc47
fix
ggbocoder Sep 5, 2024
f7eaaf6
Merge remote-tracking branch 'origin/fix/fix_changVgroup_fail' into f…
ggbocoder Sep 5, 2024
79539f2
fix
ggbocoder Sep 5, 2024
59a23ee
Merge remote-tracking branch 'upstream/2.x' into fix/fix_changVgroup_…
ggbocoder Sep 5, 2024
4930826
Merge branch '2.x' into fix/fix_changVgroup_fail
funky-eyes Sep 6, 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
3 changes: 2 additions & 1 deletion changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


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 @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -56,7 +57,11 @@ public ClusterBO getCluster(String clusterName) {
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,29 @@ public Result<String> removeGroup(Unit unit, String vGroup, String clusterName,
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));
// }
});
}

Expand All @@ -248,8 +249,8 @@ public boolean registerInstance(NamingServerNode node, String namespace, String
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());
}
});
Expand Down Expand Up @@ -360,6 +361,7 @@ public void instanceHeartBeatCheck() {
}

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<>();
Expand All @@ -384,7 +386,7 @@ public Result<String> changeGroup(String namespace, String vGroup, String cluste
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);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public Result<?> addVGroup(@RequestParam String vGroup, @RequestParam String uni
result.setCode("500");
result.setMessage("add vGroup failed!");
}
// push the newest mapping relationship
vGroupMappingStoreManager.notifyMapping();
return result;
}

Expand All @@ -93,8 +91,6 @@ public Result<?> removeVGroup(@RequestParam String vGroup) {
result.setCode("500");
result.setMessage("remove vGroup failed!");
}
// push the newest mapping relationship
vGroupMappingStoreManager.notifyMapping();
return result;
}

Expand Down
Loading