Changeset 5269


Ignore:
Timestamp:
2011-12-15 14:10:26 (17 months ago)
Author:
bruno
Message:

Fix leaking HBase/ZooKeeper connections in LilyClient? related to the hbase-based blob store.

Since this would create a new Configuration object each time, HBase would not recognize it is the same, thus leading to two extra connections per server (and growing after reconnect). Besides this, the BlobManager? can probably be shared among all the Repositories, left a comment in that regard.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/cr/process/client/src/main/java/org/lilyproject/client/LilyClient.java

    r5184 r5269  
    3737import org.lilyproject.repository.avro.AvroConverter; 
    3838import org.lilyproject.repository.impl.*; 
     39import org.lilyproject.util.hbase.HBaseAdminFactory; 
    3940import org.lilyproject.util.hbase.HBaseTableFactory; 
    4041import org.lilyproject.util.hbase.HBaseTableFactoryImpl; 
     
    156157        RemoteTypeManager typeManager = new RemoteTypeManager(parseAddressAndPort(server.lilyAddressAndPort), 
    157158                remoteConverter, idGenerator, zk, schemaCache); 
    158          
     159 
     160        // TODO BlobManager can probably be shared across all repositories 
    159161        BlobManager blobManager = getBlobManager(zk); 
    160162         
     
    169171    public static BlobManager getBlobManager(ZooKeeperItf zk) throws IOException { 
    170172        Configuration configuration = getBlobHBaseConfiguration(zk); 
     173        // Avoid HBase(Admin)/ZooKeeper connection leaks when using new Configuration objects each time. 
     174        configuration = HBaseAdminFactory.getExisting(configuration); 
    171175        HBaseTableFactory hbaseTableFactory = new HBaseTableFactoryImpl(configuration); 
    172          
     176 
    173177        URI dfsUri = getDfsUri(zk); 
    174178        FileSystem fs = FileSystem.get(DfsUri.getBaseDfsUri(dfsUri), configuration); 
  • trunk/global/hbase-util/src/main/java/org/lilyproject/util/hbase/HBaseAdminFactory.java

    r5121 r5269  
    1010 
    1111import java.util.HashMap; 
     12import java.util.Iterator; 
    1213import java.util.Map; 
    1314 
     
    4445        admins.clear(); 
    4546    } 
     47 
     48    /** 
     49     * If there is an existing configuration which has all the same properties as this configuration, return it. 
     50     * Otherwise, returns the passed conf. This is an expensive method. 
     51     */ 
     52    public static Configuration getExisting(Configuration conf) { 
     53        Configuration[] confs; 
     54        synchronized (HBaseAdminFactory.class) { 
     55            confs = admins.keySet().toArray(new Configuration[0]); 
     56        } 
     57         
     58        Map<String, String> confAsMap = toMap(conf); 
     59         
     60        for (Configuration current : confs) { 
     61            if (toMap(current).equals(confAsMap)) { 
     62                return current; 
     63            } 
     64        } 
     65         
     66        return conf; 
     67    } 
     68     
     69    private static Map<String, String> toMap(Configuration conf) { 
     70        Map<String, String> result = new HashMap<String, String>(); 
     71        Iterator<Map.Entry<String, String>> it = conf.iterator(); 
     72        while (it.hasNext()) { 
     73            Map.Entry<String, String> entry = it.next(); 
     74            result.put(entry.getKey(), entry.getValue()); 
     75        } 
     76        return result; 
     77    } 
    4678} 
Note: See TracChangeset for help on using the changeset viewer.