Search in sources :

Example 31 with ZkException

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

the class NormalTerminProcess method processDelete.

private boolean processDelete(TerminEventData data, boolean noStage, boolean retry) {
    Long pipelineId = data.getPipelineId();
    Long processId = data.getProcessId();
    boolean result = false;
    // process节点
    // 最后删除一下process节点
    String path = StagePathUtils.getProcess(pipelineId, processId);
    byte[] bytes = null;
    try {
        bytes = zookeeper.readData(path);
    } catch (ZkNoNodeException e) {
        // 说明节点已经被删除了,直接忽略
        return false;
    }
    ProcessNodeEventData nodeData = JsonUtils.unmarshalFromByte(bytes, ProcessNodeEventData.class);
    if (nodeData.getStatus().isUsed()) {
        if (noStage && nodeData.getMode().isZookeeper()) {
            // 针对rpc mode就是没有stage,不需要进行sleep
            // 处理一种case:
            // 针对两个并发操作,一个已经完成了s/e/t/l模块的所有delete,另一个刚好进来发现没有可delete的
            // 这时两个线程就一起进入createTermin操作,存在一些并发问题,针对这种case,需要错开一下
            // 不过这种情况可能会有误判,针对s模块没有处理完成,发起了一次rollback/shutdown操作就会碰上,概率比较小,忽略这种误判吧
            processDeleteFailed();
            // 再重新尝试访问一下process,看下是否已经被删除了
            return processDelete(data, false, retry);
        }
        // 在这段sleep的过程中,process可能还会跑一段,产生新的s/e/t节点,导致process删除失败,从而重复执行了createTermin
        if (!retry) {
            // modify at 2012-08-14 , 遇到一个并发bug
            // 1. 两个process a和b,a先执行完毕删除了process节点,b立马得到触发并在极端的时间内处理完成
            // 2. 最后的一个结果b创建的termin要早于a创建的termin,导致termin发送顺序不对
            // 这里修改为,先创建termin节点,再删除对应的process,触发下一个process,保证termin创建为顺序
            // 同样可以避免删除了process后,termin信号创建失败的问题
            // modify at 2012-09-06 , 遇到一个并发bug
            // 一个process只完成了s/e模块,然后进行shutdown操作,完成了termin节点创建,但在process delete时,老的process创建了t节点
            // 这时会出现process删除失败,从而触发进行一次retry操作,此时retry又会再一次创建了termin信号,导致调度出错
            // 所以这里做了一个控制,只有针对非retry模式下才会创建termin信号
            // 创建termin节点
            result = createTermin(data, pipelineId, processId);
        }
    }
    try {
        // 修改为false,已经有另一个线程添加了该节点
        result = zookeeper.deleteRecursive(StagePathUtils.getProcess(pipelineId, processId));
        if (!result) {
            // 做一次重试,可能做manager关闭的时侯,node节点还跑了一段,导致stage节点又创建了一个
            doProcess(data, true);
        }
    } catch (ZkInterruptedException e) {
        throw e;
    } catch (ZkException e) {
        // 做一次重试,可能做manager关闭的时侯,node节点还跑了一段,导致stage节点又创建了一个
        doProcess(data, true);
    }
    return result;
}
Also used : ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) ProcessNodeEventData(com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData) ZkInterruptedException(org.I0Itec.zkclient.exception.ZkInterruptedException)

Example 32 with ZkException

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

the class NormalTerminProcess method createTermin.

private boolean createTermin(TerminEventData data, Long pipelineId, Long processId) {
    // 1. 创建end节点
    String path = StagePathUtils.getTermin(pipelineId, processId);
    data.setCurrNid(ArbitrateConfigUtils.getCurrentNid());
    // 序列化
    byte[] bytes = JsonUtils.marshalToByte(data);
    try {
        zookeeper.create(path, bytes, CreateMode.PERSISTENT);
    } catch (ZkNodeExistsException e) {
        // ignore
        return false;
    } catch (ZkException e) {
        throw new ArbitrateException("Termin_single", e);
    }
    return true;
}
Also used : ZkNodeExistsException(org.I0Itec.zkclient.exception.ZkNodeExistsException) ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 33 with ZkException

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

the class MainStemMonitorTest method switchWarmup.

/**
 * 手工触发一次主备切换
 */
private void switchWarmup(Long channelId, Long pipelineId) {
    String path = ManagePathUtils.getMainStem(channelId, pipelineId);
    try {
        while (true) {
            Stat stat = new Stat();
            byte[] bytes = zookeeper.readData(path, stat);
            MainStemEventData mainStemData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
            mainStemData.setActive(false);
            try {
                zookeeper.writeData(path, JsonUtils.marshalToByte(mainStemData), stat.getVersion());
                break;
            } catch (ZkBadVersionException e) {
            // ignore , retrying
            }
        }
    } catch (ZkNoNodeException e) {
    // ignore
    } catch (ZkException e) {
        throw new ArbitrateException("releaseMainStem", pipelineId.toString(), e);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) ZkNoNodeException(org.I0Itec.zkclient.exception.ZkNoNodeException) ZkException(org.I0Itec.zkclient.exception.ZkException) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ZkBadVersionException(org.I0Itec.zkclient.exception.ZkBadVersionException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 34 with ZkException

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

the class ChannelArbitrateEvent method updateStatus.

private void updateStatus(Long channelId, ChannelStatus status) {
    String path = ManagePathUtils.getChannelByChannelId(channelId);
    // 初始化的数据对象
    byte[] data = JsonUtils.marshalToByte(status);
    try {
        zookeeper.writeData(path, data);
    } catch (ZkException e) {
        throw new ArbitrateException("Channel_init", channelId.toString(), e);
    }
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 35 with ZkException

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

Aggregations

ZkException (org.I0Itec.zkclient.exception.ZkException)41 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)27 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)22 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)7 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)7 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)5 ProcessNodeEventData (com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)5 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)5 IOException (java.io.IOException)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)3 ArrayList (java.util.ArrayList)3 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)3 TerminMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor)2 InetSocketAddress (java.net.InetSocketAddress)2 Date (java.util.Date)2 List (java.util.List)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 ZkBadVersionException (org.I0Itec.zkclient.exception.ZkBadVersionException)2