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

简介: 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.

相关实践学习
阿里云表格存储使用教程
表格存储(Table Store)是构建在阿里云飞天分布式系统之上的分布式NoSQL数据存储服务,根据99.99%的高可用以及11个9的数据可靠性的标准设计。表格存储通过数据分片和负载均衡技术,实现数据规模与访问并发上的无缝扩展,提供海量结构化数据的存储和实时访问。 产品详情:https://www.aliyun.com/product/ots
目录
相关文章
|
NoSQL Java Android开发
Remote Configuration for Android using Alibaba Cloud Table Store
In this tutorial, you will learn how to use Table Store to create a simple user information database with a form accessible on mobile devices.
1626 0
|
6月前
|
存储 索引
表格存储根据多元索引查询条件直接更新数据
表格存储是否可以根据多元索引查询条件直接更新数据?
62 3
|
SQL 存储 弹性计算
玩转Tablestore:使用Grafana快速展示时序数据
Grafana 是一款采用 go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和应用分析中最流行的时序数据展示工具,可以通过将采集的数据查询然后可视化的展示,实现报警通知;Grafana拥有丰富的数据源,官方支持以下数据源:Graphite,Elasticsearch,InfluxDB,Prometheus,Cloudwatch,MySQ
1644 0
|
1月前
|
分布式计算 DataWorks API
DataWorks常见问题之按指定条件物理删除OTS中的数据失败如何解决
DataWorks是阿里云提供的一站式大数据开发与管理平台,支持数据集成、数据开发、数据治理等功能;在本汇总中,我们梳理了DataWorks产品在使用过程中经常遇到的问题及解答,以助用户在数据处理和分析工作中提高效率,降低难度。
|
3月前
|
DataWorks NoSQL 关系型数据库
可以使用dataworks从tablestore同步数据到mysql吗?
可以使用dataworks从tablestore同步数据到mysql吗?
32 1
|
10月前
|
NoSQL 开发工具
TableStore表格存储(阿里云OTS)多行数据操作查询,支持倒序,过滤条件和分页
1. 批量读取操作 批量读取操作可以通过多种方式进行,包括: GetRow:根据主键读取一行数据。 BatchGetRow:批量读取多行数据。 GetRange:根据范围读取多行数据。
586 0
|
存储 消息中间件 NoSQL
物联网数据通过规则引擎流转到OTS|学习笔记
快速学习物联网数据通过规则引擎流转到OTS
273 0
物联网数据通过规则引擎流转到OTS|学习笔记
|
存储 负载均衡 开发者
表格存储数据多版本介绍| 学习笔记
快速学习表格存储数据多版本介绍。
227 0
表格存储数据多版本介绍| 学习笔记
|
存储 NoSQL 关系型数据库
基于TableStore的海量气象格点数据解决方案实战 王怀远
基于TableStore的海量气象格点数据解决方案实战 王怀远
316 0
基于TableStore的海量气象格点数据解决方案实战 王怀远
|
存储 SQL 运维
基于Tablestore 实现大规模订单系统海量订单/日志数据分类存储的实践
前言:从最早的互联网高速发展、到移动互联网的爆发式增长,再到今天的产业互联网、物联网的快速崛起,各种各样新应用、新系统产生了众多订单类型的需求,比如电商购物订单、银行流水、运营商话费账单、外卖订单、设备信息等,产生的数据种类和数据量越来越多;其中订单系统就是一个非常广泛、通用的系统。而随着数据规模的快速增长、大数据技术的发展、运营水平的不断提高,包括数据消费的能力要求越来越高,这对支撑订单系统的数据库设计、存储系统也提出了更多的要求。在新的需求下,传统的经典架构面临着诸多挑战,需要进一步思考架构优化,以更好支撑业务发展;
676 0
基于Tablestore 实现大规模订单系统海量订单/日志数据分类存储的实践