Objective:
As an important part of the Hadoop ecosystem, HBase, as a distributed, Columnstore, online real-time processing feature, has attracted much attention and will be able to replace the traditional relational database in many applications in the future. This article focuses on the application scenarios for time series/polygon retrieval, and how to use the characteristics of hbase to process and optimize.
Constructing the application scenario
A meteorological bureau collects and summarizes information from various sites, including site ID, point in time, and collection of elements (especially many elements). Then the data collected, the following search requirements:
1). Time Series Retrieval (retrieves the full feature information for the site within a certain time frame)
2). Polygon Retrieval (retrieves a feature information at a specific point in time for each site)
and its data information is as follows:
1). There are many kinds of elements, the meteorological related to the observed elements (humidity, temperature, wind direction, etc.)
2). Each site collects part of the information, each site's own duties (observation points of the re-different)
This shows that the distribution of the data is a large and wide table Form, the column is more sparse and distributed in a way.
Storage selection
Comparing the traditional relational data with hbase, the measured parameters of the comparison are as follows:
| Storage selection |
Scalability |
Index support |
Transaction support |
Storage mode |
Application Scenarios |
| ORACLE/DB2 (CA) |
Horizontal scaling is not supported |
Multi-Index support |
Support Transactions |
Row-type storage (fixed schema, poor support for sparse column data) |
Bank Financial institutions (places where data consistency is a high requirement) |
| Mysql Cluster (AP) |
Support Horizontal capacity expansion (sub-database table, hash type) |
Multi-Index support |
Transactions not supported (cross-Library) |
Row-type storage (fixed schema, poor support for sparse column data) |
Internet/Mobile internet (pursuit of high concurrency/high performance) |
| HBase (CP) |
Supports horizontal expansion (region by key range, interval type) |
No index, based on Key/value |
Transaction not supported |
Columnstore (non-fixed schema, support for sparse column data) |
Big Data field |
Commentary: Cap theory, in any distributed system, can only meet up to two of the CAP (consistency/high availability/partition tolerance).
From the data, we can find that the traditional relational database is difficult to satisfy the large wide table (multi-column and sparse) data storage, so we choose HBase as our storage model.
Retrieval analysis
HBase is a distributed, Columnstore, multi-and sparse-distributed data support that is very good. For real-time retrieval, HBase is implemented with Rowkey, which supports the key range/prefix search, and the retrieval performance is very good. Therefore, to apply HBase, its rowkey design becomes a crucial link. Based on actual combat experience, Rowkey is composed of multiple fields and supports key prefix retrieval, which is somewhat similar to a composite index of a traditional relational database. But the insufficient aspect is that the HBase table has only one rowkey, in other words, there is only one index, and multiple fields are composed of rowkey, which need equal width bytes to build it. These factors have an impact on the search requirements mentioned above.
Back to the initial application scenario, its retrieval requirements have time series retrieval and polygon retrieval, and the Rowkey design scheme is as follows:
1). Rowkey format: Timestamp:site_id:others, which takes a time field as a prefix to the rowkey, searches the opposite (retrieves a point in time, lists the feature information of each site) friendly, and retrieves the time series (retrieving the site's feature retrieval at a certain time range) Not friendly. The former uses the Rowkey prefix, the latter is not used, so the scanning range becomes larger and the efficiency decreases rapidly.
2). Rowkey format: site_id:timestamp:others, put the site ID in rowkey prefix, then the result is exactly the opposite.
Therefore, both rowkey design schemes can not meet the time series retrieval and polygon retrieval simultaneously. So what do we do?
Data is double-written, using data redundancy to build two tables. One table uses timestamp:site_id:others as the design of the Rowkey, and the other one uses site_id:timestamp:others as the Rowkey design scheme. At the same time, the data content of the two tables is exactly the same, so as to satisfy the requirements of the above-mentioned time series retrieval and polygon retrieval. This redundancy scheme is widely used in distributed MySQL cluster.
Commentary: Data double write, is a solution as ha (high availability), the common HA policy has a master-slave backup (there is a single point of failure).
Write optimization
Although the data bi-write scheme solves the above retrieval requirements (high read performance), the HBase table with Tiemstamp as the Rowkey prefix has a write hotspot problem. Because the region of HBase is divided by the range of Rowkey, the data is very time-intensive, which results in almost all of the data resting on the same area, leading to the writing of hot issues. Therefore, we need to complement the data bi-write scheme, so as to solve the problem of data writing hotspot.
Rowkey prefix salt, the use of random/hash (site) to generate salt, so scattered write, avoid hot issues. Of course, salt comes at a price, and it makes it harder to read data because the data is scattered across different region.
The book <
Final Solution:
For this scenario, HBase is used as the underlying storage scheme.
1). Data double write mode, build two tables, data redundancy.
2). Table A with a hash (site_id): Timestamp:site_id:others as the Rowkey, hash (site_id) means the site ID is modeled as a salt.
3). Table B with Site_id:timestamp:others as Rowkey, the number of sites (site_id) more, good dispersion.
Turn from:
HBase Combat (2)--application scenario of time series retrieval and polygon retrieval
HBase Combat (2)--application scenario of time series retrieval and polygon retrieval