Load balancing method and apparatus
By identifying high-load nodes in the distributed storage system and migrating master-slave data blocks, the problem of excessive load on storage nodes is solved, and the system load balance and stability are improved.
Patent Information
- Application Number
- PCT/CN2024/087779
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-27
- Filing Date
- 2024-04-15
- Publication Date
- 2024-10-31
AI Technical Summary
In a large-scale distributed shared storage environment, the main data block load on some storage nodes is too high, which affects system stability. It is difficult for existing load balancing strategies to achieve effective balancing in scenarios where data nodes change frequently.
By identifying high-load nodes in the distributed storage system, migrating master data blocks to low-load nodes, and switching master-slave data blocks, load balancing is achieved until there are no high-load nodes in the system.
It achieves load balancing of each storage node, improves the stability of the system, and ensures a more reasonable load distribution among data nodes.
Smart Images

Figure CN2024087779_31102024_PF_FP_ABST
Abstract
Description
A load balancing method and device
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 27, 2023, with application number 202310495222.4 and invention name “A Load Balancing Method and Device”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The embodiments of the present application relate to the field of big data. More specifically, the embodiments of the present application relate to a load balancing method and apparatus. Background Art
[0003] This section is intended to provide a background or context to the embodiments of the application that are recited in the claims. No statement herein is admitted to be prior art by virtue of its inclusion in this section.
[0004] In a large-scale distributed shared storage environment, each piece of data can be secured by forming a replica set with multiple copies of each data block. The data blocks in the replica set are stored on different data nodes. The primary data block in the replica set is responsible for interacting with the outside world and can perform data read and write operations, while the secondary data blocks serve only as backups of the primary data block and only perform data write operations.
[0005] When a storage node has too many primary data blocks, the read and write load of the node will be relatively high, affecting the stability of the system.
[0006] Summary of the Invention
[0007] To overcome the problems existing in the related art, the present application provides the following methods and devices.
[0008] In a first aspect of the embodiments of the present application, a load balancing method is provided, which is applied to a distributed storage system, wherein the distributed storage system includes multiple storage nodes; the distributed storage system stores multiple data blocks in the form of data block replica sets; wherein each data block replica set includes a primary data block and at least one corresponding secondary data block; each data block in the same data block replica set is stored on a different storage node;
[0009] The method comprises:
[0010] Determining whether there is a high-load storage node in the distributed storage system; wherein the high-load storage node is a storage node in which the number of stored primary data blocks is greater than a preset balancing threshold;
[0011] If there is a high-load storage node, repeat the following steps until a first balance condition is met; wherein the first balance condition includes that there is no high-load storage node in the distributed storage system;
[0012] Determining a first target node from the high-load storage nodes;
[0013] Determine whether there is a primary data block that meets a first migration condition among the primary data blocks stored on the first target node; wherein the first migration condition includes that the storage nodes where the corresponding secondary data blocks are located include a low-load storage node; the low-load storage node is a storage node that stores less than a preset balancing threshold number of primary data blocks:
[0014] If there is a master data block that meets the first migration condition among the master data blocks stored on the first node, a target master data block is determined from the master data blocks that meet the first migration condition, and the target master data block is switched to a slave data block; and, from the slave data blocks corresponding to the target master data block, a target slave data block whose storage node is a low-load storage node is determined, and the target slave data block is switched to the master data block.
[0015] In a second aspect of the embodiments of the present application, a load balancing device is provided, which is applied to a distributed storage system, wherein the distributed storage system includes multiple storage nodes; the distributed storage system stores multiple data blocks in the form of data block replica sets; wherein each data block replica set includes a primary data block and at least one corresponding secondary data block; each data block in the same data block replica set is stored on a different storage node; the device includes:
[0016] A first judgment unit is configured to determine whether there is a high-load storage node in the distributed storage system; wherein the high-load storage node is a storage node in which the number of stored primary data blocks is greater than a preset balancing threshold;
[0017] A first execution unit is configured to repeatedly execute the following steps if a high-load storage node exists until a first balancing condition is satisfied; wherein the first balancing condition includes that no high-load storage node exists in the distributed storage system;
[0018] A node determining unit, configured to determine a first target node from the high-load storage nodes;
[0019] a condition determination unit, configured to determine whether, among the primary data blocks stored on the first target node, there is a primary data block that meets a first migration condition; wherein the first migration condition includes that the storage nodes where the corresponding secondary data blocks are located include a low-load storage node; the low-load storage node is a storage node that stores less than a preset balancing threshold number of primary data blocks;
[0020] a switching unit for determining a target master data block from the master data blocks that satisfy the first migration condition, and switching the target master data block to a slave data block, if a master data block that satisfies the first migration condition exists among the master data blocks stored on the first node; and determining a target slave data block from the slave data blocks corresponding to the target master data block, the storage node of which is a low-load storage node, and switching the target slave data block to the master data block.
[0021] In a third aspect of the embodiments of the present application, a storage medium is provided; a computer program is stored on the storage medium, and when the computer program is executed, the steps of the method described above are implemented.
[0022] In a fourth aspect of the embodiments of the present application, a computer device is provided, 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.
[0023] The above embodiments of the present application have at least the following beneficial effects:
[0024] In the above technical solution, by switching the primary data block in the high-load storage node to a slave data block, and switching the slave data block in a data block replica set corresponding to the primary data block and located in a low-load storage node to the primary data block, the number of high-read and high-write primary data blocks in each storage node in the distributed storage system is balanced, the load balance of each storage node is achieved, and the stability of the system is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In the accompanying drawings, unless otherwise specified, the same reference numerals throughout the multiple drawings represent the same or similar components or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments disclosed in this application and should not be construed as limiting the scope of this application.
[0026] FIG1 schematically shows an architecture diagram of a load balancing method according to an embodiment of the present application;
[0027] FIG2 schematically shows an application scenario of a load balancing method according to an embodiment of the present application;
[0028] FIG3 schematically shows a flow chart of a load balancing method according to an embodiment of the present application;
[0029] FIG4 schematically shows a flow chart of a load balancing method according to an embodiment of the present application;
[0030] FIG5 schematically shows a schematic diagram of a double migration method according to an embodiment of the present application;
[0031] FIG6 schematically shows a flow chart of a load balancing method according to an embodiment of the present application;
[0032] FIG7 schematically shows a structural diagram of a load balancing system according to an embodiment of the present application;
[0033] FIG8 schematically shows a block diagram of a load balancing device according to an embodiment of the present application;
[0034] FIG9 schematically shows a hardware structure diagram of a computer device in which a load balancing method according to an embodiment of the present application is located. DETAILED DESCRIPTION
[0035] The principles and spirit of the present application will be described below with reference to several exemplary embodiments. It should be understood that these embodiments are provided solely to enable those skilled in the art to better understand and implement the present application, and are not intended to limit the scope of the present application in any way. Rather, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.
[0036] Those skilled in the art will appreciate that the embodiments of the present application may be implemented as a system, apparatus, device, method, or computer program product. Therefore, the present application may be implemented in the following forms: entirely in hardware, entirely in software (including firmware, resident software, microcode, etc.), or in a combination of hardware and software.
[0037] In large-scale distributed shared storage environments, for data security reasons, each piece of data can be organized into a data block replica set (chunk replica set) consisting of multiple data block (physical chunk) copies. The multiple data blocks in the data block replica set are stored on different data nodes in the data node cluster. If a data node where a data block replica resides fails, it will not affect the data block replicas stored on other nodes in the replica set.
[0038] To ensure the consistency of each data block copy in the data block replica set, one data block copy is usually used as the primary data block (leader chunk) responsible for external read and write requests, while other data block replica sets are used as follower chunks, which only synchronize data from the primary data block and serve as backups of the primary data block.
[0039] Since the load of the primary data block is usually much greater than that of the secondary data block, when allocating data block replica sets, it is usually necessary to balance the number of primary data blocks on each data node so that the primary data blocks on each data node are evenly distributed, thereby achieving load balancing between each data node.
[0040] However, with the creation and deletion of data block replica sets, the addition of new storage nodes, the offline of faulty storage nodes, and the switching of primary data blocks after hot upgrades of storage components in the storage environment, the number of primary data blocks in each data block replica set may no longer be balanced. For example, the data block replicas on a certain node may all be primary data, resulting in excessive load on the node, which may affect the processing speed of the node and the stability of the system.
[0041] Therefore, a load balancing strategy is needed to redistribute the distribution of primary data blocks on data nodes to make the load of each data node more balanced.
[0042] In a related technique, load balancing can be achieved by assigning a priority to each data node in advance. For example, after a data block replica set is created, the primary data block is located on node 1, and the two secondary data blocks are located on nodes 2 and 3, respectively. Therefore, the node priorities recorded in the replica set are 1, 2, and 3, respectively. This priority can be used as a reference for load balancing. For example, if node 1 fails and goes offline, the primary data block is migrated to another node. When node 1 comes back online, the primary data block is redistributed to node 1.
[0043] However, this load balancing strategy is only suitable for relatively stable service environments. In scenarios where data nodes or data block replica sets frequently change, this method is difficult to achieve load balancing. For example, in the above scenario, if node 1 goes offline and never comes back online, the priority of the primary data block in the data block replica set will no longer be valid.
[0044] To overcome the problems existing in the related art, the present application provides the following embodiments.
[0045] The solution of this application is described in detail below with reference to the accompanying drawings.
[0046] Please refer to Figure 1, which is a schematic diagram of the architecture of a load balancing system provided by an exemplary embodiment. As shown in Figure 1, the system may include a network 10, a server 11, and several electronic devices, such as mobile phones 12, 13, and 14.
[0047] The server 11 may be a physical server comprising an independent host, or the server 11 may be a virtual server hosted by a host cluster, a cloud server, or the like. Mobile phones 12-14 are just one type of electronic device that a user may use. In practice, a user may also use electronic devices such as tablet devices, laptop computers, PDAs (Personal Digital Assistants), wearable devices (such as smart glasses, smart watches, etc.), etc., and one or at least one embodiment of the present application is not limited thereto. The network 10 may include various types of wired or wireless networks.
[0048] In one embodiment, server 11 can cooperate with mobile phones 12-14; mobile phones 12-14 can accept user operations and upload the received commands and files to server 11 via network 10, and server 11 can then process the files based on the solution of this application. In another embodiment, mobile phones 12-14 can independently implement the solution of this application; mobile phones 12-14 can accept user operations and process the received commands and files based on the solution of this application to achieve load balancing.
[0049] First, the application scenario of this solution is specifically introduced, as shown in FIG2 , which is a schematic diagram of an application scenario of a load balancing method provided by an exemplary embodiment;
[0050] The load balancing method described herein is applied to a distributed storage system. The distributed storage system includes multiple storage nodes; the distributed storage system stores multiple data blocks in the form of data block replica sets; each data block replica set includes a primary data block and at least one corresponding secondary data block; and each data block in the same data block replica set is stored on a different storage node.
[0051] As shown in Figure 2, the distributed storage system may include four storage nodes, node 21, node 22, node 23, and node 24. Therein, four data block replica sets are stored, each of which includes one primary data block and two secondary data blocks.
[0052] In Figure 2, the oval legend represents data block replicas, among which the dark-colored data block replicas represent primary data blocks, such as data block 211, data block 222, data block 233 and data block 244; the light-colored data block replicas represent secondary data blocks, such as data block 221, data block 231, etc.; connected data block replicas represent that they belong to the same data block replica set, for example, primary data block 211 and secondary data blocks 221 and 231 belong to the same data block replica set, and primary data block 222 and secondary data blocks 232 and 242 belong to the same data block replica set.
[0053] Please refer to FIG. 3 , which is a flow chart of a load balancing method provided by an exemplary embodiment. The method is applied to a processing device, which may be the server 11 or mobile phones 12 - 14 shown in FIG. 1 .
[0054] The method is applied to a distributed storage system, which includes multiple storage nodes; the distributed storage system stores multiple data blocks in the form of data block replica sets; wherein each data block replica set includes a primary data block and at least one corresponding secondary data block; each data block in the same data block replica set is stored on a different storage node.
[0055] This application does not specifically limit the number of slave data blocks contained in each data block replica set. In a distributed storage system, an odd number of data block replicas is usually used to form a data block replica set, so that each data block replica set can make an election decision.
[0056] In an exemplary embodiment shown in the present application, each data block replica set includes three data block replicas, including one primary data block and two secondary data blocks.
[0057] The method may include the following steps:
[0058] Step 302: Determine whether there is a high-load storage node in the distributed storage system; wherein the high-load storage node is a storage node in which the number of stored primary data blocks is greater than a preset balancing threshold.
[0059] Whether the load of the system is balanced can be determined by determining whether there is a storage node with an excessive number of primary data blocks among the storage nodes in the distributed storage system.
[0060] Among them, the balancing threshold for judging whether the number of primary data blocks is too large can be preset by the user according to the performance of the storage node. For example, a certain proportion of the maximum number of data block copies that can be stored by the storage node, or a certain proportion of the number of data block copies stored by the storage node, such as half or one-third, can be used as the preset balancing threshold. This application does not make specific restrictions on this.
[0061] Taking into account the total load of the distributed storage system, the ratio of the number of primary data blocks stored in the system to the number of all data blocks should be the same as the ratio of the number of primary data blocks contained in each data block replica set to the number of data block replica sets.
[0062] For example, when the number of data blocks contained in each data block replica set is n, the number of storage nodes contained in the system is N, and the number of data blocks contained in each storage node is R i (i=1, 2, ..., N), then when the number of data blocks included in the system is When , the number of primary data blocks it contains is
[0063] In an ideal situation, that is, when the load is completely balanced, the number of primary data blocks that each data node should contain is R i / n. For the convenience of judgment, when R i When n is not an integer, it can be rounded up to an integer.
[0064] In an exemplary embodiment shown in this specification, the preset balance threshold is a value obtained by rounding up the ratio of the number of data blocks stored in the storage node to the number of data blocks included in each data block replica set.
[0065] For example, when the number of data blocks contained in each data block replica set is 3, that is, 1 primary data block and 2 secondary data blocks, the above-mentioned preset balance threshold can be set to the ratio of the number of data blocks stored by the storage node to the number of data blocks contained in each data block replica set, rounded up to the nearest integer.
[0066] In this application, a storage node whose number of stored primary data blocks is equal to the above-mentioned preset balancing threshold is called a load-balanced storage node; similarly, a storage node whose number of stored primary data blocks is greater than the above-mentioned preset balancing threshold is called a high-load storage node; and a storage node whose number of stored primary data blocks is less than the above-mentioned preset balancing threshold is called a low-load storage node.
[0067] In addition, in an exemplary embodiment shown in this specification, the load factor of the storage node can also be used to quantitatively represent the load condition of the storage node.
[0068] The load factor of a storage node can be represented by the difference between the number of primary data blocks contained in the storage node and the above-mentioned preset balancing threshold.
[0069] The load factor of a highly loaded storage node is greater than 0, indicating that the node needs to migrate out at least factor primary data blocks. The load factor of a low-load storage node is less than 0, indicating that the node can still migrate in factor primary data blocks. The factor of a balanced-load storage node is 0, indicating that the node does not need to migrate in a leader or migrate out a primary data block.
[0070] Step 304: If there is a storage node with a high load, the following steps are repeated until a first balancing condition is satisfied; wherein the first balancing condition includes that there is no storage node with a high load in the distributed storage system.
[0071] When there is no storage node with a high load, it can be considered that the loads among the storage nodes in the system are balanced and no load balancing is required.
[0072] When there are storage nodes with high loads, it can be considered that the loads among the storage nodes in the system are unbalanced, and load balancing is required until a load balance state is achieved among the storage nodes.
[0073] Specifically, load balancing may be performed by cyclically executing steps 306 to 310 .
[0074] Step 306: Determine a first target node from the high-load storage nodes;
[0075] For storage nodes with high load, it is necessary to reduce their load, that is, reduce the number of primary data blocks.
[0076] Furthermore, for a storage node with a larger load factor, since its load is heavier, the number of primary data blocks can be preferentially reduced from the storage node with the largest load factor.
[0077] Load balancing starts from the storage node with the highest load factor, and always determines a first target node from the high-load storage node with the largest load factor.
[0078] Step 308: Determine whether there is a master data block that meets the first migration condition among the master data blocks stored on the first target node; wherein the first migration condition includes that the storage nodes where the corresponding slave data blocks are located include low-load storage nodes; the low-load storage nodes are storage nodes in which the number of stored master data blocks is less than the preset balancing threshold.
[0079] For data blocks stored in the form of data block replica sets, you can switch the primary data block to a secondary data block, and switch a secondary data block in the database replica set to a primary data block, so as to conveniently and flexibly change the number of primary data blocks in the data node and achieve load balancing.
[0080] The number of high-load storage nodes in the system can be called the total load factor of the system, or the total load factor of the storage node cluster. When the total load factor of the cluster is equal to 0, it means that the primary data blocks of the cluster have achieved a balanced distribution.
[0081] To balance the load between storage nodes, that is, to reduce the overall load factor of the cluster, it is necessary to reduce the number of primary data blocks in highly loaded storage nodes. This means migrating primary data blocks from highly loaded nodes. Furthermore, migration should not create new highly loaded storage nodes. Primary data blocks from highly loaded storage nodes must be migrated to less loaded storage nodes.
[0082] Therefore, only when there is a high-load storage node for the master data block whose corresponding slave data block includes a low-load storage node in the storage node where the slave data block is located, can the conditions for load balancing be achieved through database master-slave switching. In this application, this condition is referred to as the first migration condition.
[0083] Step 310: If there is a master data block that meets the first migration condition among the master data blocks stored on the first target node, determine a target master data block from the master data blocks that meet the first migration condition, and switch the target master data block to a slave data block; and, determine a target slave data block whose storage node is a low-load storage node from the slave data blocks corresponding to the target master data block, and switch the target slave data block to a master data block.
[0084] When the primary data block that meets the first migration condition exists in the first target node, it indicates that the primary data block can be migrated from the first target node to reduce the total load factor of the cluster.
[0085] Specifically, a target master data block can be determined from the master data blocks that meet the first migration condition, and a slave data block corresponding to the target master data block, whose storage node is a low-load storage node, can be determined as the target slave data block, and the target master data block can be switched to a slave data block, and the target slave data block can be switched to a master data block.
[0086] Furthermore, when there are multiple master data blocks that meet the first migration condition on the first target node, or when there are multiple slave data blocks whose corresponding storage nodes that meet the first migration condition are low-load storage nodes, the master data blocks on the first target node can be preferentially migrated to the low-load node with the lowest load factor to better achieve the load balancing effect.
[0087] In an exemplary embodiment shown in the present application, determining a target primary data block from primary data blocks that meet the first migration condition includes:
[0088] Determining a storage node with the lowest load factor from among the low-load storage nodes where the slave data blocks corresponding to the master data blocks that meet the first migration condition are located as the second target node;
[0089] Determine a target primary data block from the primary data blocks that meet the first migration condition and correspond to the secondary data blocks on the second target node;
[0090] The step of determining, from the slave data blocks corresponding to the target master data block, a target slave data block whose storage node is a low-load storage node, includes:
[0091] From the slave data block corresponding to the master data block, a target slave data block whose storage node is the second target node is determined.
[0092] After the master-slave switching of the above data blocks, the first target node will contain one less master data block, which is closer to a load-balanced state.
[0093] Steps 306 to 310 are continuously executed in a loop. Each successful execution can reduce the number of primary data blocks stored in a high-load storage node by one.
[0094] When there are no more high-load storage nodes in the system, the system reaches a load-balanced state.
[0095] However, due to the master-slave switching method of data blocks, the migration of primary data blocks can only be performed within the same data block replica set. Therefore, this method may not be able to convert all high-load storage nodes in the system into load-balanced storage nodes.
[0096] There may be a situation where there are high-load storage nodes, but the primary data blocks contained in the high-load storage nodes do not meet the first migration condition. In this case, the total load factor of the system cannot continue to decrease, and it can be considered that the system has achieved relative load balance.
[0097] In an exemplary embodiment shown in this specification, the first balancing condition further includes: there are high-load storage nodes in the distributed storage system, but the primary data blocks contained in the high-load storage nodes do not meet the first migration condition.
[0098] A specific implementation according to the embodiment of this specification is described in detail below with reference to FIG. 4 .
[0099] As shown in FIG4 , FIG4 schematically shows a flow chart of a load balancing method according to an embodiment of the present application.
[0100] Load balancing can be achieved by following the steps below:
[0101] 401: Check whether the total load factor of the cluster is 0, that is, whether the system has reached a load-balanced state;
[0102] If the total load factor of the cluster is 0, the system reaches a load-balanced state and the process ends;
[0103] If the total load factor of the cluster is not 0, the system is not load balanced;
[0104] Sort the load factors of the storage nodes by their load factors, sort them from high to low, set a parameter hasMigrated and assign it a value of false;
[0105] Traverse each storage node in descending order of load factor and use it as the target node;
[0106] Whenever a target node is determined, a determination 402 is executed: determining whether all nodes have been traversed;
[0107] If all nodes have been traversed, jump to judgment 403;
[0108] If all nodes have not been traversed, determine the target node;
[0109] Determine whether the load factor of the target node is not greater than 0;
[0110] If the load factor of the target node is not greater than 0, jump to decision 403;
[0111] Otherwise, the primary data block is migrated to the target node one at a time until the target node load factor reaches 0 or cannot be further reduced.
[0112] Determine whether the load factor of the target node is reduced;
[0113] If not, jump to decision 402;
[0114] If it is lowered, assign the parameter hasMigrated to ture;
[0115] 403: Check whether the value of the parameter hasMigrated is true;
[0116] If yes, jump to judgment 401;
[0117] If not, the system has achieved relative load balancing and the process ends.
[0118] In the above method, when the total load factor of the cluster is not 0, the nodes are sorted in descending order by their load factors. The node with the highest load factor is first selected as the target node, and the primary data blocks are migrated to it until migration is no longer necessary or cannot be achieved. If at least one primary data block is successfully migrated, the above steps are repeated.
[0119] If the target node cannot migrate any primary data block, continue to use the next node as the target node and perform the above migration process until there are no high-load storage nodes (total factor = 0) or all high-load nodes cannot migrate any primary data block (hasMigrated = false).
[0120] When there are high-load storage nodes in the system, but all high-load storage nodes do not meet the first migration condition, a double migration method can be used to continue load balancing.
[0121] As shown in FIG5 , FIG5 schematically shows a schematic diagram of a double migration method according to an embodiment of the present application.
[0122] Storage node Node2 has a load factor of 1, making it a highly loaded storage node. Storage nodes Node1 and Node3, where the slave data blocks corresponding to each of its master data blocks reside, are not low-load storage nodes and therefore do not meet the first migration condition. Therefore, the load factor of storage node Node2 cannot be reduced using the methods described in the above embodiments.
[0123] However, the method shown in Figure 5 can migrate a primary data block in storage node Node2 to storage node Node3, and migrate a primary data block in storage node Node3 to storage node Node4, so that the load factors of each storage node Node2, Node3, and Node4 are converted from 1, 0, and -1 before migration to 0, 0, and 0 after migration, respectively, thereby reducing the total load factor.
[0124] The above-mentioned double migration method, through the transfer of storage node Node3, is equivalent to migrating the master data block in the high-load storage node Node2 to the low-load storage node Node4; wherein, the storage node Node2 does not have a master data block, and its corresponding slave data block is located in the storage node Node4.
[0125] In an exemplary embodiment shown in this specification, the method further includes:
[0126] If there are high-load storage nodes in the distributed storage system, but none of the primary data blocks contained in the high-load storage nodes meet the first migration condition, the following steps are further repeated until a second balance condition is met; wherein the second balance condition includes that there are no high-load storage nodes in the distributed storage system;
[0127] Determining whether there is a balanced-load storage node in the distributed storage system that meets a transfer condition; wherein the balanced-load storage node is a storage node that contains a number of master data blocks that is equal to a preset balancing threshold; the transfer condition includes that among the master data blocks included there is a master data block that meets the first migration condition, and among the slave data blocks included there is a slave data block that meets the second migration condition; the second migration condition includes that among the storage nodes where the corresponding master data blocks are located there is a high-load storage node;
[0128] If there are storage nodes with balanced loads that meet the transfer conditions, a transfer node is determined from the storage nodes with balanced loads that meet the transfer conditions;
[0129] Determine a second target master data block from the master data blocks that meet the first migration condition and are contained in the transit node, and switch the second target master data block to a slave data block; and determine a second target slave data block whose storage node is a low-load storage node from the slave data blocks corresponding to the second target master data block, and switch the second target slave data block to the master data block;
[0130] Determine a third target slave data block from the slave data blocks that meet the second migration condition and are contained in the transit node, and switch the third target slave data block to the master data block; and determine a third target master data block whose storage node is a high-load storage node from the master data blocks corresponding to the third target slave data block, and switch the third target master data block to the master data block.
[0131] However, if the single migration method cannot achieve load balancing, you can continue to use the double migration method.
[0132] A storage node that serves as a transit node between a high-load storage node and a low-load storage node must be a load-balanced storage node.
[0133] If the transit node is a high-load node, it can directly migrate the main data block to the low-load node to reduce the total load factor; if the transit node is a low-load node, it can directly receive the main data block migrated from the high-load node to reduce the total load factor.
[0134] Therefore, it is possible to determine whether load balancing can be performed through double migration by determining whether there is a transfer node that meets the transfer conditions.
[0135] The transfer node should meet the following transfer conditions:
[0136] a. The transit node is a load-balanced storage node, that is, the load factor is 0;
[0137] b. The transit node contains the master data block that can be migrated to the low-load storage node, that is, the master data block that meets the first migration condition;
[0138] c. If there is a high-load node, the master data block can be migrated to the transit node, that is, the second migration condition is met: there is a slave data block, and the storage node where the corresponding master data block is located is a high-load storage node.
[0139] When there is a transfer node that meets the transfer conditions, a double migration method can be used to balance the load of the storage nodes.
[0140] Specifically, a second target master data block may be determined from the master data blocks that meet the first migration condition and are included in the transit node, and a second target slave data block whose storage node is a low-load storage node may be determined from the slave data blocks corresponding to the second target master data block, and master-slave switching may be performed on the second target slave data block and the second target master data block;
[0141] A third target slave data block is determined from the slave data blocks that meet the second migration condition and are contained in the transit node, and a third target master data block whose storage node is a high-load storage node is determined from the master data block corresponding to the third target slave data block, and master-slave switching is performed on the third target master data block and the third target slave data block.
[0142] The following describes in detail the specific implementation of a double migration method according to the embodiment of this specification with reference to FIG6 .
[0143] As shown in FIG6 , FIG6 schematically shows a flow chart of a load balancing method according to an embodiment of the present application.
[0144] Load balancing can be achieved by following the steps below:
[0145] Decision 601: Determine whether the total load factor of the cluster is 0;
[0146] If the total load factor of the cluster is 0, the system reaches a load-balanced state and the process ends;
[0147] If the total load factor of the cluster is not 0, the system is not load balanced;
[0148] Set a parameter hasMigrated and assign it to false;
[0149] Traverse all nodes and determine them as target nodes in turn;
[0150] Whenever a target node is determined, a determination 602 is executed: determining whether all nodes have been traversed;
[0151] If the traversal is complete, jump to judgment 603;
[0152] If the traversal is not complete, determine the target node;
[0153] Determine whether the target node is a load-balanced node;
[0154] If not, jump to decision 602;
[0155] If so, find set A and determine whether it is empty; find set C and determine whether it is empty;
[0156] The set A is a high-load storage node where the master data block whose corresponding slave data block is located at the target node is located; the set B is a low-load storage node where the slave data block whose corresponding master data block is located at the target node is located;
[0157] If set A or set C is empty, jump to judgment 601;
[0158] Perform the double migration method to perform load balancing through the target node until load balancing cannot be performed through the target node, and set the parameter hasMigrated to true;
[0159] Decision 602: Determine whether the value of the parameter hasMigrated is true;
[0160] If yes, jump to judgment 601;
[0161] If not, the system has achieved relative load balance and the process ends.
[0162] In the above method, when the total load factor of the cluster is not 0, each storage node is traversed and the storage node that meets the transfer conditions is used as the transfer node for double migration. If the migration of the primary data block is successful, the above steps are continued in a loop.
[0163] If any primary data block cannot be migrated, the next node is selected as the target node and the above migration process is performed until there is no high-load storage node (total factor = 0) or all nodes do not meet the transfer condition (hasMigrated = false).
[0164] In an exemplary embodiment of the present application, a load balancing system is also provided. Please refer to Figure 7, which is a structural diagram of a load balancing device according to an embodiment of the present application.
[0165] The load balancing system is applied to a distributed storage system, which includes multiple storage nodes; the distributed storage system stores multiple data blocks in the form of data block replica sets; wherein each data block replica set includes a primary data block and at least one corresponding secondary data block; each data block in the same data block replica set is stored on a different storage node.
[0166] The load balancing device 70 includes a single migrator 701, which is used to perform the following method:
[0167] Determining whether there is a high-load storage node in the distributed storage system; wherein the high-load storage node is a storage node in which the number of stored primary data blocks is greater than a preset balancing threshold;
[0168] If there is a high-load storage node, repeat the following steps until a first balance condition is met; wherein the first balance condition includes that there is no high-load storage node in the distributed storage system;
[0169] Determining a first target node from the high-load storage nodes;
[0170] Determining whether there is a primary data block that meets a first migration condition among the primary data blocks stored on the first target node; wherein the first migration condition includes that the storage nodes where the corresponding secondary data blocks are located include a low-load storage node; the low-load storage node is a storage node that stores less than a preset balancing threshold number of primary data blocks;
[0171] If there is a master data block that meets the first migration condition among the master data blocks stored on the first target node, a target master data block is determined from the master data blocks that meet the first migration condition, and the target master data block is switched to a slave data block; and, from the slave data blocks corresponding to the target master data block, a target slave data block whose storage node is a low-load storage node is determined, and the target slave data block is switched to the master data block.
[0172] In addition, the load balancing device may further include a dual migrator 702 configured to perform the following method:
[0173] If there are high-load storage nodes in the distributed storage system, but none of the primary data blocks contained in the high-load storage nodes meet the first migration condition, the following steps are further repeated until a second balance condition is met; wherein the second balance condition includes that there are no high-load storage nodes in the distributed storage system;
[0174] Determining whether there is a balanced-load storage node in the distributed storage system that meets a transfer condition; wherein the balanced-load storage node is a storage node that contains a number of master data blocks that is equal to a preset balancing threshold; the transfer condition includes that among the master data blocks included there is a master data block that meets the first migration condition, and among the slave data blocks included there is a slave data block that meets the second migration condition; the second migration condition includes that among the storage nodes where the corresponding master data blocks are located there is a high-load storage node;
[0175] If there are storage nodes with balanced loads that meet the transfer conditions, a transfer node is determined from the storage nodes with balanced loads that meet the transfer conditions;
[0176] Determine a second target master data block from the master data blocks that meet the first migration condition and are contained in the transit node, and switch the second target master data block to a slave data block; and determine a second target slave data block whose storage node is a low-load storage node from the slave data blocks corresponding to the second target master data block, and switch the second target slave data block to the master data block;
[0177] Determine a third target slave data block from the slave data blocks that meet the second migration condition and are contained in the transit node, and switch the third target slave data block to the master data block; and determine a third target master data block whose storage node is a high-load storage node from the master data blocks corresponding to the third target slave data block, and switch the third target master data block to the master data block.
[0178] In an exemplary embodiment of the present application, a load balancing device is also provided. Please refer to Figure 8, which is a block diagram of the load balancing device in an embodiment of the present application.
[0179] The device is applied to a distributed storage system, which includes multiple storage nodes; the distributed storage system stores multiple data blocks in the form of data block replica sets; wherein each data block replica set includes a primary data block and at least one corresponding secondary data block; each data block in the same data block replica set is stored on a different storage node;
[0180] The device may include the following components:
[0181] A first judgment unit 810 is configured to determine whether there is a high-load storage node in the distributed storage system; wherein the high-load storage node is a storage node in which the number of primary data blocks stored is greater than a preset balancing threshold;
[0182] A first execution unit 820 is configured to repeatedly execute the following steps if a high-load storage node exists until a first balancing condition is satisfied; wherein the first balancing condition includes that the high-load storage node does not exist in the distributed storage system;
[0183] The target node determining unit 830 is configured to determine a first target node from the high-load storage nodes;
[0184] The first condition determination unit 840 is configured to determine whether there is a primary data block among the primary data blocks stored on the first target node that meets a first migration condition; wherein the first migration condition includes that the storage nodes where the corresponding secondary data blocks are located include a low-load storage node; the low-load storage node is a storage node that stores less than a preset balancing threshold number of primary data blocks.
[0185] The first switching unit 850 is configured to determine a target master data block from the master data blocks that satisfy the first migration condition, and switch the target master data block to a slave data block if there is a master data block that satisfies the first migration condition among the master data blocks stored on the first node; and to determine a target slave data block whose storage node is a low-load storage node from the slave data blocks corresponding to the target master data block, and switch the target slave data block to the master data block.
[0186] Optionally, the preset balancing threshold is a value obtained by rounding up the ratio of the number of data blocks stored in the storage node to the number of data blocks included in each data block replica set.
[0187] Optionally, the first switching unit 850 is specifically used to determine a first target node from the high-load storage node with the largest load factor; the load factor is the difference between the number of primary data blocks contained in the storage node and the balancing threshold.
[0188] Optionally, the first switching unit 850 is specifically configured to determine, from the low-load storage nodes where the slave data blocks corresponding to the master data blocks that meet the first migration condition are located, a storage node with the lowest load factor as the second target node;
[0189] Determine a target primary data block from the primary data blocks that meet the first migration condition and correspond to the secondary data blocks on the second target node;
[0190] And, from the slave data block corresponding to the master data block, a target slave data block whose storage node is the second target node is determined.
[0191] Optionally, the first balancing condition further includes: there are high-load storage nodes in the distributed storage system, but the primary data blocks contained in the high-load storage nodes do not meet the first migration condition.
[0192] Optionally, the device further includes:
[0193] A second execution unit 860 is configured to, if there is a high-load storage node in the distributed storage system but none of the primary data blocks contained in the high-load storage node satisfies the first migration condition, further repeatedly perform the following steps until a second balancing condition is satisfied; wherein the second balancing condition includes that there is no high-load storage node in the distributed storage system;
[0194] A second condition determination unit 870 is configured to determine whether there is a balanced-load storage node in the distributed storage system that meets a transfer condition; wherein the balanced-load storage node is a storage node that contains a number of master data blocks that is equal to a preset balancing threshold; the transfer condition includes that a master data block that meets the first migration condition exists among the included master data blocks, and a slave data block that meets the second migration condition exists among the included slave data blocks; and the second migration condition includes that a storage node containing a corresponding master data block contains a high-load storage node;
[0195] The transfer node determining unit 880 is configured to determine a transfer node from the storage nodes with balanced loads that meet the transfer condition if there are storage nodes with balanced loads that meet the transfer condition;
[0196] The second switching unit 890 is configured to determine a second target master data block from the master data blocks that meet the first migration condition and are included in the transit node, and switch the second target master data block to a slave data block; and determine a second target slave data block whose storage node is a low-load storage node from the slave data blocks corresponding to the second target master data block, and switch the second target slave data block to the master data block;
[0197] The third switching unit 800 is used to determine a third target slave data block from the slave data blocks that meet the second migration condition and are contained in the transit node, and switch the third target slave data block to the master data block; and to determine a third target master data block whose storage node is a high-load storage node from the master data blocks corresponding to the third target slave data block, and switch the third target master data block to the master data block.
[0198] Optionally, the second balancing condition further includes: there are high-load storage nodes in the distributed storage system, but there are no load-balanced storage nodes that meet the transfer condition.
[0199] Optionally, each of the data block replica sets includes a primary data block and two corresponding secondary data blocks; the preset balancing threshold is a value obtained by rounding up one third of the number of data blocks stored in the storage node.
[0200] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0201] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on at least one network unit. Some or all of the units may be selected according to actual needs to achieve the purpose of the present application scheme. A person of ordinary skill in the art can understand and implement it without paying any creative work.
[0202] In an exemplary embodiment of the present application, an embodiment of a device and a terminal to which the device is applied is also provided.
[0203] The embodiments of the device of the present application can be applied to computer equipment, such as servers or terminal devices. The device embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory for execution. From the hardware level, as shown in Figure 9, Figure 9 is a hardware structure diagram of a computer device 90 where a device of an embodiment of the present application is located. In addition to the processor 910, memory 930, network interface 920, and non-volatile memory 940 shown in Figure 9, the server or electronic device where the device is located in the embodiment may also include other hardware according to the actual function of the computer device, which will not be described in detail.
[0204] In an exemplary embodiment of the present application, a computer-readable storage medium is further provided, on which a program product capable of implementing the above-mentioned method of the present application is stored. In some possible embodiments, various aspects of the present application may also be implemented in the form of a program product, which includes program code. When the program product is executed on a terminal device, the program code is used to cause the terminal device to perform the steps described in the "Exemplary Method" section above according to the various exemplary embodiments of the present application.
[0205] According to an embodiment of the present application, a program product for implementing the above method can be a portable compact disc read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present application is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0206] The program product may employ any combination of one or at least one readable medium. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or at least one wire, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0207] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0208] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0209] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0210] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0211] Although the present application includes many specific implementation details, these should not be interpreted as limiting the scope of any invention or the scope of the claimed invention, but are mainly used to describe the features of the specific embodiments of a particular invention. Certain features described in at least one embodiment of the present application may also be implemented in combination in a single embodiment. On the other hand, the various features described in a single embodiment may also be implemented separately in at least one embodiment or in any suitable sub-combination. In addition, although features may work in certain combinations as described above and even initially claimed as such, one or at least one feature from the claimed combination may be removed from the combination in some cases, and the claimed combination may point to a sub-combination or a variation of a sub-combination.
[0212] Similarly, although operations are depicted in a particular order in the accompanying drawings, this should not be understood as requiring that these operations be performed in the particular order shown or performed sequentially, or that all illustrated operations be performed to achieve the desired result. In some cases, multitasking and parallel processing may be advantageous. In addition, the separation of various system units and components in the above-described embodiments should not be understood as requiring such separation in all embodiments, and it should be understood that the described program components and systems can generally be integrated together in a single software product, or packaged into at least one software product.
[0213] Thus, specific embodiments of the subject matter have been described. Other embodiments are within the scope of the following claims. In some cases, the actions recited in the claims can be performed in a different order and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the particular order shown or sequential sequence to achieve the desired results. In some implementations, multitasking and parallel processing may be advantageous.
[0214] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A load balancing method is applied to a distributed storage system, wherein the distributed storage system comprises a plurality of storage nodes; the distributed storage system stores a plurality of data blocks in the form of a data block replica set; wherein: Each of the data block replica sets includes a primary data block and at least one corresponding secondary data block; Each data block in the same data block replica set is stored on different storage nodes; The method comprises: Determine whether there is a high-load storage node in the distributed storage system; wherein the high-load storage node is a storage node in which the number of stored primary data blocks is greater than a preset balancing threshold; If there is a storage node with a high load, the following steps are repeatedly performed until a first balancing condition is met; wherein the first balancing condition includes that there is no storage node with a high load in the distributed storage system; Determine a first target node from the high-load storage nodes; Determine whether there is a master data block that meets a first migration condition among the master data blocks stored on the first target node; wherein the first migration condition includes that the storage nodes where the corresponding slave data blocks are located include storage nodes with low load; the storage nodes with low load are storage nodes in which the number of stored master data blocks is less than the preset balancing threshold; If there is a master data block that meets the first migration condition among the master data blocks stored on the first target node, a target master data block is determined from the master data blocks that meet the first migration condition, and the target master data block is switched to a slave data block; and, from the slave data blocks corresponding to the target master data block, a target slave data block whose storage node is a low-load storage node is determined, and the target slave data block is switched to the master data block.
2. According to the method of claim 1, the preset balance threshold is the value obtained by rounding up the ratio of the number of data blocks stored in the storage node to the number of data blocks included in each data block replica set.
3. The method according to claim 1, wherein determining a first target node from the high-load storage nodes comprises: Determining a first target node from the high-load storage nodes with the largest load factor; The load factor is the difference between the number of primary data blocks contained in the storage node and the balancing threshold.
4. The method according to claim 3, wherein determining a target primary data block from primary data blocks satisfying the first migration condition comprises: From the low-load storage nodes where the slave data blocks corresponding to the master data blocks that meet the first migration condition are located, a storage node with the lowest load factor is determined as a second target node; Determine a target primary data block from the primary data blocks satisfying the first migration condition and corresponding to the secondary data blocks on the second target node; The step of determining, from the slave data block corresponding to the target master data block, a target slave data block whose storage node is a storage node with a low load, comprises: From the slave data block corresponding to the master data block, determine a target slave data block whose storage node is the second target node.
5. The method according to claim 1, wherein the first equilibrium condition further comprises: There are high-load storage nodes in the distributed storage system, but the primary data blocks contained in the high-load storage nodes do not meet the first migration condition.
6. The method according to claim 5, further comprising: If there are high-load storage nodes in the distributed storage system, but none of the master data blocks contained in the high-load storage nodes meet the first migration condition, the following steps are further repeated until a second balance condition is met; wherein the second balance condition includes that there are no high-load storage nodes in the distributed storage system; Determine whether there is a storage node with balanced load that meets the transfer condition in the distributed storage system; wherein the storage node with balanced load is a storage node that contains a number of master data blocks that is equal to a preset balance threshold; the transfer condition includes that there is a master data block that meets the first migration condition among the master data blocks included, and there is a slave data block that meets the second migration condition among the slave data blocks included; the second migration condition includes that the storage node where the corresponding master data block is located contains a high-load storage node; If there are storage nodes with balanced loads that meet the transfer condition, a transfer node is determined from the storage nodes with balanced loads that meet the transfer condition; Determine a second target master data block from the master data blocks that meet the first migration condition and are contained in the transit node, and switch the second target master data block to a slave data block; and, determine a second target slave data block whose storage node is a low-load storage node from the slave data blocks corresponding to the second target master data block, and switch the second target slave data block to the master data block; Determine a third target slave data block from the slave data blocks that meet the second migration condition and are contained in the transit node, and switch the third target slave data block to the master data block; and, determine a third target master data block whose storage node is a high-load storage node from the master data blocks corresponding to the third target slave data block, and switch the third target master data block to the master data block.
7. The method according to claim 6, wherein the second equilibrium condition further comprises: There are storage nodes with high load in the distributed storage system, but there are no storage nodes with balanced load that meet the transfer conditions.
8. According to the method of claim 2, each of the data block replica sets includes a primary data block and two corresponding secondary data blocks; the preset balance threshold is a value obtained by rounding up one third of the number of data blocks stored in the storage node.
9. A load balancing system, wherein the load balancing system is used to execute the steps of the method according to any one of claims 1 to 8.
10. A storage medium having a computer program stored thereon, which, when executed, implements the steps of the method according to any one of claims 1 to 8.
11. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the following method is implemented: wherein, when the processor executes the program, the method as claimed in any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Data migration method, data migration device, storage medium and equipment
CN110377430A
Load adjustment method, management node and storage medium
CN114143326A
Load balancing method and device
CN116540937A
System and method for load balancing in a distributed system by dynamic migration
US20160004571A1
Load balancing method and apparatus for storage cluster, computer device, and storage medium
WO2021217864A1
Cited By
Private data processing system based on trusted data space
CN119292797A
Processing method for relieving local overhigh spatial load of performance layer of hierarchical distributed block storage
CN119781676A
Data management method and device, computer program product and storage medium
CN120353410A
Distributed block storage system performance optimization method and system
CN120803377A
