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

Stamatis Zampetakis commented on HIVE-28834:
--------------------------------------------

The best solution would be to rewrite the code to use the try-with-resources 
mechanism that can automatically deal with this kind of problems. Below an 
extract from the [JVM 
specification|https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.20.3.1]:

In a basic {{{}try{}}}-with-resources statement that manages a single resource:
 * If the initialization of the resource completes abruptly because of a 
{{throw}} of a value {{{}V{}}}, then the {{{}try{}}}-with-resources statement 
completes abruptly because of a {{throw}} of the value {{{}V{}}}.
 * If the initialization of the resource completes normally, and the {{try}} 
block completes abruptly because of a {{throw}} of a value {{{}V{}}}, then:
 ** If the automatic closing of the resource completes normally, then the 
{{{}try{}}}-with-resources statement completes abruptly because of a {{throw}} 
of the value {{{}V{}}}.
 ** If the automatic closing of the resource completes abruptly because of a 
{{throw}} of a value {{{}V2{}}}, then the {{{}try{}}}-with-resources statement 
completes abruptly because of a {{throw}} of value {{V}} with {{V2}} added to 
the suppressed exception list of {{{}V{}}}.
 * If the initialization of the resource completes normally, and the {{try}} 
block completes normally, and the automatic closing of the resource completes 
abruptly because of a {{throw}} of a value {{{}V{}}}, then the 
{{{}try{}}}-with-resources statement completes abruptly because of a {{throw}} 
of the value {{{}V{}}}.

An alternative, and possibly simpler solution, would be to catch exceptions 
during rollback, log them, and stop their propagation. This would be somewhat 
problematic if an exception only occurs during rollback.

> HMS swallows original failure when the rollback of a transaction fails
> ----------------------------------------------------------------------
>
>                 Key: HIVE-28834
>                 URL: https://issues.apache.org/jira/browse/HIVE-28834
>             Project: Hive
>          Issue Type: Bug
>          Components: Metastore
>            Reporter: Stamatis Zampetakis
>            Assignee: Stamatis Zampetakis
>            Priority: Major
>
> The problem mainly affects {{HMSHandler}} and {{ObjectStore}} but can be 
> generalized to any client that is executing rollback in a {{finally}} block.
> Some very frequent problematic patterns are outlined below.
> +Pattern in ObjectStore+
> {code:java}
>     boolean committed = false;
>     try {
>       openTransaction();
>       // some operations
>       committed = commitTransaction();
>     } finally {
>       rollbackAndCleanup(committed, null);
>     }
> {code}
>  
> +Pattern in HMSHandler+
> {code:java}
>     boolean success = false;
>     RawStore ms = getMS();
>     try {
>       ms.openTransaction();
>       // some operations
>       success = ms.commitTransaction();
>     } finally {
>        if (!success) {
>         ms.rollbackTransaction();
>       }
>     }
> {code}
> The problem is that whatever failure/exception is raised inside the {{try}} 
> block between the open and commit transaction will be completely lost if the 
> rollback fails. The exception from the rollback masks the original error.
> Most of the time the initial failure is far more important than the failure 
> inside the rollback so losing it is major issue when trying to diagnose a 
> problem in HMS.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to