github-code-scanning[bot] commented on code in PR #15024:
URL: https://github.com/apache/druid/pull/15024#discussion_r1333911713


##########
server/src/main/java/org/apache/druid/rpc/ServiceLocation.java:
##########
@@ -47,6 +52,37 @@
     return new ServiceLocation(druidNode.getHost(), 
druidNode.getPlaintextPort(), druidNode.getTlsPort(), "");
   }
 
+  private static final Splitter SPLITTER = Splitter.on(":").limit(2);
+
+  public static ServiceLocation fromDruidServerMetadata(final 
DruidServerMetadata druidServerMetadata)
+  {
+    final String host = 
getHostFromString(druidServerMetadata.getHostAndPort());
+    int plaintextPort = 
getPortFromString(druidServerMetadata.getHostAndPort());
+    int tlsPort = getPortFromString(druidServerMetadata.getHostAndTlsPort());
+    return new ServiceLocation(host, plaintextPort, tlsPort, "");
+  }
+
+  @Nullable
+  private static String getHostFromString(String s)
+  {
+    if (s == null) {
+      return null;
+    }
+    Iterator<String> iterator = SPLITTER.split(s).iterator();
+    ImmutableList<String> strings = ImmutableList.copyOf(iterator);
+    return strings.get(0);
+  }
+
+  private static int getPortFromString(String s)
+  {
+    if (s == null) {
+      return -1;
+    }
+    Iterator<String> iterator = SPLITTER.split(s).iterator();
+    ImmutableList<String> strings = ImmutableList.copyOf(iterator);
+    return Integer.parseInt(strings.get(1));

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5819)



##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/exec/TaskDataSegmentProvider.java:
##########
@@ -143,6 +161,43 @@
     }
   }
 
+  @Override
+  public Function<Query<Object>, ResourceHolder<Sequence<Object>>> 
fetchLoadedSegment(
+      RichSegmentDescriptor segmentDescriptor,
+      String dataSource,
+      ChannelCounters channelCounters
+  )
+  {
+    return query -> fetchServedSegmentInternal(
+        segmentDescriptor,
+        dataSource,
+        channelCounters,
+        query
+    );
+  }
+
+  private <T> ResourceHolder<Sequence<T>> fetchServedSegmentInternal(
+      RichSegmentDescriptor segmentDescriptor,
+      String dataSource,
+      ChannelCounters channelCounters,

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



##########
server/src/main/java/org/apache/druid/rpc/FixedSetServiceLocator.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.rpc;
+
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.druid.server.coordination.DruidServerMetadata;
+import org.jboss.netty.util.internal.ThreadLocalRandom;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Basic implmentation of {@link ServiceLocator} that returns a service 
location from a static set of locations. Returns
+ * a random location each time one is requested.
+ */
+public class FixedSetServiceLocator implements ServiceLocator
+{
+  private ServiceLocations serviceLocations;
+
+  public FixedSetServiceLocator(Set<DruidServerMetadata> servers)
+  {
+    if (servers == null) {
+      serviceLocations = ServiceLocations.closed();
+    } else {
+      Set<ServiceLocation> serviceLocationSet = servers.stream()
+                                                       
.map(ServiceLocation::fromDruidServerMetadata)
+                                                       
.collect(Collectors.toSet());
+      serviceLocations = ServiceLocations.forLocations(serviceLocationSet);
+    }
+  }
+
+  @Override
+  public ListenableFuture<ServiceLocations> locate()
+  {
+    if (serviceLocations.isClosed() || 
serviceLocations.getLocations().isEmpty()) {
+      return Futures.immediateFuture(ServiceLocations.closed());
+    }
+
+    Set<ServiceLocation> locationSet = serviceLocations.getLocations();
+    return Futures.immediateFuture(
+        ServiceLocations.forLocation(
+            locationSet.stream()
+                       .skip(new 
ThreadLocalRandom().nextInt(locationSet.size()))

Review Comment:
   ## Random used only once
   
   Random object created and used only once.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/5820)



##########
server/src/main/java/org/apache/druid/discovery/DataServerClient.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.discovery;
+
+import com.fasterxml.jackson.databind.JavaType;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.druid.client.JsonParserIterator;
+import org.apache.druid.collections.ResourceHolder;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.guava.BaseSequence;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.logger.Logger;
+import 
org.apache.druid.java.util.http.client.response.InputStreamResponseHandler;
+import org.apache.druid.java.util.http.client.response.StatusResponseHandler;
+import org.apache.druid.java.util.http.client.response.StatusResponseHolder;
+import org.apache.druid.query.Query;
+import org.apache.druid.query.context.ResponseContext;
+import org.apache.druid.query.groupby.ResultRow;
+import org.apache.druid.query.scan.ScanQuery;
+import org.apache.druid.query.scan.ScanResultValue;
+import org.apache.druid.rpc.FixedSetServiceLocator;
+import org.apache.druid.rpc.RequestBuilder;
+import org.apache.druid.rpc.ServiceClient;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.utils.CloseableUtils;
+import org.jboss.netty.handler.codec.http.HttpMethod;
+
+import java.io.InputStream;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Client to query data servers given a query.
+ */
+public class DataServerClient<T>
+{
+  private static final Logger log = new Logger(DataServerClient.class);
+  private static final String SERVED_SEGMENT_CLIENT_NAME = 
"ServedSegmentClient";
+  private final ServiceClient serviceClient;
+  private final ObjectMapper objectMapper;
+  private final ScheduledExecutorService queryCancellationExecutor;
+
+  public DataServerClient(
+      ServiceClientFactory serviceClientFactory,
+      FixedSetServiceLocator fixedSetServiceLocator,
+      ObjectMapper objectMapper
+  )
+  {
+    serviceClient = serviceClientFactory.makeClient(
+        SERVED_SEGMENT_CLIENT_NAME,
+        fixedSetServiceLocator,
+        StandardRetryPolicy.aboutAnHour()
+    );
+    this.objectMapper = objectMapper;
+    this.queryCancellationExecutor = 
Execs.scheduledSingleThreaded("query-cancellation-executor");
+  }
+
+
+  public ResourceHolder<Sequence<T>> run(Query<T> query, ResponseContext 
context)

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



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