Distributed system cluster online sharding expansion method and device

By obtaining cluster routing configuration rules and traffic volume in a distributed system, performing cluster splitting and hash iterative computing, the online shard expansion of the distributed system is realized, and the resource waste and business impact caused by expansion in the existing technology is solved. Problem, improving scalability efficiency and business continuity.

CN113505177BActive Publication Date: 2025-02-18INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110773742.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-08
Publication Date
2025-02-18
Estimated Expiration
2041-07-08

AI Technical Summary

Technical Problem

When the prior art expands capacity in a distributed system, it leads to uneven data distribution and waste of resources. Each expansion involves full data migration, affecting business continuity.

Method used

By obtaining the cluster routing configuration rules, determining the cluster to be sharded, and splitting it according to the traffic volume and database capacity, hash iterative calculation is used to determine the designated cluster corresponding to the data request, so as to achieve online shard expansion.

Benefits of technology

It reduces the amount of data replication and migration workload, shortens the expansion time, saves resource investment, and ensures business continuity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113505177B_ABST
    Figure CN113505177B_ABST
Patent Text Reader

Abstract

A distributed system cluster online sharding expansion method and device can be used in the financial field or other fields. The method includes: obtaining cluster routing configuration rules in the distributed system, and determining the cluster to be sharded according to the cluster routing configuration rules; the cluster routing configuration rules include the number of clusters, the serial number of the cluster to be sharded, and the number of cluster splits; according to the serial number of the cluster to be sharded and the number of cluster splits, the cluster to be sharded is split to obtain the sub-cluster corresponding to the cluster to be sharded; according to the received external data request, the hash value of the external data request is determined by a hash algorithm; according to the hash value, the number of clusters and each sub-cluster, a hash iterative calculation is performed using a preset number of iterations to determine the designated cluster corresponding to the external data request, and the corresponding cluster data is routed to the designated cluster. The present invention realizes sharding expansion in a distributed system, expands the cluster with insufficient specified performance capacity, reduces the impact of expansion on the business system, and saves resource costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of distributed systems, and in particular to a distributed system cluster online sharding expansion method and device. Background Art

[0002] At present, when a new business system is just launched, the business volume is relatively small. In order to save resources and costs, the minimum cluster deployment is generally adopted. For systems that adopt a unitized or microservice architecture, the database and application container are deployed together. Database sharding generally uses the business field hash and then modulo the initial cluster to determine the cluster where the data is located. The formula is: mod(hash(business field), number of clusters n). In the initial stage of business launch, the number of clusters n is relatively small. Under the deployment architecture of dual active in the same city, n is generally an even number, and the two parks are deployed in parallel, such as n=2. Subsequently, as the business volume increases, the number of clusters needs to be expanded. For 7×24 hours business, in order not to affect business continuity, the expansion downtime will be completed within the normal production time. The current common practice is to adopt a double expansion method. After the expansion, the data is distributed as follows Figure 1 As shown in the figure, the number of clusters after expansion is n×2, and the sharding calculation formula for business data in the new cluster after expansion is: mod(hash(business field), number of clusters n*2).

[0003] According to the double expansion method, the data in the original cluster 0 will be in the new cluster 0 and cluster 2 after expansion, and the data in the original cluster 1 will be in the new cluster 1 and cluster 3 after expansion. The use of database semi-synchronous replication technology can achieve online data expansion. However, in actual production, data distribution may not be uniform. The business of some clusters is relatively active, and the amount of data increases rapidly. The database performance and capacity of these clusters are soon insufficient. Double expansion every time not only wastes resources, but also involves full data migration every time, which has a large impact and a large workload. Summary of the invention

[0004] In view of the problems existing in the prior art, the main purpose of the embodiments of the present invention is to provide a distributed system cluster online sharding expansion method and device, so as to achieve the expansion of the specified business cluster, ensure the continuity of the business, reduce the amount of data copying and migration workload, shorten the expansion time, and save resource investment.

[0005] In order to achieve the above object, an embodiment of the present invention provides a distributed system cluster online sharding expansion method, the method comprising:

[0006] Obtain cluster routing configuration rules in the distributed system, and determine the cluster to be sharded according to the cluster routing configuration rules; wherein the cluster routing configuration rules include the number of clusters, the sequence number of the cluster to be sharded, and the number of cluster splits;

[0007] According to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule, the cluster to be sharded is split to obtain subclusters corresponding to the cluster to be sharded;

[0008] Determine, according to the received external data request, a hash value corresponding to the external data request using a hash algorithm;

[0009] According to the hash value, the number of clusters and each sub-cluster in the distributed system, hash iterative calculation is performed using a preset number of iterations to determine the designated cluster corresponding to the external data request, and the cluster data corresponding to the external data request is routed to the designated cluster.

[0010] Optionally, in an embodiment of the present invention, the method further includes:

[0011] Determine the sequence number of the cluster to be sharded and the number of cluster splits according to the business volume and database capacity of each cluster in the distributed system;

[0012] According to the sequence number of the cluster to be sharded and the number of cluster splits, the cluster routing configuration rules in the distributed system are updated.

[0013] Optionally, in an embodiment of the present invention, the cluster to be sharded is split according to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule to obtain subclusters corresponding to the cluster to be sharded, including:

[0014] Determine a cluster to be sharded from among multiple clusters of the distributed system according to the sequence number of the cluster to be sharded in the cluster routing configuration rule;

[0015] Turn off the service switch of the cluster to be sharded, split the cluster to be sharded according to the cluster split number in the cluster routing configuration rule, and obtain sub-clusters corresponding to the cluster to be sharded.

[0016] Optionally, in an embodiment of the present invention, the method further includes: using a standby database in the cluster to be sharded as a master database of the sub-cluster, and turning on a service switch of the cluster to be sharded.

[0017] Optionally, in an embodiment of the present invention, the method further includes: deleting redundant data in each cluster in the distributed system.

[0018] Optionally, in an embodiment of the present invention, performing hash iterative calculation using a preset number of iterations according to the hash value, the number of clusters, and each sub-cluster in the distributed system to determine the designated cluster corresponding to the external data request includes:

[0019] Calculating a first remainder value between the hash value and the number of clusters, matching the first remainder value with the cluster routing configuration rule, and determining a first cluster corresponding to the first remainder value;

[0020] The preset number of iterations is used as a dispersion factor, and hash iterative calculation is performed according to the number of subclusters corresponding to the first cluster and the dispersion factor, and the hash value and its corresponding remainder value are updated until the preset number of iterations is reached or the current cluster does not have a corresponding subcluster, then the current cluster is used as the designated cluster corresponding to the external data request.

[0021] An embodiment of the present invention further provides a distributed system cluster online sharding expansion device, the device comprising:

[0022] The cluster module to be sharded is used to obtain the cluster routing configuration rules in the distributed system and determine the cluster to be sharded according to the cluster routing configuration rules; wherein the cluster routing configuration rules include the number of clusters, the sequence number of the cluster to be sharded and the number of cluster splits;

[0023] A cluster splitting module, used to split the cluster to be sharded according to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule, to obtain subclusters corresponding to the cluster to be sharded;

[0024] A hash value module, used to determine a hash value corresponding to the external data request using a hash algorithm according to the received external data request;

[0025] A data routing module is used to perform hash iterative calculations using a preset number of iterations according to the hash value, the number of clusters and each sub-cluster in the distributed system, determine the designated cluster corresponding to the external data request, and route the cluster data corresponding to the external data request to the designated cluster.

[0026] Optionally, in one embodiment of the present invention, the device further includes:

[0027] The cluster serial number module is used to determine the serial number of the cluster to be sharded and the number of cluster splits according to the business volume and database capacity of each cluster in the distributed system;

[0028] A rule updating module is used to update the cluster routing configuration rules in the distributed system according to the sequence number of the cluster to be sharded and the number of cluster splits.

[0029] Optionally, in an embodiment of the present invention, the cluster splitting module includes:

[0030] A cluster unit to be sharded, configured to determine a cluster to be sharded from among multiple clusters of the distributed system according to a sequence number of the cluster to be sharded in the cluster routing configuration rule;

[0031] The sub-cluster unit is used to turn off the service switch of the cluster to be sharded, split the cluster to be sharded according to the cluster split number in the cluster routing configuration rule, and obtain sub-clusters corresponding to the cluster to be sharded.

[0032] Optionally, in an embodiment of the present invention, the device further includes: a service switch module, configured to use the standby database in the cluster to be sharded as the primary database of the sub-cluster and turn on the service switch of the cluster to be sharded.

[0033] Optionally, in an embodiment of the present invention, the device further includes: a redundant data module, used to delete redundant data in each cluster in the distributed system.

[0034] Optionally, in an embodiment of the present invention, the data routing module includes:

[0035] A hash value unit, configured to calculate a first remainder value between the hash value and the number of clusters, match the first remainder value with the cluster routing configuration rule, and determine a first cluster corresponding to the first remainder value;

[0036] The designated cluster unit is used to use the preset number of iterations as a dispersion factor, perform hash iterative calculation according to the number of subclusters corresponding to the first cluster and the dispersion factor, and update the hash value and its corresponding remainder value until the preset number of iterations is reached or the current cluster does not have a corresponding subcluster, and then use the current cluster as the designated cluster corresponding to the external data request.

[0037] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the program.

[0038] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above method.

[0039] The present invention realizes sharding expansion in a distributed system through a hash iteration-based approach, prevents uneven data distribution by iterating hash moduli multiple times and using the number of iterations as a dispersion factor, thereby realizing capacity expansion of a cluster with insufficient specified performance capacity, reducing the impact of expanded nodes and change time on the business system and saving resource costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0041] Figure 1 Schematic diagram of data sharding for doubling cluster capacity;

[0042] Figure 2 A flowchart of a distributed system cluster online sharding expansion method according to an embodiment of the present invention;

[0043] Figure 3 This is a schematic diagram of online sharding expansion in an embodiment of the present invention;

[0044] Figure 4 A flowchart of updating cluster routing configuration rules in an embodiment of the present invention;

[0045] Figure 5 This is a flow chart of splitting a cluster to be sharded in an embodiment of the present invention;

[0046] Figure 6 A flowchart of determining a designated cluster in an embodiment of the present invention;

[0047] Figure 7 A schematic diagram of an online sharding capacity expansion architecture of a distributed system cluster in a specific embodiment of the present invention;

[0048] Figure 8 This is a flowchart of online sharding expansion in a specific embodiment of the present invention;

[0049] Fig. 9 A schematic diagram of the structure of an online sharding expansion device for a distributed system cluster according to an embodiment of the present invention;

[0050] Fig.10 It is a structural diagram of a distributed system cluster online sharding expansion device in a specific embodiment of the present invention;

[0051] Fig.11 This is a schematic diagram of the structure of a cluster splitting module in an embodiment of the present invention;

[0052] Fig.12 It is a schematic diagram of the structure of a cluster online sharding expansion device in an embodiment of the present invention;

[0053] Fig.13 It is a structural schematic diagram of a cluster online sharding expansion device in another embodiment of the present invention;

[0054] Fig.14This is a schematic diagram of the structure of a data routing module in an embodiment of the present invention;

[0055] Fig.15 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0056] The embodiments of the present invention provide a distributed system cluster online sharding expansion method and device, which can be used in the financial field or other fields. It should be noted that the distributed system cluster online sharding expansion method and device of the present invention can be used in the financial field, and can also be used in any field other than the financial field. The application field of the distributed system cluster online sharding expansion method and device of the present invention is not limited.

[0057] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0058] The commonly used approach at present is to adopt a double expansion method. After the data is expanded, it is distributed as follows Figure 1 As shown in the figure, it is a schematic diagram of data sharding for double cluster expansion. The general steps of the expansion scheme shown in the figure are as follows:

[0059] 1. Add a cross-park semi-synchronous backup database to each original cluster database and wait for data synchronization to be completed.

[0060] 2. Modify the routing configuration, expand the number of clusters to twice the original number of clusters, use the new routing algorithm: mod(hash(business field), number of clusters n*2), and suspend external services for the newly expanded business.

[0061] 3. Change the semi-synchronous standby database to the primary database, and add a new cluster to connect to the newly added primary database. Figure 1 , business cluster 1 uses the original backup database of cluster 1, and business cluster 2 uses the original backup database of cluster 0.

[0062] 4. The newly expanded cluster starts to take over services.

[0063] 5. Delete redundant data in each cluster.

[0064] According to the double expansion method, the data in the original cluster 0 will be in the new cluster 0 and cluster 2 after expansion, and the data in the original cluster 1 will be in the new cluster 1 and cluster 3 after expansion. The use of database semi-synchronous replication technology can achieve online data expansion. However, in actual production, data distribution may not be uniform. The business of some clusters is relatively active, and the amount of data increases rapidly. The database performance and capacity of these clusters are soon insufficient. Double expansion every time not only wastes resources, but also involves full data migration every time, which has a large impact and a large workload.

[0065] like Figure 2 The flowchart of a distributed system cluster online sharding expansion method according to an embodiment of the present invention is shown. The execution subject of the distributed system cluster online sharding expansion method provided by the embodiment of the present invention includes but is not limited to a computer. The method shown in the figure includes:

[0066] Step S1, obtaining cluster routing configuration rules in a distributed system, and determining the cluster to be sharded according to the cluster routing configuration rules; wherein the cluster routing configuration rules include the number of clusters, the sequence number of the cluster to be sharded, and the number of cluster splits.

[0067] Among them, Figure 3 The figure is a schematic diagram of online shard expansion in an embodiment of the present invention. Specifically, the cluster routing configuration rule in the distributed system includes a cluster information list. For example, the cluster information list may be (0, 1), representing two clusters 0 and 1.

[0068] Furthermore, the clusters to be sharded and the number of cluster splits can be determined by the business volume of each cluster and the database capacity. The number of cluster splits represents the number of sub-clusters into which the cluster to be sharded is split. Specifically, assuming that the business volume of cluster 0 is large and the database capacity is insufficient and needs to be expanded, assuming that 2 clusters are split, that is, the number of cluster splits is 2.

[0069] Furthermore, if the cluster to be split and expanded is cluster 0, the cluster information list of the cluster routing configuration rule is modified from (0,1) to (0(0,1),1), which means that cluster 0 is split into two new sub-clusters 00 and 01, and the original cluster 1 remains unchanged. Therefore, the number of clusters, the sequence number of the cluster to be sharded, and the number of cluster splits can be known from the cluster routing configuration rule.

[0070] Step S2: split the cluster to be sharded according to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule to obtain sub-clusters corresponding to the cluster to be sharded.

[0071] According to the cluster information list of the cluster routing configuration rule, for example (0(0,1),1), cluster 0 is split into two new sub-clusters 00 and 01, and the original cluster 1 remains unchanged.

[0072] Step S3: according to the received external data request, determine the hash value corresponding to the external data request by using a hash algorithm.

[0073] Wherein, an external data request is received, and according to the business word in the external data request, for example, the business field is A. The business field A is used as the cluster sharding field, and the hash value hash(A) of the business field A is calculated.

[0074] Step S4, performing hash iterative calculations with a preset number of iterations according to the hash value, the number of clusters and each sub-cluster in the distributed system, determining the designated cluster corresponding to the external data request, and routing the cluster data corresponding to the external data request to the designated cluster.

[0075] Among them, according to the hash value and the number of clusters, the remainder value of the two is determined, that is, the result of mod(hash(A),2) is calculated. The remainder value is compared with the cluster routing configuration information. For example, 0(0,1) matches successfully, and it is found that there are subclusters under cluster 0, and the number is 2. Then the hash needs to be further calculated. In order to prevent the data from being concentrated in the new subcluster 00, it is necessary to increase the dispersion factor and obtain a new hash value. The number of iterations is used as the dispersion factor, that is, the number of iterations is connected to the end of field A, which is 1 here, and is represented by concat(A,1). Then the subcluster routing rule is mod(hash(concat(A,1)),2) to determine the specified cluster. If the result is 0, it is in the new 00 cluster, and if the result is 1, it is in the new 01 cluster.

[0076] As an embodiment of the present invention, Figure 4 As shown, the method also includes:

[0077] Step S21, determining the sequence number of the cluster to be sharded and the number of cluster splits according to the business volume and database capacity of each cluster in the distributed system;

[0078] Step S22: updating the cluster routing configuration rules in the distributed system according to the sequence number of the cluster to be sharded and the number of cluster splits.

[0079] The clusters to be sharded and the number of cluster splits can be determined by the business volume of each cluster and the database capacity. The number of cluster splits represents the number of sub-clusters into which the cluster to be sharded is split. Specifically, assuming that the business volume of cluster 0 is large and the database capacity is insufficient and needs to be expanded, assuming that 2 clusters are split, that is, the number of cluster splits is 2.

[0080] Furthermore, if the cluster to be split and expanded is cluster 0, the cluster information list of the cluster routing configuration rule is updated from (0,1) to (0(0,1),1), indicating that cluster 0 is split into two new sub-clusters 00 and 01, and the original cluster 1 remains unchanged.

[0081] As an embodiment of the present invention, Figure 5 As shown, the cluster to be sharded is split according to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule, and the sub-clusters corresponding to the cluster to be sharded include:

[0082] Step S31, determining a cluster to be sharded from multiple clusters in the distributed system according to the sequence number of the cluster to be sharded in the cluster routing configuration rule;

[0083] Step S32, turning off the service switch of the cluster to be sharded, splitting the cluster to be sharded according to the cluster split number in the cluster routing configuration rule, and obtaining sub-clusters corresponding to the cluster to be sharded.

[0084] Among them, according to the sequence number of the cluster to be sharded recorded in the cluster routing configuration rule, the sequence number corresponding to the cluster to be sharded is determined in multiple clusters of the distributed system, thereby determining the cluster to be sharded.

[0085] Furthermore, during the cluster sharding expansion process, the cluster cannot accept external data requests. For example, if cluster 0 is split, the service switch of cluster 0 is turned off. After reading the cluster routing configuration rules, it is determined that the routing cluster is cluster 0, and the feedback system is being upgraded; cluster 1 receives external data requests normally.

[0086] Furthermore, after turning off the service switch of the cluster to be sharded, the cluster to be sharded is split and expanded according to the cluster routing configuration rules to obtain a sub-cluster corresponding to the cluster to be sharded.

[0087] In this embodiment, the method further includes: using the standby database in the cluster to be sharded as the master database of the sub-cluster, and turning on the service switch of the cluster to be sharded.

[0088] Here, it is assumed that cluster 0 is split into two sub-clusters, namely cluster 00 and cluster 01. Specifically, the backup database in the original cluster 0 is modified to be the master database of the new sub-cluster. After the cluster is split, the service switch of cluster 0 is turned on, so that after connecting to the gateway, data requests from cluster 0 are received.

[0089] In this embodiment, the method further includes: deleting redundant data in each cluster in the distributed system.

[0090] Among them, according to the cluster routing configuration rules, historical data that is not in the cluster, that is, redundant data, in each cluster is deleted through batch operations.

[0091] As an embodiment of the present invention, Figure 6 As shown, according to the hash value, the number of clusters and each sub-cluster in the distributed system, a hash iteration calculation is performed using a preset number of iterations to determine the designated cluster corresponding to the external data request, including:

[0092] Step S41, calculating a first remainder value of the hash value and the number of clusters, matching the first remainder value with the cluster routing configuration rule, and determining a first cluster corresponding to the first remainder value;

[0093] Step S42, taking the preset number of iterations as a dispersion factor, performing hash iterative calculation according to the number of subclusters corresponding to the first cluster and the dispersion factor, updating the hash value and its corresponding remainder value until the preset number of iterations is reached or the current cluster does not have a corresponding subcluster, then taking the current cluster as the designated cluster corresponding to the external data request.

[0094] Among them, according to the hash value and the number of clusters, the remainder value of the two is determined, that is, the result of mod(hash(A),2) is calculated. The remainder value is compared with the cluster routing configuration information. For example, 0(0,1) matches successfully, that is, the first cluster is cluster 0. At the same time, it is found that there are subclusters under cluster 0, and the number is 2 (the number of subclusters), so the hash needs to be further calculated. In order to prevent the data from being concentrated in the new subcluster 00, it is necessary to increase the dispersion factor and obtain a new hash value. The number of iterations is used as the dispersion factor, that is, the number of iterations is connected to the end of field A, which is 1 here, and is represented by concat(A,1). Then the subcluster routing rule is mod(hash(concat(A,1)),2) to determine the specified cluster. If the result is 0, it is in the new cluster 00, and if the result is 1, it is in the new cluster 01.

[0095] In a specific embodiment of the present invention, Figure 7 The figure shows a schematic diagram of the distributed system architecture based on hash iteration and dispersion factor of the present invention, which consists of three parts: configuration center, access gateway layer and business processing layer. The configuration center stores routing configuration information and cluster flow control switches, and the access gateway layer and business processing layer both access the configuration center to obtain relevant configurations.

[0096] Among them, the present invention uses the method of hash iteration plus dispersion factor to expand the capacity of only the cluster with performance and capacity bottleneck in the distributed cluster. Therefore, the expansion has a smaller impact on the entire business system, the workload of migration is smaller, and the time for online expansion is shorter.

[0097] In a distributed system, MySQL is used as an online database, and a high-availability deployment architecture with one master database and multiple backup databases is adopted. The backup database uses semi-synchronous replication to ensure RPO=0. Use the configuration center to save cluster routing information. Assuming that there are only two clusters at the beginning of the launch, the configuration center saves the cluster information list (0,1), representing clusters 0 and 1. Assuming that the system uses business field A as the cluster sharding field, the calculation rule for sharding is mod(hash(A),2). Compare the remainder with the information list of the configuration center. If they match, route to the specified cluster. Figure 8 The figure shows the flow chart of the online sharding expansion method. Assuming that the business volume of cluster 0 is large and the database capacity is insufficient, expansion is required. Assuming that two clusters are split, the general steps are as follows:

[0098] Step S101, modify the cluster routing configuration of the configuration center to (0(0,1),1), which means that cluster 0 is split into two new sub-clusters 00 and 01, and the original cluster 1 remains unchanged.

[0099] Step S102, modify the service switch of cluster 0 in the configuration center. After the access gateway reads the configuration, it determines that the routing cluster is cluster 0, and then the feedback system is being upgraded; cluster 1 receives external requests normally;

[0100] Step S103: Change the standby database in the original cluster 0 to the master database of the new sub-cluster, change the cluster number of the original cluster 0 to 00, and change the cluster number of the newly expanded cluster to 01;

[0101] Step S104, modify the service switch of cluster 0 in the configuration center, and the access gateway starts to receive data requests from cluster 0.

[0102] Step S105, modify the routing calculation rules. For the request of the original cluster 0, the result of calculating mod(hash(A),2) is compared with the cluster routing configuration information of the configuration center 0(0,1), and the match is successful. At the same time, it is found that there are subclusters, the number of which is 2, so the hash needs to be further calculated. In order to prevent all data from being concentrated in the new subcluster 0, it is necessary to increase the dispersion factor and obtain a new hash value. Assume that the number of iterations is used as the dispersion factor, that is, the number of iterations is connected to the end of field A, which is 1 here, and is represented by concat(A,1). Then the subcluster routing rule is mod(hash(concat(A,1)),2), and the result is 0 in the new 00 cluster, and the result is 1 in the new 01 cluster.

[0103] Step S106, deleting old data: According to the cluster routing rules, historical data of clusters 00 and 01 that are not in the current cluster are deleted by batch operation.

[0104] Among them, Figure 3As shown, the present invention uses the MySQL semi-synchronous mechanism to enable the standby database of the specified cluster as the main database of the newly added cluster; at the same time, the hash iteration plus dispersion factor method is used to iterate multiple times to finally calculate the sub-cluster.

[0105] Furthermore, based on the above example, it can be deduced that increasing the number of iterations and the number of clusters expanded in each iteration can expand the capacity of a specific cluster. The routing configuration of the configuration center is as follows:

[0106] When the number of clusters is 2, (0,1);

[0107] When the number of clusters is 3, it can be (0(0,1),1), or (0,1(0,1));

[0108] When the number of clusters is 4, there are 7 possible cases: (0(0,1,2),1), (0,1(0,1,2)), (0(0,1),1(0,1)), or (0(0(0,1),1),1).

[0109] By analogy, the method of hash iteration plus hash factor can flexibly respond to various expansion needs, and the dispersion factor can be set according to actual conditions.

[0110] The present invention realizes the expansion of the designated business cluster by performing multiple hash iterations and modulo adding dispersion factors on the business fields of the sub-tables and sub-libraries. The online synchronous replication of data is realized based on the MySQL semi-synchronous replication technology, and the shard where the data is located is determined based on the hash modulo method. For the cluster that needs to be expanded, the gateway layer is used to shield the request for expanding the cluster to ensure the consistency of the data during the expansion period, and then the semi-synchronous standby database and hash iteration method are used to perform online expansion. The present invention can ensure the continuity of the business, reduce the amount of data replication and migration workload, shorten the expansion time, save resource investment, etc.

[0111] The present invention realizes sharding expansion in a distributed system through a hash iteration-based approach, prevents uneven data distribution by iterating hash moduli multiple times and using the number of iterations as a dispersion factor, thereby realizing capacity expansion of a cluster with insufficient specified performance capacity, reducing the impact of expanded nodes and change time on the business system and saving resource costs.

[0112] like Fig. 9 The figure is a schematic diagram of the structure of a distributed system cluster online sharding expansion device according to an embodiment of the present invention. The device shown in the figure includes:

[0113] The cluster module 10 to be sharded is used to obtain the cluster routing configuration rules in the distributed system and determine the cluster to be sharded according to the cluster routing configuration rules; wherein the cluster routing configuration rules include the number of clusters, the sequence number of the cluster to be sharded and the number of cluster splits.

[0114] The cluster routing configuration rules in the distributed system include a cluster information list. For example, the cluster information list may be (0, 1), representing two clusters 0 and 1.

[0115] Furthermore, the clusters to be sharded and the number of cluster splits can be determined by the business volume of each cluster and the database capacity. The number of cluster splits represents the number of sub-clusters into which the cluster to be sharded is split. Specifically, assuming that the business volume of cluster 0 is large and the database capacity is insufficient and needs to be expanded, assuming that 2 clusters are split, that is, the number of cluster splits is 2.

[0116] Furthermore, if the cluster to be split and expanded is cluster 0, the cluster information list of the cluster routing configuration rule is modified from (0,1) to (0(0,1),1), which means that cluster 0 is split into two new sub-clusters 00 and 01, and the original cluster 1 remains unchanged. Therefore, the number of clusters, the sequence number of the cluster to be sharded, and the number of cluster splits can be known from the cluster routing configuration rule.

[0117] The cluster splitting module 20 is used to split the cluster to be sharded according to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule to obtain sub-clusters corresponding to the cluster to be sharded.

[0118] According to the cluster information list of the cluster routing configuration rule, for example (0(0,1),1), cluster 0 is split into two new sub-clusters 00 and 01, and the original cluster 1 remains unchanged.

[0119] The hash value module 30 is used to determine the hash value corresponding to the external data request by using a hash algorithm according to the received external data request.

[0120] Wherein, an external data request is received, and according to the business word in the external data request, for example, the business field is A. The business field A is used as the cluster sharding field, and the hash value hash(A) of the business field A is calculated.

[0121] The data routing module 40 is used to perform hash iterative calculation according to the hash value, the number of clusters and each sub-cluster in the distributed system using a preset number of iterations, determine the designated cluster corresponding to the external data request, and route the cluster data corresponding to the external data request to the designated cluster.

[0122] Among them, according to the hash value and the number of clusters, the remainder value of the two is determined, that is, the result of mod(hash(A),2) is calculated. The remainder value is compared with the cluster routing configuration information. For example, 0(0,1) matches successfully, and it is found that there are subclusters under cluster 0, and the number is 2. Then the hash needs to be further calculated. In order to prevent the data from being concentrated in the new subcluster 00, it is necessary to increase the dispersion factor and obtain a new hash value. The number of iterations is used as the dispersion factor, that is, the number of iterations is connected to the end of field A, which is 1 here, and is represented by concat(A,1). Then the subcluster routing rule is mod(hash(concat(A,1)),2) to determine the specified cluster. If the result is 0, it is in the new 00 cluster, and if the result is 1, it is in the new 01 cluster.

[0123] As an embodiment of the present invention, Fig.10 As shown, the device also includes:

[0124] The cluster serial number module 50 is used to determine the serial number of the cluster to be sharded and the number of cluster splits according to the business volume and database capacity of each cluster in the distributed system;

[0125] The rule updating module 60 is used to update the cluster routing configuration rules in the distributed system according to the sequence number of the cluster to be sharded and the number of cluster splits.

[0126] As an embodiment of the present invention, Fig.11 As shown, the cluster splitting module 20 includes:

[0127] The to-be-sharded cluster unit 21 is configured to determine a to-be-sharded cluster from among the multiple clusters of the distributed system according to the to-be-sharded cluster sequence number in the cluster routing configuration rule;

[0128] The sub-cluster unit 22 is used to turn off the service switch of the cluster to be sharded, and split the cluster to be sharded according to the cluster split number in the cluster routing configuration rule to obtain sub-clusters corresponding to the cluster to be sharded.

[0129] In this embodiment, if Fig.12 As shown, the device further includes: a service switch module 70, which is used to use the standby database in the cluster to be sharded as the main database of the sub-cluster and turn on the service switch of the cluster to be sharded.

[0130] Here, it is assumed that cluster 0 is split into two sub-clusters, namely cluster 00 and cluster 01. Specifically, the backup database in the original cluster 0 is modified to be the master database of the new sub-cluster. After the cluster is split, the service switch of cluster 0 is turned on, so that after connecting to the gateway, data requests from cluster 0 are received.

[0131] In this embodiment, if Fig.13As shown, the device further includes: a redundant data module 80, which is used to delete redundant data in each cluster in the distributed system.

[0132] As an embodiment of the present invention, Fig.14 As shown, the data routing module 40 includes:

[0133] A hash value unit 41, configured to calculate a first remainder value between the hash value and the number of clusters, match the first remainder value with the cluster routing configuration rule, and determine a first cluster corresponding to the first remainder value;

[0134] The designated cluster unit 42 is used to use the preset number of iterations as a dispersion factor, perform hash iterative calculation according to the number of subclusters corresponding to the first cluster and the dispersion factor, and update the hash value and its corresponding remainder value until the preset number of iterations is reached or the current cluster does not have a corresponding subcluster, and then use the current cluster as the designated cluster corresponding to the external data request.

[0135] Based on the same application concept as the above-mentioned distributed system cluster online sharding expansion method, the present invention also provides the above-mentioned distributed system cluster online sharding expansion device. Since the principle of solving the problem by the distributed system cluster online sharding expansion device is similar to that of the distributed system cluster online sharding expansion method, the implementation of the distributed system cluster online sharding expansion device can refer to the implementation of the distributed system cluster online sharding expansion method, and the repeated parts will not be repeated.

[0136] The present invention realizes sharding expansion in a distributed system through a hash iteration-based approach, prevents uneven data distribution by iterating hash moduli multiple times and using the number of iterations as a dispersion factor, thereby realizing capacity expansion of a cluster with insufficient specified performance capacity, reducing the impact of expanded nodes and change time on the business system and saving resource costs.

[0137] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above method when executing the program.

[0138] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for executing the above method.

[0139] like Fig.15 As shown, the electronic device 600 may further include: a communication module 110, an input unit 120, an audio processor 130, a display 160, and a power supply 170. It is worth noting that the electronic device 600 does not necessarily have to include Fig.15In addition, the electronic device 600 may also include Fig.15 For components not shown, reference may be made to the prior art.

[0140] like Fig.15 As shown, the central processor 100 is sometimes also referred to as a controller or an operation control, and may include a microprocessor or other processor devices and / or logic devices. The central processor 100 receives inputs and controls the operations of various components of the electronic device 600.

[0141] The memory 140 may be, for example, one or more of a cache, a flash memory, a hard drive, a removable medium, a volatile memory, a non-volatile memory or other suitable devices. The above-mentioned information related to the failure may be stored, and a program for executing the relevant information may also be stored. The CPU 100 may execute the program stored in the memory 140 to implement information storage or processing.

[0142] The input unit 120 provides input to the CPU 100. The input unit 120 is, for example, a key or a touch input device. The power supply 170 is used to provide power to the electronic device 600. The display 160 is used to display display objects such as images and text. The display may be, for example, an LCD display, but is not limited thereto.

[0143] The memory 140 may be a solid-state memory, such as a read-only memory (ROM), a random access memory (RAM), a SIM card, etc. It may also be a memory that saves information even when the power is off, can be selectively erased, and is provided with more data, examples of which are sometimes referred to as EPROMs, etc. The memory 140 may also be some other type of device. The memory 140 includes a buffer memory 141 (sometimes referred to as a buffer). The memory 140 may include an application / function storage unit 142, which is used to store application programs and function programs or processes for executing the operation of the electronic device 600 through the central processor 100.

[0144] The memory 140 may also include a data storage unit 143 for storing data, such as contacts, digital data, pictures, sounds, and / or any other data used by the electronic device. The driver storage unit 144 of the memory 140 may include various drivers for communication functions of the electronic device and / or for executing other functions of the electronic device (such as messaging applications, address book applications, etc.).

[0145] The communication module 110 is a transmitter / receiver that transmits and receives signals via the antenna 111. The communication module (transmitter / receiver) 110 is coupled to the central processor 100 to provide input signals and receive output signals, which may be the same as the case of a conventional mobile communication terminal.

[0146] Based on different communication technologies, multiple communication modules 110 may be provided in the same electronic device, such as a cellular network module, a Bluetooth module and / or a wireless LAN module. The communication module (transmitter / receiver) 110 is also coupled to a speaker 131 and a microphone 132 via an audio processor 130 to provide an audio output via the speaker 131 and receive an audio input from the microphone 132, thereby realizing a common telecommunication function. The audio processor 130 may include any suitable buffer, decoder, amplifier, etc. In addition, the audio processor 130 is also coupled to the central processor 100, so that the sound can be recorded on the local machine through the microphone 132, and the sound stored on the local machine can be played through the speaker 131.

[0147] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0148] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0149] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1A function specified in one or more boxes.

[0150] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0151] The present invention uses specific embodiments to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A distributed system cluster online sharding expansion method, characterized in that: The method comprises: Obtain cluster routing configuration rules in the distributed system, and determine the cluster to be sharded according to the cluster routing configuration rules; wherein the cluster routing configuration rules include the number of clusters, the sequence number of the cluster to be sharded, and the number of cluster splits; According to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule, the cluster to be sharded is split to obtain subclusters corresponding to the cluster to be sharded; Determine, according to the received external data request, a hash value corresponding to the external data request using a hash algorithm; According to the hash value, the number of clusters and each sub-cluster in the distributed system, a hash iterative calculation is performed using a preset number of iterations to determine a designated cluster corresponding to the external data request, and the cluster data corresponding to the external data request is routed to the designated cluster; The step of performing hash iterative calculation according to the hash value, the number of clusters, and each sub-cluster in the distributed system using a preset number of iterations to determine the designated cluster corresponding to the external data request includes: Calculating a first remainder value between the hash value and the number of clusters, matching the first remainder value with the cluster routing configuration rule, and determining a first cluster corresponding to the first remainder value; The preset number of iterations is used as a dispersion factor, and hash iterative calculation is performed according to the number of subclusters corresponding to the first cluster and the dispersion factor, and the hash value and its corresponding remainder value are updated until the preset number of iterations is reached or the current cluster does not have a corresponding subcluster, then the current cluster is used as the designated cluster corresponding to the external data request.

2. The method according to claim 1, characterized in that The method further comprises: Determine the sequence number of the cluster to be sharded and the number of cluster splits according to the business volume and database capacity of each cluster in the distributed system; According to the sequence number of the cluster to be sharded and the number of cluster splits, the cluster routing configuration rules in the distributed system are updated.

3. The method according to claim 1, characterized in that The cluster to be sharded is split according to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule to obtain subclusters corresponding to the cluster to be sharded, including: Determine a cluster to be sharded from among multiple clusters of the distributed system according to the sequence number of the cluster to be sharded in the cluster routing configuration rule; Turn off the service switch of the cluster to be sharded, split the cluster to be sharded according to the cluster split number in the cluster routing configuration rule, and obtain sub-clusters corresponding to the cluster to be sharded.

4. The method according to claim 3, characterized in that The method further includes: using a standby database in the cluster to be sharded as a master database of the sub-cluster, and turning on a service switch of the cluster to be sharded.

5. The method according to claim 4, characterized in that The method further includes: deleting redundant data in each cluster in the distributed system.

6. A distributed system cluster online sharding expansion device, characterized in that: The device comprises: The cluster module to be sharded is used to obtain the cluster routing configuration rules in the distributed system and determine the cluster to be sharded according to the cluster routing configuration rules; wherein the cluster routing configuration rules include the number of clusters, the sequence number of the cluster to be sharded and the number of cluster splits; A cluster splitting module, used to split the cluster to be sharded according to the sequence number of the cluster to be sharded and the number of cluster splits in the cluster routing configuration rule, to obtain subclusters corresponding to the cluster to be sharded; A hash value module, used to determine a hash value corresponding to the external data request using a hash algorithm according to the received external data request; A data routing module, configured to perform hash iterative calculations using a preset number of iterations according to the hash value, the number of clusters, and each sub-cluster in the distributed system, determine the designated cluster corresponding to the external data request, and route the cluster data corresponding to the external data request to the designated cluster; Wherein, the data routing module includes: A hash value unit, configured to calculate a first remainder value between the hash value and the number of clusters, match the first remainder value with the cluster routing configuration rule, and determine a first cluster corresponding to the first remainder value; The designated cluster unit is used to use the preset number of iterations as a dispersion factor, perform hash iterative calculation according to the number of subclusters corresponding to the first cluster and the dispersion factor, and update the hash value and its corresponding remainder value until the preset number of iterations is reached or the current cluster does not have a corresponding subcluster, and then use the current cluster as the designated cluster corresponding to the external data request.

7. The device according to claim 6, characterized in that The device also includes: The cluster serial number module is used to determine the serial number of the cluster to be sharded and the number of cluster splits according to the business volume and database capacity of each cluster in the distributed system; A rule updating module is used to update the cluster routing configuration rules in the distributed system according to the sequence number of the cluster to be sharded and the number of cluster splits.

8. The device according to claim 6, characterized in that The cluster splitting module includes: A cluster unit to be sharded, configured to determine a cluster to be sharded from among multiple clusters of the distributed system according to a sequence number of the cluster to be sharded in the cluster routing configuration rule; The sub-cluster unit is used to turn off the service switch of the cluster to be sharded, split the cluster to be sharded according to the cluster split number in the cluster routing configuration rule, and obtain sub-clusters corresponding to the cluster to be sharded.

9. The device according to claim 8, characterized in that The device also includes: a service switch module, which is used to use the standby database in the cluster to be sharded as the main database of the sub-cluster and turn on the service switch of the cluster to be sharded.

10. The device according to claim 9, characterized in that The device also includes: a redundant data module, which is used to delete redundant data in each cluster in the distributed system.

11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 5 is implemented.

12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Intelligent hash data layout method, cluster storage system and cluster storage method

    CN102855294A

  • Expanding and shrinking method for distributed cluster with nodes supporting multiple data fragments

    CN104615657A