use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class TerminArbitrateEventTest 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().isPause()).is(true);
destoryTermin();
ArbitrateFactory.destory(pipelineId);
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class PermitMonitorTest method testPermit_init_fail.
@Test
public void testPermit_init_fail() {
// 测试下permit的初始化内容
channelEvent.start(channelId);
updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
// 一个节点挂起
updateMainStem(oppositePipelineId, MainStemEventData.Status.TAKEING);
permitMonitor = new PermitMonitor(pipelineId);
boolean isPermit = permitMonitor.isPermit();
want.bool(isPermit).is(false);
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class PermitMonitorTest method testPermit_change.
@Test
public void testPermit_change() {
channelEvent.start(channelId);
updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
// 一个节点挂起
updateMainStem(oppositePipelineId, MainStemEventData.Status.TAKEING);
permitMonitor = new PermitMonitor(pipelineId);
boolean isPermit = permitMonitor.isPermit();
want.bool(isPermit).is(false);
updateMainStem(oppositePipelineId, MainStemEventData.Status.OVERTAKE);
// 一个节点挂起
updateMainStem(pipelineId, MainStemEventData.Status.TAKEING);
// 需要sleep一下,保证数据已经更新到monitor上
sleep();
isPermit = permitMonitor.isPermit();
want.bool(isPermit).is(false);
updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
// 需要sleep一下,保证数据已经更新到monitor上
sleep();
isPermit = permitMonitor.isPermit();
want.bool(isPermit).is(true);
MonitorScheduler.unRegister(permitMonitor);
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class SelectRpcArbitrateEvent method await.
public EtlEventData await(Long pipelineId) throws InterruptedException {
Assert.notNull(pipelineId);
PermitMonitor permitMonitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
// 阻塞等待授权
permitMonitor.waitForPermit();
SelectProcessListener selectProcessListener = ArbitrateFactory.getInstance(pipelineId, SelectProcessListener.class);
// 符合条件的processId
Long processId = selectProcessListener.waitForProcess();
ChannelStatus status = permitMonitor.getChannelPermit();
if (status.isStart()) {
// 即时查询一下当前的状态,状态随时可能会变
try {
EtlEventData eventData = new EtlEventData();
eventData.setPipelineId(pipelineId);
eventData.setProcessId(processId);
// 返回当前时间
eventData.setStartTime(new Date().getTime());
// 获取下一个处理节点信息
Node node = LoadBalanceFactory.getNextExtractNode(pipelineId);
if (node == null) {
// terminEvent.single(termin);
throw new ArbitrateException("Select_single", "no next node");
} else {
eventData.setNextNid(node.getId());
// 标记为已使用
markUsed(eventData);
// 只有这一条路返回
return eventData;
}
} catch (ZkNoNodeException e) {
logger.error("pipeline[{}] processId[{}] is invalid , retry again", pipelineId, processId);
// /出现节点不存在,说明出现了error情况,递归调用重新获取一次
return await(pipelineId);
} catch (ZkException e) {
throw new ArbitrateException("Select_await", e.getMessage(), e);
}
} else {
logger.warn("pipelineId[{}] select ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
// add by ljh 2013-02-01
// 遇到一个bug:
// a. 某台机器发起了一个RESTART指令,然后开始删除process列表
// b. 此时另一个台机器(select工作节点),并没有收到PAUSE的推送,导致还会再创建一个process节点
// c. 后续收到PAUSE指令后,丢弃了processId,就出现了unused的processId
// 这里删除了,要考虑一个问题,就是和restart指令在并行删除同一个processId时的并发考虑,目前来看没问题
String path = StagePathUtils.getProcess(pipelineId, processId);
// 忽略删除失败
zookeeper.delete(path);
// 递归调用
return await(pipelineId);
}
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor in project otter by alibaba.
the class TransformRpcArbitrateEvent 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.TRANSFORM);
ChannelStatus status = permitMonitor.getChannelPermit();
if (status.isStart() || status.isPause()) {
// pause状态也让其处理,避免误删除pause状态的processId,导致通道挂起
EtlEventData eventData = stageController.getLastData(processId);
// 下一个节点信息即为自己
eventData.setNextNid(ArbitrateConfigUtils.getCurrentNid());
return eventData;
} else {
logger.warn("pipelineId[{}] transform ignore processId[{}] by status[{}]", new Object[] { pipelineId, processId, status });
// 递归调用
return await(pipelineId);
}
}
Aggregations