Search in sources :

Example 11 with ClientIdentity

use of com.alibaba.otter.canal.protocol.ClientIdentity 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)

Example 12 with ClientIdentity

use of com.alibaba.otter.canal.protocol.ClientIdentity in project canal by alibaba.

the class AbstractCanalStoreScavenge method getLatestAckPosition.

/**
     * 找出该destination中可被清理掉的position位置
     * 
     * @param destination
     */
private Position getLatestAckPosition(String destination) {
    List<ClientIdentity> clientIdentitys = canalMetaManager.listAllSubscribeInfo(destination);
    LogPosition result = null;
    if (!CollectionUtils.isEmpty(clientIdentitys)) {
        // 尝试找到一个最小的logPosition
        for (ClientIdentity clientIdentity : clientIdentitys) {
            LogPosition position = (LogPosition) canalMetaManager.getCursor(clientIdentity);
            if (position == null) {
                continue;
            }
            if (result == null) {
                result = position;
            } else {
                result = min(result, position);
            }
        }
    }
    return result;
}
Also used : ClientIdentity(com.alibaba.otter.canal.protocol.ClientIdentity) LogPosition(com.alibaba.otter.canal.protocol.position.LogPosition)

Aggregations

ClientIdentity (com.alibaba.otter.canal.protocol.ClientIdentity)12 LogPosition (com.alibaba.otter.canal.protocol.position.LogPosition)5 Position (com.alibaba.otter.canal.protocol.position.Position)4 CanalMetaManagerException (com.alibaba.otter.canal.meta.exception.CanalMetaManagerException)3 PositionRange (com.alibaba.otter.canal.protocol.position.PositionRange)3 Function (com.google.common.base.Function)3 ArrayList (java.util.ArrayList)3 ServerRunningMonitor (com.alibaba.otter.canal.common.zookeeper.running.ServerRunningMonitor)2 Packet (com.alibaba.otter.canal.protocol.CanalPacket.Packet)2 MigrateMap (com.google.common.collect.MigrateMap)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)2 CanalException (com.alibaba.otter.canal.common.CanalException)1 MediaHAController (com.alibaba.otter.canal.extend.ha.MediaHAController)1 CanalInstance (com.alibaba.otter.canal.instance.core.CanalInstance)1 CanalInstanceGenerator (com.alibaba.otter.canal.instance.core.CanalInstanceGenerator)1 CanalInstanceWithManager (com.alibaba.otter.canal.instance.manager.CanalInstanceWithManager)1