Package com.alibaba.otter.canal.protocol.position

Examples of com.alibaba.otter.canal.protocol.position.PositionRange


        if (!batchIds.contains(batchId)) {
            // 不存在对应的batchId
            return null;
        }
        PositionRange positionRange = getBatch(clientIdentity, batchId);
        if (positionRange != null) {
            String path = ZookeeperPathUtils.getBatchMarkWithIdPath(clientIdentity.getDestination(),
                                                                    clientIdentity.getClientId(), batchId);
            zkClientx.delete(path);
        }
View Full Code Here


        byte[] data = zkClientx.readData(path, true);
        if (data == null) {
            return null;
        }

        PositionRange positionRange = JsonUtils.unmarshalFromByte(data, PositionRange.class);
        return positionRange;
    }
View Full Code Here

        ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
        for (String batchIdString : nodes) {
            batchIds.add(Long.valueOf(batchIdString));
        }
        Long maxBatchId = Collections.max(batchIds);
        PositionRange result = getBatch(clientIdentity, maxBatchId);
        if (result == null) { // 出现为null,说明zk节点有变化,重新获取
            return getLastestBatch(clientIdentity);
        } else {
            return result;
        }
View Full Code Here

        ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
        for (String batchIdString : nodes) {
            batchIds.add(Long.valueOf(batchIdString));
        }
        Long minBatchId = Collections.min(batchIds);
        PositionRange result = getBatch(clientIdentity, minBatchId);
        if (result == null) { // 出现为null,说明zk节点有变化,重新获取
            return getFirstBatch(clientIdentity);
        } else {
            return result;
        }
View Full Code Here

        }

        Collections.sort(batchIds); // 从小到大排序
        Map<Long, PositionRange> positionRanges = Maps.newLinkedHashMap();
        for (Long batchId : batchIds) {
            PositionRange result = getBatch(clientIdentity, batchId);
            if (result == null) {// 出现为null,说明zk节点有变化,重新获取
                return listAllBatchs(clientIdentity);
            } else {
                positionRanges.put(batchId, result);
            }
View Full Code Here

        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();
View Full Code Here

    }

    public void doBatchTest(CanalMetaManager metaManager) {
        metaManager.subscribe(clientIdentity);

        PositionRange first = metaManager.getFirstBatch(clientIdentity);
        PositionRange lastest = metaManager.getLastestBatch(clientIdentity);

        Assert.assertNull(first);
        Assert.assertNull(lastest);

        PositionRange range1 = buildRange(1);
        Long batchId1 = metaManager.addBatch(clientIdentity, range1);

        PositionRange range2 = buildRange(2);
        Long batchId2 = metaManager.addBatch(clientIdentity, range2);
        Assert.assertEquals((batchId1.longValue() + 1), batchId2.longValue());

        // 验证get
        PositionRange getRange1 = metaManager.getBatch(clientIdentity, batchId1);
        Assert.assertEquals(range1, getRange1);
        PositionRange getRange2 = metaManager.getBatch(clientIdentity, batchId2);
        Assert.assertEquals(range2, getRange2);

        PositionRange range3 = buildRange(3);
        Long batchId3 = batchId2 + 1;
        metaManager.addBatch(clientIdentity, range3, batchId3);

        PositionRange range4 = buildRange(4);
        Long batchId4 = metaManager.addBatch(clientIdentity, range4);
        Assert.assertEquals((batchId3.longValue() + 1), batchId4.longValue());

        // 验证remove
        metaManager.removeBatch(clientIdentity, batchId1);
View Full Code Here

        metaManager.subscribe(clientIdentity);

        Position position1 = metaManager.getCursor(clientIdentity);
        Assert.assertNull(position1);

        PositionRange range = buildRange(1);

        metaManager.updateCursor(clientIdentity, range.getStart());
        Position position2 = metaManager.getCursor(clientIdentity);
        Assert.assertEquals(range.getStart(), position2);

        metaManager.updateCursor(clientIdentity, range.getEnd());
        Position position3 = metaManager.getCursor(clientIdentity);
        Assert.assertEquals(range.getEnd(), position3);

        return position3;
    }
View Full Code Here

        if (!batchIds.contains(batchId)) {
            // 不存在对应的batchId
            return null;
        }
        PositionRange positionRange = getBatch(clientIdentity, batchId);
        if (positionRange != null) {
            String path = ZookeeperPathUtils.getBatchMarkWithIdPath(clientIdentity.getDestination(),
                clientIdentity.getClientId(),
                batchId);
            zkClientx.delete(path);
View Full Code Here

        byte[] data = zkClientx.readData(path, true);
        if (data == null) {
            return null;
        }

        PositionRange positionRange = JsonUtils.unmarshalFromByte(data, PositionRange.class);
        return positionRange;
    }
View Full Code Here

TOP

Related Classes of com.alibaba.otter.canal.protocol.position.PositionRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.