use of io.airlift.http.client.Request in project presto by prestodb.
the class StatementClient method close.
@Override
public void close() {
if (!closed.getAndSet(true)) {
URI uri = currentResults.get().getNextUri();
if (uri != null) {
Request request = prepareRequest(prepareDelete(), uri).build();
httpClient.executeAsync(request, createStatusResponseHandler());
}
}
}
use of io.airlift.http.client.Request in project presto by prestodb.
the class StatementClient method cancelLeafStage.
public boolean cancelLeafStage(Duration timeout) {
checkState(!isClosed(), "client is closed");
URI uri = current().getPartialCancelUri();
if (uri == null) {
return false;
}
Request request = prepareRequest(prepareDelete(), uri).build();
HttpResponseFuture<StatusResponse> response = httpClient.executeAsync(request, createStatusResponseHandler());
try {
StatusResponse status = response.get(timeout.toMillis(), MILLISECONDS);
return familyForStatusCode(status.getStatusCode()) == Family.SUCCESSFUL;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Throwables.propagate(e);
} catch (ExecutionException e) {
throw Throwables.propagate(e.getCause());
} catch (TimeoutException e) {
return false;
}
}
use of io.airlift.http.client.Request in project presto by prestodb.
the class ContinuousTaskStatusFetcher method scheduleNextRequest.
private synchronized void scheduleNextRequest() {
// stopped or done?
TaskStatus taskStatus = getTaskStatus();
if (!running || taskStatus.getState().isDone()) {
return;
}
// outstanding request?
if (future != null && !future.isDone()) {
// this should never happen
log.error("Can not reschedule update because an update is already running");
return;
}
// if throttled due to error, asynchronously wait for timeout and try again
ListenableFuture<?> errorRateLimit = errorTracker.acquireRequestPermit();
if (!errorRateLimit.isDone()) {
errorRateLimit.addListener(this::scheduleNextRequest, executor);
return;
}
Request request = prepareGet().setUri(uriBuilderFrom(taskStatus.getSelf()).appendPath("status").build()).setHeader(CONTENT_TYPE, JSON_UTF_8.toString()).setHeader(PRESTO_CURRENT_STATE, taskStatus.getState().toString()).setHeader(PRESTO_MAX_WAIT, refreshMaxWait.toString()).build();
errorTracker.startRequest();
future = httpClient.executeAsync(request, createFullJsonResponseHandler(taskStatusCodec));
currentRequestStartNanos.set(System.nanoTime());
Futures.addCallback(future, new SimpleHttpResponseHandler<>(this, request.getUri(), stats), executor);
}
use of io.airlift.http.client.Request in project presto by prestodb.
the class HttpRemoteTask method abort.
private synchronized void abort(TaskStatus status) {
checkState(status.getState().isDone(), "cannot abort task with an incomplete status");
try (SetThreadName ignored = new SetThreadName("HttpRemoteTask-%s", taskId)) {
taskStatusFetcher.updateTaskStatus(status);
// send abort to task
HttpUriBuilder uriBuilder = getHttpUriBuilder(getTaskStatus());
Request request = prepareDelete().setUri(uriBuilder.build()).build();
scheduleAsyncCleanupRequest(new Backoff(MAX_CLEANUP_RETRY_TIME, MAX_CLEANUP_RETRY_TIME), request, "abort");
}
}
use of io.airlift.http.client.Request in project presto by prestodb.
the class HttpRemoteTask method cleanUpTask.
private synchronized void cleanUpTask() {
checkState(getTaskStatus().getState().isDone(), "attempt to clean up a task that is not done yet");
// clear pending splits to free memory
pendingSplits.clear();
pendingSourceSplitCount = 0;
partitionedSplitCountTracker.setPartitionedSplitCount(getPartitionedSplitCount());
splitQueueHasSpace = true;
whenSplitQueueHasSpace.complete(null, executor);
// cancel pending request
if (currentRequest != null) {
currentRequest.cancel(true);
currentRequest = null;
currentRequestStartNanos = 0;
}
taskStatusFetcher.stop();
// The remote task is likely to get a delete from the PageBufferClient first.
// We send an additional delete anyway to get the final TaskInfo
HttpUriBuilder uriBuilder = getHttpUriBuilder(getTaskStatus());
Request request = prepareDelete().setUri(uriBuilder.build()).build();
scheduleAsyncCleanupRequest(new Backoff(MAX_CLEANUP_RETRY_TIME, MAX_CLEANUP_RETRY_TIME), request, "cleanup");
}
Aggregations