Search in sources :

Example 21 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.

the class PrepareExceptionValve method invoke.

@Override
public void invoke(PipelineContext pipelineContext) throws Exception {
    //
    clearBuffer(response);
    Exception e = (Exception) pipelineContext.getAttribute("exception");
    log.error(e.getMessage(), e);
    Throwable cause = e.getCause();
    if (cause != null && cause instanceof ArbitrateException) {
        e = (ArbitrateException) cause;
    }
    ErrorHandlerHelper errorHandlerHelper = ErrorHandlerHelper.getInstance(request);
    errorHandlerHelper.setException(e);
    pipelineContext.invokeNext();
}
Also used : ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ErrorHandlerHelper(com.alibaba.citrus.webx.util.ErrorHandlerHelper) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)

Example 22 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException in project otter by alibaba.

the class ErrorTerminProcess method process.

public boolean process(TerminEventData data) {
    DistributedLock lock = new DistributedLock(StagePathUtils.getLoadLock(data.getPipelineId()));
    try {
        // 尝试进行锁定,等待当前的load操作完成
        boolean locked = lock.tryLock();
        if (!locked) {
            return false;
        }
        processChain(data);
        return true;
    } catch (KeeperException e) {
        throw new ArbitrateException("Termin_process", e);
    } finally {
        try {
            // 马上进行释放
            lock.unlock();
        } catch (KeeperException e1) {
        // ignore
        }
    }
}
Also used : DistributedLock(com.alibaba.otter.shared.arbitrate.impl.zookeeper.lock.DistributedLock) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) KeeperException(org.apache.zookeeper.KeeperException)

Example 23 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 24 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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 25 with ArbitrateException

use of com.alibaba.otter.shared.arbitrate.exception.ArbitrateException 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

ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)39 ZkException (org.I0Itec.zkclient.exception.ZkException)27 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)17 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)8 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)7 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)6 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)6 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 ArrayList (java.util.ArrayList)4 TerminMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor)3 KeeperException (org.apache.zookeeper.KeeperException)3 Stat (org.apache.zookeeper.data.Stat)3 StageComparator (com.alibaba.otter.shared.arbitrate.impl.setl.helper.StageComparator)2 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)2 TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)2 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)2 Date (java.util.Date)2 ZkBadVersionException (org.I0Itec.zkclient.exception.ZkBadVersionException)2 ErrorHandlerHelper (com.alibaba.citrus.webx.util.ErrorHandlerHelper)1 RemedyIndexComparator (com.alibaba.otter.shared.arbitrate.impl.setl.helper.RemedyIndexComparator)1