-
Notifications
You must be signed in to change notification settings - Fork 8.9k
feature: support raft mode registry to namingserver #7114
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
Changes from 16 commits
c45ae29
f1986cb
5c45707
b64b2ec
7c9802d
21f6bef
4c4db9f
e4a1a7a
603555e
0edf96c
5839ea5
5254210
5c7e264
4ee934e
30be558
310ec11
832d904
5484615
ca6f871
f423dea
ca68943
8ca4731
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import java.util.stream.Collectors; | ||
| import javax.annotation.PostConstruct; | ||
|
|
||
| import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
|
@@ -42,6 +43,7 @@ | |
| import org.apache.http.entity.ContentType; | ||
| import org.apache.http.protocol.HTTP; | ||
| import org.apache.seata.common.metadata.Cluster; | ||
| import org.apache.seata.common.metadata.ClusterRole; | ||
| import org.apache.seata.common.metadata.Node; | ||
| import org.apache.seata.common.metadata.namingserver.NamingServerNode; | ||
| import org.apache.seata.common.metadata.namingserver.Unit; | ||
|
|
@@ -152,7 +154,9 @@ public Result<String> createGroup(String namespace, String vGroup, String cluste | |
| LOGGER.error("no instance in cluster {}", clusterName); | ||
| return new Result<>("301", "no instance in cluster" + clusterName); | ||
| } else { | ||
| Node node = nodeList.get(0); | ||
| Node node = | ||
| nodeList.stream().filter(n -> n.getRole() == ClusterRole.LEADER || n.getRole() == ClusterRole.MEMBER) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why leader and memeber can be selected?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a Raft cluster, you need to find the leader to create the group, whereas for a regular cluster, you need to find a member to create the group. |
||
| .collect(Collectors.toList()).get(0); | ||
| String controlHost = node.getControl().getHost(); | ||
| int controlPort = node.getControl().getPort(); | ||
| String httpUrl = NamingServerConstants.HTTP_PREFIX + controlHost + NamingServerConstants.IP_PORT_SPLIT_CHAR | ||
|
|
@@ -231,6 +235,14 @@ public void notifyClusterChange(String vGroup, String namespace, String clusterN | |
| }); | ||
| } | ||
|
|
||
| public boolean registerInstances(List<NamingServerNode> node, String namespace, String clusterName) { | ||
| boolean result = true; | ||
| for (NamingServerNode namingServerNode : node) { | ||
| result = registerInstance(namingServerNode, namespace, clusterName, namingServerNode.getUnit()); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| public boolean registerInstance(NamingServerNode node, String namespace, String clusterName, String unitName) { | ||
| try { | ||
| Map<String, ClusterData> clusterDataHashMap = | ||
|
|
@@ -245,16 +257,14 @@ public boolean registerInstance(NamingServerNode node, String namespace, String | |
| // if extended metadata includes vgroup mapping relationship, add it in clusterData | ||
| if (mappingObj instanceof Map) { | ||
| Map<String, String> vGroups = (Map<String, String>)mappingObj; | ||
| if (!CollectionUtils.isEmpty(vGroups)) { | ||
| 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. | ||
| boolean changed = addGroup(namespace, clusterName, StringUtils.isBlank(v) ? unitName : v, k); | ||
| if (hasChanged || changed) { | ||
| notifyClusterChange(k, namespace, clusterName, unitName, node.getTerm()); | ||
| } | ||
| }); | ||
| } | ||
| 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. | ||
| boolean changed = addGroup(namespace, clusterName, StringUtils.isBlank(v) ? unitName : v, k); | ||
| if (hasChanged || changed) { | ||
| notifyClusterChange(k, namespace, clusterName, unitName, node.getTerm()); | ||
| } | ||
| }); | ||
| } | ||
| instanceLiveTable.put( | ||
| new InetSocketAddress(node.getTransaction().getHost(), node.getTransaction().getPort()), | ||
|
|
@@ -295,8 +305,8 @@ public boolean unregisterInstance(String namespace, String clusterName, String u | |
|
|
||
| public List<Cluster> getClusterListByVgroup(String vGroup, String namespace) { | ||
| // find the cluster where the transaction group is located | ||
| HashMap<String/* VGroup */, ConcurrentMap<String/* namespace */,NamespaceBO>> concurrentVgroupMap = new HashMap<>(vGroupMap.asMap()); | ||
| ConcurrentMap<String/* namespace */, NamespaceBO> vgroupNamespaceMap = concurrentVgroupMap.get(vGroup); | ||
| Map<String/* VGroup */, ConcurrentMap<String/* namespace */,NamespaceBO>> concurrentVgroupMap = new HashMap<>(vGroupMap.asMap()); | ||
| Map<String/* namespace */, NamespaceBO> vgroupNamespaceMap = concurrentVgroupMap.get(vGroup); | ||
| List<Cluster> clusterList = new ArrayList<>(); | ||
| if (!CollectionUtils.isEmpty(vgroupNamespaceMap)) { | ||
| NamespaceBO namespaceBO = vgroupNamespaceMap.get(namespace); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.seata.server.cluster.raft.execute.vgroup; | ||
|
|
||
| import org.apache.seata.server.cluster.raft.execute.AbstractRaftMsgExecute; | ||
| import org.apache.seata.server.cluster.raft.sync.msg.RaftBaseMsg; | ||
| import org.apache.seata.server.cluster.raft.sync.msg.RaftVGroupSyncMsg; | ||
| import org.apache.seata.server.storage.raft.sore.RaftVGroupMappingStoreManager; | ||
|
|
||
| /** | ||
| */ | ||
| public class VGroupAddExecute extends AbstractRaftMsgExecute { | ||
|
|
||
| @Override | ||
| public Boolean execute(RaftBaseMsg syncMsg) throws Throwable { | ||
| RaftVGroupSyncMsg vGroupSyncMsg = (RaftVGroupSyncMsg)syncMsg; | ||
| ((RaftVGroupMappingStoreManager)raftVGroupMappingStoreManager).localAddVGroup(vGroupSyncMsg.getMappingDO()); | ||
| return true; | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this method is not implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a reserved interface because, when multi-raft is implemented, a node will have multiple instances.