HBASE-13201 Remove HTablePool from thrift-server (Solomon Duskis)
This commit is contained in:
parent
650c9f27fd
commit
242f62ffcd
|
@ -18,7 +18,18 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.thrift2;
|
package org.apache.hadoop.hbase.thrift2;
|
||||||
|
|
||||||
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.*;
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.appendFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deleteFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.deletesFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.getFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.getsFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.incrementFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.putFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.putsFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultFromHBase;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.resultsFromHBase;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.rowMutationsFromThrift;
|
||||||
|
import static org.apache.hadoop.hbase.thrift2.ThriftUtilities.scanFromThrift;
|
||||||
import static org.apache.thrift.TBaseHelper.byteBufferToByteArray;
|
import static org.apache.thrift.TBaseHelper.byteBufferToByteArray;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -30,42 +41,40 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hbase.client.HTableFactory;
|
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.hbase.client.HTableInterface;
|
|
||||||
import org.apache.hadoop.hbase.client.HTablePool;
|
|
||||||
import org.apache.hadoop.hbase.client.ResultScanner;
|
import org.apache.hadoop.hbase.client.ResultScanner;
|
||||||
import org.apache.hadoop.hbase.client.Table;
|
import org.apache.hadoop.hbase.client.Table;
|
||||||
import org.apache.hadoop.hbase.security.UserProvider;
|
import org.apache.hadoop.hbase.security.UserProvider;
|
||||||
import org.apache.hadoop.hbase.thrift.ThriftMetrics;
|
import org.apache.hadoop.hbase.thrift.ThriftMetrics;
|
||||||
import org.apache.hadoop.hbase.thrift2.generated.*;
|
import org.apache.hadoop.hbase.thrift2.generated.TAppend;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TDelete;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TGet;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.THBaseService;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TIOError;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TIllegalArgument;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TIncrement;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TPut;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TResult;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TRowMutations;
|
||||||
|
import org.apache.hadoop.hbase.thrift2.generated.TScan;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.apache.hadoop.hbase.util.ConnectionCache;
|
import org.apache.hadoop.hbase.util.ConnectionCache;
|
||||||
import org.apache.thrift.TException;
|
import org.apache.thrift.TException;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a glue object that connects Thrift RPC calls to the HBase client API primarily
|
* This class is a glue object that connects Thrift RPC calls to the HBase client API primarily
|
||||||
* defined in the HTableInterface.
|
* defined in the HTableInterface.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
||||||
|
|
||||||
// TODO: Size of pool configuraple
|
// TODO: Size of pool configuraple
|
||||||
private final Cache<String, HTablePool> htablePools;
|
|
||||||
private final Callable<? extends HTablePool> htablePoolCreater;
|
|
||||||
private static final Log LOG = LogFactory.getLog(ThriftHBaseServiceHandler.class);
|
private static final Log LOG = LogFactory.getLog(ThriftHBaseServiceHandler.class);
|
||||||
|
|
||||||
// nextScannerId and scannerMap are used to manage scanner state
|
// nextScannerId and scannerMap are used to manage scanner state
|
||||||
|
@ -75,8 +84,6 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
||||||
new ConcurrentHashMap<Integer, ResultScanner>();
|
new ConcurrentHashMap<Integer, ResultScanner>();
|
||||||
|
|
||||||
private final ConnectionCache connectionCache;
|
private final ConnectionCache connectionCache;
|
||||||
private final HTableFactory tableFactory;
|
|
||||||
private final int maxPoolSize;
|
|
||||||
|
|
||||||
static final String CLEANUP_INTERVAL = "hbase.thrift.connection.cleanup-interval";
|
static final String CLEANUP_INTERVAL = "hbase.thrift.connection.cleanup-interval";
|
||||||
static final String MAX_IDLETIME = "hbase.thrift.connection.max-idletime";
|
static final String MAX_IDLETIME = "hbase.thrift.connection.max-idletime";
|
||||||
|
@ -123,34 +130,13 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
||||||
int maxIdleTime = conf.getInt(MAX_IDLETIME, 10 * 60 * 1000);
|
int maxIdleTime = conf.getInt(MAX_IDLETIME, 10 * 60 * 1000);
|
||||||
connectionCache = new ConnectionCache(
|
connectionCache = new ConnectionCache(
|
||||||
conf, userProvider, cleanInterval, maxIdleTime);
|
conf, userProvider, cleanInterval, maxIdleTime);
|
||||||
tableFactory = new HTableFactory() {
|
|
||||||
@Override
|
|
||||||
public HTableInterface createHTableInterface(Configuration config,
|
|
||||||
byte[] tableName) {
|
|
||||||
try {
|
|
||||||
return connectionCache.getTable(Bytes.toString(tableName));
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
throw new RuntimeException(ioe);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
htablePools = CacheBuilder.newBuilder().expireAfterAccess(
|
|
||||||
maxIdleTime, TimeUnit.MILLISECONDS).softValues().concurrencyLevel(4).build();
|
|
||||||
maxPoolSize = conf.getInt("hbase.thrift.htablepool.size.max", 1000);
|
|
||||||
htablePoolCreater = new Callable<HTablePool>() {
|
|
||||||
public HTablePool call() {
|
|
||||||
return new HTablePool(conf, maxPoolSize, tableFactory);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Table getTable(ByteBuffer tableName) {
|
private Table getTable(ByteBuffer tableName) {
|
||||||
String currentUser = connectionCache.getEffectiveUser();
|
|
||||||
try {
|
try {
|
||||||
HTablePool htablePool = htablePools.get(currentUser, htablePoolCreater);
|
return connectionCache.getTable(Bytes.toString(byteBufferToByteArray(tableName)));
|
||||||
return htablePool.getTable(byteBufferToByteArray(tableName));
|
} catch (IOException e) {
|
||||||
} catch (ExecutionException ee) {
|
throw new RuntimeException(e);
|
||||||
throw new RuntimeException(ee);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,5 +410,4 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface {
|
||||||
closeTable(htable);
|
closeTable(htable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue