Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase >> mail # user >> Correct use of HTablePool


Copy link to this message
-
RE: Correct use of HTablePool
Yes, you can use the Result once you give back the HTable reference.  Result is self contained.

> -----Original Message-----
> From: Joel Halbert [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 28, 2011 6:27 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Correct use of HTablePool
>
> Sure, but is the usage below correct in a multi-threaded context?
>
> i.e. Can i return the table to the pool before using the Result (or
> Scanner) ?
>
> HTablePool pool = myPool;
> Get get = myGet;
> HTable table = pool.getTable(myTableName);; Result result = null; try {
>      result = table.get(get);
> } finally {
>     pool.putTable(table);
> }
>
> // use Result now table has been returned to pool.
> r.getValue(Bytes.toBytes("COL"), Bytes.toBytes("ID"))
>
>
>
> On Tue, 2011-09-27 at 10:17 -0700, Jean-Daniel Cryans wrote:
> > Like the doc says:
> > http://hbase.apache.org/book.html#client.connections
> >
> > "For applications which require high-end multithreaded access (e.g.,
> > web-servers or application servers that may serve many application
> > threads in a single JVM), see HTablePool."
> >
> > J-D
> >
> > On Tue, Sep 27, 2011 at 8:52 AM, Joel Halbert <[EMAIL PROTECTED]>
> wrote:
> > > But in a highly multi-threaded context?
> > >
> > > I guess my question is: is it thread-safe?
> > >
> > > On Tue, 2011-09-27 at 09:18 -0500, Michael Segel wrote:
> > >> Outside of a M/R context, sure, why not?
> > >>
> > >>
> > >> > Subject: Correct use of HTablePool
> > >> > From: [EMAIL PROTECTED]
> > >> > To: [EMAIL PROTECTED]
> > >> > Date: Tue, 27 Sep 2011 10:19:04 +0100
> > >> >
> > >> > When using an HTablePool and calling get() or scan() can I return
> > >> > the Table to the pool as soon as I have the Result of Scanner object?
> > >> >
> > >> > i.e. is this valid?
> > >> >
> > >> > HTablePool pool = myPool;
> > >> > Get get = myGet;
> > >> > HTable table = pool.getTable(myTableName);; Result result = null;
> > >> > try {
> > >> >     result = table.get(get);
> > >> > } finally {
> > >> >     pool.putTable(table);
> > >> > }
> > >> >
> > >> > // use Result now table has been returned to pool.
> > >> > r.getValue(Bytes.toBytes("COL"), Bytes.toBytes("ID"))
> > >> >
> > >> >
> > >> > and likewise with a Scanner
> > >> >
> > >> > Rgs
> > >> > Joel
> > >>
> > >
> > >
> > >
>