@InterfaceAudience.Public @InterfaceStability.Evolving @Deprecated public class HConnectionManager extends ConnectionFactory
HConnection
s.
The simplest way to use this class is by using createConnection(Configuration)
.
This creates a new HConnection
to the cluster that is managed by the caller.
From this HConnection
HTableInterface
implementations are retrieved
with HConnection.getTable(byte[])
. Example:
HConnection connection = HConnectionManager.createConnection(config); HTableInterface table = connection.getTable(TableName.valueOf("table1")); try { // Use the table as needed, for a single operation and a single thread } finally { table.close(); connection.close(); }
This class has a static Map of HConnection
instances keyed by
HConnectionKey
; A HConnectionKey
is identified by a set of
Configuration
properties. Invocations of getConnection(Configuration)
that pass the same Configuration
instance will return the same
HConnection
instance ONLY WHEN the set of properties are the same
(i.e. if you change properties in your Configuration
instance, such as RPC timeout,
the codec used, HBase will create a new HConnection
instance. For more details on
how this is done see HConnectionKey
).
Sharing HConnection
instances is usually what you want; all clients
of the HConnection
instances share the HConnections' cache of Region
locations rather than each having to discover for itself the location of meta, etc.
But sharing connections makes clean up of HConnection
instances a little awkward.
Currently, clients cleanup by calling deleteConnection(Configuration)
. This will
shutdown the zookeeper connection the HConnection was using and clean up all
HConnection resources as well as stopping proxies to servers out on the
cluster. Not running the cleanup will not end the world; it'll
just stall the closeup some and spew some zookeeper connection failed
messages into the log. Running the cleanup on a HConnection
that is
subsequently used by another will cause breakage so be careful running
cleanup.
To create a HConnection
that is not shared by others, you can
set property "hbase.client.instance.id" to a unique value for your Configuration
instance, like the following:
conf.set("hbase.client.instance.id", "12345");
HConnection connection = HConnectionManager.getConnection(conf);
// Use the connection to your hearts' delight and then when done...
conf.set("hbase.client.instance.id", "12345");
HConnectionManager.deleteConnection(conf, true);
Cleanup used to be done inside in a shutdown hook. On startup we'd
register a shutdown hook that called deleteAllConnections()
on its way out but the order in which shutdown hooks run is not defined so
were problematic for clients of HConnection that wanted to register their
own shutdown hooks so we removed ours though this shifts the onus for
cleanup to the client.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_CACHED_CONNECTION_INSTANCES
Deprecated.
|
static String |
RETRIES_BY_SERVER_KEY
Deprecated.
|
Modifier | Constructor and Description |
---|---|
private |
HConnectionManager()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static HConnection |
createConnection(org.apache.hadoop.conf.Configuration conf)
Deprecated.
|
(package private) static HConnection |
createConnection(org.apache.hadoop.conf.Configuration conf,
boolean managed)
Deprecated.
|
(package private) static ClusterConnection |
createConnection(org.apache.hadoop.conf.Configuration conf,
boolean managed,
ExecutorService pool,
User user)
Deprecated.
|
static HConnection |
createConnection(org.apache.hadoop.conf.Configuration conf,
ExecutorService pool)
Deprecated.
|
static HConnection |
createConnection(org.apache.hadoop.conf.Configuration conf,
ExecutorService pool,
User user)
Deprecated.
|
static HConnection |
createConnection(org.apache.hadoop.conf.Configuration conf,
User user)
Deprecated.
|
static void |
deleteAllConnections()
Deprecated.
kept for backward compatibility, but the behavior is broken. HBASE-8983
|
static void |
deleteAllConnections(boolean staleConnection)
Deprecated.
|
static void |
deleteConnection(org.apache.hadoop.conf.Configuration conf)
Deprecated.
|
static void |
deleteStaleConnection(HConnection connection)
Deprecated.
|
static <T> T |
execute(HConnectable<T> connectable)
Deprecated.
Internal method, do not use thru HConnectionManager.
|
static HConnection |
getConnection(org.apache.hadoop.conf.Configuration conf)
Deprecated.
|
static void |
setServerSideHConnectionRetries(org.apache.hadoop.conf.Configuration c,
String sn,
org.apache.commons.logging.Log log)
Deprecated.
Internal method, do not use.
|
createConnection
@Deprecated public static final String RETRIES_BY_SERVER_KEY
@Deprecated public static final int MAX_CACHED_CONNECTION_INSTANCES
@Deprecated public static HConnection getConnection(org.apache.hadoop.conf.Configuration conf) throws IOException
conf
configuration instance.
If no current connection exists, method creates a new connection and keys it using
connection-specific properties from the passed Configuration
; see
HConnectionKey
.conf
- configurationconf
ZooKeeperConnectionException
IOException
@Deprecated public static HConnection createConnection(org.apache.hadoop.conf.Configuration conf) throws IOException
conf
instance.
Note: This bypasses the usual HConnection life cycle management done by
getConnection(Configuration)
. The caller is responsible for
calling Connection.close()
on the returned connection instance.
This is the recommended way to create HConnections.
HConnection connection = HConnectionManager.createConnection(conf); HTableInterface table = connection.getTable("mytable"); try { table.get(...); ... } finally { table.close(); connection.close(); }
conf
- configurationconf
ZooKeeperConnectionException
IOException
@Deprecated public static HConnection createConnection(org.apache.hadoop.conf.Configuration conf, ExecutorService pool) throws IOException
conf
instance.
Note: This bypasses the usual HConnection life cycle management done by
getConnection(Configuration)
. The caller is responsible for
calling Connection.close()
on the returned connection instance.
This is the recommended way to create HConnections.
ExecutorService pool = ...; HConnection connection = HConnectionManager.createConnection(conf, pool); HTableInterface table = connection.getTable("mytable"); table.get(...); ... table.close(); connection.close();
conf
- configurationpool
- the thread pool to use for batch operation in HTables used via this HConnectionconf
ZooKeeperConnectionException
IOException
@Deprecated public static HConnection createConnection(org.apache.hadoop.conf.Configuration conf, User user) throws IOException
conf
instance.
Note: This bypasses the usual HConnection life cycle management done by
getConnection(Configuration)
. The caller is responsible for
calling Connection.close()
on the returned connection instance.
This is the recommended way to create HConnections.
ExecutorService pool = ...; HConnection connection = HConnectionManager.createConnection(conf, pool); HTableInterface table = connection.getTable("mytable"); table.get(...); ... table.close(); connection.close();
conf
- configurationuser
- the user the connection is forconf
ZooKeeperConnectionException
IOException
@Deprecated public static HConnection createConnection(org.apache.hadoop.conf.Configuration conf, ExecutorService pool, User user) throws IOException
conf
instance.
Note: This bypasses the usual HConnection life cycle management done by
getConnection(Configuration)
. The caller is responsible for
calling Connection.close()
on the returned connection instance.
This is the recommended way to create HConnections.
ExecutorService pool = ...; HConnection connection = HConnectionManager.createConnection(conf, pool); HTableInterface table = connection.getTable("mytable"); table.get(...); ... table.close(); connection.close();
conf
- configurationpool
- the thread pool to use for batch operation in HTables used via this HConnectionuser
- the user the connection is forconf
ZooKeeperConnectionException
IOException
@Deprecated static HConnection createConnection(org.apache.hadoop.conf.Configuration conf, boolean managed) throws IOException
IOException
@Deprecated static ClusterConnection createConnection(org.apache.hadoop.conf.Configuration conf, boolean managed, ExecutorService pool, User user) throws IOException
IOException
@Deprecated public static void deleteConnection(org.apache.hadoop.conf.Configuration conf)
conf
- configuration whose identity is used to find HConnection
instance.@Deprecated public static void deleteStaleConnection(HConnection connection)
connection
- @Deprecated public static void deleteAllConnections(boolean staleConnection)
@Deprecated public static void deleteAllConnections()
@InterfaceAudience.Private @Deprecated public static <T> T execute(HConnectable<T> connectable) throws IOException
HConnectable.connect(org.apache.hadoop.hbase.client.HConnection)
implementation using a HConnection
instance that lasts just for the
duration of the invocation.T
- the return type of the connect methodconnectable
- the HConnectable
instanceIOException
@InterfaceAudience.Private @Deprecated public static void setServerSideHConnectionRetries(org.apache.hadoop.conf.Configuration c, String sn, org.apache.commons.logging.Log log)
HConnection
. Used updating catalog
tables, etc. Call this method before we create any Connections.c
- The Configuration instance to set the retries into.log
- Used to log what we set in here.Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.