Search in sources :

Example 1 with ZkNoNodeException

use of org.I0Itec.zkclient.exception.ZkNoNodeException in project canal by alibaba.

the class ZooKeeperMetaManager method listAllBatchs.

public Map<Long, PositionRange> listAllBatchs(ClientIdentity clientIdentity) {
    String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(), clientIdentity.getClientId());
    List<String> nodes = null;
    try {
        nodes = zkClientx.getChildren(path);
    } catch (ZkNoNodeException e) {
    // ignore
    }
    if (CollectionUtils.isEmpty(nodes)) {
        return Maps.newHashMap();
    }
    // 找到最大的Id
    ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
    for (String batchIdString : nodes) {
        batchIds.add(Long.valueOf(batchIdString));
    }
    // 从小到大排序
    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);
        }
    }
    return positionRanges;
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ArrayList(java.util.ArrayList) PositionRange(com.alibaba.otter.canal.protocol.position.PositionRange)

Example 2 with ZkNoNodeException

use of org.I0Itec.zkclient.exception.ZkNoNodeException in project canal by alibaba.

the class ZooKeeperMetaManager method getLastestBatch.

public PositionRange getLastestBatch(ClientIdentity clientIdentity) {
    String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(), clientIdentity.getClientId());
    List<String> nodes = null;
    try {
        nodes = zkClientx.getChildren(path);
    } catch (ZkNoNodeException e) {
    // ignore
    }
    if (CollectionUtils.isEmpty(nodes)) {
        return null;
    }
    // 找到最大的Id
    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;
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ArrayList(java.util.ArrayList) PositionRange(com.alibaba.otter.canal.protocol.position.PositionRange)

Example 3 with ZkNoNodeException

use of org.I0Itec.zkclient.exception.ZkNoNodeException in project otter by alibaba.

the class SelectZooKeeperArbitrateEvent method single.

/**
     * <pre>
     * 算法:
     * 1. 创建对应的selected节点,标志selected已完成
     * </pre>
     * 
     * @param pipelineId 同步流id
     */
public void single(EtlEventData data) {
    Assert.notNull(data);
    String path = StagePathUtils.getSelectStage(data.getPipelineId(), data.getProcessId());
    data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
    // 序列化
    byte[] bytes = JsonUtils.marshalToByte(data, SerializerFeature.WriteClassName);
    try {
        zookeeper.create(path, bytes, CreateMode.PERSISTENT);
    } catch (ZkNoNodeException e) {
        // process节点不存在,出现了rollback/shutdown操作,直接忽略
        logger.warn("pipelineId[{}] select ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
    } catch (ZkNodeExistsException e) {
        // process节点已存在,出现了ConnectionLoss retry操作
        logger.warn("pipelineId[{}] select ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
    } catch (ZkException e) {
        throw new ArbitrateException("Select_single", e.getMessage(), e);
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 4 with ZkNoNodeException

use of org.I0Itec.zkclient.exception.ZkNoNodeException in project otter by alibaba.

the class SelectZooKeeperArbitrateEvent method await.

// private TerminArbitrateEvent terminEvent;
/**
     * <pre>
     * 算法:
     * 1. 检查当前的Permit,阻塞等待其授权(解决Channel的pause状态处理)
     * 2. 开始阻塞获取符合条件的processId,创建空的EventData对象,添加next node信息后直接返回
     * </pre>
     */
public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    SelectStageListener selectStageListener = ArbitrateFactory.getInstance(pipelineId, SelectStageListener.class);
    // 符合条件的processId
    Long processId = selectStageListener.waitForProcess();
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        try {
            EtlEventData eventData = new EtlEventData();
            eventData.setPipelineId(pipelineId);
            eventData.setProcessId(processId);
            // 返回当前时间
            eventData.setStartTime(new Date().getTime());
            // 获取下一个处理节点信息
            Node node = LoadBalanceFactory.getNextExtractNode(pipelineId);
            if (node == null) {
                // terminEvent.single(termin);
                throw new ArbitrateException("Select_single", "no next node");
            } else {
                eventData.setNextNid(node.getId());
                // 标记为已使用
                markUsed(eventData);
                // 只有这一条路返回
                return eventData;
            }
        } catch (ZkNoNodeException e) {
            logger.error("pipeline[{}] processId[{}] is invalid , retry again", pipelineId, processId);
            // /出现节点不存在,说明出现了error情况,递归调用重新获取一次
            return await(pipelineId);
        } catch (ZkException e) {
            throw new ArbitrateException("Select_await", e.getMessage(), e);
        }
    } else {
        logger.warn("pipelineId[{}] select ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        // add by ljh 2013-02-01
        // 遇到一个bug:
        // a. 某台机器发起了一个RESTART指令,然后开始删除process列表
        // b. 此时另一个台机器(select工作节点),并没有收到PAUSE的推送,导致还会再创建一个process节点
        // c. 后续收到PAUSE指令后,丢弃了processId,就出现了unused的processId
        // 这里删除了,要考虑一个问题,就是和restart指令在并行删除同一个processId时的并发考虑,目前来看没问题
        String path = StagePathUtils.getProcess(pipelineId, processId);
        // 忽略删除失败
        zookeeper.delete(path);
        // 递归调用
        return await(pipelineId);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) SelectStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Node(com.alibaba.otter.shared.common.model.config.node.Node) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) Date(java.util.Date) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 5 with ZkNoNodeException

use of org.I0Itec.zkclient.exception.ZkNoNodeException in project otter by alibaba.

the class TerminZooKeeperArbitrateEvent method ack.

/**
     * <pre>
     * 算法:
     * 1. 客户端处理完成对应的termin事件后,反馈给仲裁器处理完成。仲裁器根据对应S.E.T.L的反馈情况,判断是否删除对应的termin信号
     * </pre>
     */
public void ack(TerminEventData data) {
    Assert.notNull(data);
    // 目前只有select模块需要发送ack信号,这里一旦收到一个信号后就删除对应的termin节点,后续可扩展
    // 删除termin节点
    String path = StagePathUtils.getTermin(data.getPipelineId(), data.getProcessId());
    try {
        zookeeper.delete(path);
    } catch (ZkNoNodeException e) {
    // ignore,说明节点已经被删除
    } catch (ZkException e) {
        throw new ArbitrateException("Termin_ack", e);
    }
    TerminMonitor terminMonitor = ArbitrateFactory.getInstance(data.getPipelineId(), TerminMonitor.class);
    terminMonitor.ack(data.getProcessId());
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) TerminMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Aggregations

ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)27 ZkException (org.I0Itec.zkclient.exception.ZkException)22 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)17 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)5 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)5 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)5 ArrayList (java.util.ArrayList)4 PositionRange (com.alibaba.otter.canal.protocol.position.PositionRange)3 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)3 Node (com.alibaba.otter.shared.common.model.config.node.Node)3 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)3 TerminMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor)2 Date (java.util.Date)2 ZkBadVersionException (org.I0Itec.zkclient.exception.ZkBadVersionException)2 Stat (org.apache.zookeeper.data.Stat)2 CanalMetaManagerException (com.alibaba.otter.canal.meta.exception.CanalMetaManagerException)1 ClientIdentity (com.alibaba.otter.canal.protocol.ClientIdentity)1 CanalClientException (com.alibaba.otter.canal.protocol.exception.CanalClientException)1 StageComparator (com.alibaba.otter.shared.arbitrate.impl.setl.helper.StageComparator)1