|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.client.CoprocessorHConnection
public class CoprocessorHConnection
Connection to an HTable from within a Coprocessor. Can do some nice tricks since we know we are on a regionserver.
This shouldn't be used by usual HBase clients - its merely in this package to maintain visibility
considerations for the HConnectionManager.HConnectionImplementation
.
Method Summary | ||
---|---|---|
void |
abort(String msg,
Throwable t)
Abort the server or client. |
|
void |
clearCaches(String sn)
Clear any caches that pertain to server name sn |
|
void |
clearRegionCache()
Allows flushing the region cache. |
|
void |
clearRegionCache(byte[] tableName)
Allows flushing the region cache of all locations that pertain to tableName |
|
void |
close()
|
|
void |
deleteCachedRegionLocation(HRegionLocation location)
Deletes cached locations for the specific region. |
|
protected void |
finalize()
Close the connection for good, regardless of what the current value of refCount is. |
|
org.apache.hadoop.conf.Configuration |
getConfiguration()
|
|
static HConnection |
getConnectionForEnvironment(CoprocessorEnvironment env)
Create an unmanaged HConnection based on the environment in which we are running the
coprocessor. |
|
protected ExecutorService |
getCurrentBatchPool()
|
|
int |
getCurrentNrHRS()
Scan zookeeper to get the number of region servers |
|
HRegionInterface |
getHRegionConnection(HServerAddress hsa)
Establishes a connection to the region server at the specified address. |
|
HRegionInterface |
getHRegionConnection(HServerAddress hsa,
boolean master)
Establishes a connection to the region server at the specified address. |
|
HRegionInterface |
getHRegionConnection(String hostname,
int port)
Establishes a connection to the region server at the specified address. |
|
HRegionInterface |
getHRegionConnection(String hostname,
int port,
boolean master)
Establishes a connection to the region server at the specified address. |
|
HTableDescriptor |
getHTableDescriptor(byte[] tableName)
|
|
HTableDescriptor[] |
getHTableDescriptors(List<String> tableNames)
|
|
HMasterInterface |
getMaster()
|
|
boolean |
getRegionCachePrefetch(byte[] tableName)
Check whether region cache prefetch is enabled or not. |
|
HRegionLocation |
getRegionLocation(byte[] name,
byte[] row,
boolean reload)
Find region location hosting passed row |
|
|
getRegionServerWithoutRetries(ServerCallable<T> callable)
Pass in a ServerCallable with your particular bit of logic defined and this method will pass it to the defined region server. |
|
|
getRegionServerWithRetries(ServerCallable<T> callable)
Pass in a ServerCallable with your particular bit of logic defined and this method will manage the process of doing retries with timed waits and refinds of missing regions. |
|
HTableInterface |
getTable(byte[] tableName)
Retrieve an HTableInterface implementation for access to a table. |
|
HTableInterface |
getTable(byte[] tableName,
ExecutorService pool)
Retrieve an HTableInterface implementation for access to a table. |
|
HTableInterface |
getTable(String tableName)
Retrieve an HTableInterface implementation for access to a table. |
|
HTableInterface |
getTable(String tableName,
ExecutorService pool)
Retrieve an HTableInterface implementation for access to a table. |
|
String[] |
getTableNames()
|
|
ZooKeeperWatcher |
getZooKeeperWatcher()
Deprecated. |
|
boolean |
isAborted()
Check if the server or client was aborted. |
|
boolean |
isClosed()
|
|
boolean |
isMasterRunning()
|
|
boolean |
isTableAvailable(byte[] tableName)
|
|
boolean |
isTableDisabled(byte[] tableName)
|
|
boolean |
isTableEnabled(byte[] tableName)
A table that isTableEnabled == false and isTableDisabled == false is possible. |
|
HTableDescriptor[] |
listTables()
List all the userspace tables. |
|
HRegionLocation |
locateRegion(byte[] regionName)
Gets the location of the region of regionName. |
|
HRegionLocation |
locateRegion(byte[] tableName,
byte[] row)
Find the location of the region of tableName that row lives in. |
|
List<HRegionLocation> |
locateRegions(byte[] tableName)
Gets the locations of all regions in the specified table, tableName. |
|
List<HRegionLocation> |
locateRegions(byte[] tableName,
boolean useCache,
boolean offlined)
Gets the locations of all regions in the specified table, tableName. |
|
void |
prewarmRegionCache(byte[] tableName,
Map<HRegionInfo,HServerAddress> regions)
Load the region map and warm up the global region cache for the table. |
|
void |
processBatch(List<? extends Row> list,
byte[] tableName,
ExecutorService pool,
Object[] results)
Process a mixed batch of Get, Put and Delete actions. |
|
|
processBatchCallback(List<? extends Row> list,
byte[] tableName,
ExecutorService pool,
Object[] results,
Batch.Callback<R> callback)
Parameterized batch processing, allowing varying return types for different Row implementations. |
|
|
processExecs(Class<T> protocol,
List<byte[]> rows,
byte[] tableName,
ExecutorService pool,
Batch.Call<T,R> callable,
Batch.Callback<R> callback)
Executes the given Batch.Call
callable for each row in the
given list and invokes
Batch.Callback.update(byte[], byte[], Object)
for each result returned. |
|
HRegionLocation |
relocateRegion(byte[] tableName,
byte[] row)
Find the location of the region of tableName that row lives in, ignoring any value that might be in the cache. |
|
void |
setRegionCachePrefetch(byte[] tableName,
boolean enable)
Enable or disable region cache prefetch for the table. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static HConnection getConnectionForEnvironment(CoprocessorEnvironment env) throws IOException
HConnection
based on the environment in which we are running the
coprocessor. The HConnection
must be externally cleaned up (we bypass the usual HTable
cleanup mechanisms since we own everything).
env
- environment hosting the HConnection
HConnection
.
IOException
- if we cannot create the basic connectionpublic HTableInterface getTable(String tableName) throws IOException
HConnection
HConnectionManager.createConnection(Configuration)
).
getTable
in interface HConnection
IOException
public HTableInterface getTable(byte[] tableName) throws IOException
HConnection
HConnectionManager.createConnection(Configuration)
).
getTable
in interface HConnection
IOException
public HTableInterface getTable(String tableName, ExecutorService pool) throws IOException
HConnection
HConnectionManager.createConnection(Configuration)
).
getTable
in interface HConnection
pool
- The thread pool to use for batch operations, null to use a default pool.
IOException
public HTableInterface getTable(byte[] tableName, ExecutorService pool) throws IOException
HConnection
HConnectionManager.createConnection(Configuration)
).
getTable
in interface HConnection
pool
- The thread pool to use for batch operations, null to use a default pool.
IOException
protected ExecutorService getCurrentBatchPool()
public org.apache.hadoop.conf.Configuration getConfiguration()
getConfiguration
in interface HConnection
public HMasterInterface getMaster() throws MasterNotRunningException, ZooKeeperConnectionException
getMaster
in interface HConnection
MasterNotRunningException
- if the master is not running
ZooKeeperConnectionException
- if unable to connect to zookeeperpublic boolean isMasterRunning() throws MasterNotRunningException, ZooKeeperConnectionException
isMasterRunning
in interface HConnection
MasterNotRunningException
ZooKeeperConnectionException
public HRegionLocation getRegionLocation(byte[] name, byte[] row, boolean reload) throws IOException
HConnection
getRegionLocation
in interface HConnection
name
- table namerow
- Row to find.reload
- If true do not use cache, otherwise bypass.
IOException
- if a remote or network exception occurspublic boolean isTableEnabled(byte[] tableName) throws IOException
HConnection
isTableEnabled
in interface HConnection
tableName
- table name
IOException
- if a remote or network exception occurspublic boolean isTableDisabled(byte[] tableName) throws IOException
isTableDisabled
in interface HConnection
tableName
- table name
IOException
- if a remote or network exception occurspublic boolean isTableAvailable(byte[] tableName) throws IOException
isTableAvailable
in interface HConnection
tableName
- table name
IOException
- if a remote or network exception occurspublic HRegionLocation locateRegion(byte[] regionName) throws IOException
HConnection
locateRegion
in interface HConnection
regionName
- name of the region to locate
IOException
- if a remote or network exception occurspublic List<HRegionLocation> locateRegions(byte[] tableName) throws IOException
HConnection
locateRegions
in interface HConnection
tableName
- table to get regions of
IOException
public List<HRegionLocation> locateRegions(byte[] tableName, boolean useCache, boolean offlined) throws IOException
HConnection
locateRegions
in interface HConnection
tableName
- table to get regions ofuseCache
- Should we use the cache to retrieve the region information.offlined
- True if we are to include offlined regions, false and we'll leave out offlined
regions from returned list.
IOException
public HRegionLocation locateRegion(byte[] tableName, byte[] row) throws IOException
HConnection
locateRegion
in interface HConnection
tableName
- name of the table row is inrow
- row key you're trying to find the region of
IOException
- if a remote or network exception occurspublic HRegionLocation relocateRegion(byte[] tableName, byte[] row) throws IOException
HConnection
relocateRegion
in interface HConnection
tableName
- name of the table row is inrow
- row key you're trying to find the region of
IOException
- if a remote or network exception occurspublic void deleteCachedRegionLocation(HRegionLocation location)
HConnection
deleteCachedRegionLocation
in interface HConnection
location
- The location object for the region, to be purged from cache.public void clearCaches(String sn)
HConnection
sn
clearCaches
in interface HConnection
sn
- A server name as hostname:portpublic void clearRegionCache()
HConnection
clearRegionCache
in interface HConnection
public void clearRegionCache(byte[] tableName)
HConnection
tableName
clearRegionCache
in interface HConnection
tableName
- Name of the table whose regions we are to remove from
cache.public HRegionInterface getHRegionConnection(HServerAddress hsa) throws IOException
HConnection
getHRegionConnection
in interface HConnection
hsa
- - the server to connect to
IOException
- if a remote or network exception occurspublic HRegionInterface getHRegionConnection(String hostname, int port) throws IOException
HConnection
getHRegionConnection
in interface HConnection
hostname
- RegionServer hostnameport
- RegionServer port
IOException
- if a remote or network exception occurspublic HRegionInterface getHRegionConnection(HServerAddress hsa, boolean master) throws IOException
HConnection
getHRegionConnection
in interface HConnection
hsa
- - the server to connect tomaster
- - do we check if master is alive
IOException
- if a remote or network exception occurspublic HRegionInterface getHRegionConnection(String hostname, int port, boolean master) throws IOException
HConnection
getHRegionConnection
in interface HConnection
hostname
- RegionServer hostnameport
- RegionServer portmaster
- - do we check if master is alive
IOException
- if a remote or network exception occurs@Deprecated public ZooKeeperWatcher getZooKeeperWatcher() throws ZooKeeperConnectionException
getZooKeeperWatcher
in interface HConnection
ZooKeeperConnectionException
- if there's a problem connecting to zkpublic <T> T getRegionServerWithRetries(ServerCallable<T> callable) throws IOException, RuntimeException
HConnection
getRegionServerWithRetries
in interface HConnection
T
- the type of the return valuecallable
- callable to run
IOException
- if a remote or network exception occurs
RuntimeException
- other unspecified errorpublic <T> T getRegionServerWithoutRetries(ServerCallable<T> callable) throws IOException, RuntimeException
HConnection
getRegionServerWithoutRetries
in interface HConnection
T
- the type of the return valuecallable
- callable to run
IOException
- if a remote or network exception occurs
RuntimeException
- other unspecified errorpublic void processBatch(List<? extends Row> list, byte[] tableName, ExecutorService pool, Object[] results) throws IOException, InterruptedException
HConnection
processBatch
in interface HConnection
list
- The collection of actions.tableName
- Name of the hbase tablepool
- thread pool for parallel executionresults
- An empty array, same size as list. If an exception is thrown,
you can test here for partial results, and to determine which actions
processed successfully.
IOException
- if there are problems talking to META. Per-item
exceptions are stored in the results array.
InterruptedException
public <T extends CoprocessorProtocol,R> void processExecs(Class<T> protocol, List<byte[]> rows, byte[] tableName, ExecutorService pool, Batch.Call<T,R> callable, Batch.Callback<R> callback) throws IOException, Throwable
Batch.Call
callable for each row in the
given list and invokes
Batch.Callback.update(byte[], byte[], Object)
for each result returned.
processExecs
in interface HConnection
T
- the protocol interface typeR
- the callable's return typeprotocol
- the protocol interface being calledrows
- a list of row keys for which the callable should be invokedtableName
- table name for the coprocessor invokedpool
- ExecutorService used to submit the calls per rowcallable
- instance on which to invoke
Batch.Call.call(Object)
for each rowcallback
- instance on which to invoke
Batch.Callback.update(byte[], byte[], Object)
for each result
IOException
Throwable
public <R> void processBatchCallback(List<? extends Row> list, byte[] tableName, ExecutorService pool, Object[] results, Batch.Callback<R> callback) throws IOException, InterruptedException
Row
implementations.
processBatchCallback
in interface HConnection
IOException
InterruptedException
public void setRegionCachePrefetch(byte[] tableName, boolean enable)
HConnection
setRegionCachePrefetch
in interface HConnection
tableName
- name of table to configure.enable
- Set to true to enable region cache prefetch.public boolean getRegionCachePrefetch(byte[] tableName)
HConnection
getRegionCachePrefetch
in interface HConnection
tableName
- name of table to check
public void prewarmRegionCache(byte[] tableName, Map<HRegionInfo,HServerAddress> regions)
HConnection
prewarmRegionCache
in interface HConnection
tableName
- name of the table to perform region cache prewarm.regions
- a region map.public void abort(String msg, Throwable t)
Abortable
abort
in interface Abortable
msg
- Why we're aborting.t
- Throwable that caused abort. Can be null.public boolean isClosed()
isClosed
in interface HConnection
public boolean isAborted()
Abortable
isAborted
in interface Abortable
public int getCurrentNrHRS() throws IOException
HConnection
getCurrentNrHRS
in interface HConnection
IOException
- if a remote or network exception occurspublic void close()
close
in interface Closeable
protected void finalize() throws Throwable
refCount
is. Ideally, refCount
should be zero at this
point, which would be the case if all of its consumers close the
connection. However, on the off chance that someone is unable to close
the connection, perhaps because it bailed out prematurely, the method
below will ensure that this HConnection
instance is cleaned up.
Caveat: The JVM may take an unknown amount of time to call finalize on an
unreachable object, so our hope is that every consumer cleans up after
itself, like any good citizen.
finalize
in class Object
Throwable
public HTableDescriptor[] listTables() throws IOException
HConnection
listTables
in interface HConnection
IOException
- if a remote or network exception occurspublic HTableDescriptor[] getHTableDescriptors(List<String> tableNames) throws IOException
getHTableDescriptors
in interface HConnection
tableNames
- List of table names
IOException
- if a remote or network exception occurspublic String[] getTableNames() throws IOException
getTableNames
in interface HConnection
IOException
- if a remote or network exception occurspublic HTableDescriptor getHTableDescriptor(byte[] tableName) throws IOException
getHTableDescriptor
in interface HConnection
tableName
- table name
IOException
- if a remote or network exception occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |