use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor in project otter by alibaba.
the class TerminZooKeeperArbitrateEvent method await.
/**
* <pre>
* 算法:
* 1. 开始阻塞获取符合条件的processId,获取对应的data数据直接返回
* </pre>
*/
public TerminEventData await(Long pipelineId) throws InterruptedException {
Assert.notNull(pipelineId);
TerminMonitor terminMonitor = ArbitrateFactory.getInstance(pipelineId, TerminMonitor.class);
// 符合条件的processId
Long processId = terminMonitor.waitForProcess();
if (logger.isDebugEnabled()) {
logger.debug("## await pipeline[{}] processId[{}] is termin", pipelineId, processId);
}
// 根据pipelineId+processId构造对应的path
String path = StagePathUtils.getTermin(pipelineId, processId);
try {
byte[] data = zookeeper.readData(path);
return JsonUtils.unmarshalFromByte(data, TerminEventData.class);
} catch (ZkNoNodeException e) {
logger.error("pipeline[{}] processId[{}] is process", pipelineId, processId);
// modify for 2012-09-08, 发生主备切换时,await会进入死循环,针对NoNode后直接从内存队列中移除
terminMonitor.ack(processId);
// 再取下一个节点
return await(pipelineId);
} catch (ZkException e) {
throw new ArbitrateException("Termin_await", e);
}
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor in project otter by alibaba.
the class TerminZooKeeperArbitrateEvent method exhaust.
/**
* 消耗掉所有的termin信号
*/
public void exhaust(Long pipelineId) {
Assert.notNull(pipelineId);
TerminMonitor terminMonitor = ArbitrateFactory.getInstance(pipelineId, TerminMonitor.class);
int size = terminMonitor.size();
try {
for (int i = 0; i < size; i++) {
Long processId;
processId = terminMonitor.waitForProcess();
TerminEventData data = new TerminEventData();
data.setPipelineId(pipelineId);
data.setProcessId(processId);
ack(data);
}
} catch (InterruptedException e) {
throw new ArbitrateException(e);
}
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor in project otter by alibaba.
the class TerminZooKeeperArbitrateEvent method ack.
/**
* <pre>
* 算法:
* 1. 客户端处理完成对应的termin事件后,反馈给仲裁器处理完成。仲裁器根据对应S.E.T.L的反馈情况,判断是否删除对应的termin信号
* </pre>
*/
public void ack(TerminEventData data) {
Assert.notNull(data);
// 目前只有select模块需要发送ack信号,这里一旦收到一个信号后就删除对应的termin节点,后续可扩展
// 删除termin节点
String path = StagePathUtils.getTermin(data.getPipelineId(), data.getProcessId());
try {
zookeeper.delete(path);
} catch (ZkNoNodeException e) {
// ignore,说明节点已经被删除
} catch (ZkException e) {
throw new ArbitrateException("Termin_ack", e);
}
TerminMonitor terminMonitor = ArbitrateFactory.getInstance(data.getPipelineId(), TerminMonitor.class);
terminMonitor.ack(data.getProcessId());
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor in project otter by alibaba.
the class TerminZooKeeperArbitrateEvent method size.
/**
* 查询当前待处理的termin信号的总数
*/
public int size(Long pipelineId) {
Assert.notNull(pipelineId);
TerminMonitor terminMonitor = ArbitrateFactory.getInstance(pipelineId, TerminMonitor.class);
return terminMonitor.size();
}
use of com.alibaba.otter.shared.arbitrate.impl.setl.monitor.TerminMonitor in project otter by alibaba.
the class TerminMonitorTest method test_init.
@Test
public void test_init() {
initTermin(1L);
initTermin(2L);
try {
terminMonitor = new TerminMonitor(pipelineId);
Long p1 = terminMonitor.waitForProcess();
terminMonitor.ack(p1);
Long p2 = terminMonitor.waitForProcess();
terminMonitor.ack(p2);
want.bool(p1.equals(1L)).is(true);
want.bool(p2.equals(2L)).is(true);
terminMonitor.destory();
} catch (InterruptedException e) {
want.fail();
} finally {
destoryTermin(1L);
destoryTermin(2L);
}
}
Aggregations