How to Use HBase Client to Access Alibaba Cloud NoSQL Table Store

本文涉及的产品
表格存储 Tablestore,50G 2个月
简介: HBase client helps users to access HBase conveniently. It supports reading, writing, scanning, batch operation, table management as well as other features.

86e43d940883c108c3166060805b39ee921d58eb_jpeg

Introduction

The Alibaba Cloud NoSQL Table Store is a scalable and fully managed NoSQL database service, based on automatic data partitioning and load balancing technologies. Built on SSD technology, this cloud NoSQL database service enables you to store large quantities of structured and semi-structured data with real-time access. Furthermore, it facilitates strong consistency and single-digit millisecond latency.

Using HBase Client to Access Alibaba Cloud NoSQL Table Store has the following advantages:

● Authenticates each request to prevent unauthorized data access to NoSQL servers.
● Easily scales reserved resources based on real-time application hosting needs.
● Provides seamless scaling of applications hosted on the cloud.
● Automated failure detection and quick failure recovery.

We will go into the details of how you can use HBase client to access Alibaba Cloud Table Store. However, we will start by briefly introducing related terms such as Apache HBase, Table Store, and HBase Client. This information will help you understand the steps in a more effective manner.

Apache HBase

Apache HBase is a Hadoop database that belongs to the Hadoop ecosystem. Since the release of Google’s publications on ‘The Google File System, MapReduce: Simplified Data Processing on Large Clusters and Bigtable: A Distributed Storage System for Structured Data', four years ago, the open source circle has been taking these as inspiration to design the three open-source systems. The best one being the Hadoop ecology, which corresponds to Hadoop, HDFS and HBase respectively. The current Hadoop ecology is a benchmark in the industry owing to its large-scale application and honing for more than a decade. So established is the current Hadoop ecology that it is "forcing" NoSQL's originator Google Bigtable to support HBase wrapper and provide the Bigtable HBase client.

Table Store

Unlike HBase which uses Java, Table Store is a NoSQL database independently developed by Alibaba Cloud. It uses C++ for development, just like Bigtable.

Since Table Store is a NoSQL database similar to HBase, it plays a significant role in its functioning. In most scenarios, Table Store may even outperform HBase. However, Table Store has certain advanced features not available in HBase.

HBase Client

HBase client, provided by HBase is for users to access HBase conveniently. It supports reading, writing, scanning, batch operation, table management as well as other features.

Now that we have explained the related elements, let us move forward towards understanding the various aspects of using HBase client to access Alibaba Cloud NoSQL Table Store.

The Challenge

Since a long time, Hadoop Ecology has been a widely applied solution amongst various organizations as the only open-source big data solution. At present, most companies with self-built data processing systems use Hadoop ecosystems, such as HBase. Earlier, when migrating data to Alibaba Cloud's NoSQL Table Store, the users required to rewrite the client code to use Table Store. Though this approach results in higher performance and is user-friendly, it is highly time-consuming in the early stages. Table Store introduced the Table Store HBase client last year to address this problem.

Usage

If you were previously using HBase Client to access HBase, you only require changing the dependency on HBase Client to Table Store HBase client in the project now. Furthermore, you also need to modify the hbase.client.connection.impl value in the hbase-site.xml to com.alicloud.tablestore.hbase.TablestoreConnection without any other changes to the code. Let us look at an example and the steps for effective usage of HBase client. This would make understanding the concept much easier.

Code Location

We will adopt the current program as an example using the HBase API to access the Table Store service. The complete program is accessible at Github's Alibaba Cloud Table Store HBase client for Java project, which is at src/test/java/samples/HelloWorld.java.

Steps for Using HBase Client to Access Alibaba Cloud NoSQL Table Store

Step 1. Configure Project Dependencies

The first step in this would be to configure project dependencies.
You can configure the Maven dependency as follows:

<dependencies>
        <dependency>
            <groupId>com.aliyun.openservices</groupId>
            <artifactId>tablestore-hbase-client</artifactId>
            <version>1.2.0</version>
        </dependency>
</dependencies>

Step 2. Configure files

Then you would need to add the following configuration items in hbase-site.xml:

<configuration>
    <property>
        <name>hbase.client.connection.impl</name>
        <value>com.alicloud.tablestore.hbase.TablestoreConnection</value>
    </property>
    <property>
        <name>tablestore.client.endpoint</name>
        <value>endpoint</value>
    </property>
    <property>
        <name>tablestore.client.instancename</name>
        <value>instance_name</value>
    </property>
    <property>
        <name>tablestore.client.accesskeyid</name>
        <value>access_key_id</value>
    </property>
    <property>
        <name>tablestore.client.accesskeysecret</name>
        <value>access_key_secret</value>
    </property>
    <property>
        <name>hbase.client.tablestore.family</name>
        <value>f1</value>
    </property>
    <property>
        <name>hbase.client.tablestore.table</name>
        <value>ots_adaptor</value>
    </property>
</configuration>

Step 3. Connect to Table Store

Next, connect to Table Store service by creating a Table Store connection object by executing the following code:

        Configuration config = HBaseConfiguration.create();

        // Create a Table Store connection
        Connection connection = ConnectionFactory.createConnection(config);

        // Admin is in charge of creating, managing and deleting connections.
        Admin admin = connection.getAdmin();

Step 4. Create a Table

Once you have connected to a Table Store service, specify the table name to create a table. For this, use default values for MaxVersion and TimeToLive.

        // Create an HTableDescriptor with only one column family
        HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));

        // Create a column family. Use default values for MaxVersion and TimeToLive. The default value of MaxVersion is 1 and the default value of TimeToLive is Integer.INF_MAX. 
        descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME));

        // Create a table using the Admin createTable interface
        System.out.println("Create table " + descriptor.getNameAsString());
        admin.createTable(descriptor);

Step 5. Write Data

You would now need to write a row of data to Table Store. The steps of writing data are:

// Create a Table Store table for reading, writing, updating and deleting operations on a single table
        Table table = connection.getTable(TableName.valueOf(TABLE_NAME));

        // Create a Put object with the primary key as row_1
        System.out.println("Write one row to the table");
        Put put = new Put(ROW_KEY);

     // Add a column. Table Store only supports single column families. The column family name is configured in hbase-site.xml. If it is not configured, the default value of "f" applies. Therefore, you can leave the COLUMN_FAMILY_NAME null when writing data. 
 put.addColumn(COLUMN_FAMILY_NAME, COLUMN_NAME, COLUMN_VALUE);

 // Execute the table put operation. Use the HBase API to write the row of data to Table Store. 
  table.put(put);

Step 6. Read Data

Further, you need to read data in a specified row by running the code below.

  // Create a Get object and read the row with a primary key of ROW_KEY
        Result getResult = table.get(new Get(ROW_KEY));
        Result result = table.get(get);

  // Prints the results
        String value = Bytes.toString(getResult.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME));
        System.out.println("Get one row by row key");
        System.out.printf("\t%s = %s\n", Bytes.toString(ROW_KEY), value);

Step 7. Scan Data

Then, read data by range by executing the following:

    Scan data in all the rows in the table.
    System.out.println("Scan for all rows:");
    Scan scan = new Scan();

    ResultScanner scanner = table.getScanner(scan);

    // Print the result in cycles
    for (Result row : scanner) {
        byte[] valueBytes = row.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME);
        System.out.println('\t' + Bytes.toString(valueBytes));
    }

Step 8. Delete a Table

Next, use Admin API to delete a table.

        print("Delete the table");
        admin.disableTable(table.getName());
        admin.deleteTable(table.getName());

Conclusion

At present, some users use Table Store. Constant optimization takes place for Table Store HBase client based on user feedback with an aim to elevate its performance close to the level of the native Table Store.

Although Table Store HBase client can also access Table Store, users are recommended to access Table Store with the Table Store SDK for better performance, a wider range of features and a better price. Therefore, in OLTP (OnLine Transaction Processing) scenarios, Table Store is better suited for web applications, for example, social networks, games, media sharing, IoT, and log monitoring. You can access the official Alibaba Cloud website for Table Store for more information.

相关实践学习
消息队列+Serverless+Tablestore:实现高弹性的电商订单系统
基于消息队列以及函数计算,快速部署一个高弹性的商品订单系统,能够应对抢购场景下的高并发情况。
阿里云表格存储使用教程
表格存储(Table Store)是构建在阿里云飞天分布式系统之上的分布式NoSQL数据存储服务,根据99.99%的高可用以及11个9的数据可靠性的标准设计。表格存储通过数据分片和负载均衡技术,实现数据规模与访问并发上的无缝扩展,提供海量结构化数据的存储和实时访问。 产品详情:https://www.aliyun.com/product/ots
目录
相关文章
|
6月前
|
存储 NoSQL Java
HBase是一个开源的、分布式的、面向列的NoSQL数据库系统
HBase是一个开源的、分布式的、面向列的NoSQL数据库系统
122 0
|
7月前
|
SQL 分布式数据库 HIVE
分布式NoSQL列存储数据库Hbase(六)
分布式NoSQL列存储数据库Hbase(六)
84 0
|
7月前
|
存储 NoSQL 分布式数据库
分布式NoSQL列存储数据库Hbase(一)Hbase的功能与应用场景、基本设计思想
分布式NoSQL列存储数据库Hbase(一)Hbase的功能与应用场景、基本设计思想
465 0
|
7月前
|
缓存 分布式计算 NoSQL
分布式NoSQL列存储数据库Hbase_MR集成Hbase:读写Hbase规则(九)
分布式NoSQL列存储数据库Hbase_MR集成Hbase:读写Hbase规则(九)
67 0
|
7月前
|
NoSQL 分布式数据库 数据库
分布式NoSQL列存储数据库Hbase_列族的设计(五)
分布式NoSQL列存储数据库Hbase_列族的设计(五)
267 0
|
7月前
|
存储 NoSQL 分布式数据库
分布式NoSQL列存储数据库Hbase_高级思想(八)
分布式NoSQL列存储数据库Hbase_高级思想(八)
70 0
|
7月前
|
存储 NoSQL 分布式数据库
分布式NoSQL列存储数据库Hbase Java API(四)
分布式NoSQL列存储数据库Hbase Java API(四)
74 0
|
7月前
|
存储 NoSQL 分布式数据库
分布式NoSQL列存储数据库Hbase Java API(三)
分布式NoSQL列存储数据库Hbase Java API(三)
68 0
|
7月前
|
SQL 存储 NoSQL
分布式NoSQL列存储数据库Hbase操作(二)
分布式NoSQL列存储数据库Hbase操作(二)
154 0
|
NoSQL 数据挖掘 分布式数据库
《第十二届 BigData NoSQL Meetup — 快手HBase在千亿级用户特征数据分析中的应用与实践》电子版地址
第十二届 BigData NoSQL Meetup — 快手HBase在千亿级用户特征数据分析中的应用与实践
130 0
《第十二届 BigData NoSQL Meetup — 快手HBase在千亿级用户特征数据分析中的应用与实践》电子版地址