HBASE-3673 Reduce HTable Pool Contention Using Concurrent Collections
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1085169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
39bb359b53
commit
a344cd98b7
|
@ -95,6 +95,8 @@ Release 0.91.0 - Unreleased
|
||||||
HBASE-3468 Enhance checkAndPut and checkAndDelete with comparators
|
HBASE-3468 Enhance checkAndPut and checkAndDelete with comparators
|
||||||
HBASE-3683 NMapInputFormat should use a different config param for
|
HBASE-3683 NMapInputFormat should use a different config param for
|
||||||
number of maps
|
number of maps
|
||||||
|
HBASE-3673 Reduce HTable Pool Contention Using Concurrent Collections
|
||||||
|
(Karthick Sankarachary via Stack)
|
||||||
|
|
||||||
TASK
|
TASK
|
||||||
HBASE-3559 Move report of split to master OFF the heartbeat channel
|
HBASE-3559 Move report of split to master OFF the heartbeat channel
|
||||||
|
|
|
@ -21,8 +21,10 @@ package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
|
@ -42,8 +44,8 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
* <p>Pool will manage its own cluster to the cluster. See {@link HConnectionManager}.
|
* <p>Pool will manage its own cluster to the cluster. See {@link HConnectionManager}.
|
||||||
*/
|
*/
|
||||||
public class HTablePool {
|
public class HTablePool {
|
||||||
private final ConcurrentMap<String, LinkedList<HTableInterface>> tables =
|
private final Map<String, Queue<HTableInterface>> tables =
|
||||||
new ConcurrentHashMap<String, LinkedList<HTableInterface>>();
|
new ConcurrentHashMap<String, Queue<HTableInterface>>();
|
||||||
private final Configuration config;
|
private final Configuration config;
|
||||||
private final int maxSize;
|
private final int maxSize;
|
||||||
private final HTableInterfaceFactory tableFactory;
|
private final HTableInterfaceFactory tableFactory;
|
||||||
|
@ -82,16 +84,13 @@ public class HTablePool {
|
||||||
* @throws RuntimeException if there is a problem instantiating the HTable
|
* @throws RuntimeException if there is a problem instantiating the HTable
|
||||||
*/
|
*/
|
||||||
public HTableInterface getTable(String tableName) {
|
public HTableInterface getTable(String tableName) {
|
||||||
LinkedList<HTableInterface> queue = tables.get(tableName);
|
Queue<HTableInterface> queue = tables.get(tableName);
|
||||||
if(queue == null) {
|
if(queue == null) {
|
||||||
queue = new LinkedList<HTableInterface>();
|
queue = new ConcurrentLinkedQueue<HTableInterface>();
|
||||||
tables.putIfAbsent(tableName, queue);
|
tables.put(tableName, queue);
|
||||||
return createHTable(tableName);
|
return createHTable(tableName);
|
||||||
}
|
}
|
||||||
HTableInterface table;
|
HTableInterface table = queue.poll();
|
||||||
synchronized(queue) {
|
|
||||||
table = queue.poll();
|
|
||||||
}
|
|
||||||
if(table == null) {
|
if(table == null) {
|
||||||
return createHTable(tableName);
|
return createHTable(tableName);
|
||||||
}
|
}
|
||||||
|
@ -118,11 +117,9 @@ public class HTablePool {
|
||||||
* @param table table
|
* @param table table
|
||||||
*/
|
*/
|
||||||
public void putTable(HTableInterface table) {
|
public void putTable(HTableInterface table) {
|
||||||
LinkedList<HTableInterface> queue = tables.get(Bytes.toString(table.getTableName()));
|
Queue<HTableInterface> queue = tables.get(Bytes.toString(table.getTableName()));
|
||||||
synchronized(queue) {
|
if(queue.size() >= maxSize) return;
|
||||||
if(queue.size() >= maxSize) return;
|
queue.add(table);
|
||||||
queue.add(table);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HTableInterface createHTable(String tableName) {
|
protected HTableInterface createHTable(String tableName) {
|
||||||
|
@ -140,12 +137,10 @@ public class HTablePool {
|
||||||
*/
|
*/
|
||||||
public void closeTablePool(final String tableName) {
|
public void closeTablePool(final String tableName) {
|
||||||
Queue<HTableInterface> queue = tables.get(tableName);
|
Queue<HTableInterface> queue = tables.get(tableName);
|
||||||
synchronized (queue) {
|
HTableInterface table = queue.poll();
|
||||||
HTableInterface table = queue.poll();
|
while (table != null) {
|
||||||
while (table != null) {
|
this.tableFactory.releaseHTableInterface(table);
|
||||||
this.tableFactory.releaseHTableInterface(table);
|
table = queue.poll();
|
||||||
table = queue.poll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
HConnectionManager.deleteConnection(this.config, true);
|
HConnectionManager.deleteConnection(this.config, true);
|
||||||
}
|
}
|
||||||
|
@ -161,8 +156,6 @@ public class HTablePool {
|
||||||
|
|
||||||
int getCurrentPoolSize(String tableName) {
|
int getCurrentPoolSize(String tableName) {
|
||||||
Queue<HTableInterface> queue = tables.get(tableName);
|
Queue<HTableInterface> queue = tables.get(tableName);
|
||||||
synchronized(queue) {
|
return queue.size();
|
||||||
return queue.size();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue