jihoonson commented on a change in pull request #11643:
URL: https://github.com/apache/druid/pull/11643#discussion_r700615601
##########
File path: sql/src/main/java/org/apache/druid/sql/http/SqlResource.java
##########
@@ -222,11 +261,70 @@ public Response doPost(
}
}
- Response buildNonOkResponse(int status, Exception e) throws
JsonProcessingException
+ private void endLifecycle(
+ String sqlQueryId,
+ SqlLifecycle lifecycle,
+ @Nullable final Throwable e,
+ @Nullable final String remoteAddress,
+ final long bytesWritten
+ )
+ {
+ lifecycle.emitLogsAndMetrics(e, remoteAddress, bytesWritten);
+ sqlLifecycleManager.remove(sqlQueryId, lifecycle);
+ }
+
+ private Response buildCanceledResponse(String sqlQueryId) throws
JsonProcessingException
+ {
+ return buildNonOkResponse(
+ Status.INTERNAL_SERVER_ERROR.getStatusCode(),
+ new QueryInterruptedException(
+ QueryInterruptedException.QUERY_CANCELLED,
+ StringUtils.format("Query is canceled [%s]", sqlQueryId),
+ null,
+ null
+ )
+ );
+ }
+
+ private Response buildNonOkResponse(int status, Exception e) throws
JsonProcessingException
{
return Response.status(status)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(jsonMapper.writeValueAsBytes(e))
.build();
}
+
+ @DELETE
+ @Path("{id}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response cancelQuery(
+ @PathParam("id") String sqlQueryId,
+ @Context final HttpServletRequest req
+ )
+ {
+ log.debug("Received cancel request for query [%s]", sqlQueryId);
+
+ List<SqlLifecycle> lifecycles = sqlLifecycleManager.getAll(sqlQueryId);
+ if (lifecycles.isEmpty()) {
+ return Response.status(Status.NOT_FOUND).build();
+ }
+ Set<Resource> resources = lifecycles
+ .stream()
+ .flatMap(lifecycle -> lifecycle.getAuthorizedResources().stream())
+ .collect(Collectors.toSet());
+ Access access = AuthorizationUtils.authorizeAllResourceActions(
+ req,
+ Iterables.transform(resources,
AuthorizationUtils.RESOURCE_READ_RA_GENERATOR),
+ authorizerMapper
+ );
+
+ if (access.isAllowed()) {
+ sqlLifecycleManager.removeAll(sqlQueryId, lifecycles);
Review comment:
That case can happen and it is intentional to not cancel those queries.
This should remove only the lifecycles in the snapshot. After all, you cannot
cancel future queries that can be issued after the cancel request is processed.
--
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]