[ 
https://issues.apache.org/jira/browse/HIVE-16213?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15969460#comment-15969460
 ] 

Vihang Karajgaonkar commented on HIVE-16213:
--------------------------------------------

Hi [~akolb] I looked into the possibility of using QueryWrapper which 
implements Autocloseable and then use try-with-resources in Objectstore. For 
that I think I will need to create another QueryWrapperBuilder class which is 
used to create the QueryWrapper object based on the various query arguments 
like filter, result, ordering, unique etc. Once the queryBuilder is initialized 
I can do something like this :

{noformat}
try (QueryWrapper query = queryBuilder.build()) {
...
query.execute();
....
} finally {
if(!successful) {
  rollback();
}
}
{noformat}

If we use this approach the patch is becoming very big since there are ~90 
instances in ObjectStore.java which uses Query. We will have to replace all 
these instances with a QueryWrapper. Given that JDO 3.2 is going to implement 
Autocloseable for Query (https://issues.apache.org/jira/browse/JDO-735) I am 
not sure if advantages of using this approach are really worth the effort. How 
about we use the HIVE-16213.01.patch for now until JDO 3.2 is released. Once 
JDO 3.2 is released I can create another JIRA to start consuming it and then 
use try-with-resources directly on the query object.

What do think?

> ObjectStore can leak Queries when rollbackTransaction throws an exception
> -------------------------------------------------------------------------
>
>                 Key: HIVE-16213
>                 URL: https://issues.apache.org/jira/browse/HIVE-16213
>             Project: Hive
>          Issue Type: Bug
>          Components: Hive
>            Reporter: Alexander Kolbasov
>            Assignee: Vihang Karajgaonkar
>         Attachments: HIVE-16213.01.patch
>
>
> In ObjectStore.java there are a few places with the code similar to:
> {code}
>     Query query = null;
>     try {
>       openTransaction();
>       query = pm.newQuery(Something.class);
>       ...
>       commited = commitTransaction();
>     } finally {
>       if (!commited) {
>         rollbackTransaction();
>       }
>       if (query != null) {
>         query.closeAll();
>       }
>     }
> {code}
> The problem is that rollbackTransaction() may throw an exception in which 
> case query.closeAll() wouldn't be executed. 
> The fix would be to wrap rollbackTransaction in its own try-catch block.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to