mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed admin
This commit is contained in:
@@ -16,6 +16,7 @@ public class ServerRunningData implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 92260481691855281L;
|
||||
|
||||
@Deprecated
|
||||
private Long cid;
|
||||
private String address;
|
||||
private boolean active = true;
|
||||
@@ -23,8 +24,7 @@ public class ServerRunningData implements Serializable {
|
||||
public ServerRunningData(){
|
||||
}
|
||||
|
||||
public ServerRunningData(Long cid, String address){
|
||||
this.cid = cid;
|
||||
public ServerRunningData(String address){
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
|
||||
}
|
||||
|
||||
if (!runningData.isActive() && isMine(runningData.getAddress())) { // 说明出现了主动释放的操作,并且本机之前是active
|
||||
release = true;
|
||||
releaseRunning();// 彻底释放mainstem
|
||||
}
|
||||
|
||||
@@ -116,7 +115,7 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
|
||||
if (zkClient != null) {
|
||||
releaseRunning(); // 尝试一下release
|
||||
} else {
|
||||
processActiveExit(); // 没有zk,直接启动
|
||||
processActiveExit(); // 没有zk,直接退出
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,8 +184,8 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
|
||||
boolean result = isMine(activeData.getAddress());
|
||||
if (!result) {
|
||||
logger.warn("canal is running in node[{}] , but not in node[{}]",
|
||||
activeData.getCid(),
|
||||
serverData.getCid());
|
||||
activeData.getAddress(),
|
||||
serverData.getAddress());
|
||||
}
|
||||
return result;
|
||||
} catch (ZkNoNodeException e) {
|
||||
@@ -204,6 +203,7 @@ public class ServerRunningMonitor extends AbstractCanalLifeCycle {
|
||||
|
||||
private boolean releaseRunning() {
|
||||
if (check()) {
|
||||
release = true;
|
||||
String path = ZookeeperPathUtils.getDestinationServerRunning(destination);
|
||||
zkClient.delete(path);
|
||||
mutex.set(false);
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.alibaba.otter.canal.common.zookeeper.ZookeeperPathUtils;
|
||||
import com.alibaba.otter.canal.common.zookeeper.running.ServerRunningData;
|
||||
import com.alibaba.otter.canal.common.zookeeper.running.ServerRunningListener;
|
||||
import com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor;
|
||||
|
||||
@Ignore
|
||||
public class ServerRunningTest extends AbstractZkTest {
|
||||
|
||||
@@ -38,7 +39,7 @@ public class ServerRunningTest extends AbstractZkTest {
|
||||
@Test
|
||||
public void testOneServer() {
|
||||
final CountDownLatch countLatch = new CountDownLatch(2);
|
||||
ServerRunningMonitor runningMonitor = buildServerRunning(countLatch, 1L, "127.0.0.1", 2088);
|
||||
ServerRunningMonitor runningMonitor = buildServerRunning(countLatch, "127.0.0.1", 2088);
|
||||
runningMonitor.start();
|
||||
sleep(2000L);
|
||||
runningMonitor.stop();
|
||||
@@ -52,9 +53,9 @@ public class ServerRunningTest extends AbstractZkTest {
|
||||
@Test
|
||||
public void testMultiServer() {
|
||||
final CountDownLatch countLatch = new CountDownLatch(30);
|
||||
final ServerRunningMonitor runningMonitor1 = buildServerRunning(countLatch, 1L, "127.0.0.1", 2088);
|
||||
final ServerRunningMonitor runningMonitor2 = buildServerRunning(countLatch, 2L, "127.0.0.1", 2089);
|
||||
final ServerRunningMonitor runningMonitor3 = buildServerRunning(countLatch, 3L, "127.0.0.1", 2090);
|
||||
final ServerRunningMonitor runningMonitor1 = buildServerRunning(countLatch, "127.0.0.1", 2088);
|
||||
final ServerRunningMonitor runningMonitor2 = buildServerRunning(countLatch, "127.0.0.1", 2089);
|
||||
final ServerRunningMonitor runningMonitor3 = buildServerRunning(countLatch, "127.0.0.1", 2090);
|
||||
final ExecutorService executor = Executors.newFixedThreadPool(3);
|
||||
executor.submit(new Runnable() {
|
||||
|
||||
@@ -110,29 +111,29 @@ public class ServerRunningTest extends AbstractZkTest {
|
||||
sleep(30000L);
|
||||
}
|
||||
|
||||
private ServerRunningMonitor buildServerRunning(final CountDownLatch countLatch, final Long cid, final String ip,
|
||||
private ServerRunningMonitor buildServerRunning(final CountDownLatch countLatch, final final String ip,
|
||||
final int port) {
|
||||
ServerRunningData serverData = new ServerRunningData(cid, ip + ":" + port);
|
||||
ServerRunningData serverData = new ServerRunningData(ip + ":" + port);
|
||||
ServerRunningMonitor runningMonitor = new ServerRunningMonitor(serverData);
|
||||
runningMonitor.setDestination(destination);
|
||||
runningMonitor.setListener(new ServerRunningListener() {
|
||||
|
||||
public void processActiveEnter() {
|
||||
System.out.println(String.format("cid:%s ip:%s:%s has start", cid, ip, port));
|
||||
System.out.println(String.format("cid:%s ip:%s:%s has start", ip, port));
|
||||
countLatch.countDown();
|
||||
}
|
||||
|
||||
public void processActiveExit() {
|
||||
System.out.println(String.format("cid:%s ip:%s:%s has stop", cid, ip, port));
|
||||
System.out.println(String.format("cid:%s ip:%s:%s has stop", ip, port));
|
||||
countLatch.countDown();
|
||||
}
|
||||
|
||||
public void processStart() {
|
||||
System.out.println(String.format("cid:%s ip:%s:%s processStart", cid, ip, port));
|
||||
System.out.println(String.format("cid:%s ip:%s:%s processStart", ip, port));
|
||||
}
|
||||
|
||||
public void processStop() {
|
||||
System.out.println(String.format("cid:%s ip:%s:%s processStop", cid, ip, port));
|
||||
System.out.println(String.format("cid:%s ip:%s:%s processStop", ip, port));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user