HBase客户端API基本操作
Java类与HBase数据模型
包名 : org.apache.hadoop.hbase.HBaseConfiguration
作用:对HBase进行配置。
用法示例:
包名 : org.apache.hadoop.hbase.client.HBaseAdmin
作用:提供了一个接口来管理HBase数据库的表信息。
它提供的方法包括:创建表,删除表,列出表项,使表有效或无效,以及添加或删除表列族成员等。
用法示例:
包名: org.apache.hadoop.hbase.HTableDescriptor
作用:包含了表的名字及其对应表的列族。
用法示例:
包名: org.apache.hadoop.hbase.HColumnDescriptor
作用:维护着关于列族的信息,例如版本号,压缩设置等。
它通常在创建表或者为表添加列族的时候使用。
列族被创建后不能直接修改,只能通过删除,然后重新创建的方式。
列族被删除的时候,列族里面的数据也会同时被删除。
用法示例:
包名: org.apache.hadoop.hbase.client.HTable
作用:可以用来和HBase表直接通信。此方法对于更新操作来说是非线程安全的。
用法示例:
包名: org.apache.hadoop.hbase.client.HTablePool
作用:可以解决HTable存在的线程不安全问题,同时通过维护固定数量的HTable对象,能够在程序运行期间复用这些HTable资源对象。
说明:
1. HTablePool可以自动创建HTable对象,而且对客户端来说使用上是完全透明的,可以避免多线程间数据并发修改问题。
2. HTablePool中的HTable对象之间是公用Configuration连接的,,能够可以减少网络开销。
HTablePool的使用很简单:每次进行操作前,通过HTablePool的getTable方法取得一个HTable对象,然后进行put/get/scan/delete等操作,最后通过HTablePool的putTable方法将HTable对象放回到HTablePool中。
/** * A simple pool of HTable instances. * * Each HTablePool acts as a pool for all tables. To use, instantiate an * HTablePool and use {@link #getTable(String)} to get an HTable from the pool. * * This method is not needed anymore, clients should call HTableInterface.close() * rather than returning the tables to the pool * * Once you are done with it, close your instance of {@link HTableInterface} * by calling {@link HTableInterface#close()} rather than returning the tables * to the pool with (deprecated) {@link #putTable(HTableInterface)}. * * <p> * A pool can be created with a <i>maxSize</i> which defines the most HTable * references that will ever be retained for each table. Otherwise the default * is {@link Integer#MAX_VALUE}. * * <p> * Pool will manage its own connections to the cluster. See * {@link HConnectionManager}. * @deprecated as of 0.98.1. See {@link HConnection#getTable(String)}. */ @InterfaceAudience.Private @Deprecated public class HTablePool implements Closeable { } Put温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70338.html