github-advanced-security[bot] commented on code in PR #17787:
URL: https://github.com/apache/druid/pull/17787#discussion_r1987090684


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/worker/DartWorkerClientImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.msq.dart.worker;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.Pair;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
+import org.apache.druid.msq.dart.controller.sql.DartSqlEngine;
+import org.apache.druid.msq.dart.worker.http.DartWorkerResource;
+import org.apache.druid.msq.exec.WorkerClient;
+import org.apache.druid.msq.rpc.BaseWorkerClientImpl;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.IgnoreHttpResponseHandler;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.ServiceRetryPolicy;
+import org.apache.druid.utils.CloseableUtils;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+
+import javax.annotation.Nullable;
+import java.io.Closeable;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Dart implementation of {@link WorkerClient}. Uses the same {@link 
BaseWorkerClientImpl} as the task-based engine.
+ * Each instance of this class is scoped to a single query.
+ */
+public class DartWorkerClientImpl extends BaseWorkerClientImpl implements 
DartWorkerClient
+{
+  private static final Logger log = new Logger(DartWorkerClientImpl.class);
+
+  private final String queryId;
+  private final ServiceClientFactory clientFactory;
+  private final ServiceRetryPolicy retryPolicy;
+
+  @Nullable
+  private final String controllerHost;
+
+  @GuardedBy("clientMap")
+  private final Map<String, Pair<ServiceClient, Closeable>> clientMap = new 
HashMap<>();
+
+  /**
+   * Create a worker client.
+   *
+   * @param queryId        dart query ID. see {@link 
DartSqlEngine#CTX_DART_QUERY_ID}
+   * @param clientFactory  service client factor
+   * @param smileMapper    Smile object mapper
+   * @param controllerHost Controller host (see {@link 
DartWorkerResource#HEADER_CONTROLLER_HOST}) if this is a
+   *                       controller-to-worker client. Null if this is a 
worker-to-worker client.
+   */
+  public DartWorkerClientImpl(
+      final String queryId,
+      final ServiceClientFactory clientFactory,
+      final ObjectMapper smileMapper,
+      @Nullable final String controllerHost
+  )
+  {
+    super(smileMapper, SmileMediaTypes.APPLICATION_JACKSON_SMILE);
+    this.queryId = queryId;
+    this.clientFactory = clientFactory;
+    this.controllerHost = controllerHost;
+
+    if (controllerHost == null) {
+      // worker -> worker client. Retry HTTP 503 in case worker A starts up 
before worker B, and needs to
+      // contact it immediately.
+      this.retryPolicy = new DartWorkerRetryPolicy(true);
+    } else {
+      // controller -> worker client. Do not retry any HTTP error codes. If we 
retry HTTP 503 for controller -> worker,
+      // we can get stuck trying to contact workers that have exited.
+      this.retryPolicy = new DartWorkerRetryPolicy(false);
+    }
+  }
+
+  @Override
+  protected ServiceClient getClient(final String workerIdString)
+  {
+    final WorkerId workerId = WorkerId.fromString(workerIdString);
+    if (!queryId.equals(workerId.getQueryId())) {
+      throw DruidException.defensive("Unexpected queryId[%s]. Expected 
queryId[%s]", workerId.getQueryId(), queryId);
+    }
+
+    synchronized (clientMap) {
+      return clientMap.computeIfAbsent(workerId.getHostAndPort(), ignored -> 
makeNewClient(workerId)).left();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public void closeClient(final String workerHost)

Review Comment:
   ## Missing Override annotation
   
   This method overrides [DartWorkerClient.closeClient](1); it is advisable to 
add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5058)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,
+        ServiceClientFactory clientFactory,

Review Comment:
   ## Useless parameter
   
   The parameter 'clientFactory' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8712)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,
+        ServiceClientFactory clientFactory,
+        ObjectMapper smileMapper,

Review Comment:
   ## Useless parameter
   
   The parameter 'smileMapper' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8713)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,

Review Comment:
   ## Useless parameter
   
   The parameter 'queryId' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5051)



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/worker/DartWorkerClientImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.msq.dart.worker;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.Pair;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
+import org.apache.druid.msq.dart.controller.sql.DartSqlEngine;
+import org.apache.druid.msq.dart.worker.http.DartWorkerResource;
+import org.apache.druid.msq.exec.WorkerClient;
+import org.apache.druid.msq.rpc.BaseWorkerClientImpl;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.IgnoreHttpResponseHandler;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.ServiceRetryPolicy;
+import org.apache.druid.utils.CloseableUtils;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+
+import javax.annotation.Nullable;
+import java.io.Closeable;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Dart implementation of {@link WorkerClient}. Uses the same {@link 
BaseWorkerClientImpl} as the task-based engine.
+ * Each instance of this class is scoped to a single query.
+ */
+public class DartWorkerClientImpl extends BaseWorkerClientImpl implements 
DartWorkerClient
+{
+  private static final Logger log = new Logger(DartWorkerClientImpl.class);
+
+  private final String queryId;
+  private final ServiceClientFactory clientFactory;
+  private final ServiceRetryPolicy retryPolicy;
+
+  @Nullable
+  private final String controllerHost;
+
+  @GuardedBy("clientMap")
+  private final Map<String, Pair<ServiceClient, Closeable>> clientMap = new 
HashMap<>();
+
+  /**
+   * Create a worker client.
+   *
+   * @param queryId        dart query ID. see {@link 
DartSqlEngine#CTX_DART_QUERY_ID}
+   * @param clientFactory  service client factor
+   * @param smileMapper    Smile object mapper
+   * @param controllerHost Controller host (see {@link 
DartWorkerResource#HEADER_CONTROLLER_HOST}) if this is a
+   *                       controller-to-worker client. Null if this is a 
worker-to-worker client.
+   */
+  public DartWorkerClientImpl(
+      final String queryId,
+      final ServiceClientFactory clientFactory,
+      final ObjectMapper smileMapper,
+      @Nullable final String controllerHost
+  )
+  {
+    super(smileMapper, SmileMediaTypes.APPLICATION_JACKSON_SMILE);
+    this.queryId = queryId;
+    this.clientFactory = clientFactory;
+    this.controllerHost = controllerHost;
+
+    if (controllerHost == null) {
+      // worker -> worker client. Retry HTTP 503 in case worker A starts up 
before worker B, and needs to
+      // contact it immediately.
+      this.retryPolicy = new DartWorkerRetryPolicy(true);
+    } else {
+      // controller -> worker client. Do not retry any HTTP error codes. If we 
retry HTTP 503 for controller -> worker,
+      // we can get stuck trying to contact workers that have exited.
+      this.retryPolicy = new DartWorkerRetryPolicy(false);
+    }
+  }
+
+  @Override
+  protected ServiceClient getClient(final String workerIdString)
+  {
+    final WorkerId workerId = WorkerId.fromString(workerIdString);
+    if (!queryId.equals(workerId.getQueryId())) {
+      throw DruidException.defensive("Unexpected queryId[%s]. Expected 
queryId[%s]", workerId.getQueryId(), queryId);
+    }
+
+    synchronized (clientMap) {
+      return clientMap.computeIfAbsent(workerId.getHostAndPort(), ignored -> 
makeNewClient(workerId)).left();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public void closeClient(final String workerHost)
+  {
+    synchronized (clientMap) {
+      final Pair<ServiceClient, Closeable> clientPair = 
clientMap.remove(workerHost);
+      if (clientPair != null) {
+        CloseableUtils.closeAndWrapExceptions(clientPair.right());
+      }
+    }
+  }
+
+  /**
+   * Close all outstanding clients.
+   */
+  @Override
+  public void close()
+  {
+    synchronized (clientMap) {
+      for (Map.Entry<String, Pair<ServiceClient, Closeable>> entry : 
clientMap.entrySet()) {
+        CloseableUtils.closeAndSuppressExceptions(
+            entry.getValue().right(),
+            e -> log.warn(e, "Failed to close client[%s]", entry.getKey())
+        );
+      }
+
+      clientMap.clear();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public ListenableFuture<?> stopWorker(String workerId)

Review Comment:
   ## Missing Override annotation
   
   This method overrides [DartWorkerClient.stopWorker](1); it is advisable to 
add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8717)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,
+        ServiceClientFactory clientFactory,

Review Comment:
   ## Useless parameter
   
   The parameter 'clientFactory' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5052)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)

Review Comment:
   ## Missing Override annotation
   
   This method overrides [DartControllerContext.registerController](1); it is 
advisable to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5061)



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/worker/DartWorkerClientImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.msq.dart.worker;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.Pair;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
+import org.apache.druid.msq.dart.controller.sql.DartSqlEngine;
+import org.apache.druid.msq.dart.worker.http.DartWorkerResource;
+import org.apache.druid.msq.exec.WorkerClient;
+import org.apache.druid.msq.rpc.BaseWorkerClientImpl;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.IgnoreHttpResponseHandler;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.ServiceRetryPolicy;
+import org.apache.druid.utils.CloseableUtils;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+
+import javax.annotation.Nullable;
+import java.io.Closeable;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Dart implementation of {@link WorkerClient}. Uses the same {@link 
BaseWorkerClientImpl} as the task-based engine.
+ * Each instance of this class is scoped to a single query.
+ */
+public class DartWorkerClientImpl extends BaseWorkerClientImpl implements 
DartWorkerClient
+{
+  private static final Logger log = new Logger(DartWorkerClientImpl.class);
+
+  private final String queryId;
+  private final ServiceClientFactory clientFactory;
+  private final ServiceRetryPolicy retryPolicy;
+
+  @Nullable
+  private final String controllerHost;
+
+  @GuardedBy("clientMap")
+  private final Map<String, Pair<ServiceClient, Closeable>> clientMap = new 
HashMap<>();
+
+  /**
+   * Create a worker client.
+   *
+   * @param queryId        dart query ID. see {@link 
DartSqlEngine#CTX_DART_QUERY_ID}
+   * @param clientFactory  service client factor
+   * @param smileMapper    Smile object mapper
+   * @param controllerHost Controller host (see {@link 
DartWorkerResource#HEADER_CONTROLLER_HOST}) if this is a
+   *                       controller-to-worker client. Null if this is a 
worker-to-worker client.
+   */
+  public DartWorkerClientImpl(
+      final String queryId,
+      final ServiceClientFactory clientFactory,
+      final ObjectMapper smileMapper,
+      @Nullable final String controllerHost
+  )
+  {
+    super(smileMapper, SmileMediaTypes.APPLICATION_JACKSON_SMILE);
+    this.queryId = queryId;
+    this.clientFactory = clientFactory;
+    this.controllerHost = controllerHost;
+
+    if (controllerHost == null) {
+      // worker -> worker client. Retry HTTP 503 in case worker A starts up 
before worker B, and needs to
+      // contact it immediately.
+      this.retryPolicy = new DartWorkerRetryPolicy(true);
+    } else {
+      // controller -> worker client. Do not retry any HTTP error codes. If we 
retry HTTP 503 for controller -> worker,
+      // we can get stuck trying to contact workers that have exited.
+      this.retryPolicy = new DartWorkerRetryPolicy(false);
+    }
+  }
+
+  @Override
+  protected ServiceClient getClient(final String workerIdString)
+  {
+    final WorkerId workerId = WorkerId.fromString(workerIdString);
+    if (!queryId.equals(workerId.getQueryId())) {
+      throw DruidException.defensive("Unexpected queryId[%s]. Expected 
queryId[%s]", workerId.getQueryId(), queryId);
+    }
+
+    synchronized (clientMap) {
+      return clientMap.computeIfAbsent(workerId.getHostAndPort(), ignored -> 
makeNewClient(workerId)).left();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public void closeClient(final String workerHost)
+  {
+    synchronized (clientMap) {
+      final Pair<ServiceClient, Closeable> clientPair = 
clientMap.remove(workerHost);
+      if (clientPair != null) {
+        CloseableUtils.closeAndWrapExceptions(clientPair.right());
+      }
+    }
+  }
+
+  /**
+   * Close all outstanding clients.
+   */
+  @Override
+  public void close()
+  {
+    synchronized (clientMap) {
+      for (Map.Entry<String, Pair<ServiceClient, Closeable>> entry : 
clientMap.entrySet()) {
+        CloseableUtils.closeAndSuppressExceptions(
+            entry.getValue().right(),
+            e -> log.warn(e, "Failed to close client[%s]", entry.getKey())
+        );
+      }
+
+      clientMap.clear();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public ListenableFuture<?> stopWorker(String workerId)

Review Comment:
   ## Missing Override annotation
   
   This method overrides [DartWorkerClient.stopWorker](1); it is advisable to 
add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5057)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,

Review Comment:
   ## Useless parameter
   
   The parameter 'queryId' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8711)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,
+        ServiceClientFactory clientFactory,
+        ObjectMapper smileMapper,

Review Comment:
   ## Useless parameter
   
   The parameter 'smileMapper' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5053)



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/dart/worker/DartWorkerClientImpl.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.msq.dart.worker;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.Pair;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
+import org.apache.druid.msq.dart.controller.sql.DartSqlEngine;
+import org.apache.druid.msq.dart.worker.http.DartWorkerResource;
+import org.apache.druid.msq.exec.WorkerClient;
+import org.apache.druid.msq.rpc.BaseWorkerClientImpl;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.IgnoreHttpResponseHandler;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.ServiceRetryPolicy;
+import org.apache.druid.utils.CloseableUtils;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+
+import javax.annotation.Nullable;
+import java.io.Closeable;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Dart implementation of {@link WorkerClient}. Uses the same {@link 
BaseWorkerClientImpl} as the task-based engine.
+ * Each instance of this class is scoped to a single query.
+ */
+public class DartWorkerClientImpl extends BaseWorkerClientImpl implements 
DartWorkerClient
+{
+  private static final Logger log = new Logger(DartWorkerClientImpl.class);
+
+  private final String queryId;
+  private final ServiceClientFactory clientFactory;
+  private final ServiceRetryPolicy retryPolicy;
+
+  @Nullable
+  private final String controllerHost;
+
+  @GuardedBy("clientMap")
+  private final Map<String, Pair<ServiceClient, Closeable>> clientMap = new 
HashMap<>();
+
+  /**
+   * Create a worker client.
+   *
+   * @param queryId        dart query ID. see {@link 
DartSqlEngine#CTX_DART_QUERY_ID}
+   * @param clientFactory  service client factor
+   * @param smileMapper    Smile object mapper
+   * @param controllerHost Controller host (see {@link 
DartWorkerResource#HEADER_CONTROLLER_HOST}) if this is a
+   *                       controller-to-worker client. Null if this is a 
worker-to-worker client.
+   */
+  public DartWorkerClientImpl(
+      final String queryId,
+      final ServiceClientFactory clientFactory,
+      final ObjectMapper smileMapper,
+      @Nullable final String controllerHost
+  )
+  {
+    super(smileMapper, SmileMediaTypes.APPLICATION_JACKSON_SMILE);
+    this.queryId = queryId;
+    this.clientFactory = clientFactory;
+    this.controllerHost = controllerHost;
+
+    if (controllerHost == null) {
+      // worker -> worker client. Retry HTTP 503 in case worker A starts up 
before worker B, and needs to
+      // contact it immediately.
+      this.retryPolicy = new DartWorkerRetryPolicy(true);
+    } else {
+      // controller -> worker client. Do not retry any HTTP error codes. If we 
retry HTTP 503 for controller -> worker,
+      // we can get stuck trying to contact workers that have exited.
+      this.retryPolicy = new DartWorkerRetryPolicy(false);
+    }
+  }
+
+  @Override
+  protected ServiceClient getClient(final String workerIdString)
+  {
+    final WorkerId workerId = WorkerId.fromString(workerIdString);
+    if (!queryId.equals(workerId.getQueryId())) {
+      throw DruidException.defensive("Unexpected queryId[%s]. Expected 
queryId[%s]", workerId.getQueryId(), queryId);
+    }
+
+    synchronized (clientMap) {
+      return clientMap.computeIfAbsent(workerId.getHostAndPort(), ignored -> 
makeNewClient(workerId)).left();
+    }
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public void closeClient(final String workerHost)

Review Comment:
   ## Missing Override annotation
   
   This method overrides [DartWorkerClient.closeClient](1); it is advisable to 
add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8718)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,
+        ServiceClientFactory clientFactory,
+        ObjectMapper smileMapper,
+        String controllerHost, Map<String, Worker> workerMap)

Review Comment:
   ## Useless parameter
   
   The parameter 'controllerHost' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8714)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)
+      {
+        super.registerController(currentController, closer);
+        controller = currentController;
+      }
+    };
+  }
+
+  public class DartTestWorkerClient extends MSQTestWorkerClient implements 
DartWorkerClient
+  {
+    private final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
+
+    public DartTestWorkerClient(
+        String queryId,
+        ServiceClientFactory clientFactory,
+        ObjectMapper smileMapper,
+        String controllerHost, Map<String, Worker> workerMap)

Review Comment:
   ## Useless parameter
   
   The parameter 'controllerHost' is never used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5054)



##########
extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/TestDartControllerContextFactoryImpl.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.msq.test;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import org.apache.druid.client.TimelineServerView;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.guice.annotations.Self;
+import org.apache.druid.guice.annotations.Smile;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.msq.dart.Dart;
+import org.apache.druid.msq.dart.controller.DartControllerContext;
+import org.apache.druid.msq.dart.controller.DartControllerContextFactoryImpl;
+import org.apache.druid.msq.dart.worker.DartWorkerClient;
+import org.apache.druid.msq.exec.Controller;
+import org.apache.druid.msq.exec.ControllerContext;
+import org.apache.druid.msq.exec.MemoryIntrospector;
+import org.apache.druid.msq.exec.Worker;
+import org.apache.druid.msq.exec.WorkerImpl;
+import org.apache.druid.msq.exec.WorkerStorageParameters;
+import org.apache.druid.msq.kernel.StageId;
+import org.apache.druid.msq.kernel.WorkOrder;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.DruidNode;
+
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class TestDartControllerContextFactoryImpl extends 
DartControllerContextFactoryImpl
+{
+  private Map<String, Worker> workerMap;
+  public Controller controller;
+
+  @Inject
+  public TestDartControllerContextFactoryImpl(
+      final Injector injector,
+      @Json final ObjectMapper jsonMapper,
+      @Smile final ObjectMapper smileMapper,
+      @Self final DruidNode selfNode,
+      @EscalatedGlobal final ServiceClientFactory serviceClientFactory,
+      final MemoryIntrospector memoryIntrospector,
+      final TimelineServerView serverView,
+      final ServiceEmitter emitter,
+      @Dart Map<String, Worker> workerMap)
+  {
+    super(injector, jsonMapper, smileMapper, selfNode, serviceClientFactory, 
memoryIntrospector, serverView, emitter);
+    this.workerMap = workerMap;
+  }
+
+  @Override
+  public ControllerContext newContext(String queryId)
+  {
+    return new DartControllerContext(
+        injector,
+        jsonMapper,
+        selfNode,
+        new DartTestWorkerClient(queryId, serviceClientFactory, smileMapper, 
selfNode.getHostAndPortToUse(), workerMap),
+        memoryIntrospector,
+        serverView,
+        emitter
+    )
+    {
+      public void registerController(Controller currentController, Closer 
closer)

Review Comment:
   ## Missing Override annotation
   
   This method overrides [DartControllerContext.registerController](1); it is 
advisable to add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/8719)



-- 
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]

Reply via email to