Search in sources :

Example 6 with TerminEventData

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

the class OtterDownStreamHandler method notifyFailed.

private void notifyFailed() {
    detectingSuccessedCount.set(0);
    long failedCount = detectingFailedCount.incrementAndGet();
    if (failedCount == 1) {
        // 系数重置
        detectingExpCount = 1;
        notifyMainstemStatus(MainStemEventData.Status.TAKEING);
    }
    if (failedCount >= detectingThresoldCount * detectingExpCount * detectingExpCount) {
        notifyMainstemStatus(MainStemEventData.Status.TAKEING);
        // 系数增大一次
        detectingExpCount++;
        // 并且发送一次报警信息,系统不太正常了,超过一定时间一次都没有拿到对应的数据
        // 可能出现的情况:
        // 1. 主备发生切换,定位position花费了过久的时间
        // 2. MysqlEventParser工作不正常,一直拿不到数据,比如数据库挂了,但是又没通知其进行主备切换
        TerminEventData errorEventData = new TerminEventData();
        errorEventData.setPipelineId(pipelineId);
        errorEventData.setType(TerminType.WARNING);
        errorEventData.setCode("mainstem");
        errorEventData.setDesc(String.format(DETECTING_FAILED_MESSAGE, pipelineId, String.valueOf(detectingIntervalInSeconds * failedCount)));
        arbitrateEventService.terminEvent().single(errorEventData);
    }
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData)

Example 7 with TerminEventData

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

the class SelectTask method processTermin.

private boolean processTermin(boolean lastStatus, Long batchId, Long processId) throws InterruptedException {
    int retry = 0;
    SelectException exception = null;
    TerminEventData terminData = null;
    while (retry++ < 30) {
        // 因为存在网络因素,而且在Load进行termin处理时,因为是异步处理,有一定的概率会出现termin不按顺序过来
        terminData = arbitrateEventService.terminEvent().await(pipelineId);
        Long terminBatchId = terminData.getBatchId();
        Long terminProcessId = terminData.getProcessId();
        if (terminBatchId == null && processId != -1L && !processId.equals(terminProcessId)) {
            // 针对manager发起rollback,terminBatchId可能为null,需要特殊处理下
            exception = new SelectException("unmatched processId, SelectTask batchId = " + batchId + " processId = " + processId + " and Termin Event: " + terminData.toString());
            // sleep 1秒,等新的数据包
            Thread.sleep(1000);
        } else if (terminBatchId != null && batchId != -1L && !batchId.equals(terminBatchId)) {
            exception = new SelectException("unmatched terminId, SelectTask batchId = " + batchId + " processId = " + processId + " and Termin Event: " + terminData.toString());
            // sleep 1秒,等新的数据包
            Thread.sleep(1000);
        } else {
            // batchId/processId对上了,退出
            exception = null;
            break;
        }
    }
    if (exception != null) {
        throw exception;
    }
    if (needCheck) {
        checkContinueWork();
    }
    boolean status = terminData.getType().isNormal();
    if (lastStatus == false && status == true) {
        // 上一批失败,这一批成功,说明调度有问题
        throw new SelectException(String.format("last status is rollback , but now [batchId:%d , processId:%d] is ack", batchId, terminData.getProcessId()));
    }
    if (terminData.getType().isNormal()) {
        ack(batchId);
        sendDelayStat(pipelineId, terminData.getEndTime(), terminData.getFirstTime());
    } else {
        rollback(batchId);
    }
    // 先发送对应的数据
    arbitrateEventService.terminEvent().ack(terminData);
    return status;
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) SelectException(com.alibaba.otter.node.etl.select.exceptions.SelectException)

Example 8 with TerminEventData

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

the class ArbitrateOppositeIntegration method testDemo.

@Test
public void testDemo() {
    // 设置启动标志
    // channelEvent.start(channelId);
    // sleep(); //停顿一下
    // 优先启动主导线程
    mainStem.submit(pipelineId);
    PermitMonitor permit = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    try {
        // 阻塞等待授权
        permit.waitForPermit();
    } catch (InterruptedException e1) {
        want.fail();
    }
    // 启动
    select.submit(pipelineId);
    extract.submit(pipelineId);
    view.submit(pipelineId);
    this.termin.submit(pipelineId);
    // 注意是反方向的
    transform.submit(oppositePipelineId);
    // 注意是反方向的
    load.submit(oppositePipelineId);
    try {
        System.in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 发送结束事件
    TerminEventData termin = new TerminEventData();
    termin.setPipelineId(pipelineId);
    termin.setType(TerminType.SHUTDOWN);
    arbitrateEventService.terminEvent().single(termin);
    // 等待处理完所有的termin事件
    sleep(5 * 1000L);
    // 关闭
    select.destory(pipelineId);
    extract.destory(pipelineId);
    view.destory(pipelineId);
    this.termin.destory(pipelineId);
    transform.destory(oppositePipelineId);
    load.destory(oppositePipelineId);
    ArbitrateFactory.destory(pipelineId);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) IOException(java.io.IOException) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 9 with TerminEventData

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

the class TerminMemoryArbitrateEventTest method test_Shutdown.

@Test
public void test_Shutdown() {
    normalProcess();
    // 发送shutdown信号
    TerminEventData shutdown = new TerminEventData();
    shutdown.setPipelineId(pipelineId);
    shutdown.setType(TerminType.SHUTDOWN);
    terminEvent.single(shutdown);
    PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    want.bool(monitor.getChannelPermit(true).isStop()).is(true);
    destoryTermin();
    ArbitrateFactory.destory(pipelineId);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Example 10 with TerminEventData

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

the class TerminMemoryArbitrateEventTest method test_Rollback.

@Test
public void test_Rollback() {
    normalProcess();
    // 发送rollback信号
    TerminEventData rollback = new TerminEventData();
    rollback.setPipelineId(pipelineId);
    rollback.setType(TerminType.ROLLBACK);
    terminEvent.single(rollback);
    PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    want.bool(monitor.getChannelPermit(true).isPause()).is(true);
    destoryTermin();
    ArbitrateFactory.destory(pipelineId);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Aggregations

TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)32 Test (org.testng.annotations.Test)12 PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)9 BaseArbitrateEventTest (com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)9 ArrayList (java.util.ArrayList)7 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)6 Mock (mockit.Mock)5 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)3 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)3 Date (java.util.Date)3 ExtractMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.ExtractMemoryArbitrateEvent)2 LoadMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.LoadMemoryArbitrateEvent)2 SelectMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.SelectMemoryArbitrateEvent)2 TransformMemoryArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.memory.TransformMemoryArbitrateEvent)2 ExtractZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent)2 LoadZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.LoadZooKeeperArbitrateEvent)2 SelectZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent)2 TransformZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.TransformZooKeeperArbitrateEvent)2 IOException (java.io.IOException)2 SelectException (com.alibaba.otter.node.etl.select.exceptions.SelectException)1