mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
动态刷新同步锁状态 (#2181)
* 解决修改数据库远程配置,canal-adapter 一直循环destroy、init。 * 解决动态添加instance和对应的adapter无锁状态问题。
This commit is contained in:
@@ -64,6 +64,27 @@ public class SyncSwitch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void refresh() {
|
||||||
|
for (String destination : adapterCanalConfig.DESTINATIONS) {
|
||||||
|
BooleanMutex booleanMutex;
|
||||||
|
if (mode == Mode.DISTRIBUTED) {
|
||||||
|
CuratorFramework curator = curatorClient.getCurator();
|
||||||
|
booleanMutex = DISTRIBUTED_LOCK.get(destination);
|
||||||
|
if (booleanMutex == null) {
|
||||||
|
BooleanMutex mutex = new BooleanMutex(true);
|
||||||
|
initMutex(curator, destination, mutex);
|
||||||
|
DISTRIBUTED_LOCK.put(destination, mutex);
|
||||||
|
startListen(destination, mutex);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
booleanMutex = LOCAL_LOCK.get(destination);
|
||||||
|
if (booleanMutex == null) {
|
||||||
|
LOCAL_LOCK.put(destination, new BooleanMutex(true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
private synchronized void startListen(String destination, BooleanMutex mutex) {
|
private synchronized void startListen(String destination, BooleanMutex mutex) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ public class CanalAdapterService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
syncSwitch.refresh();
|
||||||
|
logger.info("## syncSwitch refreshed.");
|
||||||
logger.info("## start the canal client adapters.");
|
logger.info("## start the canal client adapters.");
|
||||||
adapterLoader = new CanalAdapterLoader(adapterCanalConfig);
|
adapterLoader = new CanalAdapterLoader(adapterCanalConfig);
|
||||||
adapterLoader.init();
|
adapterLoader.init();
|
||||||
|
|||||||
Reference in New Issue
Block a user