@InterfaceAudience.Private class ConnectionImplementation extends Object implements ClusterConnection, Closeable
Connection
and ClusterConnection
interfaces.
Encapsulates connection to zookeeper and regionservers.Modifier and Type | Class and Description |
---|---|
(package private) static class |
ConnectionImplementation.MasterServiceState
State of the MasterService connection/setup.
|
private class |
ConnectionImplementation.MasterServiceStubMaker
Class to make a MasterServiceStubMaker stub.
|
(package private) static class |
ConnectionImplementation.ServerErrorTracker
The record of errors for servers.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
aborted |
private String |
alternateBufferedMutatorClassName
Allow setting an alternate BufferedMutator implementation via
config.
|
private AsyncProcess |
asyncProcess |
private ChoreService |
authService |
private ClientBackoffPolicy |
backoffPolicy |
private ThreadPoolExecutor |
batchPool |
private boolean |
cleanupPool |
private boolean |
closed |
protected String |
clusterId |
(package private) ClusterStatusListener |
clusterStatusListener |
private org.apache.hadoop.conf.Configuration |
conf |
private ConnectionConfiguration |
connectionConfig |
private boolean |
hostnamesCanChange |
private RetryingCallerInterceptor |
interceptor |
private static org.slf4j.Logger |
LOG |
private Object |
masterLock |
(package private) ConnectionImplementation.MasterServiceState |
masterServiceState |
private MetaCache |
metaCache |
private ThreadPoolExecutor |
metaLookupPool |
private Object |
metaRegionLock |
private int |
metaReplicaCallTimeoutScanInMicroSecond |
private MetricsConnection |
metrics |
private static NonceGenerator |
nonceGenerator
Global nonceGenerator shared per client.Currently there's no reason to limit its scope.
|
private static Object |
nonceGeneratorCreateLock
The nonce generator lock.
|
private int |
numTries |
private long |
pause |
private long |
pauseForCQTBE |
private ConnectionRegistry |
registry
Cluster registry of basic info such as clusterid and meta region location.
|
private static String |
RESOLVE_HOSTNAME_ON_FAIL_KEY |
static String |
RETRIES_BY_SERVER_KEY |
private RpcRetryingCallerFactory |
rpcCallerFactory |
private RpcClient |
rpcClient |
private RpcControllerFactory |
rpcControllerFactory |
(package private) int |
rpcTimeout |
private ServerStatisticTracker |
stats |
private ConcurrentMap<String,Object> |
stubs |
private boolean |
useMetaReplicas |
protected User |
user |
private ReentrantLock |
userRegionLock
lock guards against multiple threads trying to query the meta region at the same time
|
HBASE_CLIENT_CONNECTION_IMPL
Constructor and Description |
---|
ConnectionImplementation(org.apache.hadoop.conf.Configuration conf,
ExecutorService pool,
User user)
constructor
|
Modifier and Type | Method and Description |
---|---|
void |
abort(String msg,
Throwable t)
Abort the server or client.
|
void |
cacheLocation(TableName tableName,
RegionLocations location)
Put a newly discovered HRegionLocation into the cache.
|
private void |
cacheLocation(TableName tableName,
ServerName source,
HRegionLocation location)
Put a newly discovered HRegionLocation into the cache.
|
private void |
checkClosed() |
void |
clearCaches(ServerName serverName)
Clear any caches that pertain to server name
sn . |
void |
clearRegionCache(TableName tableName)
Allows flushing the region cache of all locations that pertain to
tableName |
void |
clearRegionCache(TableName tableName,
byte[] row) |
void |
clearRegionLocationCache()
Clear all the entries in the region location cache, for all the tables.
|
void |
close() |
private void |
closeMaster()
Immediate close of the shared master.
|
private void |
closeMasterService(ConnectionImplementation.MasterServiceState mss) |
void |
deleteCachedRegionLocation(HRegionLocation location)
Deletes cached locations for the specific region.
|
protected void |
finalize()
Close the connection for good.
|
private static <T> T |
get(CompletableFuture<T> future) |
Admin |
getAdmin()
Retrieve an Admin implementation to administer an HBase cluster.
|
org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService.BlockingInterface |
getAdmin(ServerName serverName)
Establishes a connection to the region server at the specified address.
|
org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService.BlockingInterface |
getAdminForMaster()
Get the admin service for master.
|
AsyncProcess |
getAsyncProcess() |
ClientBackoffPolicy |
getBackoffPolicy() |
private ThreadPoolExecutor |
getBatchPool() |
BufferedMutator |
getBufferedMutator(BufferedMutatorParams params)
Retrieve a
BufferedMutator for performing client-side buffering of writes. |
BufferedMutator |
getBufferedMutator(TableName tableName)
Retrieve a
BufferedMutator for performing client-side buffering of writes. |
(package private) RegionLocations |
getCachedLocation(TableName tableName,
byte[] row)
Search the cache for a location that fits our table and row key.
|
org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService.BlockingInterface |
getClient(ServerName serverName)
Establishes a connection to the region server at the specified address, and returns
a region client protocol.
|
org.apache.hadoop.conf.Configuration |
getConfiguration() |
ConnectionConfiguration |
getConnectionConfiguration() |
MetricsConnection |
getConnectionMetrics() |
protected ExecutorService |
getCurrentBatchPool() |
protected ExecutorService |
getCurrentMetaLookupPool() |
Hbck |
getHbck()
Retrieve an Hbck implementation to fix an HBase cluster.
|
Hbck |
getHbck(ServerName masterServer)
Retrieve an Hbck implementation to fix an HBase cluster.
|
private MasterKeepAliveConnection |
getKeepAliveMasterService() |
MasterKeepAliveConnection |
getMaster()
Returns a
MasterKeepAliveConnection to the active master |
private ThreadPoolExecutor |
getMetaLookupPool() |
RpcRetryingCallerFactory |
getNewRpcRetryingCallerFactory(org.apache.hadoop.conf.Configuration conf)
Returns a new RpcRetryingCallerFactory from the given
Configuration . |
NonceGenerator |
getNonceGenerator() |
(package private) int |
getNumberOfCachedRegionLocations(TableName tableName) |
HRegionLocation |
getRegionLocation(TableName tableName,
byte[] row,
boolean reload)
Find region location hosting passed row
|
RegionLocator |
getRegionLocator(TableName tableName)
Retrieve a RegionLocator implementation to inspect region information on a table.
|
(package private) RpcClient |
getRpcClient()
For tests only.
|
RpcControllerFactory |
getRpcControllerFactory() |
RpcRetryingCallerFactory |
getRpcRetryingCallerFactory() |
ServerStatisticTracker |
getStatisticsTracker() |
Table |
getTable(TableName tableName)
Retrieve a Table implementation for accessing a table.
|
TableBuilder |
getTableBuilder(TableName tableName,
ExecutorService pool)
Returns an
TableBuilder for creating Table . |
TableState |
getTableState(TableName tableName)
Retrieve TableState, represent current table state.
|
private ThreadPoolExecutor |
getThreadPool(int maxThreads,
int coreThreads,
String nameHint,
BlockingQueue<Runnable> passedWorkQueue) |
boolean |
hasCellBlockSupport() |
(package private) static NonceGenerator |
injectNonceGeneratorForTesting(ClusterConnection conn,
NonceGenerator cnm) |
boolean |
isAborted()
Check if the server or client was aborted.
|
boolean |
isClosed()
Returns whether the connection is closed or not.
|
private boolean |
isDeadServer(ServerName sn) |
private boolean |
isKeepAliveMasterConnectedAndRunning(ConnectionImplementation.MasterServiceState mss) |
boolean |
isMasterRunning()
Deprecated.
this has been deprecated without a replacement
|
boolean |
isTableAvailable(TableName tableName,
byte[][] splitKeys)
Use this api to check if the table has been created with the specified number of
splitkeys which was used while creating the given table.
|
boolean |
isTableDisabled(TableName tableName) |
boolean |
isTableEnabled(TableName tableName)
A table that isTableEnabled == false and isTableDisabled == false
is possible.
|
private RegionLocations |
locateMeta(TableName tableName,
boolean useCache,
int replicaId) |
HRegionLocation |
locateRegion(byte[] regionName)
Gets the location of the region of regionName.
|
HRegionLocation |
locateRegion(TableName tableName,
byte[] row)
Find the location of the region of tableName that row
lives in.
|
RegionLocations |
locateRegion(TableName tableName,
byte[] row,
boolean useCache,
boolean retry) |
RegionLocations |
locateRegion(TableName tableName,
byte[] row,
boolean useCache,
boolean retry,
int replicaId) |
private RegionLocations |
locateRegionInMeta(TableName tableName,
byte[] row,
boolean useCache,
boolean retry,
int replicaId)
Search the hbase:meta table for the HRegionLocation info that contains the table and row we're
seeking.
|
List<HRegionLocation> |
locateRegions(TableName tableName)
Gets the locations of all regions in the specified table, tableName.
|
List<HRegionLocation> |
locateRegions(TableName tableName,
boolean useCache,
boolean offlined)
Gets the locations of all regions in the specified table, tableName.
|
private static void |
release(ConnectionImplementation.MasterServiceState mss) |
(package private) void |
releaseMaster(ConnectionImplementation.MasterServiceState mss) |
HRegionLocation |
relocateRegion(TableName tableName,
byte[] row)
Find the location of the region of tableName that row
lives in, ignoring any value that might be in the cache.
|
RegionLocations |
relocateRegion(TableName tableName,
byte[] row,
int replicaId)
Find the location of the region of tableName that row
lives in, ignoring any value that might be in the cache.
|
private void |
resetMasterServiceState(ConnectionImplementation.MasterServiceState mss) |
protected void |
retrieveClusterId() |
(package private) void |
setUseMetaReplicas(boolean useMetaReplicas) |
private void |
shutdownBatchPool(ExecutorService pool) |
private void |
shutdownPools() |
private void |
spawnRenewalChore(org.apache.hadoop.security.UserGroupInformation user) |
String |
toString()
An identifier that will remain the same for a given connection.
|
(package private) void |
updateCachedLocation(RegionInfo hri,
ServerName source,
ServerName serverName,
long seqNum) |
void |
updateCachedLocations(TableName tableName,
byte[] regionName,
byte[] rowkey,
Object exception,
ServerName source)
Update the location with the new value (if the exception is a RegionMovedException)
or delete it from the cache.
|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
clearRegionCache
getTable
public static final String RETRIES_BY_SERVER_KEY
private static final org.slf4j.Logger LOG
private static final String RESOLVE_HOSTNAME_ON_FAIL_KEY
private final boolean hostnamesCanChange
private final long pause
private final long pauseForCQTBE
private boolean useMetaReplicas
private final int metaReplicaCallTimeoutScanInMicroSecond
private final int numTries
final int rpcTimeout
private static volatile NonceGenerator nonceGenerator
private static final Object nonceGeneratorCreateLock
private final AsyncProcess asyncProcess
private final ServerStatisticTracker stats
private volatile boolean closed
private volatile boolean aborted
ClusterStatusListener clusterStatusListener
private final Object metaRegionLock
private final Object masterLock
private volatile ThreadPoolExecutor batchPool
private volatile ThreadPoolExecutor metaLookupPool
private volatile boolean cleanupPool
private final org.apache.hadoop.conf.Configuration conf
private final ConnectionConfiguration connectionConfig
private final MetricsConnection metrics
private final RpcRetryingCallerFactory rpcCallerFactory
private final RpcControllerFactory rpcControllerFactory
private final RetryingCallerInterceptor interceptor
private final ConnectionRegistry registry
private final ClientBackoffPolicy backoffPolicy
private final String alternateBufferedMutatorClassName
private final ReentrantLock userRegionLock
private ChoreService authService
private final ConcurrentMap<String,Object> stubs
final ConnectionImplementation.MasterServiceState masterServiceState
ConnectionImplementation(org.apache.hadoop.conf.Configuration conf, ExecutorService pool, User user) throws IOException
conf
- Configuration objectIOException
private void spawnRenewalChore(org.apache.hadoop.security.UserGroupInformation user)
void setUseMetaReplicas(boolean useMetaReplicas)
useMetaReplicas
- static NonceGenerator injectNonceGeneratorForTesting(ClusterConnection conn, NonceGenerator cnm)
conn
- The connection for which to replace the generator.cnm
- Replaces the nonce generator used, for testing.public Table getTable(TableName tableName) throws IOException
Connection
The caller is responsible for calling Table.close()
on the returned
table instance.
Since 0.98.1 this method no longer checks table existence. An exception will be thrown if the table does not exist only when the first operation is attempted.
getTable
in interface Connection
tableName
- the name of the tableIOException
public TableBuilder getTableBuilder(TableName tableName, ExecutorService pool)
Connection
TableBuilder
for creating Table
.getTableBuilder
in interface Connection
tableName
- the name of the tablepool
- the thread pool to use for requests like batch and scanpublic BufferedMutator getBufferedMutator(BufferedMutatorParams params)
Connection
BufferedMutator
for performing client-side buffering of writes. The
BufferedMutator
returned by this method is thread-safe. This object can be used for
long lived table operations. The caller is responsible for calling
BufferedMutator.close()
on the returned BufferedMutator
instance.getBufferedMutator
in interface Connection
params
- details on how to instantiate the BufferedMutator
.BufferedMutator
for the supplied tableName.public BufferedMutator getBufferedMutator(TableName tableName)
Connection
Retrieve a BufferedMutator
for performing client-side buffering of writes. The
BufferedMutator
returned by this method is thread-safe. This BufferedMutator will
use the Connection's ExecutorService. This object can be used for long lived operations.
The caller is responsible for calling BufferedMutator.close()
on
the returned BufferedMutator
instance.
This accessor will use the connection's ExecutorService and will throw an exception in the main thread when an asynchronous exception occurs.
getBufferedMutator
in interface Connection
tableName
- the name of the tableBufferedMutator
for the supplied tableName.public RegionLocator getRegionLocator(TableName tableName) throws IOException
Connection
Closeable.close()
on the returned
RegionLocator instance.
RegionLocator needs to be unmanagedgetRegionLocator
in interface Connection
tableName
- Name of the table who's region is to be examinedIOException
public Admin getAdmin() throws IOException
Connection
Admin.close()
on the returned
Admin instance.getAdmin
in interface Connection
IOException
public Hbck getHbck() throws IOException
Connection
Closeable.close()
on the returned Hbck instance.
getHbck
in interface Connection
IOException
public Hbck getHbck(ServerName masterServer) throws IOException
Connection
Closeable.close()
on the returned Hbck instance.
getHbck
in interface Connection
masterServer
- explicit ServerName
for master serverIOException
public MetricsConnection getConnectionMetrics()
getConnectionMetrics
in interface ClusterConnection
private ThreadPoolExecutor getBatchPool()
private ThreadPoolExecutor getThreadPool(int maxThreads, int coreThreads, String nameHint, BlockingQueue<Runnable> passedWorkQueue)
private ThreadPoolExecutor getMetaLookupPool()
protected ExecutorService getCurrentMetaLookupPool()
protected ExecutorService getCurrentBatchPool()
private void shutdownPools()
private void shutdownBatchPool(ExecutorService pool)
RpcClient getRpcClient()
protected void retrieveClusterId()
public org.apache.hadoop.conf.Configuration getConfiguration()
getConfiguration
in interface Connection
private void checkClosed() throws DoNotRetryIOException
DoNotRetryIOException
@Deprecated public boolean isMasterRunning() throws MasterNotRunningException, ZooKeeperConnectionException
isMasterRunning
in interface ClusterConnection
MasterNotRunningException
- - if the master is not runningZooKeeperConnectionException
public HRegionLocation getRegionLocation(TableName tableName, byte[] row, boolean reload) throws IOException
ClusterConnection
getRegionLocation
in interface ClusterConnection
tableName
- table namerow
- Row to find.reload
- If true do not use cache, otherwise bypass.IOException
- if a remote or network exception occurspublic boolean isTableEnabled(TableName tableName) throws IOException
ClusterConnection
isTableEnabled
in interface ClusterConnection
tableName
- table nameIOException
- if a remote or network exception occurspublic boolean isTableDisabled(TableName tableName) throws IOException
isTableDisabled
in interface ClusterConnection
tableName
- table nameIOException
- if a remote or network exception occurspublic boolean isTableAvailable(TableName tableName, @Nullable byte[][] splitKeys) throws IOException
ClusterConnection
isTableAvailable
in interface ClusterConnection
tableName
- tableNamesplitKeys
- splitKeys used while creating tableIOException
- if a remote or network exception occurspublic HRegionLocation locateRegion(byte[] regionName) throws IOException
ClusterConnection
locateRegion
in interface ClusterConnection
regionName
- name of the region to locateIOException
- if a remote or network exception occursprivate boolean isDeadServer(ServerName sn)
public List<HRegionLocation> locateRegions(TableName tableName) throws IOException
ClusterConnection
locateRegions
in interface ClusterConnection
tableName
- table to get regions ofIOException
- if IO failure occurspublic List<HRegionLocation> locateRegions(TableName tableName, boolean useCache, boolean offlined) throws IOException
ClusterConnection
locateRegions
in interface ClusterConnection
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
- if IO failure occurspublic HRegionLocation locateRegion(TableName tableName, byte[] row) throws IOException
ClusterConnection
locateRegion
in interface ClusterConnection
tableName
- name of the table row is inrow
- row key you're trying to find the region ofIOException
- if a remote or network exception occurspublic HRegionLocation relocateRegion(TableName tableName, byte[] row) throws IOException
ClusterConnection
relocateRegion
in interface ClusterConnection
tableName
- name of the table row is inrow
- row key you're trying to find the region ofIOException
- if a remote or network exception occurspublic RegionLocations relocateRegion(TableName tableName, byte[] row, int replicaId) throws IOException
ClusterConnection
relocateRegion
in interface ClusterConnection
tableName
- name of the table row is inrow
- row key you're trying to find the region ofreplicaId
- the replicaId of the regionIOException
- if a remote or network exception occurspublic RegionLocations locateRegion(TableName tableName, byte[] row, boolean useCache, boolean retry) throws IOException
locateRegion
in interface ClusterConnection
tableName
- table to get regions ofrow
- the rowuseCache
- Should we use the cache to retrieve the region information.retry
- do we retryIOException
- if IO failure occurspublic RegionLocations locateRegion(TableName tableName, byte[] row, boolean useCache, boolean retry, int replicaId) throws IOException
locateRegion
in interface ClusterConnection
tableName
- table to get regions ofrow
- the rowuseCache
- Should we use the cache to retrieve the region information.retry
- do we retryreplicaId
- the replicaId for the regionIOException
- if IO failure occursprivate RegionLocations locateMeta(TableName tableName, boolean useCache, int replicaId) throws IOException
IOException
private RegionLocations locateRegionInMeta(TableName tableName, byte[] row, boolean useCache, boolean retry, int replicaId) throws IOException
IOException
public void cacheLocation(TableName tableName, RegionLocations location)
cacheLocation
in interface ClusterConnection
tableName
- The table name.location
- the new locationRegionLocations getCachedLocation(TableName tableName, byte[] row)
public void clearRegionCache(TableName tableName, byte[] row)
public void clearCaches(ServerName serverName)
ClusterConnection
sn
.clearCaches
in interface ClusterConnection
serverName
- A server namepublic void clearRegionLocationCache()
Connection
RegionLocator.clearRegionLocationCache()
.
This may cause performance issue so use it with caution.clearRegionLocationCache
in interface Connection
public void clearRegionCache(TableName tableName)
ClusterConnection
tableName
clearRegionCache
in interface ClusterConnection
tableName
- Name of the table whose regions we are to remove from
cache.private void cacheLocation(TableName tableName, ServerName source, HRegionLocation location)
tableName
- The table name.source
- the source of the new location, if it's not coming from metalocation
- the new locationpublic org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService.BlockingInterface getAdminForMaster() throws IOException
ClusterConnection
getAdminForMaster
in interface ClusterConnection
IOException
public org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService.BlockingInterface getAdmin(ServerName serverName) throws IOException
ClusterConnection
getAdmin
in interface ClusterConnection
serverName
- the region server to connect toIOException
- if a remote or network exception occurspublic org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ClientService.BlockingInterface getClient(ServerName serverName) throws IOException
ClusterConnection
getClient
in interface ClusterConnection
serverName
- the region server to connect toIOException
- if a remote or network exception occurspublic MasterKeepAliveConnection getMaster() throws IOException
ClusterConnection
MasterKeepAliveConnection
to the active mastergetMaster
in interface ClusterConnection
IOException
private void resetMasterServiceState(ConnectionImplementation.MasterServiceState mss)
private MasterKeepAliveConnection getKeepAliveMasterService() throws IOException
IOException
private static void release(ConnectionImplementation.MasterServiceState mss)
private boolean isKeepAliveMasterConnectedAndRunning(ConnectionImplementation.MasterServiceState mss)
void releaseMaster(ConnectionImplementation.MasterServiceState mss)
private void closeMasterService(ConnectionImplementation.MasterServiceState mss)
private void closeMaster()
void updateCachedLocation(RegionInfo hri, ServerName source, ServerName serverName, long seqNum)
public void deleteCachedRegionLocation(HRegionLocation location)
ClusterConnection
deleteCachedRegionLocation
in interface ClusterConnection
location
- The location object for the region, to be purged from cache.public void updateCachedLocations(TableName tableName, byte[] regionName, byte[] rowkey, Object exception, ServerName source)
updateCachedLocations
in interface ClusterConnection
exception
- an object (to simplify user code) on which we will try to find a nested
or wrapped or both RegionMovedExceptionsource
- server that is the source of the location update.tableName
- the table nameregionName
- the region namerowkey
- the rowpublic AsyncProcess getAsyncProcess()
getAsyncProcess
in interface ClusterConnection
public ServerStatisticTracker getStatisticsTracker()
getStatisticsTracker
in interface ClusterConnection
public ClientBackoffPolicy getBackoffPolicy()
getBackoffPolicy
in interface ClusterConnection
int getNumberOfCachedRegionLocations(TableName tableName)
public void abort(String msg, Throwable t)
Abortable
public boolean isClosed()
Connection
isClosed
in interface Connection
public boolean isAborted()
Abortable
public void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Connection
protected void finalize() throws Throwable
public NonceGenerator getNonceGenerator()
getNonceGenerator
in interface ClusterConnection
public TableState getTableState(TableName tableName) throws IOException
ClusterConnection
getTableState
in interface ClusterConnection
tableName
- table state forIOException
public RpcRetryingCallerFactory getNewRpcRetryingCallerFactory(org.apache.hadoop.conf.Configuration conf)
ClusterConnection
Configuration
.
This RpcRetryingCallerFactory lets the users create RpcRetryingCaller
s which can be
intercepted with the configured RetryingCallerInterceptor
getNewRpcRetryingCallerFactory
in interface ClusterConnection
conf
- configurationpublic boolean hasCellBlockSupport()
hasCellBlockSupport
in interface ClusterConnection
Codec
and so
supports cell blocks.public ConnectionConfiguration getConnectionConfiguration()
getConnectionConfiguration
in interface ClusterConnection
public RpcRetryingCallerFactory getRpcRetryingCallerFactory()
getRpcRetryingCallerFactory
in interface ClusterConnection
public RpcControllerFactory getRpcControllerFactory()
getRpcControllerFactory
in interface ClusterConnection
private static <T> T get(CompletableFuture<T> future) throws IOException
IOException
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.