mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-02 12:17:43 +08:00
[Fix][Master] Fix master-server execution logic thread unsafe problem (#8707)
* Fix thread safety issue in master service * optimize code.
This commit is contained in:
parent
d3cbf8eeaf
commit
c4fc59c9bb
@ -33,6 +33,7 @@ import org.apache.dolphinscheduler.service.queue.TaskPriorityQueue;
|
||||
import org.apache.dolphinscheduler.service.queue.entity.TaskExecutionContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@ -120,7 +121,7 @@ public class TaskPriorityQueueConsumer extends Thread {
|
||||
* batch dispatch with thread pool
|
||||
*/
|
||||
private List<TaskPriority> batchDispatch(int fetchTaskNum) throws TaskPriorityQueueException, InterruptedException {
|
||||
List<TaskPriority> failedDispatchTasks = new ArrayList<>();
|
||||
List<TaskPriority> failedDispatchTasks = Collections.synchronizedList(new ArrayList<>());
|
||||
CountDownLatch latch = new CountDownLatch(fetchTaskNum);
|
||||
|
||||
for (int i = 0; i < fetchTaskNum; i++) {
|
||||
|
@ -36,6 +36,7 @@ import org.apache.dolphinscheduler.service.process.ProcessService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
@ -179,7 +180,8 @@ public class MasterSchedulerService extends Thread {
|
||||
}
|
||||
|
||||
private List<ProcessInstance> command2ProcessInstance(List<Command> commands) {
|
||||
List<ProcessInstance> processInstances = new ArrayList<>(commands.size());
|
||||
|
||||
List<ProcessInstance> processInstances = Collections.synchronizedList(new ArrayList<>(commands.size()));
|
||||
CountDownLatch latch = new CountDownLatch(commands.size());
|
||||
for (final Command command : commands) {
|
||||
masterPrepareExecService.execute(() -> {
|
||||
|
@ -886,11 +886,11 @@ public class ProcessService {
|
||||
//reset command parameter
|
||||
if (processInstance.getCommandParam() != null) {
|
||||
Map<String, String> processCmdParam = JSONUtils.toMap(processInstance.getCommandParam());
|
||||
for (Map.Entry<String, String> entry : processCmdParam.entrySet()) {
|
||||
if (!cmdParam.containsKey(entry.getKey())) {
|
||||
cmdParam.put(entry.getKey(), entry.getValue());
|
||||
processCmdParam.forEach((key, value) -> {
|
||||
if (!cmdParam.containsKey(key)) {
|
||||
cmdParam.put(key, value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// reset command parameter if sub process
|
||||
if (cmdParam != null && cmdParam.containsKey(Constants.CMD_PARAM_SUB_PROCESS)) {
|
||||
|
Loading…
Reference in New Issue
Block a user