use of com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData in project otter by alibaba.
the class SelectRpcArbitrateEvent method markUsed.
/**
* 标记一下当前process为已使用
*/
private void markUsed(EtlEventData data) throws ZkNoNodeException, ZkException {
String path = StagePathUtils.getProcess(data.getPipelineId(), data.getProcessId());
// 序列化
ProcessNodeEventData eventData = new ProcessNodeEventData();
Long nid = ArbitrateConfigUtils.getCurrentNid();
eventData.setNid(nid);
// 标记为已使用
eventData.setStatus(ProcessNodeEventData.Status.USED);
// 直接声明为rpc模式
eventData.setMode(ArbitrateMode.RPC);
byte[] bytes = JsonUtils.marshalToByte(eventData);
zookeeper.writeData(path, bytes);
}
use of com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData in project otter by alibaba.
the class SelectProcessListener method recovery.
/**
* 尝试载入一下上一次未使用的processId,可能发生mainstem切换,新的S模块需要感知前S模块已创建但未使用的process,不然就是一个死锁。而针对已经使用的processId会由e/t/l节点进行处理
*/
private void recovery(Long pipelineId) {
List<Long> currentProcessIds = processMonitor.getCurrentProcessIds(false);
for (Long processId : currentProcessIds) {
String path = StagePathUtils.getProcess(pipelineId, processId);
try {
byte[] bytes = zookeeper.readData(path);
ProcessNodeEventData nodeData = JsonUtils.unmarshalFromByte(bytes, ProcessNodeEventData.class);
if (nodeData.getStatus().isUnUsed()) {
// 加入未使用的processId
addReply(processId);
}
} catch (ZkException e) {
logger.error("recovery error!", e);
}
}
}
use of com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData in project otter by alibaba.
the class SelectStageListener method processChanged.
public void processChanged(List<Long> processIds) {
super.processChanged(processIds);
// add by ljh at 2012-09-13,解决zookeeper ConnectionLoss问题
for (Long processId : processIds) {
if (!replyProcessIds.contains(processId)) {
logger.warn("process is not in order, please check processId:{}", processId);
addReply(processId);
}
}
try {
String path = StagePathUtils.getProcessRoot(getPipelineId());
// 根据并行度创建任务
int size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - processIds.size();
if (size > 0) {
// 创建一个节点
PermitMonitor permit = ArbitrateFactory.getInstance(getPipelineId(), PermitMonitor.class);
if (permit.isPermit() == false) {
// 如果非授权,则不做任何处理
return;
}
String mainStemPath = StagePathUtils.getMainStem(getPipelineId());
byte[] bytes = zookeeper.readData(mainStemPath, true);
if (bytes == null) {
return;
}
MainStemEventData eventData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class);
if (eventData.getNid().equals(ArbitrateConfigUtils.getCurrentNid()) == false) {
// 如果非自己设置的mainStem,则不做任何处理
return;
}
synchronized (this) {
// 重新再取一次, dobble-check
List<String> currentProcesses = zookeeper.getChildren(path);
size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - currentProcesses.size();
if (size > 0) {
// 创建一个节点
ProcessNodeEventData nodeData = new ProcessNodeEventData();
// 标记为未使用
nodeData.setStatus(ProcessNodeEventData.Status.UNUSED);
nodeData.setNid(ArbitrateConfigUtils.getCurrentNid());
byte[] nodeBytes = JsonUtils.marshalToByte(nodeData);
String processPath = zookeeper.create(path + "/", nodeBytes, CreateMode.PERSISTENT_SEQUENTIAL);
// 创建为顺序的节点
String processNode = StringUtils.substringAfterLast(processPath, "/");
// 添加到当前的process列表
Long processId = StagePathUtils.getProcessId(processNode);
addReply(processId);
}
}
}
} catch (ZkException e) {
// 出现异常后进行一次recovery,读取一下当前最新值,解决出现ConnectionLoss时create成功问题
recovery(getPipelineId());
logger.error("SelectStageListener", e);
}
}
Aggregations