Search in sources :

Example 1 with RetryPolicy

use of org.apache.druid.indexing.common.RetryPolicy in project druid by druid-io.

the class RemoteTaskActionClient method submit.

@Override
public <RetType> RetType submit(TaskAction<RetType> taskAction) throws IOException {
    log.debug("Performing action for task[%s]: %s", task.getId(), taskAction);
    byte[] dataToSend = jsonMapper.writeValueAsBytes(new TaskActionHolder(task, taskAction));
    final RetryPolicy retryPolicy = retryPolicyFactory.makeRetryPolicy();
    while (true) {
        try {
            final StringFullResponseHolder fullResponseHolder;
            log.debug("Submitting action for task[%s] to Overlord: %s", task.getId(), jsonMapper.writeValueAsString(taskAction));
            fullResponseHolder = druidLeaderClient.go(druidLeaderClient.makeRequest(HttpMethod.POST, "/druid/indexer/v1/action").setContent(MediaType.APPLICATION_JSON, dataToSend));
            if (fullResponseHolder.getStatus().getCode() / 100 == 2) {
                final Map<String, Object> responseDict = jsonMapper.readValue(fullResponseHolder.getContent(), JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT);
                return jsonMapper.convertValue(responseDict.get("result"), taskAction.getReturnTypeReference());
            } else {
                // Want to retry, so throw an IOException.
                throw new IOE("Error with status[%s] and message[%s]. Check overlord logs for details.", fullResponseHolder.getStatus(), fullResponseHolder.getContent());
            }
        } catch (IOException | ChannelException e) {
            log.noStackTrace().warn(e, "Exception submitting action for task[%s]: %s", task.getId(), jsonMapper.writeValueAsString(taskAction));
            final Duration delay = retryPolicy.getAndIncrementRetryDelay();
            if (delay == null) {
                throw e;
            } else {
                try {
                    final long sleepTime = jitter(delay.getMillis());
                    log.warn("Will try again in [%s].", new Duration(sleepTime).toString());
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e2) {
                    throw new RuntimeException(e2);
                }
            }
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Duration(org.joda.time.Duration) IOException(java.io.IOException) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) RetryPolicy(org.apache.druid.indexing.common.RetryPolicy) IOE(org.apache.druid.java.util.common.IOE) ChannelException(org.jboss.netty.channel.ChannelException)

Example 2 with RetryPolicy

use of org.apache.druid.indexing.common.RetryPolicy in project druid by druid-io.

the class SeekableStreamIndexTaskClient method pause.

public Map<PartitionIdType, SequenceOffsetType> pause(final String id) {
    log.debug("Pause task[%s]", id);
    try {
        final StringFullResponseHolder response = submitRequestWithEmptyContent(id, HttpMethod.POST, "pause", null, true);
        final HttpResponseStatus responseStatus = response.getStatus();
        final String responseContent = response.getContent();
        if (responseStatus.equals(HttpResponseStatus.OK)) {
            log.info("Task [%s] paused successfully", id);
            return deserializeMap(responseContent, Map.class, getPartitionType(), getSequenceType());
        } else if (responseStatus.equals(HttpResponseStatus.ACCEPTED)) {
            // The task received the pause request, but its status hasn't been changed yet.
            final RetryPolicy retryPolicy = newRetryPolicy();
            while (true) {
                final SeekableStreamIndexTaskRunner.Status status = getStatus(id);
                if (status == SeekableStreamIndexTaskRunner.Status.PAUSED) {
                    return getCurrentOffsets(id, true);
                }
                final Duration delay = retryPolicy.getAndIncrementRetryDelay();
                if (delay == null) {
                    throw new ISE("Task [%s] failed to change its status from [%s] to [%s], aborting", id, status, SeekableStreamIndexTaskRunner.Status.PAUSED);
                } else {
                    final long sleepTime = delay.getMillis();
                    log.info("Still waiting for task [%s] to change its status to [%s]; will try again in [%s]", id, SeekableStreamIndexTaskRunner.Status.PAUSED, new Duration(sleepTime).toString());
                    Thread.sleep(sleepTime);
                }
            }
        } else {
            throw new ISE("Pause request for task [%s] failed with response [%s] : [%s]", id, responseStatus, responseContent);
        }
    } catch (NoTaskLocationException e) {
        log.error("Exception [%s] while pausing Task [%s]", e.getMessage(), id);
        return ImmutableMap.of();
    } catch (IOException | InterruptedException e) {
        throw new RE(e, "Exception [%s] while pausing Task [%s]", e.getMessage(), id);
    }
}
Also used : HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) RE(org.apache.druid.java.util.common.RE) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) Duration(org.joda.time.Duration) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) RetryPolicy(org.apache.druid.indexing.common.RetryPolicy)

Example 3 with RetryPolicy

use of org.apache.druid.indexing.common.RetryPolicy in project druid by druid-io.

the class DruidInputSource method getTimelineForInterval.

public static List<TimelineObjectHolder<String, DataSegment>> getTimelineForInterval(CoordinatorClient coordinatorClient, RetryPolicyFactory retryPolicyFactory, String dataSource, Interval interval) {
    Preconditions.checkNotNull(interval);
    // This call used to use the TaskActionClient, so for compatibility we use the same retry configuration
    // as TaskActionClient.
    final RetryPolicy retryPolicy = retryPolicyFactory.makeRetryPolicy();
    Collection<DataSegment> usedSegments;
    while (true) {
        try {
            usedSegments = coordinatorClient.fetchUsedSegmentsInDataSourceForIntervals(dataSource, Collections.singletonList(interval));
            break;
        } catch (Throwable e) {
            LOG.warn(e, "Exception getting database segments");
            final Duration delay = retryPolicy.getAndIncrementRetryDelay();
            if (delay == null) {
                throw e;
            } else {
                final long sleepTime = jitter(delay.getMillis());
                LOG.info("Will try again in [%s].", new Duration(sleepTime).toString());
                try {
                    Thread.sleep(sleepTime);
                } catch (InterruptedException e2) {
                    throw new RuntimeException(e2);
                }
            }
        }
    }
    return VersionedIntervalTimeline.forSegments(usedSegments).lookup(interval);
}
Also used : Duration(org.joda.time.Duration) RetryPolicy(org.apache.druid.indexing.common.RetryPolicy) DataSegment(org.apache.druid.timeline.DataSegment)

Aggregations

RetryPolicy (org.apache.druid.indexing.common.RetryPolicy)3 Duration (org.joda.time.Duration)3 IOException (java.io.IOException)2 StringFullResponseHolder (org.apache.druid.java.util.http.client.response.StringFullResponseHolder)2 IOE (org.apache.druid.java.util.common.IOE)1 ISE (org.apache.druid.java.util.common.ISE)1 RE (org.apache.druid.java.util.common.RE)1 DataSegment (org.apache.druid.timeline.DataSegment)1 ChannelException (org.jboss.netty.channel.ChannelException)1 HttpResponseStatus (org.jboss.netty.handler.codec.http.HttpResponseStatus)1