Design method of mass data Hash fragmentation storage and high-availability system in redis cluster mode

By designing the data structure to Hash format and building a load balancing system in Redis cluster mode, the problem of real-time querying of massive data with high concurrency and low latency was solved, achieving highly available data access and improving the stability and responsiveness of the system.

CN118626488APending Publication Date: 2024-09-10HAINA ZHIYUAN DIGITAL TECH (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410723453.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-05
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

Existing relational and distributed databases struggle to meet the stable millisecond-level response requirements for high-concurrency, low-latency, real-time queries of massive amounts of data. Traditional Redis caching technology is limited by capacity bottlenecks and data structure design, failing to meet the storage needs of general data structures, and fault recovery has a temporary impact on clients.

Method used

Two stable Redis cluster modes are adopted, and the data structure is designed to be in Redis Hash format through data structure transformation to build a load balancing system, so as to realize high availability, high concurrency, low latency online real-time data access. Data sharding and failover are performed using a 1 master 1 slave cluster mode and a load balancing client.

Benefits of technology

It enables high-concurrency, low-latency real-time querying of massive amounts of data, solves the data skew problem, ensures system stability and continuous fault recovery, simplifies database switching awareness in application systems, and improves the response stability and elasticity of online services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626488A
    Figure CN118626488A
Patent Text Reader

Abstract

The invention discloses a method for designing a mass data Hash fragmentation storage and high availability system in a redis cluster mode. The method comprises the following steps of: 1, deploying a redis cluster with the same capacity according to the total byte number of data to be stored; 2, classifying data to be stored according to dimensions of a logic table concept; 3, designing the data in the logic table according to a RowKey-Value format rule, wherein Value is final storage data; step 4, performing hash calculation on the Rowkey and taking the remainder of the 16384 to obtain a remainder, and adding the remainder by using the table name of the logic table as a Key value of a Hash data structure of redis; step 5, taking the RowKey of the logic table as a field value of a Hash data structure of redis, and taking a Value corresponding to the RowKey of the logic table as a value value of the Hash data structure; step 6, deploying a redis cluster with the same scale and capacity as a standby cluster, and writing the same data; and 7, constructing a load balancing system as an entrance for accessing the two redis clusters.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Internet technology, and in particular to a design method for massive data Hash sharding storage and high-availability system in a redis cluster mode. Background Art

[0002] High availability, high concurrency, low latency real-time query of massive data has always been a technical challenge faced by data products or services. Traditional relational databases cannot meet the storage, high concurrency and low latency access of massive data. In recent years, the popular OLAP (analytical database) type database has performed well in massive data analysis scenarios, but the stable millisecond-level response requirements in high-concurrency scenarios are far from being met. Distributed databases are a good choice. They solve the bottleneck of traditional database storage capacity and have good performance for high-concurrency real-time queries. However, most distributed databases are based on file storage data. When accessing, the query time fluctuation caused by the high and low file block cache hit rate makes it difficult to guarantee the stable millisecond-level low-latency response requirements under high-concurrency queries. For real-time queries, stable query time is crucial. Even occasional timeout responses will affect the user experience and requirements when using online data products and services. In the fiercely competitive Internet online products, system stability is also a basic requirement for enterprise survival. Among many distributed products, redis cache technology undoubtedly performs best in terms of high concurrency, low latency, stable real-time query. However, redis's capacity bottleneck and its semi-structured data structure design limit its application scenarios and cannot meet general data structures, such as table structure type data of traditional databases. Although redis itself has high availability characteristics, it still has a short-term impact on the client during the fault recovery process. Summary of the invention

[0003] In view of the above problems, the present invention provides a design method for massive data Hash sharding storage and high-availability system under redis cluster mode. By deploying two sets of stable redis clusters and converting different data structures, the data structure storage form of redis Hash is finally met, and the problems of data search and data skew are solved. A load balancing system is constructed as the client of the two redis clusters, and the design requirements of the online real-time data access system with high availability, high concurrency and low latency for massive data are met.

[0004] Glossary:

[0005] 1. redis: a distributed cache database in semi-structured data format in key-value (key-value pair) format.

[0006] 2. Redis Hash: It is a data storage format of Redis, which consists of three parts: key (key value), field (attribute value), and value (data value). Field and value constitute a Map (key-value pair data structure). Multiple Map data can be added under one key.

[0007] 3. JSON: It is a lightweight data exchange format.

[0008] 4. csv: Its file stores tabular data in plain text form with comma separated values.

[0009] 5. Hash calculation: transform input of arbitrary length into output of fixed length through hash algorithm, which is the hash value.

[0010] 6. Load balancing: refers to balancing the load (work tasks) and distributing them to multiple operating units for operation.

[0011] 7. 1 master and 1 slave: Redis failover relies on the master-slave mode. The master node is responsible for data writing, and the slave node synchronizes data from the master node. When the master node hangs up, the slave node can replace the master node to become the new master node and continue to provide the same data services.

[0012] In order to achieve the above technical objectives and the above technical effects, the present invention is implemented through the following technical solutions:

[0013] A design method for massive data Hash sharding storage and high availability system in redis cluster mode, the specific steps are as follows:

[0014] Step 1. Calculate the data size based on the total amount of data to be stored. Calculate the size of the entire redis cluster based on the obtained data volume and the standard of 20G capacity of each redis node in the redis cluster. Deploy a redis cluster in 1 master-1 slave cluster mode. Building a 1 master-1 slave cluster mode can not only meet the basic needs of failover but also save hardware resources to the maximum extent, which is a very good balance choice.

[0015] Step 2: Analyze the data structure to be stored and split it into data in a table structure consisting of rows and columns. The table classifies the data according to the set dimension, and the column classifies the data according to the attributes of the data.

[0016] Step 3: Aggregate the data in the table structure obtained in step 2 into two columns, one for the unique identifier of each row of data, and the other for the aggregation of attributes, in json (a standard data structure consisting of attributes and values) or csv (a standard data structure, comma-separated) format, where the first column is the unique Rowkey (primary key value), and the second column is the actual data Value to be stored;

[0017] Step 4. Give the logical table obtained in step 3 a unique and easily identifiable table name with a business identifier, perform hash calculation on the Rowkey and obtain the remainder by taking the remainder from 16384, and use the complete string value of the table name concatenated with the remainder as the key value of the redisHash data structure;

[0018] Step 5: Use the Rowkey value of each row of the logical table obtained in step 4 as the field value of its corresponding Hash key, and use the Value data stored in csv or json format in step 3 as the value of the Hash key;

[0019] Step 6: Deploy another redis cluster of the same size and capacity as a backup cluster. Each time data is written to the redis cluster, the two redis clusters write the same data at the same time.

[0020] Step 7: Build a load balancing system as a client to access the two redis clusters. The client can divert read requests and automatically switch to another cluster to continue the request after reading one cluster fails.

[0021] Preferably, when planning the scale of a redis cluster, ensure that the storage capacity of each redis node does not exceed 30G. This ensures the stability of the cluster and the speed of failover.

[0022] Preferably, the unstructured data is converted into structured data for subsequent processing. If the data to be stored is structured data itself, step 2 is skipped.

[0023] Designing the Key value of Hash data based on Rowkey can ensure two important points: First, as long as there is Rowkey, the Hash key and filed value can be determined, and the business data corresponding to the Rowkey can be accessed; second, by taking the modulus of the hash of the Rowkey, it can ensure that the Hash data is evenly distributed in the Redis cluster, which will not cause data skew.

[0024] The design of the Rowkey is particularly important. You can choose various IDs as Rowkeys, and their uniqueness within the table dimension must be guaranteed.

[0025] Preferably, the forms of business data and table structure data are both logical concepts. The data finally stored in redis is scattered in different hash data. Rowkey is the only query condition, and Rowkey corresponds to each row of business data one by one.

[0026] Compared with the prior art, the beneficial effects of the present invention are:

[0027] 1) The massive data sharding storage solution is applicable to various data structures, and the data structure is no longer restricted by the database selection.

[0028] 2) The Redis cluster itself is highly available and has the feature of fast fault recovery. During the short fault recovery process, because the active-active Redis cluster can accept client requests, theoretically it can greatly guarantee the continuity of the Redis service.

[0029] 3) The design of the load balancing client can completely shield the application system from the switching perception of the database system, greatly simplifying the use of the application system client.

[0030] 4) The key value strategy of redis Hash data solves the data skew problem caused by large keys, and also solves the single point capacity problem that may occur in redis. The expansion of redis cluster is more convenient and more stable.

[0031] 5) The high concurrency, high throughput and low latency characteristics of redis cache technology are fully utilized, making online services extremely flexible and responsive. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 This is a redis cluster read-write and read-write high availability architecture diagram of the present invention;

[0033] Figure 2 It is a hash sharding solution strategy diagram in a redis cluster mode of the present invention.

[0034] Among them: user is the user, read is reading, redis cluster is the redis cluster mode, write is writing, redis client is the redis client, and rowkey is the primary key value. DETAILED DESCRIPTION

[0035] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.

[0036] like Figure 1 , 2 As shown in the figure, a design method for massive data Hash sharding storage and high availability system in redis cluster mode is shown in the figure. The specific steps are as follows:

[0037] Step 1. Calculate the data size based on the total amount of data to be stored. Calculate the size of the entire redis cluster based on the obtained data volume and the standard of 20G capacity of each redis node in the redis cluster. Deploy a redis cluster in 1 master-1 slave cluster mode. Building a 1 master-1 slave cluster mode can not only meet the basic needs of failover but also save hardware resources to the maximum extent, which is a very good balance choice.

[0038] Step 2: Analyze the data structure to be stored and split it into data in a table structure consisting of rows and columns. The table classifies the data according to the set dimension, and the column classifies the data according to the attributes of the data.

[0039] Step 3: Aggregate the data in the table structure obtained in step 2 into two columns, one for the unique identifier of each row of data, and the other for the aggregation of attributes, in json (a standard data structure consisting of attributes and values) or csv (a standard data structure, comma-separated) format, where the first column is the unique Rowkey (primary key value), and the second column is the actual data Value to be stored;

[0040] Step 4. Give the logical table obtained in step 3 a unique and easily identifiable table name with a business identifier, perform hash calculation on the Rowkey and obtain the remainder by taking the remainder from 16384, and use the complete string value of the table name concatenated with the remainder as the key value of the redisHash data structure;

[0041] Step 5: Use the Rowkey value of each row of the logical table obtained in step 4 as the field value of its corresponding Hash key, and use the Value data stored in csv or json format in step 3 as the value of the Hash key;

[0042] Step 6: Deploy another redis cluster of the same size and capacity as a backup cluster. Each time data is written to the redis cluster, the two redis clusters write the same data at the same time.

[0043] Step 7: Build a load balancing system as a client to access the two redis clusters. The client can divert read requests and automatically switch to another cluster to continue the request after reading one cluster fails.

[0044] When calculating the capacity of the entire redis cluster, only the cluster master node needs to be considered. The capacity value obtained by multiplying the number of master nodes by a single node is the maximum capacity of the cluster. However, in order to ensure the stability of redis, the redis cluster should only use 80% of its capacity, and the monitoring and alarm functions of redis capacity usage should be done well so that timely intervention and processing can be carried out. If the data of the redis cluster is likely to grow in the future, then when planning the cluster scale, it is necessary to consider this part of the growth capacity and deploy a larger-scale redis cluster in advance to meet future storage needs.

[0045] The concept of Rowkey comes from Hbase (a distributed, column-oriented open source database). Its meaning is the same as Hbase. Its value is the core of the entire data storage. It must be unique, such as using an ID card with unique identification characteristics. It can be derived from business data extraction. According to Rowkey, the Key value of redis Hash data can be calculated. The stored business data can be queried from the redis cluster through the key value and Rowkey value. Business data needs to be classified into several features, and the feature value is used as the column name, so that the data of all columns can be aggregated into json data or csv. Both formats of data are complete strings and can be easily stored in the value of the redis Hash data structure. The difference between these two data formats is that json data contains the column name of the data, which may be easier for business or users to identify data. csv does not contain column names, and only uses comma separators to combine multiple columns of data together. The advantage of this is that it saves memory space and hardware resources. Both solutions are acceptable, each with its own advantages and disadvantages, and can be selected as needed.

[0046] The client of redis with load balancing function can be a coded SDK embedded in the business system (a specific type of toolkit for auxiliary development), or it can be a microservice provided to the business system for calling. The first method is recommended, which has better performance, is more stable, and saves resources. The client should consider using the redis thread pool, capturing redis request exceptions, request retries, request switching, traffic distribution and other functions, and expose the corresponding parameters for the business system client to configure and use on demand. It is also necessary to add necessary log printing for observation, monitoring, and debugging.

[0047] The design method of massive data Hash shard storage and high-availability system under the redis cluster mode described in this embodiment is adopted. The massive data shard storage solution is applicable to various data structures, and the data structure is no longer restricted by the database selection. The redis cluster itself has the characteristics of high availability with fast fault recovery. In the short fault recovery process, because there is a dual-active redis cluster that can accept client requests, the continuity of the redis service can be greatly guaranteed. The design of the load balancing client can completely shield the application system's perception of the switching of the database system, greatly simplifying the use of the application system client. The setting of the key value strategy of the redis hash data solves the problem of data skew caused by large keys, and also solves the single-point capacity problem that may occur in redis. The redis cluster expansion is more convenient and more stable. The high concurrency, high throughput and low latency characteristics of the redis cache technology itself are fully utilized, so that the online service has great flexibility and response stability.

[0048] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A design method for massive data Hash sharding storage and high availability system in redis cluster mode, characterized in that: The specific steps are as follows: Step 1: Calculate the data size based on the total amount of data to be stored, calculate the size of the entire redis cluster based on the obtained data size and the standard of 20G capacity of each redis node in the redis cluster, and deploy a redis cluster in 1 master 1 slave cluster mode; Step 2: Analyze the data structure to be stored and split it into data in a table structure consisting of rows and columns. The table classifies the data according to the set dimension, and the column classifies the data according to the attributes of the data. Step 3: Aggregate the data in the table structure obtained in step 2 into two columns, one for the unique identifier of each row of data, and one for the aggregation of attributes in json or csv format. The first column is the unique Rowkey, and the second column is the actual data Value to be stored. Step 4. Give the logical table obtained in step 3 a unique and easily identifiable table name with a business identifier, perform hash calculation on the Rowkey and obtain the remainder by taking the remainder from 16384, and use the complete string value of the table name concatenated with the remainder as the key value of the redisHash data structure; Step 5: Use the Rowkey value of each row of the logical table obtained in step 4 as the field value of its corresponding Hash key, and use the Value data stored in csv or json format in step 3 as the value of the Hash key; Step 6: Deploy another redis cluster of the same size and capacity as a backup cluster. Each time data is written to the redis cluster, the two redis clusters write the same data at the same time. Step 7: Build a load balancing system as a client to access the two redis clusters. The client can divert read requests and automatically switch to another cluster to continue the request after reading one cluster fails.

2. According to the design method of a massive data Hash sharding storage and high availability system in a redis cluster mode in claim 1, it is characterized by: When planning the scale of the Redis cluster, ensure that the storage capacity of each Redis node does not exceed 30G.

3. According to the design method of a massive data Hash sharding storage and high availability system in a redis cluster mode in claim 1, it is characterized by: If the data to be stored is structured data, skip step 2.

4. According to the design method of a massive data Hash sharding storage and high availability system in a redis cluster mode in claim 1, it is characterized by: Rowkey is the only query condition, and Rowkey must correspond one-to-one to each row of business data.