cryptoe commented on code in PR #12696:
URL: https://github.com/apache/druid/pull/12696#discussion_r912896599
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexSupervisorTaskClient.java:
##########
@@ -19,122 +19,28 @@
package org.apache.druid.indexing.common.task.batch.parallel;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.druid.indexing.common.IndexTaskClient;
-import org.apache.druid.indexing.common.TaskInfoProvider;
-import org.apache.druid.java.util.common.ISE;
-import org.apache.druid.java.util.http.client.HttpClient;
-import
org.apache.druid.java.util.http.client.response.StringFullResponseHolder;
import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
-import org.jboss.netty.handler.codec.http.HttpMethod;
import org.joda.time.DateTime;
-import org.joda.time.Duration;
import javax.annotation.Nullable;
import java.io.IOException;
-public class ParallelIndexSupervisorTaskClient extends IndexTaskClient
+public interface ParallelIndexSupervisorTaskClient
{
- ParallelIndexSupervisorTaskClient(
- HttpClient httpClient,
- ObjectMapper objectMapper,
- TaskInfoProvider taskInfoProvider,
- Duration httpTimeout,
- String callerId,
- long numRetries
- )
- {
- super(httpClient, objectMapper, taskInfoProvider, httpTimeout, callerId,
1, numRetries);
- }
-
/**
* See {@link SinglePhaseParallelIndexTaskRunner#allocateNewSegment(String,
DateTime)}.
*/
@Deprecated
- public SegmentIdWithShardSpec allocateSegment(String supervisorTaskId,
DateTime timestamp) throws IOException
- {
- final StringFullResponseHolder response = submitSmileRequest(
- supervisorTaskId,
- HttpMethod.POST,
- "segment/allocate",
- null,
- serialize(timestamp),
- true
- );
- if (!isSuccess(response)) {
- throw new ISE(
- "task[%s] failed to allocate a new segment identifier with the HTTP
code[%d] and content[%s]",
- supervisorTaskId,
- response.getStatus().getCode(),
- response.getContent()
- );
- } else {
- return deserialize(
- response.getContent(),
- new TypeReference<SegmentIdWithShardSpec>()
- {
- }
- );
- }
- }
+ SegmentIdWithShardSpec allocateSegment(DateTime timestamp) throws
IOException;
/**
* See {@link SinglePhaseParallelIndexTaskRunner#allocateNewSegment(String,
DateTime, String, String)}.
*/
- public SegmentIdWithShardSpec allocateSegment(
- String supervisorTaskId,
+ SegmentIdWithShardSpec allocateSegment(
DateTime timestamp,
String sequenceName,
@Nullable String prevSegmentId
- ) throws IOException
- {
- final StringFullResponseHolder response = submitSmileRequest(
- supervisorTaskId,
- HttpMethod.POST,
- "segment/allocate",
- null,
- serialize(new SegmentAllocationRequest(timestamp, sequenceName,
prevSegmentId)),
- true
- );
- if (!isSuccess(response)) {
- throw new ISE(
- "task[%s] failed to allocate a new segment identifier with the HTTP
code[%d] and content[%s]",
- supervisorTaskId,
- response.getStatus().getCode(),
- response.getContent()
- );
- } else {
- return deserialize(
- response.getContent(),
- new TypeReference<SegmentIdWithShardSpec>()
- {
- }
- );
- }
- }
+ ) throws IOException;
- public void report(String supervisorTaskId, SubTaskReport report)
- {
- try {
- final StringFullResponseHolder response = submitSmileRequest(
- supervisorTaskId,
- HttpMethod.POST,
- "report",
- null,
- serialize(report),
- true
- );
- if (!isSuccess(response)) {
- throw new ISE(
- "Failed to send taskReports to task[%s] with the HTTP code [%d]",
- supervisorTaskId,
- response.getStatus().getCode()
- );
- }
- }
- catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ void report(SubTaskReport report);
Review Comment:
Super Nit: as this is a interface, IMHO we should documentation to this
method
##########
server/src/main/java/org/apache/druid/rpc/ServiceClientImpl.java:
##########
@@ -0,0 +1,424 @@
+/*
+ * 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.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.apache.druid.java.util.common.Either;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.http.client.HttpClient;
+import org.apache.druid.java.util.http.client.Request;
+import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
+import
org.apache.druid.java.util.http.client.response.ObjectOrErrorResponseHandler;
+import
org.apache.druid.java.util.http.client.response.StringFullResponseHolder;
+import org.jboss.netty.handler.codec.http.HttpResponseStatus;
+
+import javax.annotation.Nullable;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Consumer;
+
+/**
+ * Production implementation of {@link ServiceClient}.
+ */
+public class ServiceClientImpl implements ServiceClient
Review Comment:
Should we implement this in an autoCloseable?
In case of a `close/shutdown` or an error condition
1. we should not schedule new async requests (infinite retry case)
2. Wait for existing requests to either timeout or abort them. I guess that
would depend if the shutdown is gracefully or not.
--
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]