Search in sources :

Example 11 with ZkNoNodeException

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

the class ExtractZooKeeperArbitrateEvent method single.

/**
     * <pre>
     * 算法:
     * 1. 创建对应的extracted节点,标志extract已完成
     * </pre>
     * 
     * @param pipelineId 同步流id
     */
public void single(EtlEventData data) {
    Assert.notNull(data);
    String path = StagePathUtils.getExtractStage(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[{}] extract ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
    } catch (ZkNodeExistsException e) {
        // process节点已存在,出现了ConnectionLoss retry操作
        logger.warn("pipelineId[{}] extract ignore processId[{}] single by data:{}", new Object[] { data.getPipelineId(), data.getProcessId(), data });
    } catch (ZkInterruptedException e) {
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("Extract_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) ZkInterruptedException(org.I0Itec.zkclient.exception.ZkInterruptedException)

Example 12 with ZkNoNodeException

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

the class MainstemMonitor method check.

/**
     * 检查当前的状态
     */
public boolean check() {
    String path = StagePathUtils.getMainStem(getPipelineId());
    try {
        byte[] bytes = zookeeper.readData(path);
        Long nid = ArbitrateConfigUtils.getCurrentNid();
        MainStemEventData eventData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
        // 更新下为最新值
        activeData = eventData;
        // 检查下nid是否为自己
        boolean result = nid.equals(eventData.getNid());
        if (!result) {
            logger.warn("mainstem is running in node[{}] , but not in node[{}]", eventData.getNid(), nid);
        }
        return result;
    } catch (ZkNoNodeException e) {
        logger.warn("mainstem is not run any in node");
        return false;
    } catch (ZkInterruptedException e) {
        logger.warn("mainstem check is interrupt");
        // 清除interrupt标记
        Thread.interrupted();
        return check();
    } catch (ZkException e) {
        logger.warn("mainstem check is failed");
        return false;
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ZkInterruptedException(org.I0Itec.zkclient.exception.ZkInterruptedException)

Example 13 with ZkNoNodeException

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

the class ChannelArbitrateEvent method init.

/**
     * 初始化对应的channel节点,同步调用
     */
public void init(Long channelId) {
    String path = ManagePathUtils.getChannelByChannelId(channelId);
    // 初始化的数据对象
    byte[] data = JsonUtils.marshalToByte(ChannelStatus.STOP);
    try {
        zookeeper.create(path, data, CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
    // 如果节点已经存在,则不抛异常
    // ignore
    } catch (ZkNoNodeException e) {
        //创建父节点
        zookeeper.createPersistent(path, data, true);
    } catch (ZkException e) {
        throw new ArbitrateException("Channel_init", channelId.toString(), 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 14 with ZkNoNodeException

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

the class PipelineArbitrateEvent method destory.

/**
     * 销毁对应的pipeline节点,同步调用
     */
public void destory(Long channelId, Long pipelineId) {
    String path = ManagePathUtils.getPipeline(channelId, pipelineId);
    String processRootPath = ManagePathUtils.getProcessRoot(channelId, pipelineId);
    String terminRootPath = ManagePathUtils.getTerminRoot(channelId, pipelineId);
    String remedyRootPath = ManagePathUtils.getRemedyRoot(channelId, pipelineId);
    String lockRootPath = ManagePathUtils.getLockRoot(channelId, pipelineId);
    String loadLockPath = lockRootPath + "/" + ArbitrateConstants.NODE_LOCK_LOAD;
    try {
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(loadLockPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(lockRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(terminRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(remedyRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(processRootPath);
        // 删除节点,不关心版本
        zookeeper.deleteRecursive(path);
    } catch (ZkNoNodeException e) {
    // 如果节点已经不存在,则不抛异常
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("Pipeline_destory", pipelineId.toString(), e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 15 with ZkNoNodeException

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

the class TransformStageListener method stageChannged.

public void stageChannged(Long processId, List<String> stageNodes) {
    try {
        // 1. 根据pipelineId+processId构造对应的path
        String path = StagePathUtils.getProcess(getPipelineId(), processId);
        // 2.1 判断是否存在了error节点,end节点或者current节点
        if (stageNodes.contains(currentNode)) {
            if (replyProcessIds.remove(processId)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("## remove reply id [{}]", processId);
                }
            }
            // 不需要监听了
            return;
        }
        if (replyProcessIds.contains(processId)) {
            // 避免重复处理
            return;
        }
        // 2.2 判断是否存在了prev节点
        if (stageNodes.contains(prevNode)) {
            // 2.2.1 获取上一个节点的next node节点信息
            byte[] data = zookeeper.readData(path + "/" + prevNode);
            EtlEventData eventData = JsonUtils.unmarshalFromByte(data, EtlEventData.class);
            if (eventData.getNextNid().equals(ArbitrateConfigUtils.getCurrentNid())) {
                // 添加到返回队列,唤醒wait阻塞
                addReply(processId);
            }
        }
    } catch (ZkNoNodeException e) {
    // 出现节点不存在,说明出现了error情况
    } catch (ZkException e) {
        logger.error("TransformStageListener", e);
    }
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

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