You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Mingtao Zhang <ma...@gmail.com> on 2014/08/11 20:28:32 UTC

table.close()?

Hi,

I am looking at some code like this.

    public void put(String tableName, Put put) {
        HTableInterface table = null;
        try {
            table = connection.getTable(tableName);
            table.put(put);
        } catch (Throwable e) {
            log.error("put to HBase failed", e);
        } finally {
            if (null != table) {
                try {
                    //
http://hbase.apache.org/book/perf.writing.html#perf.hbase.client.autoflush
                    table.close();
                } catch (Exception e) {
                    log.error("close HTable failed", e);
                }
            }
        }
    }

By looking at the documentation, conncetion.getTable(tableName) will be a
'cheap' operation. But table.close() will flush things to network.

I wonder do I need to call table.close()? or it will be managed by HBase
client?

Best Regards,
Mingtao

Re: table.close()?

Posted by Mingtao Zhang <ma...@gmail.com>.
Thank you!

Mingtao Sent from iPhone

> On Aug 11, 2014, at 2:32 PM, Ted Yu <yu...@gmail.com> wrote:
> 
> You don't need to close table for every Put.
> 
> But table should be closed at some point - before your client exits.
> 
> 
> On Mon, Aug 11, 2014 at 11:28 AM, Mingtao Zhang <ma...@gmail.com>
> wrote:
> 
>> Hi,
>> 
>> I am looking at some code like this.
>> 
>>    public void put(String tableName, Put put) {
>>        HTableInterface table = null;
>>        try {
>>            table = connection.getTable(tableName);
>>            table.put(put);
>>        } catch (Throwable e) {
>>            log.error("put to HBase failed", e);
>>        } finally {
>>            if (null != table) {
>>                try {
>>                    //
>> http://hbase.apache.org/book/perf.writing.html#perf.hbase.client.autoflush
>>                    table.close();
>>                } catch (Exception e) {
>>                    log.error("close HTable failed", e);
>>                }
>>            }
>>        }
>>    }
>> 
>> By looking at the documentation, conncetion.getTable(tableName) will be a
>> 'cheap' operation. But table.close() will flush things to network.
>> 
>> I wonder do I need to call table.close()? or it will be managed by HBase
>> client?
>> 
>> Best Regards,
>> Mingtao
>> 

Re: table.close()?

Posted by Ted Yu <yu...@gmail.com>.
You don't need to close table for every Put.

But table should be closed at some point - before your client exits.


On Mon, Aug 11, 2014 at 11:28 AM, Mingtao Zhang <ma...@gmail.com>
wrote:

> Hi,
>
> I am looking at some code like this.
>
>     public void put(String tableName, Put put) {
>         HTableInterface table = null;
>         try {
>             table = connection.getTable(tableName);
>             table.put(put);
>         } catch (Throwable e) {
>             log.error("put to HBase failed", e);
>         } finally {
>             if (null != table) {
>                 try {
>                     //
> http://hbase.apache.org/book/perf.writing.html#perf.hbase.client.autoflush
>                     table.close();
>                 } catch (Exception e) {
>                     log.error("close HTable failed", e);
>                 }
>             }
>         }
>     }
>
> By looking at the documentation, conncetion.getTable(tableName) will be a
> 'cheap' operation. But table.close() will flush things to network.
>
> I wonder do I need to call table.close()? or it will be managed by HBase
> client?
>
> Best Regards,
> Mingtao
>