Search in sources :

Example 26 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class TransformMemoryArbitrateEvent method await.

public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    MemoryStageController stageController = ArbitrateFactory.getInstance(pipelineId, MemoryStageController.class);
    // 符合条件的processId
    Long processId = stageController.waitForProcess(StageType.TRANSFORM);
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        // 即时查询一下当前的状态,状态随时可能会变
        return stageController.getLastData(processId);
    } else {
        logger.warn("pipelineId[{}] transform ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        // 递归调用
        return await(pipelineId);
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 27 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class PermitMonitor method initChannelStatus.

private void initChannelStatus(byte[] bytes) {
    ChannelStatus newChannelStatus = JsonUtils.unmarshalFromByte(bytes, ChannelStatus.class);
    if (logger.isDebugEnabled()) {
        logger.debug("pipeline[{}] newChannelStatus is [{}]", getPipelineId(), newChannelStatus);
    }
    synchronized (this) {
        // 发生变化,才触发权限检查
        if (!newChannelStatus.equals(channelStatus)) {
            channelStatus = newChannelStatus;
            permitSem();
        }
    }
}
Also used : ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 28 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class LoadRpcArbitrateEvent 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.LOAD);
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        // 即时查询一下当前的状态,状态随时可能会变
        return stageController.getLastData(processId);
    } else {
        // 需要进一步check,避免丢失load信号
        status = permitMonitor.getChannelPermit(true);
        if (status.isStart()) {
            return stageController.getLastData(processId);
        } else if (status.isPause()) {
            String path = StagePathUtils.getProcess(pipelineId, processId);
            if (zookeeper.exists(path)) {
                // 如果存在process,那说明没有被rollback掉(可能刚好在做rollback),这种运行进行load处理
                return stageController.getLastData(processId);
            }
        }
        logger.warn("pipelineId[{}] load ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        // 递归调用
        return await(pipelineId);
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)

Example 29 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class SelectMemoryArbitrateEvent method await.

public EtlEventData await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    // 阻塞等待授权
    permitMonitor.waitForPermit();
    MemoryStageController stageController = ArbitrateFactory.getInstance(pipelineId, MemoryStageController.class);
    // 符合条件的processId
    Long processId = stageController.waitForProcess(StageType.SELECT);
    ChannelStatus status = permitMonitor.getChannelPermit();
    if (status.isStart()) {
        // 即时查询一下当前的状态,状态随时可能会变
        EtlEventData eventData = new EtlEventData();
        eventData.setPipelineId(pipelineId);
        eventData.setProcessId(processId);
        // 返回当前时间
        eventData.setStartTime(new Date().getTime());
        Long nid = ArbitrateConfigUtils.getCurrentNid();
        eventData.setCurrNid(nid);
        eventData.setNextNid(nid);
        // 只有这一条路返回
        return eventData;
    } else {
        logger.warn("pipelineId[{}] select ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
        //将progress中清理掉,避免阻塞后续调度,因为最小的Id一直处于extract未完成阶段
        stageController.clearProgress(processId);
        // 递归调用
        return await(pipelineId);
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) Date(java.util.Date) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 30 with ChannelStatus

use of com.alibaba.otter.shared.common.model.config.channel.ChannelStatus in project otter by alibaba.

the class MainStemArbitrateEvent method await.

/**
     * <pre>
     * 算法:
     * 1. 检查当前的Permit,阻塞等待其授权(解决Channel的pause状态处理)
     * 2. 尝试创建对应的mainStem节点(非持久化节点)
     *  a. 如果创建成功,则直接构造结果返回
     *  b. 如果创建失败,则关注该节点的exist信号. 继续执行步骤2
     * </pre>
     */
public void await(Long pipelineId) throws InterruptedException {
    Assert.notNull(pipelineId);
    PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    ChannelStatus status = permitMonitor.getChannelPermit(true);
    boolean isRuning = check(pipelineId);
    if (!status.isStart() && isRuning) {
        // 当前状态不为启动,强制设置为taking,下次授权启动后重新追数据
        MainStemEventData data = new MainStemEventData();
        data.setPipelineId(pipelineId);
        data.setStatus(MainStemEventData.Status.TAKEING);
        single(data);
        // 阻塞等待挂起
        permitMonitor.waitForChannelPermit();
        return;
    } else if (status.isStart() && isRuning) {
        // 正常状态
        return;
    } else if (isRuning == false) {
        if (!status.isStart()) {
            // 阻塞等待挂起
            permitMonitor.waitForChannelPermit();
        }
        MainstemMonitor mainstemMonitor = ArbitrateFactory.getInstance(pipelineId, MainstemMonitor.class);
        // 等待自己成为active
        mainstemMonitor.waitForActive();
        status = permitMonitor.getChannelPermit(false);
        if (status.isStart()) {
            return;
        } else {
            logger.info("pipelineId[{}] mainstem ignore by status[{}]", new Object[] { pipelineId, status });
            // 重新进行check一次
            await(pipelineId);
        }
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) ChannelStatus(com.alibaba.otter.shared.common.model.config.channel.ChannelStatus) MainstemMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor)

Aggregations

ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)30 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)13 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)8 ArrayList (java.util.ArrayList)8 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)7 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)6 Date (java.util.Date)5 ZkException (org.I0Itec.zkclient.exception.ZkException)5 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)5 InvalidConfigureException (com.alibaba.otter.manager.biz.common.exceptions.InvalidConfigureException)4 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)4 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)4 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)4 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 Test (org.testng.annotations.Test)4 ChannelDO (com.alibaba.otter.manager.biz.config.channel.dal.dataobject.ChannelDO)3 HashMap (java.util.HashMap)3 SystemParameter (com.alibaba.otter.shared.common.model.config.parameter.SystemParameter)2