@InterfaceAudience.Public public interface Connection extends Abortable, Closeable
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.
ConnectionFactory
Modifier and Type | Method and Description |
---|---|
void |
clearRegionLocationCache()
Clear all the entries in the region location cache, for all the tables.
|
void |
close() |
Admin |
getAdmin()
Retrieve an Admin implementation to administer an HBase cluster.
|
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. |
default String |
getClusterId()
Returns the cluster ID unique to this HBase cluster.
|
org.apache.hadoop.conf.Configuration |
getConfiguration()
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.
|
RegionLocator |
getRegionLocator(TableName tableName)
Retrieve a RegionLocator implementation to inspect region information on a table.
|
default Table |
getTable(TableName tableName)
Retrieve a Table implementation for accessing a table.
|
default Table |
getTable(TableName tableName,
ExecutorService pool)
Retrieve a Table implementation for accessing a table.
|
TableBuilder |
getTableBuilder(TableName tableName,
ExecutorService pool)
Returns an
TableBuilder for creating Table . |
boolean |
isClosed()
Returns whether the connection is closed or not.
|
org.apache.hadoop.conf.Configuration getConfiguration()
default Table getTable(TableName tableName) throws IOException
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.
tableName
- the name of the tableIOException
default Table getTable(TableName tableName, ExecutorService pool) throws IOException
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.
tableName
- the name of the tablepool
- The thread pool to use for batch operations, null to use a default pool.IOException
BufferedMutator getBufferedMutator(TableName tableName) throws IOException
Retrieve a BufferedMutator
for performing client-side buffering of writes. The
BufferedMutator
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 returned
BufferedMutator
instance.
tableName
- the name of the tableBufferedMutator
for the supplied tableName.IOException
BufferedMutator getBufferedMutator(BufferedMutatorParams params) throws IOException
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. 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 calls
BufferedMutator.close()
. The caller is responsible for calling
BufferedMutator.close()
on the returned BufferedMutator
instance.params
- details on how to instantiate the BufferedMutator
.BufferedMutator
for the supplied tableName.IOException
RegionLocator getRegionLocator(TableName tableName) throws IOException
Closeable.close()
on the returned
RegionLocator instance. RegionLocator needs to be unmanagedtableName
- Name of the table who's region is to be examinedIOException
void clearRegionLocationCache()
RegionLocator.clearRegionLocationCache()
.
This may cause performance issue so use it with caution.Admin getAdmin() throws IOException
Admin.close()
on the returned Admin instance.IOException
void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
IOException
boolean isClosed()
TableBuilder getTableBuilder(TableName tableName, ExecutorService pool)
TableBuilder
for creating Table
.tableName
- the name of the tablepool
- the thread pool to use for requests like batch and scandefault String getClusterId()
@InterfaceAudience.LimitedPrivate(value="HBCK") default Hbck getHbck() throws IOException
Closeable.close()
on the returned Hbck instance. IOException
@InterfaceAudience.LimitedPrivate(value="HBCK") default Hbck getHbck(ServerName masterServer) throws IOException
Closeable.close()
on the returned Hbck instance. masterServer
- explicit ServerName
for master serverIOException
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.