}
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());
Thread.sleep(1000); // sleep 1秒,等新的数据包
} else if (terminBatchId != null && batchId != -1L && !batchId.equals(terminBatchId)) {
exception = new SelectException("unmatched terminId, SelectTask batchId = " + batchId + " processId = "
+ processId + " and Termin Event: " + terminData.toString());
Thread.sleep(1000); // sleep 1秒,等新的数据包
} else {
exception = null; // batchId/processId对上了,退出
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); // 先发送对应的数据