Search in sources :

Example 1 with ZooKeeperMetaManager

use of com.alibaba.otter.canal.meta.ZooKeeperMetaManager in project canal by alibaba.

the class CanalInstanceWithManager method initMetaManager.

protected void initMetaManager() {
    logger.info("init metaManager begin...");
    MetaMode mode = parameters.getMetaMode();
    if (mode.isMemory()) {
        metaManager = new MemoryMetaManager();
    } else if (mode.isZookeeper()) {
        metaManager = new ZooKeeperMetaManager();
        ((ZooKeeperMetaManager) metaManager).setZkClientx(getZkclientx());
    } else if (mode.isMixed()) {
        // metaManager = new MixedMetaManager();
        // 换用优化过的mixed, at
        metaManager = new PeriodMixedMetaManager();
        // 2012-09-11
        // 设置内嵌的zk metaManager
        ZooKeeperMetaManager zooKeeperMetaManager = new ZooKeeperMetaManager();
        zooKeeperMetaManager.setZkClientx(getZkclientx());
        ((PeriodMixedMetaManager) metaManager).setZooKeeperMetaManager(zooKeeperMetaManager);
    } else {
        throw new CanalException("unsupport MetaMode for " + mode);
    }
    logger.info("init metaManager end! \n\t load CanalMetaManager:{} ", metaManager.getClass().getName());
}
Also used : MemoryMetaManager(com.alibaba.otter.canal.meta.MemoryMetaManager) MetaMode(com.alibaba.otter.canal.instance.manager.model.CanalParameter.MetaMode) PeriodMixedMetaManager(com.alibaba.otter.canal.meta.PeriodMixedMetaManager) ZooKeeperMetaManager(com.alibaba.otter.canal.meta.ZooKeeperMetaManager) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 2 with ZooKeeperMetaManager

use of com.alibaba.otter.canal.meta.ZooKeeperMetaManager in project canal by alibaba.

the class MetaLogPositionManagerTest method testAll.

@Test
public void testAll() {
    MixedMetaManager metaManager = new MixedMetaManager();
    ZooKeeperMetaManager zooKeeperMetaManager = new ZooKeeperMetaManager();
    zooKeeperMetaManager.setZkClientx(zkclientx);
    metaManager.setZooKeeperMetaManager(zooKeeperMetaManager);
    metaManager.start();
    MetaLogPositionManager logPositionManager = new MetaLogPositionManager();
    logPositionManager.setMetaManager(metaManager);
    logPositionManager.start();
    // 构建meta信息
    ClientIdentity client1 = new ClientIdentity(destination, (short) 1);
    metaManager.subscribe(client1);
    PositionRange range1 = buildRange(1);
    metaManager.updateCursor(client1, range1.getEnd());
    PositionRange range2 = buildRange(2);
    metaManager.updateCursor(client1, range2.getEnd());
    ClientIdentity client2 = new ClientIdentity(destination, (short) 2);
    metaManager.subscribe(client2);
    PositionRange range3 = buildRange(3);
    metaManager.updateCursor(client2, range3.getEnd());
    PositionRange range4 = buildRange(4);
    metaManager.updateCursor(client2, range4.getEnd());
    LogPosition logPosition = logPositionManager.getLatestIndexBy(destination);
    Assert.assertEquals(range2.getEnd(), logPosition);
    metaManager.stop();
    logPositionManager.stop();
}
Also used : ClientIdentity(com.alibaba.otter.canal.protocol.ClientIdentity) PositionRange(com.alibaba.otter.canal.protocol.position.PositionRange) MixedMetaManager(com.alibaba.otter.canal.meta.MixedMetaManager) ZooKeeperMetaManager(com.alibaba.otter.canal.meta.ZooKeeperMetaManager) LogPosition(com.alibaba.otter.canal.protocol.position.LogPosition) Test(org.junit.Test)

Aggregations

ZooKeeperMetaManager (com.alibaba.otter.canal.meta.ZooKeeperMetaManager)2 CanalException (com.alibaba.otter.canal.common.CanalException)1 MetaMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.MetaMode)1 MemoryMetaManager (com.alibaba.otter.canal.meta.MemoryMetaManager)1 MixedMetaManager (com.alibaba.otter.canal.meta.MixedMetaManager)1 PeriodMixedMetaManager (com.alibaba.otter.canal.meta.PeriodMixedMetaManager)1 ClientIdentity (com.alibaba.otter.canal.protocol.ClientIdentity)1 LogPosition (com.alibaba.otter.canal.protocol.position.LogPosition)1 PositionRange (com.alibaba.otter.canal.protocol.position.PositionRange)1 Test (org.junit.Test)1