Search in sources :

Example 21 with ZkNoNodeException

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

the class SelectRpcArbitrateEvent method await.

public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    SelectProcessListener selectProcessListener = ArbitrateFactory.getInstance(pipelineId, SelectProcessListener.class);
    // 符合条件的processId
    Long processId = selectProcessListener.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) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Node(com.alibaba.otter.shared.common.model.config.node.Node) SelectProcessListener(com.alibaba.otter.shared.arbitrate.impl.setl.rpc.monitor.SelectProcessListener) 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 22 with ZkNoNodeException

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

the class ExtractZooKeeperArbitrateEvent method await.

// private TerminArbitrateEvent terminEvent;
/**
     * <pre>
     * 算法:
     * 1. 检查当前的Permit,阻塞等待其授权(解决Channel的pause状态处理)
     * 2. 开始阻塞获取符合条件的processId
     * 3. 检查当前的即时Permit状态 (在阻塞获取processId过程会出现一些error信号,process节点会被删除)
     * 4. 获取Select传递的EventData数据,添加next node信息后直接返回
     * </pre>
     * 
     * @return
     */
public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    ExtractStageListener extractStageListener = ArbitrateFactory.getInstance(pipelineId, ExtractStageListener.class);
    // 符合条件的processId
    Long processId = extractStageListener.waitForProcess();
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        // 即时查询一下当前的状态,状态随时可能会变
        // 根据pipelineId+processId构造对应的path
        String path = StagePathUtils.getSelectStage(pipelineId, processId);
        try {
            byte[] data = zookeeper.readData(path);
            EtlEventData eventData = JsonUtils.unmarshalFromByte(data, EtlEventData.class);
            // 获取下一个处理节点信息
            Node node = LoadBalanceFactory.getNextTransformNode(pipelineId);
            if (node == null) {
                // terminEvent.single(termin);
                throw new ArbitrateException("Extract_single", "no next node");
            } else {
                eventData.setNextNid(node.getId());
                // 只有这一条路返回
                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("Extract_await", e.getMessage(), e);
        }
    } else {
        logger.warn("pipelineId[{}] extract ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        // 递归调用
        return await(pipelineId);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) 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) ExtractStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.ExtractStageListener) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 23 with ZkNoNodeException

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

the class LoadZooKeeperArbitrateEvent method await.

// private Map<Long, DistributedLock> locks = new ConcurrentHashMap<Long, DistributedLock>();
/**
     * <pre>
     * 算法:
     * 1. 检查当前的Permit,阻塞等待其授权(解决Channel的pause状态处理)
     * 2. 开始阻塞获取符合条件的processId
     * 3. 检查当前的即时Permit状态 (在阻塞获取processId过程会出现一些error信号,process节点会被删除)
     * 4. 获取Select传递的EventData数据,添加next node信息后直接返回
     * </pre>
     */
public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    LoadStageListener loadStageListener = ArbitrateFactory.getInstance(pipelineId, LoadStageListener.class);
    // 符合条件的processId
    Long processId = loadStageListener.waitForProcess();
    // DistributedLock lock = getLock(pipelineId);
    try {
        // 使用锁的理由:
        // 1. 针对双向同步时,其中一个方向出现了异常,需要发起另一端的关闭,此时对方正好在执行某个process的load
        // 2. 单向同步时,如果出现node节点异常,此时正常的节点正在执行某个process的load
        // 为避免因load无法中端引起的数据重复录入,所以针对load阶段添加分布式锁。在有process load过程中不允许进行pipeline关闭操作
        // lock.lock();
        ChannelStatus status = permitMonitor.getChannelPermit();
        if (status.isStart()) {
            // 即时查询一下当前的状态,状态随时可能会变
            // 根据pipelineId+processId构造对应的path
            String path = StagePathUtils.getTransformStage(pipelineId, processId);
            try {
                byte[] data = zookeeper.readData(path);
                // 反序列化并返回
                return JsonUtils.unmarshalFromByte(data, EtlEventData.class);
            } catch (ZkNoNodeException e) {
                logger.error("pipeline[{}] processId[{}] is invalid , retry again", pipelineId, processId);
                // /出现节点不存在,说明出现了error情况,递归调用重新获取一次
                return await(pipelineId);
            } catch (ZkException e) {
                throw e;
            }
        } else {
            logger.warn("pipelineId[{}] load ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
            // 出现rollback情况,递归调用重新获取一次,当前的processId可丢弃
            return await(pipelineId);
        }
    } catch (InterruptedException e) {
        throw e;
    } catch (Exception e) {
        throw new ArbitrateException(e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) LoadStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.LoadStageListener) ZkException(org.I0Itec.zkclient.exception.ZkException) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ZkException(org.I0Itec.zkclient.exception.ZkException) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException)

Example 24 with ZkNoNodeException

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

the class ChannelArbitrateEvent method status.

/**
     * 查询当前channel的运行状态,是否同步调用
     */
public ChannelStatus status(Long channelId) {
    String path = StagePathUtils.getChannelByChannelId(channelId);
    byte[] data = null;
    try {
        data = zookeeper.readData(path);
    } catch (ZkNoNodeException e) {
        // ignore
        return null;
    } catch (ZkException e) {
        throw new ArbitrateException("Channel_status", channelId.toString(), e);
    }
    return JsonUtils.unmarshalFromByte(data, ChannelStatus.class);
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 25 with ZkNoNodeException

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

the class SystemArbitrateEvent method destory.

/**
     * 销毁对应的系统节点,同步调用
     */
public void destory() {
    String rootPath = ManagePathUtils.getRoot();
    String channelRootPath = ManagePathUtils.getChannelRoot();
    String nodeRootPath = ManagePathUtils.getNodeRoot();
    try {
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(channelRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(nodeRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(rootPath);
    } catch (ZkNoNodeException e) {
    // 如果节点已经不存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("system_destory", e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) 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