[
https://issues.apache.org/jira/browse/HIVE-14799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15550164#comment-15550164
]
Chaoyu Tang commented on HIVE-14799:
------------------------------------
[~sershe] Thanks for looking into the patch, please see the following comments
and hope they are helpful:
1. The query thread could stop at some points like wait, sleep, and throws
InterruptedException in response to the interrupt signal, but the only place
that so far has such waiting is in DriverContext.pollFinished(), which is
almost at the end of query process. We need some checkpoints which can stop the
process sooner, especially before some expensive operations.
2. The driver encapsulated in SQLOperation is kind of stateful and keep its
referenced resources in instance variables (ctx, plan, resStream, locks,
contextDriver etc). The compile/run releases resources only related itself such
as plan, driverContext after the query is processed, but most other resources
(ctx, resStream, fetchTask, locks etc) are released by explicitly calling
close/destroy in a separate step. The patch does not change the cleaning
responsibility of these methods but only coordinates the order of the cleaning.
The whole cancel process is quite straightforward:
a) the close process flags to query process and requests for a stop
b) the query process (run/compile) aborts the checkpoint, rollback and cleans
its own used resource (like in a normal case), then signals to the query
process to continue
c) close process continues to clean all resources which it should do in a
normal close operation.
I add the DriverState to facilitate the order coordination. Of course, the way
you pointed out is doable, but it looks to me a little complex since we should
determine cleaning responsibility and add that to query process (run/compile)
which under normal situation it is not responsible for.
3. As for your comments "interrupt the driver thread via system call and exit
(does it have to wait?)": yes, the running query should stop gracefully by
rolling back, cleaning its used resources, returning error status.
> Query operation are not thread safe during its cancellation
> -----------------------------------------------------------
>
> Key: HIVE-14799
> URL: https://issues.apache.org/jira/browse/HIVE-14799
> Project: Hive
> Issue Type: Bug
> Components: HiveServer2
> Reporter: Chaoyu Tang
> Assignee: Chaoyu Tang
> Attachments: HIVE-14799.patch
>
>
> When a query is cancelled either via Beeline (Ctrl-C) or API call
> TCLIService.Client.CancelOperation, SQLOperation.cancel is invoked in a
> different thread from that running the query to close/destroy its
> encapsulated Driver object. Both SQLOperation and Driver are not thread-safe
> which could sometimes result in Runtime exceptions like NPE. The errors from
> the running query are not handled properly therefore probably causing some
> stuffs (files, locks etc) not being cleaned after the query termination.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)