Merge pull request #521 from lcybo/monitor

修改InstanceConfig未生成或已销毁时造成ServerRunningMonitor running状态与实际不一致的问题
This commit is contained in:
agapple
2018-02-10 11:22:48 +08:00
committed by GitHub

View File

@@ -4,6 +4,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.alibaba.otter.canal.common.CanalException;
import org.I0Itec.zkclient.IZkDataListener; import org.I0Itec.zkclient.IZkDataListener;
import org.I0Itec.zkclient.exception.ZkException; import org.I0Itec.zkclient.exception.ZkException;
import org.I0Itec.zkclient.exception.ZkInterruptedException; import org.I0Itec.zkclient.exception.ZkInterruptedException;
@@ -91,8 +92,9 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
processStart(); processStart();
} }
public void start() { public synchronized void start() {
super.start(); super.start();
try {
processStart(); processStart();
if (zkClient != null) { if (zkClient != null) {
// 如果需要尽可能释放instance资源,不需要监听running节点,不然即使stop了这台机器,另一台机器立马会start // 如果需要尽可能释放instance资源,不需要监听running节点,不然即使stop了这台机器,另一台机器立马会start
@@ -103,6 +105,12 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
} else { } else {
processActiveEnter();// 没有zk,直接启动 processActiveEnter();// 没有zk,直接启动
} }
} catch (Exception e) {
logger.error("start failed", e);
// 没有正常启动,重置一下状态,避免干扰下一次start
stop();
}
} }
public void release() { public void release() {
@@ -113,7 +121,7 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
} }
} }
public void stop() { public synchronized void stop() {
super.stop(); super.stop();
if (zkClient != null) { if (zkClient != null) {
@@ -234,11 +242,7 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
private void processActiveEnter() { private void processActiveEnter() {
if (listener != null) { if (listener != null) {
try {
listener.processActiveEnter(); listener.processActiveEnter();
} catch (Exception e) {
logger.error("processActiveEnter failed", e);
}
} }
} }