com.alibaba.otter.canal.meta.exception.CanalMetaManagerException Java Examples

The following examples show how to use com.alibaba.otter.canal.meta.exception.CanalMetaManagerException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GatewayMetaManager.java    From DataLink with Apache License 2.0 6 votes vote down vote up
/**
 * 需要加同步锁,保证在获取最小Position的时候,metaManager是不可变的
 *
 * @throws CanalMetaManagerException
 */
@Override
public synchronized Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    // 入参clientIdentity没有什么作用,因为该方法需要返回所有"Sub Meta Manager"中最小的Position
    List<ClientIdentity> clientIdentities = listAllSubscribeInfo("");
    LogPosition result = null;
    if (!CollectionUtils.isEmpty(clientIdentities)) {
        // 尝试找到一个最小的logPosition
        for (ClientIdentity item : clientIdentities) {
            LogPosition position = (LogPosition) attachedMetaManagers.get(item.getDestination()).getCursor(item);
            if (position == null) {
                continue;
            }

            if (result == null) {
                result = position;
            } else {
                result = CanalEventUtils.min(result, position);
            }
        }
    }

    return result;
}
 
Example #2
Source File: FileMixedLogPositionManager.java    From canal with Apache License 2.0 5 votes vote down vote up
private File getDataFile(String destination) {
    File destinationMetaDir = new File(dataDir, destination);
    if (!destinationMetaDir.exists()) {
        try {
            FileUtils.forceMkdir(destinationMetaDir);
        } catch (IOException e) {
            throw new CanalMetaManagerException(e);
        }
    }

    String dataFileName = "parse.dat";
    return new File(destinationMetaDir, dataFileName);
}
 
Example #3
Source File: MixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public Long addBatch(final ClientIdentity clientIdentity, final PositionRange positionRange)
                                                                                            throws CanalMetaManagerException {
    final Long batchId = super.addBatch(clientIdentity, positionRange);
    // 异步刷新
    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.addBatch(clientIdentity, positionRange, batchId);
        }
    });
    return batchId;
}
 
Example #4
Source File: ZooKeeperMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public void addBatch(ClientIdentity clientIdentity, PositionRange positionRange,
                     Long batchId) throws CanalMetaManagerException {
    String path = ZookeeperPathUtils
        .getBatchMarkWithIdPath(clientIdentity.getDestination(), clientIdentity.getClientId(), batchId);
    byte[] data = JsonUtils.marshalToByte(positionRange, SerializerFeature.WriteClassName);
    zkClientx.createPersistent(path, data, true);
}
 
Example #5
Source File: MixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void unsubscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.unsubscribe(clientIdentity);

    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.unsubscribe(clientIdentity);
        }
    });
}
 
Example #6
Source File: MixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void updateCursor(final ClientIdentity clientIdentity, final Position position)
                                                                                      throws CanalMetaManagerException {
    super.updateCursor(clientIdentity, position);

    // 异步刷新
    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.updateCursor(clientIdentity, position);
        }
    });
}
 
Example #7
Source File: MixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public void clearAllBatchs(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.clearAllBatchs(clientIdentity);

    // 异步刷新
    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.clearAllBatchs(clientIdentity);
        }
    });
}
 
Example #8
Source File: FileMixedLogPositionManager.java    From canal with Apache License 2.0 5 votes vote down vote up
private void flushDataToFile(String destination, File dataFile) {
    LogPosition position = memoryLogPositionManager.getLatestIndexBy(destination);
    if (position != null && position != nullPosition) {
        String json = JsonUtils.marshalToString(position);
        try {
            FileUtils.writeStringToFile(dataFile, json);
        } catch (IOException e) {
            throw new CanalMetaManagerException(e);
        }
    }
}
 
Example #9
Source File: FileMixedLogPositionManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void flushDataToFile(String destination, File dataFile) {
    LogPosition position = memoryLogPositionManager.getLatestIndexBy(destination);
    if (position != null && position != nullPosition) {
        String json = JsonUtils.marshalToString(position);
        try {
            FileUtils.writeStringToFile(dataFile, json);
        } catch (IOException e) {
            throw new CanalMetaManagerException(e);
        }
    }
}
 
Example #10
Source File: ZooKeeperMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public void clearAllBatchs(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
        clientIdentity.getClientId());
    List<String> batchChilds = zkClientx.getChildren(path);

    for (String batchChild : batchChilds) {
        String batchPath = path + ZookeeperPathUtils.ZOOKEEPER_SEPARATOR + batchChild;
        zkClientx.delete(batchPath);
    }
}
 
Example #11
Source File: ZooKeeperMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    String path = ZookeeperPathUtils.getCursorPath(clientIdentity.getDestination(), clientIdentity.getClientId());

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

    return JsonUtils.unmarshalFromByte(data, Position.class);
}
 
Example #12
Source File: PeriodMixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public void subscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.subscribe(clientIdentity);

    // 订阅信息频率发生比较低,不需要做定时merge处理
    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.subscribe(clientIdentity);
        }
    });
}
 
Example #13
Source File: PeriodMixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    Position position = super.getCursor(clientIdentity);
    if (position == nullCursor) {
        return null;
    } else {
        return position;
    }
}
 
Example #14
Source File: MemoryMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public synchronized void subscribe(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    List<ClientIdentity> clientIdentitys = destinations.get(clientIdentity.getDestination());

    if (clientIdentitys.contains(clientIdentity)) {
        clientIdentitys.remove(clientIdentity);
    }

    clientIdentitys.add(clientIdentity);
}
 
Example #15
Source File: PeriodMixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void unsubscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.unsubscribe(clientIdentity);

    // 订阅信息频率发生比较低,不需要做定时merge处理
    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.unsubscribe(clientIdentity);
        }
    });
}
 
Example #16
Source File: PeriodMixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void subscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.subscribe(clientIdentity);

    // 订阅信息频率发生比较低,不需要做定时merge处理
    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.subscribe(clientIdentity);
        }
    });
}
 
Example #17
Source File: CanalReaderMetaManager.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@Override
public Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    Position position = super.getCursor(clientIdentity);
    if (position == nullCursor) {
        return null;
    } else {
        return position;
    }
}
 
Example #18
Source File: FileMixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public void unsubscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.unsubscribe(clientIdentity);

    // 订阅信息频率发生比较低,不需要做定时merge处理
    executor.submit(new Runnable() {

        public void run() {
            flushDataToFile(clientIdentity.getDestination());
        }
    });
}
 
Example #19
Source File: PeriodMixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    Position position = super.getCursor(clientIdentity);
    if (position == nullCursor) {
        return null;
    } else {
        return position;
    }
}
 
Example #20
Source File: FileMixedLogPositionManager.java    From canal with Apache License 2.0 5 votes vote down vote up
private LogPosition loadDataFromFile(File dataFile) {
    try {
        if (!dataFile.exists()) {
            return null;
        }

        String json = FileUtils.readFileToString(dataFile, charset.name());
        return JsonUtils.unmarshalFromString(json, LogPosition.class);
    } catch (IOException e) {
        throw new CanalMetaManagerException(e);
    }
}
 
Example #21
Source File: FileMixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private FileMetaInstanceData loadDataFromFile(File dataFile) {
    try {
        if (!dataFile.exists()) {
            return null;
        }

        String json = FileUtils.readFileToString(dataFile, charset.name());
        return JsonUtils.unmarshalFromString(json, FileMetaInstanceData.class);
    } catch (IOException e) {
        throw new CanalMetaManagerException(e);
    }
}
 
Example #22
Source File: MixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
@Override
public Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    Position position = super.getCursor(clientIdentity);
    if (position == nullCursor) {
        return null;
    } else {
        return position;
    }
}
 
Example #23
Source File: ZooKeeperMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void updateCursor(ClientIdentity clientIdentity, Position position) throws CanalMetaManagerException {
    String path = ZookeeperPathUtils.getCursorPath(clientIdentity.getDestination(), clientIdentity.getClientId());
    byte[] data = JsonUtils.marshalToByte(position, SerializerFeature.WriteClassName);
    try {
        zkClientx.writeData(path, data);
    } catch (ZkNoNodeException e) {
        zkClientx.createPersistent(path, data, true);// 第一次节点不存在,则尝试重建
    }
}
 
Example #24
Source File: FileMixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public Position getCursor(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    Position position = super.getCursor(clientIdentity);
    if (position == nullCursor) {
        return null;
    } else {
        return position;
    }
}
 
Example #25
Source File: MixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public void subscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.subscribe(clientIdentity);

    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.subscribe(clientIdentity);
        }
    });
}
 
Example #26
Source File: ZooKeeperMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public PositionRange removeBatch(ClientIdentity clientIdentity, Long batchId) throws CanalMetaManagerException {
    String batchsPath = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
        clientIdentity.getClientId());
    List<String> nodes = zkClientx.getChildren(batchsPath);
    if (CollectionUtils.isEmpty(nodes)) {
        // 没有batch记录
        return null;
    }

    // 找到最小的Id
    ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
    for (String batchIdString : nodes) {
        batchIds.add(Long.valueOf(batchIdString));
    }
    Long minBatchId = Collections.min(batchIds);
    if (!minBatchId.equals(batchId)) {
        // 检查一下提交的ack/rollback,必须按batchId分出去的顺序提交,否则容易出现丢数据
        throw new CanalMetaManagerException(String.format("batchId:%d is not the firstly:%d", batchId, minBatchId));
    }

    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);
    }

    return positionRange;
}
 
Example #27
Source File: ZooKeeperMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public PositionRange getBatch(ClientIdentity clientIdentity, Long batchId) throws CanalMetaManagerException {
    String path = ZookeeperPathUtils
        .getBatchMarkWithIdPath(clientIdentity.getDestination(), clientIdentity.getClientId(), batchId);
    byte[] data = zkClientx.readData(path, true);
    if (data == null) {
        return null;
    }

    PositionRange positionRange = JsonUtils.unmarshalFromByte(data, PositionRange.class);
    return positionRange;
}
 
Example #28
Source File: ZooKeeperMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void clearAllBatchs(ClientIdentity clientIdentity) throws CanalMetaManagerException {
    String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(),
        clientIdentity.getClientId());
    List<String> batchChilds = zkClientx.getChildren(path);

    for (String batchChild : batchChilds) {
        String batchPath = path + ZookeeperPathUtils.ZOOKEEPER_SEPARATOR + batchChild;
        zkClientx.delete(batchPath);
    }
}
 
Example #29
Source File: FileMixedMetaManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public void subscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.subscribe(clientIdentity);

    // 订阅信息频率发生比较低,不需要做定时merge处理
    executor.submit(new Runnable() {

        public void run() {
            flushDataToFile(clientIdentity.getDestination());
        }
    });
}
 
Example #30
Source File: PeriodMixedMetaManager.java    From canal with Apache License 2.0 5 votes vote down vote up
public void unsubscribe(final ClientIdentity clientIdentity) throws CanalMetaManagerException {
    super.unsubscribe(clientIdentity);

    // 订阅信息频率发生比较低,不需要做定时merge处理
    executor.submit(new Runnable() {

        public void run() {
            zooKeeperMetaManager.unsubscribe(clientIdentity);
        }
    });
}