Tablestore HBase Client is encapsulated based on HBase Client. Compared with HBase Client, Tablestore HBase Client is used in a similar but differentiated way. This topic describes how to migrate from HBase Client to Tablestore HBase Client.
Add dependencies
Tablestore HBase Client V1.2.0 depends on HBase Client 1.2.0 and Tablestore SDK for Java V4.2.1. The following sample code provides an example on how to add dependencies to the pom.xml file:
<dependencies>
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>tablestore-hbase-client</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
If you want to use other versions of HBase Client or Tablestore SDK for Java, you can use the exclusion tag. In the following example, HBase Client 1.2.1 and Tablestore SDK for Java V4.2.0 are used:
<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>
Tablestore HBase Client V1.2.x is compatible only with HBase Client 1.2.x because HBase Client 1.2.x has different operations from other versions.
If you want to use HBase Client 1.1.x, you must use Tablestore HBase Client V1.1.x.
If you want to use HBase Client 0.x.x, refer to Make Tablestore HBase Client compatible with HBase versions earlier than 1.0.
Modify the configuration file
To migrate from HBase Client to Tablestore HBase Client, you must modify the following configuration items in the configuration file:
HBase Connection type
Set the HBase Connection type to TablestoreConnection.
<property> <name>hbase.client.connection.impl</name> <value>com.alicloud.tablestore.hbase.TablestoreConnection</value> </property>
Configuration items of Tablestore
Tablestore is a cloud service that enables strict permission management. To access Tablestore, you must configure the authentication method such as AccessKey pairs.
You must configure the following items before you can access Tablestore:
tablestore.client.endpoint
specifies the endpoint of the Tablestore instance.tablestore.client.instancename
specifies the name of the Tablestore instance.tablestore.client.accesskeyid
andtablestore.client.accesskeysecret
specify the AccessKey ID and AccessKey secret of an Alibaba Cloud account or a Resource Access Management (RAM) user.<property> <name>tablestore.client.endpoint</name> <value>https://exampleinstabce.cn-hangzhou.ots.aliyuncs.com</value> </property> <property> <name>tablestore.client.instancename</name> <value>exampleinstabce</value> </property> <property> <name>tablestore.client.accesskeyid</name> <value>*****************</value> </property> <property> <name>tablestore.client.accesskeysecret</name> <value>***********</value> </property>
The following configuration items are optional:
<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>
Optional configuration items:
hbase.client.tablestore.family
andhbase.client.tablestore.family.$tablename
Tablestore supports only single-column families. When you call the HBase API, you must specify the content of the family.
hbase.client.tablestore.family
specifies the global configurations, andhbase.client.tablestore.family.$tablename
specifies the configurations of a single table.For a table named T, search for
hbase.client.tablestore.family.T
. If the family does not exist, search forhbase.client.tablestore.family
. If the family does not exist, use the default value f.tablestore.client.max.connections
: the maximum number of connections. Default value: 300.tablestore.client.socket.timeout
: the timeout period of the socket connection. Default value: 15. Unit: seconds.tablestore.client.connection.timeout
: the connection timeout period. Default value: 15. Unit: seconds.tablestore.client.operation.timeout
: the timeout period of the API. Default value:Integer.MAX_VALUE
, which specifies that the operation never times out.tablestore.client.retries
: the number of retry attempts when a request fails. Default value: 3.