mirror of https://github.com/apache/druid.git
Don't need to double synchronize on simple map operations (#14435)
* Don't need to double syncronize on simple map operations * remove lock
This commit is contained in:
parent
04fb75719e
commit
bd07c3dd43
|
@ -134,18 +134,16 @@ public class KubernetesTaskRunner implements TaskLogStreamer, TaskRunner
|
|||
@Override
|
||||
public ListenableFuture<TaskStatus> run(Task task)
|
||||
{
|
||||
synchronized (tasks) {
|
||||
tasks.computeIfAbsent(task.getId(), k -> new KubernetesWorkItem(task, exec.submit(() -> runTask(task))));
|
||||
return tasks.get(task.getId()).getResult();
|
||||
}
|
||||
return tasks.computeIfAbsent(
|
||||
task.getId(), k -> new KubernetesWorkItem(task, exec.submit(() -> runTask(task)))
|
||||
).getResult();
|
||||
}
|
||||
|
||||
protected ListenableFuture<TaskStatus> joinAsync(Task task)
|
||||
{
|
||||
synchronized (tasks) {
|
||||
tasks.computeIfAbsent(task.getId(), k -> new KubernetesWorkItem(task, exec.submit(() -> joinTask(task))));
|
||||
return tasks.get(task.getId()).getResult();
|
||||
}
|
||||
return tasks.computeIfAbsent(
|
||||
task.getId(), k -> new KubernetesWorkItem(task, exec.submit(() -> joinTask(task)))
|
||||
).getResult();
|
||||
}
|
||||
|
||||
private TaskStatus runTask(Task task)
|
||||
|
@ -163,7 +161,6 @@ public class KubernetesTaskRunner implements TaskLogStreamer, TaskRunner
|
|||
{
|
||||
KubernetesPeonLifecycle peonLifecycle = peonLifecycleFactory.build(task);
|
||||
|
||||
synchronized (tasks) {
|
||||
KubernetesWorkItem workItem = tasks.get(task.getId());
|
||||
|
||||
if (workItem == null) {
|
||||
|
@ -175,7 +172,6 @@ public class KubernetesTaskRunner implements TaskLogStreamer, TaskRunner
|
|||
}
|
||||
|
||||
workItem.setKubernetesPeonLifecycle(peonLifecycle);
|
||||
}
|
||||
|
||||
try {
|
||||
TaskStatus taskStatus;
|
||||
|
@ -202,11 +198,9 @@ public class KubernetesTaskRunner implements TaskLogStreamer, TaskRunner
|
|||
}
|
||||
|
||||
finally {
|
||||
synchronized (tasks) {
|
||||
tasks.remove(task.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Task task, TaskStatus status)
|
||||
|
@ -322,10 +316,8 @@ public class KubernetesTaskRunner implements TaskLogStreamer, TaskRunner
|
|||
@Override
|
||||
public Collection<? extends TaskRunnerWorkItem> getKnownTasks()
|
||||
{
|
||||
synchronized (tasks) {
|
||||
return Lists.newArrayList(tasks.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -393,24 +385,20 @@ public class KubernetesTaskRunner implements TaskLogStreamer, TaskRunner
|
|||
@Override
|
||||
public Collection<TaskRunnerWorkItem> getRunningTasks()
|
||||
{
|
||||
synchronized (tasks) {
|
||||
return tasks.values()
|
||||
.stream()
|
||||
.filter(KubernetesWorkItem::isRunning)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<TaskRunnerWorkItem> getPendingTasks()
|
||||
{
|
||||
synchronized (tasks) {
|
||||
return tasks.values()
|
||||
.stream()
|
||||
.filter(KubernetesWorkItem::isPending)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue