[ 
https://issues.apache.org/jira/browse/HADOOP-2261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12546006
 ] 

Michael Bieniosek commented on HADOOP-2261:
-------------------------------------------

No, I don't think you understand my complaint.

The problem with the current API is that I have to explicitly catch all the 
exceptions that my code can throw, so I can catch them and call abort().

It is error-prone to list all the exceptions my code could possibly throw and 
attempt to catch and rethrow them.  For example, it is easy to forget 
RuntimeException and Error.  You can't just catch Throwable, because then you 
have to rethrow a Throwable, which changes the method's exception signature.

When I wrote code against hibernate's API, (as far as I remember) I did 
something like 

<pre>
Transaction transaction = session.beginTransaction();
try {
  ...
  transaction.commit();
} finally {
  transaction.rollback();
}
</pre>

This had the nice property that calling rollback() after commit() was a no-op.  
This is what I'd like to see in hbase.  

> [hbase] Change abort to finalize; does nothing if commit ran successfully
> -------------------------------------------------------------------------
>
>                 Key: HADOOP-2261
>                 URL: https://issues.apache.org/jira/browse/HADOOP-2261
>             Project: Hadoop
>          Issue Type: Improvement
>          Components: contrib/hbase
>            Reporter: stack
>            Assignee: Jim Kellerman
>             Fix For: 0.16.0
>
>         Attachments: patch.txt
>
>
> From Michael Bieniosek:
> {code}I'm trying to do an update row, so I write code like:
> long lockid = table.startUpdate(new Text(article.getName())); try {
>      for (File articleInfo: article.listFiles(new NonDirectories())) {        
>   articleTable.put(lockid, columnName(articleInfo.getName()), 
> readFile(articleInfo));     }
>      table.commit(lockid);
> } finally {
>     table.abort(lockid);
> }
> This doesn't work, because in the normal case it calls abort after commit.  
> But I'm not sure what the code should be, eg.:
> long lockid = table.startUpdate(new Text(article.getName())); try {
>      for (File articleInfo: article.listFiles(new NonDirectories())) {        
>   articleTable.put(lockid, columnName(articleInfo.getName()), 
> readFile(articleInfo));     }
>      table.commit(lockid);
> } catch (IOException e) {
>     table.abort(lockid);
>     throw e;
> } catch (RuntimeException e) {
>     table.abort(lockid);
>     throw e;
> }
> This gets unwieldy very quickly.  Could you maybe change abort() to 
> finalize() which either aborts or does nothing if a commit was successful?
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to