Tablestore HBase Client是基于HBase Client的封装,使用方法和HBase Client基本一致,但仍存在一些差别。本文主要为您介绍如何从HBase Client迁移到Tablestore HBase Client 。
依赖
Tablestore HBase Client 1.2.0版本依赖了HBase Client 1.2.0版本和Tablestore Java SDK 4.2.1版本。pom.xml配置如下:
<dependencies>
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore-hbase-client</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
如果需要使用其他版本的HBase Client或Tablestore Java SDK,可以使用exclusion标签。下面示例中使用HBase Client 1.2.1版本和Tablestore4.2.0版本。
<dependencies>
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore-hbase-client</artifactId>
<version>1.2.0</version>
<exclusions>
<exclusion>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore</artifactId>
<classifier>jar-with-dependencies</classifier>
<version>4.2.0</version>
</dependency>
</dependencies>
HBase Client 1.2.x和其他版本(如 1.1.x)存在接口变化,而Tablestore HBase Client 1.2.x版本只能兼容HBase Client 1.2.x。
如果需要使用HBase Client 1.1.x版本,请使用Tablestore HBase Client 1.1.x版本。
如果需要使用HBase Client 0.x.x版本,请参考迁移较早版本的 HBase。
配置文件
从HBase Client迁移到Tablestore HBase Client,需要在配置文件中修改以下两点:
- HBase Connection类型
Connection需要配置为TablestoreConnection。
<property> <name>hbase.client.connection.impl</name> <value>com.alicloud.tablestore.hbase.TablestoreConnection</value> </property>
- 表格存储的配置项
表格存储是云服务,提供了严格的权限管理。要访问表格存储,需要配置密钥等信息。
-
必须配置以下四个配置项才能成功访问表格存储:
<property> <name>tablestore.client.endpoint</name> <value></value> </property> <property> <name>tablestore.client.instancename</name> <value></value> </property> <property> <name>tablestore.client.accesskeyid</name> <value></value> </property> <property> <name>tablestore.client.accesskeysecret</name> <value></value> </property>
-
下面为可选配置项:
<property> <name>hbase.client.tablestore.family</name> <value>f1</value> </property> <property> <name>hbase.client.tablestore.family.$tablename</name> <value>f2</value> </property> <property> <name>tablestore.client.max.connections</name> <value>300</value> </property> <property> <name>tablestore.client.socket.timeout</name> <value>15000</value> </property> <property> <name>tablestore.client.connection.timeout</name> <value>15000</value> </property> <property> <name>tablestore.client.operation.timeout</name> <value>2147483647</value> </property> <property> <name>tablestore.client.retries</name> <value>3</value> </property>
- hbase.client.tablestore.family与hbase.client.tablestore.family.$tablename
- 表格存储只支持单列族,使用HBase API时,需要有一项family的内容,因此通过配置来填充此项family的内容。
其中,
hbase.client.tablestore.family
为全局配置,hbase.client.tablestore.family.$tablename
为单个表的配置。 - 规则为:对表名为T的表,先找
hbase.client.tablestore.family.T
,如果不存在则找hbase.client.tablestore.family
,如果依然不存在则取默认值f。
- 表格存储只支持单列族,使用HBase API时,需要有一项family的内容,因此通过配置来填充此项family的内容。
-
tablestore.client.max.connections
最大链接数,默认是300。
-
tablestore.client.socket.timeout
Socket超时时间,默认是15秒。
-
tablestore.client.connection.timeout
连接超时时间,默认是15秒。
-
tablestore.client.operation.timeout
API超时时间,默认是Integer.MAX_VALUE,类似于永不超时。
-
tablestore.client.retries
请求失败时,重试次数,默认是3次。
- hbase.client.tablestore.family与hbase.client.tablestore.family.$tablename
-