|
|
@ -96,6 +96,8 @@ public class TaskGroupCoordinator extends BaseDaemonThread { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ProcessInstanceDao processInstanceDao; |
|
|
|
private ProcessInstanceDao processInstanceDao; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static int DEFAULT_LIMIT = 1000; |
|
|
|
|
|
|
|
|
|
|
|
public TaskGroupCoordinator() { |
|
|
|
public TaskGroupCoordinator() { |
|
|
|
super("TaskGroupCoordinator"); |
|
|
|
super("TaskGroupCoordinator"); |
|
|
|
} |
|
|
|
} |
|
|
@ -147,10 +149,10 @@ public class TaskGroupCoordinator extends BaseDaemonThread { |
|
|
|
if (CollectionUtils.isEmpty(taskGroups)) { |
|
|
|
if (CollectionUtils.isEmpty(taskGroups)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
StopWatch taskGroupCoordinatorRoundTimeCost = StopWatch.createStarted(); |
|
|
|
|
|
|
|
|
|
|
|
for (TaskGroup taskGroup : taskGroups) { |
|
|
|
for (TaskGroup taskGroup : taskGroups) { |
|
|
|
List<TaskGroupQueue> taskGroupQueues = |
|
|
|
int actualUseSize = taskGroupQueueDao.countUsingTaskGroupQueueByGroupId(taskGroup.getId()); |
|
|
|
taskGroupQueueDao.queryAcquiredTaskGroupQueueByGroupId(taskGroup.getId()); |
|
|
|
|
|
|
|
int actualUseSize = taskGroupQueues.size(); |
|
|
|
|
|
|
|
if (taskGroup.getUseSize() == actualUseSize) { |
|
|
|
if (taskGroup.getUseSize() == actualUseSize) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
@ -160,13 +162,35 @@ public class TaskGroupCoordinator extends BaseDaemonThread { |
|
|
|
taskGroup.setUseSize(actualUseSize); |
|
|
|
taskGroup.setUseSize(actualUseSize); |
|
|
|
taskGroupDao.updateById(taskGroup); |
|
|
|
taskGroupDao.updateById(taskGroup); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.info("Success amend TaskGroup useSize cost: {}/ms", taskGroupCoordinatorRoundTimeCost.getTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Make sure the TaskGroupQueue status is {@link TaskGroupQueueStatus#RELEASE} when the related {@link TaskInstance} is not exist or status is finished. |
|
|
|
* Make sure the TaskGroupQueue status is {@link TaskGroupQueueStatus#RELEASE} when the related {@link TaskInstance} is not exist or status is finished. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void amendTaskGroupQueueStatus() { |
|
|
|
private void amendTaskGroupQueueStatus() { |
|
|
|
List<TaskGroupQueue> taskGroupQueues = taskGroupQueueDao.queryAllInQueueTaskGroupQueue(); |
|
|
|
int minTaskGroupQueueId = -1; |
|
|
|
|
|
|
|
int limit = DEFAULT_LIMIT; |
|
|
|
|
|
|
|
StopWatch taskGroupCoordinatorRoundTimeCost = StopWatch.createStarted(); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
List<TaskGroupQueue> taskGroupQueues = |
|
|
|
|
|
|
|
taskGroupQueueDao.queryInQueueTaskGroupQueue(minTaskGroupQueueId, limit); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(taskGroupQueues)) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
amendTaskGroupQueueStatus(taskGroupQueues); |
|
|
|
|
|
|
|
if (taskGroupQueues.size() < limit) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
minTaskGroupQueueId = taskGroupQueues.get(taskGroupQueues.size() - 1).getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("Success amend TaskGroupQueue status cost: {}/ms", taskGroupCoordinatorRoundTimeCost.getTime()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Make sure the TaskGroupQueue status is {@link TaskGroupQueueStatus#RELEASE} when the related {@link TaskInstance} is not exist or status is finished. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void amendTaskGroupQueueStatus(List<TaskGroupQueue> taskGroupQueues) { |
|
|
|
List<Integer> taskInstanceIds = taskGroupQueues.stream() |
|
|
|
List<Integer> taskInstanceIds = taskGroupQueues.stream() |
|
|
|
.map(TaskGroupQueue::getTaskId) |
|
|
|
.map(TaskGroupQueue::getTaskId) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
.collect(Collectors.toList()); |
|
|
@ -198,10 +222,30 @@ public class TaskGroupCoordinator extends BaseDaemonThread { |
|
|
|
// Find the force start task group queue(Which is inQueue and forceStart is YES)
|
|
|
|
// Find the force start task group queue(Which is inQueue and forceStart is YES)
|
|
|
|
// Notify the related waiting task instance
|
|
|
|
// Notify the related waiting task instance
|
|
|
|
// Set the taskGroupQueue status to RELEASE and remove it from queue
|
|
|
|
// Set the taskGroupQueue status to RELEASE and remove it from queue
|
|
|
|
List<TaskGroupQueue> taskGroupQueues = taskGroupQueueDao.queryAllInQueueTaskGroupQueue() |
|
|
|
// We use limit here to avoid OOM, and we will retry to notify force start queue at next time
|
|
|
|
.stream() |
|
|
|
int minTaskGroupQueueId = -1; |
|
|
|
.filter(taskGroupQueue -> Flag.YES.getCode() == taskGroupQueue.getForceStart()) |
|
|
|
int limit = DEFAULT_LIMIT; |
|
|
|
.collect(Collectors.toList()); |
|
|
|
StopWatch taskGroupCoordinatorRoundTimeCost = StopWatch.createStarted(); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
|
|
|
|
List<TaskGroupQueue> taskGroupQueues = |
|
|
|
|
|
|
|
taskGroupQueueDao.queryWaitNotifyForceStartTaskGroupQueue(minTaskGroupQueueId, limit); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(taskGroupQueues)) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
dealWithForceStartTaskGroupQueue(taskGroupQueues); |
|
|
|
|
|
|
|
if (taskGroupQueues.size() < limit) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
minTaskGroupQueueId = taskGroupQueues.get(taskGroupQueues.size() - 1).getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.info("Success deal with force start TaskGroupQueue cost: {}/ms", |
|
|
|
|
|
|
|
taskGroupCoordinatorRoundTimeCost.getTime()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void dealWithForceStartTaskGroupQueue(List<TaskGroupQueue> taskGroupQueues) { |
|
|
|
|
|
|
|
// Find the force start task group queue(Which is inQueue and forceStart is YES)
|
|
|
|
|
|
|
|
// Notify the related waiting task instance
|
|
|
|
|
|
|
|
// Set the taskGroupQueue status to RELEASE and remove it from queue
|
|
|
|
for (TaskGroupQueue taskGroupQueue : taskGroupQueues) { |
|
|
|
for (TaskGroupQueue taskGroupQueue : taskGroupQueues) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
LogUtils.setTaskInstanceIdMDC(taskGroupQueue.getTaskId()); |
|
|
|
LogUtils.setTaskInstanceIdMDC(taskGroupQueue.getTaskId()); |
|
|
|