Search in sources :

Example 11 with ArbitrateException

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

the class ExtractRpcArbitrateEvent method await.

public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    RpcStageController stageController = ArbitrateFactory.getInstance(pipelineId, RpcStageController.class);
    // 符合条件的processId
    Long processId = stageController.waitForProcess(StageType.EXTRACT);
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart() || status.isPause()) {
        // pause状态也让其处理,避免误删除pause状态的processId,导致通道挂起
        EtlEventData eventData = stageController.getLastData(processId);
        // 获取下一个处理节点信息
        Node node = LoadBalanceFactory.getNextTransformNode(pipelineId);
        if (node == null) {
            // 没有后端节点
            throw new ArbitrateException("Extract_single", "no next node");
        } else {
            eventData.setNextNid(node.getId());
            // 只有这一条路返回
            return eventData;
        }
    } else {
        logger.warn("pipelineId[{}] extract ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        String path = StagePathUtils.getProcess(pipelineId, processId);
        zookeeper.exists(path);
        // 递归调用
        return await(pipelineId);
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Node(com.alibaba.otter.shared.common.model.config.node.Node) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 12 with ArbitrateException

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

Example 13 with ArbitrateException

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

the class ChannelArbitrateEvent method pause.

/**
     * 停止对应的channel同步,是个异步调用
     */
public boolean pause(Long channelId, boolean needTermin) {
    ChannelStatus currstatus = status(channelId);
    boolean status = false;
    boolean result = !needTermin;
    if (currstatus.isStart()) {
        // stop的优先级高于pause,这里只针对start状态进行状态更新
        updateStatus(channelId, ChannelStatus.PAUSE);
        // 避免stop时发生rollback报警
        status = true;
    }
    if (needTermin) {
        try {
            // 调用termin进行关闭
            result |= termin(channelId, TerminType.ROLLBACK);
        } catch (Throwable e) {
            // 出错了,直接挂起
            updateStatus(channelId, ChannelStatus.PAUSE);
            throw new ArbitrateException(e);
        }
    }
    return result && status;
}
Also used : ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 14 with ArbitrateException

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

the class ChannelArbitrateEvent method restart.

/**
     * 停止对应的channel同步,是个异步调用
     */
public boolean restart(final Long channelId, boolean needTermin) {
    boolean result = !needTermin;
    boolean status = false;
    if (status(channelId).isStop() == false) {
        // stop的优先级高于pause
        updateStatus(channelId, ChannelStatus.PAUSE);
        status = true;
    }
    if (needTermin) {
        try {
            result |= termin(channelId, TerminType.RESTART);
        } catch (Throwable e) {
            // 出错了,直接挂起
            updateStatus(channelId, ChannelStatus.PAUSE);
            throw new ArbitrateException(e);
        }
    }
    // 处理一下重启操作,只处理pause状态
    if (status || result) {
        // 异步启动
        arbitrateExecutor.submit(new Runnable() {

            public void run() {
                // sleep一段时间,保证rollback信息有足够的时间能被处理完成
                try {
                    Thread.sleep(5000L + RandomUtils.nextInt(2000));
                } catch (InterruptedException e) {
                // ignore
                }
                Channel channel = ArbitrateConfigUtils.getChannelByChannelId(channelId);
                ChannelStatus status = status(channel.getId());
                if (status.isStop()) {
                    // stop优先级最高,不允许自动重启
                    logger.info("channel[{}] is already stop , restart is ignored", channel.getId());
                } else if (canStart(channel)) {
                    // 出现stop,就不允许进行自动重启,stop优先级最高
                    start(channelId);
                }
            }
        });
    }
    return result && status;
}
Also used : Channel(com.alibaba.otter.shared.common.model.config.channel.Channel) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 15 with ArbitrateException

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

the class ChannelArbitrateEvent method stop.

/**
     * 停止对应的channel同步,是个异步调用
     */
public boolean stop(Long channelId, boolean needTermin) {
    // stop优先级高于pause
    updateStatus(channelId, ChannelStatus.STOP);
    boolean result = !needTermin;
    if (needTermin) {
        try {
            result |= termin(channelId, TerminType.SHUTDOWN);
        } catch (Throwable e) {
            // 出错了,直接挂起
            updateStatus(channelId, ChannelStatus.STOP);
            throw new ArbitrateException(e);
        }
    }
    return result;
}
Also used : 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