Skip to content
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

Nacos客户端磁盘降级需求 issues:11053 #11207

Merged
merged 32 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
44b739c
使用磁盘实现Nacos客户端版本降级
guozongkang Sep 28, 2023
6af7bbc
使用磁盘实现Nacos客户端版本降级
guozongkang Sep 28, 2023
938dfb8
使用磁盘实现Nacos客户端版本降级
guozongkang Sep 28, 2023
36a4546
使用磁盘实现Nacos客户端版本降级
guozongkang Sep 29, 2023
18cfd5f
创建对象时去除cachedir,去除磁盘定时保存任务
guozongkang Oct 7, 2023
93af51a
创建对象时去除cachedir,去除磁盘定时保存任务
guozongkang Oct 7, 2023
066b256
删除saveFailoverData方法
guozongkang Oct 7, 2023
714d2f4
移除getServiceInfo方法中的容灾逻辑
guozongkang Oct 7, 2023
6b3abe9
移除getServiceInfo方法中的容灾逻辑
guozongkang Oct 7, 2023
77e817c
删除掉注释的方法
guozongkang Oct 7, 2023
76c5eb3
使用serviceMap对比
guozongkang Oct 8, 2023
d38d494
使用serviceMap对比
guozongkang Oct 8, 2023
f692b4d
failoverSwith去除serviceNameSet集合
guozongkang Oct 8, 2023
ce8b205
failoverSwith去除serviceNameSet集合
guozongkang Oct 8, 2023
7f555ec
failoverSwith去除serviceNameSet集合
guozongkang Oct 8, 2023
aec2cfc
特殊情况下增补日志
guozongkang Oct 15, 2023
425a318
格式化checkstyle
guozongkang Oct 19, 2023
781a8de
对UtilAndComs checkstyle
guozongkang Oct 19, 2023
282e2ab
对test类 checkstyle
guozongkang Oct 19, 2023
bfe1740
去除无效变量
guozongkang Oct 19, 2023
1eb8cee
去除无效变量
guozongkang Oct 19, 2023
8f91c08
修改serviceInfo对象被重新覆盖的问题
guozongkang Oct 19, 2023
f8a6b5e
优化getServiceInfo方法
guozongkang Oct 24, 2023
d05d452
降级开关初次开启时发送通知
guozongkang Oct 25, 2023
289a81e
降级开关开启时,也发送通知
guozongkang Oct 26, 2023
c00d087
当降级开启时,不再订阅服务信息。去除多余的init方法
guozongkang Nov 1, 2023
b86e132
本地修复CI报错
guozongkang Nov 10, 2023
778222f
本地修复CI报错
guozongkang Nov 10, 2023
e048010
本地修复CI报错
guozongkang Nov 10, 2023
469a126
监控指标优化内部版本同步
guozongkang Nov 10, 2023
0ac2cc9
监控指标优化内部版本同步
guozongkang Nov 10, 2023
de60b8a
serviceName字段去除""
guozongkang Nov 12, 2023
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
4 changes: 4 additions & 0 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
nkorange marked this conversation as resolved.
Show resolved Hide resolved
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
nkorange marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.alibaba.nacos.client.utils.PreInitUtils;
import com.alibaba.nacos.client.utils.ValidatorUtils;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.StringUtils;

import java.util.ArrayList;
Expand All @@ -47,6 +48,8 @@
import java.util.Properties;
import java.util.UUID;

import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;

/**
* Nacos Naming Service.
*
Expand Down Expand Up @@ -235,17 +238,8 @@ public List<Instance> getAllInstances(String serviceName, List<String> clusters,
@Override
public List<Instance> getAllInstances(String serviceName, String groupName, List<String> clusters,
boolean subscribe) throws NacosException {
ServiceInfo serviceInfo;
String clusterString = StringUtils.join(clusters, ",");
if (subscribe) {
serviceInfo = serviceInfoHolder.getServiceInfo(serviceName, groupName, clusterString);
if (null == serviceInfo || !clientProxy.isSubscribed(serviceName, groupName, clusterString)) {
serviceInfo = clientProxy.subscribe(serviceName, groupName, clusterString);
}
} else {
serviceInfo = clientProxy.queryInstancesOfService(serviceName, groupName, clusterString, false);
}
List<Instance> list;
ServiceInfo serviceInfo = getServiceInfo(serviceName, groupName, clusters, subscribe);
if (serviceInfo == null || CollectionUtils.isEmpty(list = serviceInfo.getHosts())) {
return new ArrayList<>();
}
Expand Down Expand Up @@ -295,17 +289,7 @@ public List<Instance> selectInstances(String serviceName, List<String> clusters,
@Override
public List<Instance> selectInstances(String serviceName, String groupName, List<String> clusters, boolean healthy,
boolean subscribe) throws NacosException {

ServiceInfo serviceInfo;
String clusterString = StringUtils.join(clusters, ",");
if (subscribe) {
serviceInfo = serviceInfoHolder.getServiceInfo(serviceName, groupName, clusterString);
if (null == serviceInfo || !clientProxy.isSubscribed(serviceName, groupName, clusterString)) {
serviceInfo = clientProxy.subscribe(serviceName, groupName, clusterString);
}
} else {
serviceInfo = clientProxy.queryInstancesOfService(serviceName, groupName, clusterString, false);
}
ServiceInfo serviceInfo = getServiceInfo(serviceName, groupName, clusters, subscribe);
return selectInstances(serviceInfo, healthy);
}

Expand All @@ -326,6 +310,41 @@ private List<Instance> selectInstances(ServiceInfo serviceInfo, boolean healthy)
return list;
}

private ServiceInfo getServiceInfoByFailover(String serviceName, String groupName, String clusterString) {
return serviceInfoHolder.getFailoverServiceInfo(serviceName, groupName, clusterString);
}

private ServiceInfo getServiceInfoBySubscribe(String serviceName, String groupName, String clusterString,
boolean subscribe) throws NacosException {
ServiceInfo serviceInfo;
if (subscribe) {
serviceInfo = serviceInfoHolder.getServiceInfo(serviceName, groupName, clusterString);
if (null == serviceInfo || !clientProxy.isSubscribed(serviceName, groupName, clusterString)) {
serviceInfo = clientProxy.subscribe(serviceName, groupName, clusterString);
}
} else {
serviceInfo = clientProxy.queryInstancesOfService(serviceName, groupName, clusterString, false);
}
return serviceInfo;
}

private ServiceInfo getServiceInfo(String serviceName, String groupName, List<String> clusters, boolean subscribe)
throws NacosException {
ServiceInfo serviceInfo;
String clusterString = StringUtils.join(clusters, ",");
if (serviceInfoHolder.isFailoverSwitch()) {
serviceInfo = getServiceInfoByFailover(serviceName, groupName, clusterString);
if (serviceInfo != null && serviceInfo.getHosts().size() > 0) {
NAMING_LOGGER.debug("getServiceInfo from failover,serviceName: {} data:{}", serviceName,
JacksonUtils.toJson(serviceInfo.getHosts()));
return serviceInfo;
}
}

serviceInfo = getServiceInfoBySubscribe(serviceName, groupName, clusterString, subscribe);
return serviceInfo;
}

@Override
public Instance selectOneHealthyInstance(String serviceName) throws NacosException {
return selectOneHealthyInstance(serviceName, new ArrayList<>());
Expand Down Expand Up @@ -367,17 +386,8 @@ public Instance selectOneHealthyInstance(String serviceName, List<String> cluste
@Override
public Instance selectOneHealthyInstance(String serviceName, String groupName, List<String> clusters,
boolean subscribe) throws NacosException {
String clusterString = StringUtils.join(clusters, ",");
if (subscribe) {
ServiceInfo serviceInfo = serviceInfoHolder.getServiceInfo(serviceName, groupName, clusterString);
if (null == serviceInfo || !clientProxy.isSubscribed(serviceName, groupName, clusterString)) {
serviceInfo = clientProxy.subscribe(serviceName, groupName, clusterString);
}
return Balancer.RandomByWeight.selectHost(serviceInfo);
} else {
ServiceInfo serviceInfo = clientProxy.queryInstancesOfService(serviceName, groupName, clusterString, false);
return Balancer.RandomByWeight.selectHost(serviceInfo);
}
ServiceInfo serviceInfo = getServiceInfo(serviceName, groupName, clusters, subscribe);
return Balancer.RandomByWeight.selectHost(serviceInfo);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.client.naming.backups;

/**
* Failover Data.
*
* @author zongkang.guo
*/
public class FailoverData {

/**
* failover type,naming or config.
*/
private DataType dataType;

/**
* failover data.
*/
private Object data;

public FailoverData(DataType dataType, Object data) {
this.data = data;
this.dataType = dataType;
}

public enum DataType {
/**
* naming.
*/
naming,
/**
* config.
*/
config
}

public DataType getDataType() {
return dataType;
}

public void setDataType(DataType dataType) {
this.dataType = dataType;
}

public Object getData() {
return data;
}

public void setData(Object data) {
this.data = data;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.client.naming.backups;

import java.util.Map;

/**
* Failover Service Interface.
*
* @author Nacos
*/
public interface FailoverDataSource {

/**
* Get current disaster recovery switch.
*
* @return
*/
FailoverSwitch getSwitch();


/**
* Get current disaster recovery data.
*
* @return map
*/
Map<String, FailoverData> getFailoverData();

}
Loading
Loading