Search in sources :

Example 26 with ZkException

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

the class MainstemMonitor method single.

/**
 * 更新mainStem的同步状态数据
 */
public void single(MainStemEventData data) {
    Assert.notNull(data);
    Long nid = ArbitrateConfigUtils.getCurrentNid();
    if (!check()) {
        return;
    }
    // 设置当前的nid
    data.setNid(nid);
    String path = StagePathUtils.getMainStem(data.getPipelineId());
    // 初始化的数据对象
    byte[] bytes = JsonUtils.marshalToByte(data);
    try {
        zookeeper.writeData(path, bytes);
    } catch (ZkException e) {
        throw new ArbitrateException("mainStem_single", data.toString(), e);
    }
    activeData = data;
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 27 with ZkException

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

the class ErrorTerminProcess method processChain.

public void processChain(TerminEventData data) {
    // 关闭对应的服务
    Long pipelineId = data.getPipelineId();
    // 清理对应的process
    String processRoot = StagePathUtils.getProcessRoot(pipelineId);
    try {
        List<String> processNodes = zookeeper.getChildren(processRoot);
        // 3. 循环处理每个process
        List<Long> processIds = new ArrayList<Long>();
        for (String process : processNodes) {
            processIds.add(StagePathUtils.getProcessId(process));
        }
        // 排序一下
        Collections.sort(processIds);
        Long processId = data.getProcessId();
        if (processId != null) {
            // 可能为空
            normalTerminProcess.process(data);
        }
        for (Long currProcessId : processIds) {
            if (processId != null && currProcessId <= processId) {
                continue;
            }
            // 发送给最小的一个process的termin信号,进行链式的触发
            data.setProcessId(currProcessId);
            // 处理异常信息
            processChain(data);
            break;
        }
    } catch (ZkException e) {
        throw new ArbitrateException("Termin_process", e);
    }
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) ArrayList(java.util.ArrayList) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 28 with ZkException

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

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

the class SelectStageListener method processChanged.

public void processChanged(List<Long> processIds) {
    super.processChanged(processIds);
    // add by ljh at 2012-09-13,解决zookeeper ConnectionLoss问题
    for (Long processId : processIds) {
        if (!replyProcessIds.contains(processId)) {
            logger.warn("process is not in order, please check processId:{}", processId);
            addReply(processId);
        }
    }
    try {
        String path = StagePathUtils.getProcessRoot(getPipelineId());
        // 根据并行度创建任务
        int size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - processIds.size();
        if (size > 0) {
            // 创建一个节点
            PermitMonitor permit = ArbitrateFactory.getInstance(getPipelineId(), PermitMonitor.class);
            if (permit.isPermit() == false) {
                // 如果非授权,则不做任何处理
                return;
            }
            String mainStemPath = StagePathUtils.getMainStem(getPipelineId());
            byte[] bytes = zookeeper.readData(mainStemPath, true);
            if (bytes == null) {
                return;
            }
            MainStemEventData eventData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
            if (eventData.getNid().equals(ArbitrateConfigUtils.getCurrentNid()) == false) {
                // 如果非自己设置的mainStem,则不做任何处理
                return;
            }
            synchronized (this) {
                // 重新再取一次, dobble-check
                List<String> currentProcesses = zookeeper.getChildren(path);
                size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - currentProcesses.size();
                if (size > 0) {
                    // 创建一个节点
                    ProcessNodeEventData nodeData = new ProcessNodeEventData();
                    // 标记为未使用
                    nodeData.setStatus(ProcessNodeEventData.Status.UNUSED);
                    nodeData.setNid(ArbitrateConfigUtils.getCurrentNid());
                    byte[] nodeBytes = JsonUtils.marshalToByte(nodeData);
                    String processPath = zookeeper.create(path + "/", nodeBytes, CreateMode.PERSISTENT_SEQUENTIAL);
                    // 创建为顺序的节点
                    String processNode = StringUtils.substringAfterLast(processPath, "/");
                    // 添加到当前的process列表
                    Long processId = StagePathUtils.getProcessId(processNode);
                    addReply(processId);
                }
            }
        }
    } catch (ZkException e) {
        // 出现异常后进行一次recovery,读取一下当前最新值,解决出现ConnectionLoss时create成功问题
        recovery(getPipelineId());
        logger.error("SelectStageListener", e);
    }
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ProcessNodeEventData(com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)

Example 30 with ZkException

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

the class NormalTerminProcess method doProcess.

private boolean doProcess(TerminEventData data, boolean retry) {
    Long pipelineId = data.getPipelineId();
    Long processId = data.getProcessId();
    List<String> currentStages = null;
    try {
        currentStages = zookeeper.getChildren(StagePathUtils.getProcess(pipelineId, processId));
        Collections.sort(currentStages, new StageComparator());
    } catch (ZkNoNodeException e) {
        // ignore,说明节点已经被删除了
        return false;
    } catch (ZkException e) {
        throw new ArbitrateException("Termin_process", e);
    }
    // s节点
    if (currentStages == null || currentStages.contains(ArbitrateConstants.NODE_SELECTED)) {
        try {
            boolean successed = zookeeper.delete(StagePathUtils.getSelectStage(pipelineId, processId));
            if (!successed) {
                processDeleteFailed();
            }
        } catch (ZkException e) {
            throw new ArbitrateException("Termin_process", e);
        }
    }
    // e节点
    if (currentStages == null || currentStages.contains(ArbitrateConstants.NODE_EXTRACTED)) {
        try {
            boolean successed = zookeeper.delete(StagePathUtils.getExtractStage(pipelineId, processId));
            if (!successed) {
                processDeleteFailed();
            }
        } catch (ZkException e) {
            throw new ArbitrateException("Termin_process", e);
        }
    }
    // t节点
    if (currentStages == null || currentStages.contains(ArbitrateConstants.NODE_TRANSFORMED)) {
        try {
            boolean successed = zookeeper.delete(StagePathUtils.getTransformStage(pipelineId, processId));
            if (!successed) {
                processDeleteFailed();
            }
        } catch (ZkException e) {
            throw new ArbitrateException("Termin_process", e);
        }
    }
    // 不过会有遗漏判断,比如并发时都是一个线程全删除成功
    return processDelete(data, CollectionUtils.isEmpty(currentStages), retry);
}
Also used : StageComparator(com.alibaba.otter.shared.arbitrate.impl.setl.helper.StageComparator) 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