fix metadata batch operation may delete instance problem.
This commit is contained in:
parent
d22e5909d4
commit
6cdead245e
@ -21,6 +21,7 @@ import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.utils.NamingUtils;
|
||||
import com.alibaba.nacos.common.utils.IPUtil;
|
||||
import com.alibaba.nacos.common.utils.JacksonUtils;
|
||||
import com.alibaba.nacos.common.utils.Objects;
|
||||
import com.alibaba.nacos.core.cluster.Member;
|
||||
import com.alibaba.nacos.core.cluster.ServerMemberManager;
|
||||
import com.alibaba.nacos.naming.consistency.ConsistencyService;
|
||||
@ -580,7 +581,7 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
}
|
||||
|
||||
/**
|
||||
* locate consistency's datum by all or instances provided.
|
||||
* Locate consistency's datum by all or instances provided.
|
||||
*
|
||||
* @param namespaceId namespace
|
||||
* @param serviceName serviceName
|
||||
@ -618,16 +619,22 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
return locatedInstance;
|
||||
}
|
||||
|
||||
private Instance locateInstance(List<Instance> instances, Instance instance) {
|
||||
int target = 0;
|
||||
while (target >= 0) {
|
||||
target = instances.indexOf(instance);
|
||||
if (target >= 0) {
|
||||
Instance result = instances.get(target);
|
||||
if (result.getClusterName().equals(instance.getClusterName())) {
|
||||
return result;
|
||||
/**
|
||||
* Locate instance.
|
||||
*
|
||||
* @param sources the instanceList in DistroConsistencyServiceImpl.dataStore
|
||||
* @param target the instance need to locate
|
||||
* @return the located instance
|
||||
*/
|
||||
private Instance locateInstance(List<Instance> sources, Instance target) {
|
||||
if (CollectionUtils.isEmpty(sources)) {
|
||||
return null;
|
||||
}
|
||||
instances.remove(target);
|
||||
|
||||
for (Instance element : sources) {
|
||||
//also need clusterName equals, the same instance maybe exist in two cluster.
|
||||
if (Objects.equals(element, target) && Objects.equals(element.getClusterName(), target.getClusterName())) {
|
||||
return element;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -963,7 +970,8 @@ public class ServiceManager implements RecordListener<Service> {
|
||||
List<Instance> instances = service.allIPs();
|
||||
for (Instance instance : instances) {
|
||||
if (IPUtil.containsPort(containedInstance)) {
|
||||
if (StringUtils.equals(instance.getIp() + IPUtil.IP_PORT_SPLITER + instance.getPort(), containedInstance)) {
|
||||
if (StringUtils.equals(instance.getIp() + IPUtil.IP_PORT_SPLITER + instance.getPort(),
|
||||
containedInstance)) {
|
||||
contained = true;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user