Search in sources :

Example 1 with ZkNodeExistsException

use of org.I0Itec.zkclient.exception.ZkNodeExistsException 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 2 with ZkNodeExistsException

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

the class TransformZooKeeperArbitrateEvent method single.

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

use of org.I0Itec.zkclient.exception.ZkNodeExistsException 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 4 with ZkNodeExistsException

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

the class MainstemMonitor method initMainstem.

public void initMainstem() {
    if (isStop()) {
        return;
    }
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(getPipelineId(), PermitMonitor.class);
    ChannelStatus status = permitMonitor.getChannelPermit(true);
    if (status.isStop()) {
        // 如果已经关闭则退出
        return;
    }
    Long nid = ArbitrateConfigUtils.getCurrentNid();
    String path = StagePathUtils.getMainStem(getPipelineId());
    MainStemEventData data = new MainStemEventData();
    data.setStatus(MainStemEventData.Status.TAKEING);
    data.setPipelineId(getPipelineId());
    // 设置当前的nid
    data.setNid(nid);
    // 序列化
    byte[] bytes = JsonUtils.marshalToByte(data);
    try {
        mutex.set(false);
        zookeeper.create(path, bytes, CreateMode.EPHEMERAL);
        activeData = data;
        // 触发一下事件
        processActiveEnter();
        mutex.set(true);
    } catch (ZkNodeExistsException e) {
        bytes = zookeeper.readData(path, true);
        if (bytes == null) {
            // 如果不存在节点,立即尝试一次
            initMainstem();
        } else {
            activeData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
            if (nid.equals(activeData.getNid())) {
                // reload时会重复创建,如果是自己就触发一下
                mutex.set(true);
            }
        }
    }
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 5 with ZkNodeExistsException

use of org.I0Itec.zkclient.exception.ZkNodeExistsException 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)

Aggregations

ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)11 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)7 ZkException (org.I0Itec.zkclient.exception.ZkException)7 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)5 CanalMetaManagerException (com.alibaba.otter.canal.meta.exception.CanalMetaManagerException)1 CanalClientException (com.alibaba.otter.canal.protocol.exception.CanalClientException)1 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)1 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ZkClient (org.I0Itec.zkclient.ZkClient)1 ZkConnection (org.I0Itec.zkclient.ZkConnection)1 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)1 SamzaException (org.apache.samza.SamzaException)1 Before (org.junit.Before)1