Search in sources :

Example 6 with ProcessNodeEventData

use of com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData in project otter by alibaba.

the class SelectRpcArbitrateEvent method markUsed.

/**
     * 标记一下当前process为已使用
     */
private void markUsed(EtlEventData data) throws ZkNoNodeException, ZkException {
    String path = StagePathUtils.getProcess(data.getPipelineId(), data.getProcessId());
    // 序列化
    ProcessNodeEventData eventData = new ProcessNodeEventData();
    Long nid = ArbitrateConfigUtils.getCurrentNid();
    eventData.setNid(nid);
    // 标记为已使用
    eventData.setStatus(ProcessNodeEventData.Status.USED);
    // 直接声明为rpc模式
    eventData.setMode(ArbitrateMode.RPC);
    byte[] bytes = JsonUtils.marshalToByte(eventData);
    zookeeper.writeData(path, bytes);
}
Also used : ProcessNodeEventData(com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)

Example 7 with ProcessNodeEventData

use of com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData in project otter by alibaba.

the class SelectProcessListener method recovery.

/**
     * 尝试载入一下上一次未使用的processId,可能发生mainstem切换,新的S模块需要感知前S模块已创建但未使用的process,不然就是一个死锁。而针对已经使用的processId会由e/t/l节点进行处理
     */
private void recovery(Long pipelineId) {
    List<Long> currentProcessIds = processMonitor.getCurrentProcessIds(false);
    for (Long processId : currentProcessIds) {
        String path = StagePathUtils.getProcess(pipelineId, processId);
        try {
            byte[] bytes = zookeeper.readData(path);
            ProcessNodeEventData nodeData = JsonUtils.unmarshalFromByte(bytes, ProcessNodeEventData.class);
            if (nodeData.getStatus().isUnUsed()) {
                // 加入未使用的processId
                addReply(processId);
            }
        } catch (ZkException e) {
            logger.error("recovery error!", e);
        }
    }
}
Also used : ZkException(org.I0Itec.zkclient.exception.ZkException) ProcessNodeEventData(com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)

Example 8 with ProcessNodeEventData

use of com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData 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)

Aggregations

ProcessNodeEventData (com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)8 ZkException (org.I0Itec.zkclient.exception.ZkException)5 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)2 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)2 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)1 StageComparator (com.alibaba.otter.shared.arbitrate.impl.setl.helper.StageComparator)1 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)1 StageType (com.alibaba.otter.shared.common.model.config.enums.StageType)1 ProcessStat (com.alibaba.otter.shared.common.model.statistics.stage.ProcessStat)1 StageStat (com.alibaba.otter.shared.common.model.statistics.stage.StageStat)1 ZooKeeperx (com.alibaba.otter.shared.common.utils.zookeeper.ZooKeeperx)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IZkConnection (org.I0Itec.zkclient.IZkConnection)1 ZkInterruptedException (org.I0Itec.zkclient.exception.ZkInterruptedException)1 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)1 KeeperException (org.apache.zookeeper.KeeperException)1 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)1