use of io.hetu.core.transport.execution.buffer.SerializedPage in project hetu-core by openlookeng.
the class NestedLoopJoinPagesBuilder method restore.
@Override
public void restore(Object state, BlockEncodingSerdeProvider serdeProvider) {
NestedLoopJoinPagesBuilderState myState = (NestedLoopJoinPagesBuilderState) state;
this.pages.clear();
PagesSerde serde = (PagesSerde) serdeProvider;
for (Object obj : myState.pages) {
SerializedPage sp = SerializedPage.restoreSerializedPage(obj);
this.pages.add(serde.deserialize(sp));
}
this.finished = myState.finished;
this.estimatedSize = myState.estimatedSize;
}
use of io.hetu.core.transport.execution.buffer.SerializedPage in project hetu-core by openlookeng.
the class TaskResource method getResults.
@GET
@Path("{taskId}/results/{bufferId}/{token}")
@Produces(PRESTO_PAGES)
public void getResults(@PathParam("taskId") TaskId taskId, @PathParam("bufferId") OutputBufferId bufferId, @PathParam("token") final long token, @HeaderParam(PRESTO_MAX_SIZE) DataSize maxSize, @HeaderParam(PRESTO_TASK_INSTANCE_ID) String taskInstanceId, @Suspended AsyncResponse asyncResponse) {
SecurityRequireNonNull.requireNonNull(taskId, "taskId is null");
SecurityRequireNonNull.requireNonNull(bufferId, "bufferId is null");
long start = System.nanoTime();
ListenableFuture<BufferResult> bufferResultFuture = taskManager.getTaskResults(taskId, bufferId, token, maxSize, taskInstanceId);
if (bufferResultFuture == null) {
// Request came from task has been cancelled.
asyncResponse.resume(Response.status(Status.NO_CONTENT).header(PRESTO_PAGE_TOKEN, token).header(PRESTO_PAGE_NEXT_TOKEN, token).header(PRESTO_BUFFER_COMPLETE, // keep requesting task running, until they are cancelled (to resume)
false).build());
return;
}
Duration waitTime = randomizeWaitTime(DEFAULT_MAX_WAIT_TIME);
bufferResultFuture = addTimeout(bufferResultFuture, () -> BufferResult.emptyResults(token, false), waitTime, timeoutExecutor);
ListenableFuture<Response> responseFuture = Futures.transform(bufferResultFuture, result -> {
List<SerializedPage> serializedPages = result.getSerializedPages();
GenericEntity<?> entity = null;
Status status;
if (serializedPages.isEmpty()) {
status = Status.NO_CONTENT;
} else {
entity = new GenericEntity<>(serializedPages, new TypeToken<List<Page>>() {
}.getType());
status = Status.OK;
}
return Response.status(status).entity(entity).header(PRESTO_PAGE_TOKEN, result.getToken()).header(PRESTO_PAGE_NEXT_TOKEN, result.getNextToken()).header(PRESTO_BUFFER_COMPLETE, result.isBufferComplete()).build();
}, directExecutor());
// For hard timeout, add an additional time to max wait for thread scheduling contention and GC
Duration timeout = new Duration(waitTime.toMillis() + ADDITIONAL_WAIT_TIME.toMillis(), MILLISECONDS);
bindAsyncResponse(asyncResponse, responseFuture, responseExecutor).withTimeout(timeout, Response.status(Status.NO_CONTENT).header(PRESTO_PAGE_TOKEN, token).header(PRESTO_PAGE_NEXT_TOKEN, token).header(PRESTO_BUFFER_COMPLETE, false).build());
responseFuture.addListener(() -> readFromOutputBufferTime.add(Duration.nanosSince(start)), directExecutor());
asyncResponse.register((CompletionCallback) throwable -> resultsRequestTime.add(Duration.nanosSince(start)));
}
Aggregations