github-advanced-security[bot] commented on code in PR #16889:
URL: https://github.com/apache/druid/pull/16889#discussion_r1714871826
##########
indexing-service/src/main/java/org/apache/druid/indexing/overlord/config/TaskQueueConfig.java:
##########
@@ -64,6 +74,15 @@
this.restartDelay = defaultDuration(restartDelay, "PT30S");
this.storageSyncRate = defaultDuration(storageSyncRate, "PT1M");
this.maxTaskPayloadSize = maxTaskPayloadSize;
+ if (controllerTaskSlotRatio != null && maxControllerTaskSlots != null) {
+ throw new IllegalArgumentException(
+ "Only one controller task limit parameter should be specified,
controllerTaskSlotRatio or maxControllerTaskSlots");
+ } else if (controllerTaskSlotRatio != null && controllerTaskSlotRatio > 1
&& controllerTaskSlotRatio <= 0) {
Review Comment:
## Useless comparison test
Test is always false, because of [this condition](1).
[Show more
details](https://github.com/apache/druid/security/code-scanning/7707)
##########
indexing-service/src/test/java/org/apache/druid/indexing/overlord/SimpleTaskRunner.java:
##########
@@ -0,0 +1,325 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.indexing.overlord;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import org.apache.druid.indexer.RunnerTaskState;
+import org.apache.druid.indexer.TaskLocation;
+import org.apache.druid.indexer.TaskStatus;
+import org.apache.druid.indexing.common.task.NoopTask;
+import org.apache.druid.indexing.common.task.Task;
+import org.apache.druid.indexing.overlord.autoscaling.ScalingStats;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.java.util.common.concurrent.ScheduledExecutors;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.joda.time.Duration;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class SimpleTaskRunner implements TaskRunner
+{
+ private static final Logger log = new Logger(TestTaskRunner.class);
+ private static final Duration T_PENDING_TO_RUNNING =
Duration.standardSeconds(2);
+ private static final Duration T_SHUTDOWN_ACK = Duration.millis(8);
+ private static final Duration T_SHUTDOWN_COMPLETE =
Duration.standardSeconds(2);
+ @GuardedBy("knownTasks")
+ private final Map<String, TestTaskRunnerWorkItem> knownTasks = new
HashMap<>();
+ private final ScheduledExecutorService exec = ScheduledExecutors.fixed(8,
"TaskQueueScaleTest-%s");
+ private int capacity;
+
+ public SimpleTaskRunner(final int capacity)
+ {
+ this.capacity = capacity;
+ }
+
+ public SimpleTaskRunner()
+ {
+ capacity = -1;
+ }
+
+ static void threadSleep(Duration duration)
+ {
+ try {
+ Thread.sleep(duration.getMillis());
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void start()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ListenableFuture<TaskStatus> run(Task task)
+ {
+ // Production task runners generally do not take a long time to execute
"run", but may take a long time to
+ // go from "running" to "pending".
+ synchronized (knownTasks) {
+ final TestTaskRunnerWorkItem item = knownTasks.computeIfAbsent(
+ task.getId(),
+ id -> new TestTaskRunnerWorkItem(
+ id,
+ task.getType()
+ )
+ );
+ exec.schedule(
+ () -> {
+ try {
+ synchronized (knownTasks) {
+ final TestTaskRunnerWorkItem item2 =
knownTasks.get(task.getId());
+ if (item2.getState() == RunnerTaskState.PENDING) {
+ knownTasks.put(task.getId(),
item2.withState(RunnerTaskState.RUNNING));
+ }
+ }
+
+ exec.schedule(
+ () -> {
+ try {
+ final TestTaskRunnerWorkItem item2;
+ synchronized (knownTasks) {
+ item2 = knownTasks.get(task.getId());
+ knownTasks.put(task.getId(),
item2.withState(RunnerTaskState.NONE));
Review Comment:
## Dereferenced variable may be null
Variable [item2](1) may be null at this access as suggested by [this](2)
null guard.
[Show more
details](https://github.com/apache/druid/security/code-scanning/7708)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]