Browse Source

add ServerRunningMonitor.init

agapple 8 years ago
parent
commit
83d8a39d16

+ 4 - 0
common/src/main/java/com/alibaba/otter/canal/common/zookeeper/running/ServerRunningMonitor.java

@@ -87,6 +87,10 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
 
 
     }
     }
 
 
+    public void init() {
+        processStart();
+    }
+
     public void start() {
     public void start() {
         super.start();
         super.start();
         processStart();
         processStart();

+ 6 - 0
deployer/src/main/java/com/alibaba/otter/canal/deployer/CanalController.java

@@ -5,6 +5,7 @@ import java.util.Properties;
 
 
 import org.I0Itec.zkclient.IZkStateListener;
 import org.I0Itec.zkclient.IZkStateListener;
 import org.I0Itec.zkclient.exception.ZkNoNodeException;
 import org.I0Itec.zkclient.exception.ZkNoNodeException;
+import org.I0Itec.zkclient.exception.ZkNodeExistsException;
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -172,6 +173,8 @@ public class CanalController {
                 if (zkclientx != null) {
                 if (zkclientx != null) {
                     runningMonitor.setZkClient(zkclientx);
                     runningMonitor.setZkClient(zkclientx);
                 }
                 }
+                // 触发创建一下cid节点
+                runningMonitor.init();
                 return runningMonitor;
                 return runningMonitor;
             }
             }
         }));
         }));
@@ -448,6 +451,9 @@ public class CanalController {
                 String parentDir = path.substring(0, path.lastIndexOf('/'));
                 String parentDir = path.substring(0, path.lastIndexOf('/'));
                 zkclientx.createPersistent(parentDir, true);
                 zkclientx.createPersistent(parentDir, true);
                 zkclientx.createEphemeral(path);
                 zkclientx.createEphemeral(path);
+            } catch (ZkNodeExistsException e) {
+                // ignore
+                // 因为第一次启动时创建了cid,但在stop/start的时可能会关闭和新建,允许出现NodeExists问题s
             }
             }
 
 
         }
         }