hbase中托管和非托管hconnection有什么区别?
what difference of managed and unmanaged hconnection in hbase?
当我尝试以这种方式创建一个 HTable 实例时。
Configuration conf = HBaseConfiguration.create();
HConnection conn = HConnectionManager.getConnection(conf);
conn.getTable("TABLE_NAME");
然后我得到一个异常。
@Override
public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException {
if (managed) {
throw new IOException("The connection has to be unmanaged.");
}
return new HTable(tableName, this, pool);
}
那么,我想知道managed和'unmanaged'Hconnection的具体体现?
在调用 HConnectionManager.getConnection
之前,您必须使用 HConnectionManager.createConnection
传递给它之前创建的 HBaseConfiguration
实例来创建连接。 HConnectionManager.getConnection
return 已存在的连接。关于它如何处理连接池的一些 HConnectionManager
javadoc:
This class has a static Map of HConnection instances keyed by Configuration; all invocations of getConnection(Configuration) that pass the sameConfiguration instance will be returned the sameHConnection instance
在您的情况下,您只需使用 HConnectionManager.createConnection
创建连接并使用 returned 连接打开 HTable
编辑:
@ifidddddddbest,我找到了 HConnectionImplementation
的 javadocs,其中描述了托管标志(可能会帮助您理解):
@param managed If true, does not do full shutdown on close; i.e.
cleanup of connection to zk and shutdown of all services; we just
close down the resources this connection was responsible for and
decrement usage counters. It is up to the caller to do the full
cleanup. It is set when we want have connection sharing going on --
reuse of zk connection, and cached region locations, established
regionserver connections, etc. When connections are shared, we have
reference counting going on and will only do full cleanup when no more
users of an HConnectionImplementation instance.
在较新版本的 HBase(>1.0) 中,托管标志消失了,所有连接管理现在都在客户端,例如客户端负责关闭它,如果它这样做,它会关闭与 ZK、HBase master 等的所有内部连接,不仅会减少引用计数器。
当我尝试以这种方式创建一个 HTable 实例时。
Configuration conf = HBaseConfiguration.create();
HConnection conn = HConnectionManager.getConnection(conf);
conn.getTable("TABLE_NAME");
然后我得到一个异常。
@Override
public HTableInterface getTable(TableName tableName, ExecutorService pool) throws IOException {
if (managed) {
throw new IOException("The connection has to be unmanaged.");
}
return new HTable(tableName, this, pool);
}
那么,我想知道managed和'unmanaged'Hconnection的具体体现?
在调用 HConnectionManager.getConnection
之前,您必须使用 HConnectionManager.createConnection
传递给它之前创建的 HBaseConfiguration
实例来创建连接。 HConnectionManager.getConnection
return 已存在的连接。关于它如何处理连接池的一些 HConnectionManager
javadoc:
This class has a static Map of HConnection instances keyed by Configuration; all invocations of getConnection(Configuration) that pass the sameConfiguration instance will be returned the sameHConnection instance
在您的情况下,您只需使用 HConnectionManager.createConnection
创建连接并使用 returned 连接打开 HTable
编辑:
@ifidddddddbest,我找到了 HConnectionImplementation
的 javadocs,其中描述了托管标志(可能会帮助您理解):
@param managed If true, does not do full shutdown on close; i.e. cleanup of connection to zk and shutdown of all services; we just close down the resources this connection was responsible for and decrement usage counters. It is up to the caller to do the full cleanup. It is set when we want have connection sharing going on -- reuse of zk connection, and cached region locations, established regionserver connections, etc. When connections are shared, we have reference counting going on and will only do full cleanup when no more users of an HConnectionImplementation instance.
在较新版本的 HBase(>1.0) 中,托管标志消失了,所有连接管理现在都在客户端,例如客户端负责关闭它,如果它这样做,它会关闭与 ZK、HBase master 等的所有内部连接,不仅会减少引用计数器。