Interface Connection
- All Superinterfaces:
Abortable
,AutoCloseable
,Closeable
- All Known Subinterfaces:
ClusterConnection
- All Known Implementing Classes:
ConnectionImplementation
,ConnectionUtils.MasterlessConnection
,ServerConnectionUtils.ShortCircuitingClusterConnection
,SharedConnection
,ThriftConnection
ConnectionFactory
class. The lifecycle of the connection is managed by the caller, who has to close()
the
connection to release the resources.
The connection object contains logic to find the master, locate regions out on the cluster, keeps
a cache of locations and then knows how to re-calibrate after they move. The individual
connections to servers, meta cache, zookeeper connection, etc are all shared by the Table
and Admin
instances obtained from this connection.
Connection creation is a heavy-weight operation. Connection implementations are thread-safe, so
that the client can create a connection once, and share it with different threads. Table
and Admin
instances, on the other hand, are light-weight and are not thread-safe.
Typically, a single connection per client application is instantiated and every thread will
obtain its own Table instance. Caching or pooling of Table
and Admin
is not
recommended.
- Since:
- 0.99.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear all the entries in the region location cache, for all the tables.void
close()
getAdmin()
Retrieve an Admin implementation to administer an HBase cluster.Retrieve aBufferedMutator
for performing client-side buffering of writes.getBufferedMutator
(TableName tableName) Retrieve aBufferedMutator
for performing client-side buffering of writes.default String
Returns the cluster ID unique to this HBase cluster.org.apache.hadoop.conf.Configuration
Returns Configuration instance being used by this Connection instance.default Hbck
getHbck()
Retrieve an Hbck implementation to fix an HBase cluster.default Hbck
getHbck
(ServerName masterServer) Retrieve an Hbck implementation to fix an HBase cluster.getRegionLocator
(TableName tableName) Retrieve a RegionLocator implementation to inspect region information on a table.default Table
Retrieve a Table implementation for accessing a table.default Table
getTable
(TableName tableName, ExecutorService pool) Retrieve a Table implementation for accessing a table.getTableBuilder
(TableName tableName, ExecutorService pool) Returns anTableBuilder
for creatingTable
.boolean
isClosed()
Returns whether the connection is closed or not.
-
Method Details
-
getConfiguration
org.apache.hadoop.conf.Configuration getConfiguration()Returns Configuration instance being used by this Connection instance. -
getTable
Retrieve a Table implementation for accessing a table. The returned Table is not thread safe, a new instance should be created for each using thread. This is a lightweight operation, pooling or caching of the returned Table is neither required nor desired.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.
- Parameters:
tableName
- the name of the table- Returns:
- a Table to use for interactions with this table
- Throws:
IOException
-
getTable
Retrieve a Table implementation for accessing a table. The returned Table is not thread safe, a new instance should be created for each using thread. This is a lightweight operation, pooling or caching of the returned Table is neither required nor desired.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.
- Parameters:
tableName
- the name of the tablepool
- The thread pool to use for batch operations, null to use a default pool.- Returns:
- a Table to use for interactions with this table
- Throws:
IOException
-
getBufferedMutator
Retrieve a
BufferedMutator
for performing client-side buffering of writes. TheBufferedMutator
returned by this method is thread-safe. This accessor will create a new ThreadPoolExecutor and will be shutdown once we close the BufferedMutator. This object can be used for long lived operations.The caller is responsible for calling
BufferedMutator.close()
on the returnedBufferedMutator
instance.- Parameters:
tableName
- the name of the table- Returns:
- a
BufferedMutator
for the supplied tableName. - Throws:
IOException
-
getBufferedMutator
Retrieve aBufferedMutator
for performing client-side buffering of writes. TheBufferedMutator
returned by this method is thread-safe. This object can be used for long lived table operations. If user passes ThreadPool in BufferedMutatorParams then we will use that otherwise we will create for the user. For user specified ThreadPool, it is the user's responsibility to shutdown. For ThreadPool created by us, we will shutdown when user callsBufferedMutator.close()
. The caller is responsible for callingBufferedMutator.close()
on the returnedBufferedMutator
instance.- Parameters:
params
- details on how to instantiate theBufferedMutator
.- Returns:
- a
BufferedMutator
for the supplied tableName. - Throws:
IOException
-
getRegionLocator
Retrieve a RegionLocator implementation to inspect region information on a table. The returned RegionLocator is not thread-safe, so a new instance should be created for each using thread. This is a lightweight operation. Pooling or caching of the returned RegionLocator is neither required nor desired.
The caller is responsible for callingCloseable.close()
on the returned RegionLocator instance. RegionLocator needs to be unmanaged- Parameters:
tableName
- Name of the table who's region is to be examined- Returns:
- A RegionLocator instance
- Throws:
IOException
-
clearRegionLocationCache
void clearRegionLocationCache()Clear all the entries in the region location cache, for all the tables. If you only want to clear the cache for a specific table, useRegionLocator.clearRegionLocationCache()
. This may cause performance issue so use it with caution. -
getAdmin
Retrieve an Admin implementation to administer an HBase cluster. The returned Admin is not guaranteed to be thread-safe. A new instance should be created for each using thread. This is a lightweight operation. Pooling or caching of the returned Admin is not recommended.
The caller is responsible for callingAdmin.close()
on the returned Admin instance.- Returns:
- an Admin instance for cluster administration
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
isClosed
boolean isClosed()Returns whether the connection is closed or not.- Returns:
- true if this connection is closed
-
getTableBuilder
Returns anTableBuilder
for creatingTable
.- Parameters:
tableName
- the name of the tablepool
- the thread pool to use for requests like batch and scan
-
getClusterId
Returns the cluster ID unique to this HBase cluster.
The default implementation is added to keep client compatibility. -
getHbck
Retrieve an Hbck implementation to fix an HBase cluster. The returned Hbck is not guaranteed to be thread-safe. A new instance should be created by each thread. This is a lightweight operation. Pooling or caching of the returned Hbck instance is not recommended.
The caller is responsible for callingCloseable.close()
on the returned Hbck instance.
This will be used mostly by hbck tool.- Returns:
- an Hbck instance for active master. Active master is fetched from the zookeeper.
- Throws:
IOException
-
getHbck
Retrieve an Hbck implementation to fix an HBase cluster. The returned Hbck is not guaranteed to be thread-safe. A new instance should be created by each thread. This is a lightweight operation. Pooling or caching of the returned Hbck instance is not recommended.
The caller is responsible for callingCloseable.close()
on the returned Hbck instance.
This will be used mostly by hbck tool. This may only be used to by pass getting registered master from ZK. In situations where ZK is not available or active master is not registered with ZK and user can get master address by other means, master can be explicitly specified.- Parameters:
masterServer
- explicitServerName
for master server- Returns:
- an Hbck instance for a specified master server
- Throws:
IOException
-