hbase-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stack <st...@duboce.net>
Subject Re: Why doesn't HConnectionManager implement double checked locking ?
Date Thu, 25 Aug 2011 05:03:19 GMT
I'd imagine the Connection creation expensive, too expensive for the
putIfAbsent idiom.  What you think Akash?
St.Ack

On Thu, Aug 25, 2011 at 4:55 AM, Akash Ashok <thehellmaker@gmail.com> wrote:
> I was just curious as to whether this was a hotspot or not. I mean as Ryan
> said if its not a part of high perf code path then its ok.
>
> Also now I'm wondering why can't we do a putIfAbsent? More like
>
>    HConnectionKey connectionKey = new HConnectionKey(conf);
>    HConnectionImplementation connection
> = HBASE_INSTANCES.get(connectionKey);
>    if(connection==null){
>        synchronized (HBASE_INSTANCES) {
>          if (connection == null) {
>             connection = new HConnectionImplementation(conf);
>             HBASE_INSTANCES.put(connectionKey, connection);
>         }
>    }
>    connection.incCount();// Making this act on an AtomicInteger
>    return connection;
>
> This would work just fine right ??
>
> Cheers,
> Akash A
>
> On Thu, Aug 25, 2011 at 3:42 AM, Stack <stack@duboce.net> wrote:
>
>> How would double-checked -- a problematic pattern at the best of times
>> in java (see http://en.wikipedia.org/wiki/Double-checked_locking) --
>> help here?  What you thinking?  We can't really do putIfAbsent w/ a
>> connection instance?
>>
>> Good on you Akash,
>> St.Ack
>>
>> On Tue, Aug 23, 2011 at 11:45 AM, Akash Ashok <thehellmaker@gmail.com>
>> wrote:
>> > Hi,
>> >     I have pasted the code below for HConnectionManager.getConnection
>> >
>> >  public static HConnection getConnection(Configuration conf)
>> >  throws ZooKeeperConnectionException {
>> >    HConnectionKey connectionKey = new HConnectionKey(conf);
>> >    synchronized (HBASE_INSTANCES) {
>> >      HConnectionImplementation connection =
>> > HBASE_INSTANCES.get(connectionKey);
>> >      if (connection == null) {
>> >        connection = new HConnectionImplementation(conf);
>> >        HBASE_INSTANCES.put(connectionKey, connection);
>> >      }
>> >      connection.incCount();
>> >      return connection;
>> >    }
>> >  }
>> >
>> > just curious as to why double checked locking isn't implemented here ? Is
>> it
>> > because there's won't be too many threads calling this method
>> simultaneouly.
>> > ?
>> >
>> > Cheers,
>> > Akash A
>> >
>>
>

Mime
View raw message