Skip to content

Commit

Permalink
0.5.0 (#352)
Browse files Browse the repository at this point in the history
* Feat/sync support2.x#mutiple thread sync02 (#304)

* update port

* Multithreading sync

* solve conflict

* imple SyncService

* adapter deregister

* optimization some code

* fix deregister instance equals logic

Co-authored-by: Oliver <[email protected]>
Co-authored-by: paderlol <[email protected]>

* Optimize the code for assigning tasks. (#320)

* Develop (#321)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix #305 (#322)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code (#323)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code.

* Refactoring the Nacos Sync to Consul Logic (#324)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code.

* Refactoring the Nacos Sync to Consul Logic.

* #346 #350:nacos 2 nacos 同步关闭后心跳没有停止问题 ,nacos-sync删除目标节点问题 (#347)

* update port

* fix #297 (#298)

Co-authored-by: yangchun2 <[email protected]>

* Revert "fix #297 (#298)" (#318)

This reverts commit a9df169.

* 0.4.9-pre (#325)

* Feat/sync support2.x#mutiple thread sync02 (#304)

* update port

* Multithreading sync

* solve conflict

* imple SyncService

* adapter deregister

* optimization some code

* fix deregister instance equals logic

Co-authored-by: Oliver <[email protected]>
Co-authored-by: paderlol <[email protected]>

* Optimize the code for assigning tasks. (#320)

* Develop (#321)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix #305 (#322)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code (#323)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code.

* Refactoring the Nacos Sync to Consul Logic (#324)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code.

* Refactoring the Nacos Sync to Consul Logic.

---------

Co-authored-by: chenhao26 <[email protected]>
Co-authored-by: Oliver <[email protected]>

* fix:nacos 2 nacos 同步关闭后心跳没有停止问题

* fix:nacos 2 nacos 同步关闭后心跳没有停止问题

* fix:集群信息保存 cluster_level 为 null

* fix:
1、注册时根据中心化逻辑判断同步,但是删除时逻辑不一致问题
2、如果停止同步nameservice为空问题

* 问题在于对destInstances列表的更新方式。在Java中,方法参数是按值传递的。这意味着当你传递一个对象到方法中时,实际上传递的是对象引用的副本。因此,如果你在方法内部改变了这个引用指向的对象(例如,将其指向一个新的对象),这个改变不会影响到原始的对象引用。

在你的代码中,destInstances = newDestInstance;这一行只是改变了destInstances引用在方法内部的指向,而不会改变方法外部传入的destInstances列表对象。这意味着,尽管你筛选出了需要反注册的实例,但这个改变不会反映到方法调用者那里。

---------

Co-authored-by: Oliver <[email protected]>
Co-authored-by: paderlol <[email protected]>
Co-authored-by: 杨春 <[email protected]>
Co-authored-by: yangchun2 <[email protected]>
Co-authored-by: chenhao26 <[email protected]>

* 0.5.0 (#351)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code.

* Refactoring the Nacos Sync to Consul Logic.

* 1. 重新设计全量 Nacos 同步 Nacos
2. 修复Nacos Instance equals无效导致出现无法注册成功问题
3. 升级Nacos Sync JDK/Spring Boot版本
4. 保底同步从改成并发同步
5. 增加部分注释

* Develop (#353)

* Optimize the code for assigning tasks.

* Adds prefix to the input string if it doesn't already have it.#308

* Fix .#305

* Fix cyclic dependency code.

* Refactoring the Nacos Sync to Consul Logic.

* 1. 重新设计全量 Nacos 同步 Nacos
2. 修复Nacos Instance equals无效导致出现无法注册成功问题
3. 升级Nacos Sync JDK/Spring Boot版本
4. 保底同步从改成并发同步
5. 增加部分注释

---------

Co-authored-by: chenhao26 <[email protected]>
Co-authored-by: Oliver <[email protected]>
Co-authored-by: 龙竹 <[email protected]>
Co-authored-by: 杨春 <[email protected]>
Co-authored-by: yangchun2 <[email protected]>
  • Loading branch information
6 people authored May 18, 2024
1 parent a1d683a commit 8185fec
Show file tree
Hide file tree
Showing 32 changed files with 1,026 additions and 1,023 deletions.
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The path to the target file:

``` xml

nacos-sync/nacossync-distribution/target/nacos-sync-0.4.8.tar.gz
nacos-sync/nacossync-distribution/target/nacos-sync-0.5.0.tar.gz

```

Expand Down Expand Up @@ -157,4 +157,16 @@ sh startup.sh start

http://127.0.0.1:8083/#/serviceSync

```
```

## Advanced Configuration

### Full Synchronization from Zookeeper to Nacos (Dubbo)
When “*” is entered in the “Service Name” field of this form, it will fully synchronize all services from Zookeeper to Nacos, but only when using Dubbo.
![img_1.png](img_1.png)

### Full Synchronization from Nacos to Nacos
When “All” is entered in the “Service Name” field of this form, it will automatically synchronize all registered services within the **default group** of the current cluster.

This description explains the functionality clearly for English-speaking users.
![img_2.png](img_2.png)
Binary file added img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 6 additions & 11 deletions nacossync-worker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,12 @@
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -169,8 +164,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* @author NacosSync
* @version $Id: SkyWalkerMain.java, v 0.1 2018-09-24 PM12:42 NacosSync Exp $$
*/
@EnableSwagger2
@SpringBootApplication(exclude = EurekaClientAutoConfiguration.class)
public class NacosSyncMain {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
import com.alibaba.nacossync.pojo.model.TaskDO;
import com.alibaba.nacossync.util.SkyWalkerUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;

/**
* @author NacosSync
* @version $Id: SkyWalkerCacheServices.java, v 0.1 2018-09-27 AM2:47 NacosSync Exp $$
Expand All @@ -48,7 +49,7 @@ public class SkyWalkerCacheServices {
@Autowired
private ObjectMapper objectMapper;

private static Map<String, FinishedTask> finishedTaskMap = new ConcurrentHashMap<>();
private static final Map<String, FinishedTask> finishedTaskMap = new ConcurrentHashMap<>();

public String getClusterConnectKey(String clusterId) {
List<String> allClusterConnectKey = getAllClusterConnectKey(clusterId);
Expand Down Expand Up @@ -90,22 +91,22 @@ public FinishedTask getFinishedTask(TaskDO taskDO) {

String operationId = SkyWalkerUtil.getOperationId(taskDO);

if (StringUtils.isEmpty(operationId)) {
if (StringUtils.hasLength(operationId)) {
return null;
}

return finishedTaskMap.get(operationId);
}

public FinishedTask getFinishedTask(String operationId) {
if (StringUtils.isEmpty(operationId)) {
if (StringUtils.hasLength(operationId)) {
return null;
}
return finishedTaskMap.get(operationId);
}

public FinishedTask removeFinishedTask(String operationId) {
if (StringUtils.isEmpty(operationId)) {
if (StringUtils.hasLength(operationId)) {
return null;
}
return finishedTaskMap.remove(operationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public class SkyWalkerConstants {
public static final String PAGE_NO="pageNo";
public static final String PAGE_SIZE="pageSize";
public static final String SYNC_INSTANCE_TAG="sync.instance.tag";
public static final Integer MAX_THREAD_NUM = 200;
public static final String NACOS_ALL_SERVICE_NAME = "ALL";

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alibaba.nacossync.dao;

import com.alibaba.nacossync.constant.SkyWalkerConstants;
import com.alibaba.nacossync.pojo.QueryCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void deleteTaskById(String taskId) {
*/
public void deleteTaskInBatch(List<String> taskIds) {
List<TaskDO> tds=taskRepository.findAllByTaskIdIn(taskIds);
taskRepository.deleteInBatch(tds);
taskRepository.deleteAllInBatch(tds);
}

public Iterable<TaskDO> findAll() {
Expand Down Expand Up @@ -115,8 +116,12 @@ private Page<TaskDO> getTaskDOS(QueryCondition queryCondition, Pageable pageable
}, pageable);
}

public List<TaskDO> findServiceNameIsNull() {
return taskRepository.findAllByServiceNameEquals("ALL");
public List<TaskDO> findAllByServiceNameEqualAll() {
return taskRepository.findAllByServiceNameEqualsIgnoreCase(SkyWalkerConstants.NACOS_ALL_SERVICE_NAME);
}

public List<TaskDO> findAllByServiceNameNotEqualAll() {
return taskRepository.findAllByServiceNameNotIgnoreCase(SkyWalkerConstants.NACOS_ALL_SERVICE_NAME);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
*/
package com.alibaba.nacossync.dao.repository;

import java.util.List;

import javax.transaction.Transactional;

import com.alibaba.nacossync.pojo.model.TaskDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository;

import com.alibaba.nacossync.pojo.model.TaskDO;
import javax.transaction.Transactional;
import java.util.List;

/**
* @author NacosSync
Expand All @@ -47,6 +45,7 @@ public interface TaskRepository extends CrudRepository<TaskDO, Integer>, JpaRepo
* @param serviceName
* @return
*/
List<TaskDO> findAllByServiceNameEquals(String serviceName);
List<TaskDO> findAllByServiceNameEqualsIgnoreCase(String serviceName);
List<TaskDO> findAllByServiceNameNotIgnoreCase(String serviceName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.alibaba.nacossync.event;

import com.alibaba.nacossync.pojo.model.TaskDO;
import lombok.Data;

@Data
public class DeleteAllSubTaskEvent {
public DeleteAllSubTaskEvent(TaskDO taskDO) {
this.taskDO = taskDO;
}

private final TaskDO taskDO;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@
*/
package com.alibaba.nacossync.event.listener;

import javax.annotation.PostConstruct;

import com.alibaba.nacossync.constant.MetricsStatisticsType;
import com.alibaba.nacossync.monitor.MetricsManager;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.nacossync.cache.SkyWalkerCacheServices;
import com.alibaba.nacossync.constant.MetricsStatisticsType;
import com.alibaba.nacossync.event.DeleteTaskEvent;
import com.alibaba.nacossync.event.SyncTaskEvent;
import com.alibaba.nacossync.extension.SyncManagerService;
import com.alibaba.nacossync.monitor.MetricsManager;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

/**
* @author NacosSync
Expand Down Expand Up @@ -80,7 +78,7 @@ public void listenerDeleteTaskEvent(DeleteTaskEvent deleteTaskEvent) {
try {
long start = System.currentTimeMillis();
if (syncManagerService.delete(deleteTaskEvent.getTaskDO())) {
skyWalkerCacheServices.addFinishedTask(deleteTaskEvent.getTaskDO());
skyWalkerCacheServices.removeFinishedTask(deleteTaskEvent.getTaskDO().getOperationId());
metricsManager.record(MetricsStatisticsType.DELETE_TASK_RT, System.currentTimeMillis() - start);
} else {
log.warn("listenerDeleteTaskEvent delete failure");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
*/
package com.alibaba.nacossync.extension;

import static com.alibaba.nacossync.util.SkyWalkerUtil.generateSyncKey;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacossync.cache.SkyWalkerCacheServices;
import com.alibaba.nacossync.constant.ClusterTypeEnum;
import com.alibaba.nacossync.extension.annotation.NacosSyncService;
import com.alibaba.nacossync.pojo.model.TaskDO;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.nacossync.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import java.util.concurrent.ConcurrentHashMap;

import static com.alibaba.nacossync.util.SkyWalkerUtil.generateSyncKey;

/**
* @author NacosSync
* @version $Id: SyncManagerService.java, v 0.1 2018-09-25 PM5:17 NacosSync Exp $$
Expand Down Expand Up @@ -60,11 +62,11 @@ public boolean sync(TaskDO taskDO, Integer index) {

@Override
public void afterPropertiesSet() {
this.applicationContext.getBeansOfType(SyncService.class).forEach((key, value) -> {
this.applicationContext.getBeansWithAnnotation(NacosSyncService.class).forEach((key, value) -> {
NacosSyncService nacosSyncService = value.getClass().getAnnotation(NacosSyncService.class);
ClusterTypeEnum sourceCluster = nacosSyncService.sourceCluster();
ClusterTypeEnum destinationCluster = nacosSyncService.destinationCluster();
syncServiceMap.put(generateSyncKey(sourceCluster, destinationCluster), value);
syncServiceMap.put(generateSyncKey(sourceCluster, destinationCluster), (SyncService) value);
});
}

Expand All @@ -74,7 +76,9 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
}

public SyncService getSyncService(String sourceClusterId, String destClusterId) {

if (StringUtils.isEmpty(sourceClusterId) || StringUtils.isEmpty(destClusterId)) {
throw new IllegalArgumentException("Source cluster id and destination cluster id must not be null or empty");
}
ClusterTypeEnum sourceClusterType = this.skyWalkerCacheServices.getClusterType(sourceClusterId);
ClusterTypeEnum destClusterType = this.skyWalkerCacheServices.getClusterType(destClusterId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface SyncQueryClient {


List<TaskModel> getAllInstance(InstanceQueryModel instanceQueryModel);



}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
package com.alibaba.nacossync.extension.holder;

import com.alibaba.nacossync.cache.SkyWalkerCacheServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
* @author paderlol
* @date 2018-12-24 22:08
*/
@Slf4j
public abstract class AbstractServerHolderImpl<T> implements Holder {
public abstract class AbstractServerHolderImpl<T> implements Holder<T> {

protected final Map<String, T> serviceMap = new ConcurrentHashMap<>();

Expand Down
Loading

0 comments on commit 8185fec

Please sign in to comment.