Method for carrying out load balancing on distributed storage system under capacity reduction scene
By obtaining node scaling-down instructions and setting hash slot weights, and using a load balancing algorithm to calculate scaling-down routing information, the problem that static strategies cannot adapt to dynamic business changes is solved, and efficient load balancing and stable operation of the distributed storage system during the scaling-down process are achieved.
Patent Information
- Application Number
- CN202511543157.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-27
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2045-10-27
AI Technical Summary
Existing static load balancing strategies cannot adapt to dynamic business changes during the scaling-down process of distributed storage systems, leading to increased risk of hotspot overload and deterioration of system performance.
By obtaining node scaling-down instructions, detecting scaling-down conditions, acquiring original routing information, setting hash slot weights, calculating scaling-down routing information using a load balancing algorithm, and guiding data migration and route switching based on scaling-down state metadata, dynamic redistribution of data is achieved.
While ensuring high system availability, it reduces unnecessary data migration, avoids performance bottlenecks and service avalanche risks caused by uneven load, and achieves smooth, efficient and stable operation of the distributed storage system during the scaling-down process.
Smart Images

Figure CN121397006A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of distributed storage, and particularly relates to a method for load balancing of a distributed storage system in a capacity reduction scenario. BACKGROUND
[0002] In the current application of the distributed storage system, if a fault node occurs or the demand for optimizing resource allocation occurs, the number of nodes in the distributed storage system often needs to be reduced.
[0003] However, the capacity reduction process of the distributed storage system faces severe technical challenges. Since the data distribution is closely bound to the node routing, the deletion of the node will lead to unbalanced load of the remaining nodes if not accompanied by reasonable redistribution of data, and even may cause global service avalanche risk due to local overload. At the same time, in the data migration process, the related technology often calculates based on the static situation at the moment before capacity reduction, and no longer changes after the migration is completed. However, in fact, the access mode of real-time business is dynamically changing, and new, unpredictable overload hotspots may be generated after capacity reduction, and the existing static load balancing strategy cannot adaptively adjust according to the real-time load of the distributed storage.
[0004] Therefore, how to avoid the risk of hotspot overload caused by the static capacity reduction load balancing strategy that cannot adapt to the dynamic business load has become a technical problem to be solved at present. SUMMARY
[0005] Embodiments of the present application provide a method for load balancing of a distributed storage system in a capacity reduction scenario, aiming to solve the technical problem that the static capacity reduction load balancing strategy in the related art cannot adapt to dynamic business changes, thereby intensifying the risk of hotspot overload after capacity reduction and deteriorating system performance.
[0006] In a first aspect, embodiments of the present application provide a method for load balancing of a distributed storage system in a capacity reduction scenario, comprising: obtaining a node capacity reduction instruction, wherein the node capacity reduction instruction is used to indicate that a second number of capacity reduction nodes are reduced from a first number of original nodes in the distributed storage system, and a third number of reserved nodes are left; in response to the obtaining of the node capacity reduction instruction, detecting whether current capacity reduction associated information satisfies a predetermined capacity reduction condition, wherein the current capacity reduction associated information includes a current state of the distributed storage system and a real-time state of the capacity reduction node; if the current capacity reduction associated information satisfies the predetermined capacity reduction condition, obtaining original routing information of the distributed storage system, wherein the original routing information includes: a standby node of each of the original nodes in the distributed storage system, an original slot managed by each of the original nodes, and a plurality of hash slots in each of the original slots. setting a slot weight for each of the hash slots according to a predetermined slot weight setting mode; obtaining a difference between the first quantity and the second quantity as a first shrinkage slot block quantity calculation parameter, and obtaining a difference between the first shrinkage slot block quantity calculation parameter and 1 as a second shrinkage slot block quantity calculation parameter, and determining a product of the first shrinkage slot block quantity calculation parameter and the second shrinkage slot block quantity calculation parameter as a target slot block quantity of the distributed storage system after shrinkage; determining a shrinkage routing information of the distributed storage system according to a predetermined load balancing algorithm based on the original routing information, the slot weight of each of the hash slots and the target slot block quantity; determining a shrinkage state metadata based on the original routing information and the shrinkage routing information, wherein the shrinkage state metadata is used to reflect a hash slot distribution in each of the reserved nodes and a shrinkage action information of each of the original nodes; re-allocating all hash slots managed by the original nodes to the reserved nodes according to the shrinkage state metadata.
[0007] In an embodiment of the present application, optionally, the detecting whether the current shrinkage association information satisfies a predetermined shrinkage condition comprises: detecting whether the distributed storage system is in a normal service state, wherein the normal service state indicates that the distributed storage system has no ongoing data migration task, and detecting whether the shrinkage node is a registered secure node and has been bound to the original routing information, wherein, if the distributed storage system is in the normal service state, and the shrinkage node is a registered secure node and has been bound to the original routing information, it is determined that the current shrinkage association information satisfies the predetermined shrinkage condition.
[0008] In an embodiment of the present application, optionally, the setting a slot weight for each of the hash slots according to a predetermined slot weight setting mode comprises: setting the slot weight of each of the hash slots as 1; or for each of the hash slots, obtaining a storage space of the hash slot, and determining a space ratio of the storage space to a predetermined storage unit, and setting the slot weight of the hash slot as an upward integer value of the space ratio; or normalizing all storage spaces of the hash slots, and discretizing a result of the normalization to a first target interval, and taking each of first discrete results of all the hash slots as a respective slot weight of the hash slot, wherein a lower limit and an upper limit of the first target interval are 1 and half of a single node maximum backup number respectively.
[0009] In an embodiment of the present application, optionally, the setting the slot weight of each hash slot according to the predetermined slot weight setting mode comprises: For each hash slot, obtaining the access frequency of the hash slot; determining the frequency ratio of the access frequency to a predetermined frequency unit, and setting the slot weight of the hash slot as the upward integer value of the frequency ratio; or normalizing the access frequencies of all hash slots, and discretizing the result of the normalization to a second target interval, taking the respective second discrete results of all hash slots as the respective slot weights of all hash slots, wherein the lower limit and the upper limit of the second target interval are 1 and one-half of the maximum backup number of single nodes, respectively.
[0010] In an embodiment of the present application, optionally, the determining the shrinkage routing information of the distributed storage system based on the original routing information, the slot weight of each hash slot and the target slot block number according to the predetermined load balancing algorithm comprises: calculating the average weight and the remainder of the target slot block number based on the slot weight of each hash slot and the target slot block number; determining the original slot block division number and the division slot block aggregation number based on the original slot block number of all original nodes and the target slot block number, wherein the greatest common divisor of the original slot block number and the target slot block number is determined, the original slot block division number is the quotient of the target slot block number and the greatest common divisor, indicating the number of division slot blocks each original slot block needs to be divided into, and the division slot block aggregation number is the quotient of the original slot block number and the greatest common divisor, indicating the number of division slot blocks required for a single aggregation operation in the first round of clustering processing; dividing each original slot block according to the original slot block division number, and adding the divided division slot block to the set of to-be-merged slot blocks as a to-be-merged slot block; determining the affinity weight of each to-be-merged slot block and each reserved node based on the original routing information and the slot weight of each hash slot; clustering all to-be-merged slot blocks based on the division slot block aggregation number and the affinity weight of each to-be-merged slot block, to obtain an aggregated slot block; if the slot block weight of the aggregated slot block is greater than or equal to the average weight, determining the aggregated slot block as a post-shrinkage slot block, wherein the slot block weight of the aggregated slot block is the sum of the slot weights of all hash slots in the aggregated slot block; If the weight of the aggregated bucket is less than the average weight, the aggregated bucket is put back into the set of buckets to be merged, and the step of determining the affinity weight of each of the buckets to be merged and each of the reserved nodes is performed again until no aggregated bucket with a weight less than the average weight is obtained.
[0011] In an embodiment of the present application, the determining of the affinity weight of each of the buckets to be merged and each of the reserved nodes comprises: constructing an affinity matrix based on each of the buckets to be merged and each of the reserved nodes, wherein the affinity matrix is used to reflect the distribution position of each of the buckets to be merged and the respective association of each of the reserved nodes; determining a main bucket intersection vector, a main bucket weight coefficient matrix, a backup bucket intersection vector, a backup bucket weight coefficient matrix and a no intersection vector based on the affinity matrix, wherein the main bucket intersection vector is used to reflect the historical relationship between the buckets to be merged and the reserved nodes when the reserved nodes are main nodes, the backup bucket intersection vector is used to reflect the historical relationship between the buckets to be merged and the reserved nodes when the reserved nodes are backup nodes, the main bucket weight coefficient matrix is used to reflect the affinity or non-affinity between the buckets to be merged and the reserved nodes when the reserved nodes are main nodes, the backup bucket weight coefficient matrix is used to reflect the affinity or non-affinity between the buckets to be merged and the reserved nodes when the reserved nodes are backup nodes, and the no intersection vector is used to reflect the association between the buckets to be merged and the reserved nodes, wherein the no intersection vector is 0 if at least one hash bucket in the buckets to be merged is managed by the reserved nodes before the shrink, and otherwise, the no intersection vector is 1; determining the affinity weight of the buckets to be merged based on the main bucket intersection vector, the main bucket weight coefficient matrix, the backup bucket intersection vector, the backup bucket weight coefficient matrix and the no intersection vector, wherein the affinity weight is used to reflect the historical association between the buckets to be merged and the reserved nodes.
[0012] In an embodiment of the present application, the determining of the affinity weight of the buckets to be merged based on the main bucket intersection vector, the main bucket weight coefficient matrix, the backup bucket intersection vector, the backup bucket weight coefficient matrix and the no intersection vector comprises: determining a first product of the main bucket intersection vector and the main bucket weight coefficient matrix, and determining a second product of the backup bucket intersection vector and the backup bucket weight coefficient matrix; calculating a product sum of the first product and the second product, and determining a difference between the product sum and the no-intersection vector as an affinity weight of the to-be-merged slot block.
[0013] In an embodiment of the present application, optionally, the determining the scaling-down routing information of the distributed storage system according to the predetermined load balancing algorithm based on the original routing information, the slot weight of each hash slot and the target number of slot blocks further comprises: determining, through a permutation and combination algorithm and a pruning optimization mode, a set of scaling-down slot blocks that can be managed by each of the reserved nodes among all the scaling-down slot blocks; determining, based on the set of scaling-down slot blocks that can be managed by each of the reserved nodes, a primary node and a standby node of each of the scaling-down slot blocks among all the reserved nodes.
[0014] In a second aspect, the embodiments of the present application provide a computer device, comprising: at least one processor; and a memory in communication connection with the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are configured to execute the method of the first aspect.
[0015] In a third aspect, the embodiments of the present application provide a computer readable storage medium storing computer executable instructions, and the computer executable instructions are used to execute the method of the first aspect.
[0016] The above technical solution is proposed to solve the technical problem that in the related art, the static scaling-down load balancing strategy cannot adapt to dynamic business changes, thereby causing the risk of hotspot overload to be intensified after scaling down and the system performance to be deteriorated. The present application proposes a technical solution for load balancing of a distributed storage system in a scaling-down scenario. By obtaining a node scaling-down instruction and verifying a scaling-down condition, the original routing information and the finely set hash slot weight are used to calculate an optimized routing considering data locality and load balancing by using a load balancing algorithm. Finally, the generated scaling-down state metadata is used to guide data migration and routing switching. The solution can realize dynamic redistribution of data when a node is offline, ensures high availability of the system while reducing unnecessary data migration amount, effectively avoids the risk of performance bottleneck or even service avalanche caused by uneven load, and realizes smooth, efficient and stable operation of the distributed storage system in the scaling-down process. BRIEF DESCRIPTION OF DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed in the embodiments will be briefly introduced as follows. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0018] Figure 1 A flowchart is shown illustrating a method for load balancing a distributed storage system in a scaling-down scenario according to an embodiment of this application. Figure 2 A flowchart of a load balancing algorithm according to an embodiment of this application is shown; Figure 3 A schematic diagram of the scaling state machine operation according to an embodiment of this application is shown; Figure 4 A schematic diagram showing a list of scaling operations according to an embodiment of this application is provided. Figure 5 A block diagram of a computer device according to one embodiment of this application is shown; Figure 6 A block diagram of a computer device according to another embodiment of this application is shown. Detailed Implementation
[0019] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0020] Figure 1 A flowchart illustrating a method for load balancing a distributed storage system in a scaling-down scenario, according to an embodiment of this application, is shown.
[0021] like Figure 1 As shown, a method for load balancing a distributed storage system in a scaling-down scenario according to an embodiment of this application includes: Step 102: Obtain node shrinkage instruction, wherein the node shrinkage instruction is used to instruct the reduction of a second number of shrinkage nodes and the retention of a third number of reserved nodes from a first number of original nodes in the distributed storage system.
[0022] Optionally, when a node hardware failure or continuous service anomaly occurs in the distributed storage system, if the problem cannot be quickly resolved, in order to avoid affecting the overall stability of the distributed storage system, the distributed storage system can proactively issue a node scaling-down command to remove the faulty node from the cluster.
[0023] Optionally, during periods of low business activity or resource optimization, the distributed storage system can elastically shrink resources to reduce operational costs by using node shrinkage commands to reduce the number of redundant nodes.
[0024] Optionally, when performing version upgrade or hardware iteration of the distributed storage system, the old version or old model nodes need to be safely offline first, at which time the targeted capacity reduction processing for these specific old version or old model nodes is triggered.
[0025] Optionally, when it is monitored that some nodes have performance bottlenecks, or it is monitored that the resource configuration of some nodes is unreasonable, the node distribution of the distributed storage system can also be re-planned through capacity reduction to improve the overall performance of the distributed storage system.
[0026] In summary, the node capacity reduction instruction indicates the nodes to be removed from the original node cluster and the nodes to be retained, providing a clear target for subsequent data migration, so that the distributed storage system can respond to various actual operation and maintenance needs. Whether it is to handle faulty nodes, optimize resource costs, or perform system upgrade, the standardized capacity reduction process can be triggered through a unified instruction, thereby ensuring that the distributed storage system can achieve dynamic load balancing when facing different scenarios.
[0027] It should be noted that in any of the technical solutions mentioned in the context, the subject of execution can be the distributed storage system or a third-party system dedicated to managing the data storage of the distributed storage system.
[0028] Step 104, in response to the acquisition of the node capacity reduction instruction, detecting whether the current capacity reduction associated information meets a predetermined capacity reduction condition, wherein the current capacity reduction associated information includes the current state of the distributed storage system and the real-time state of the capacity reduction node.
[0029] In one possible design, the predetermined capacity reduction condition refers to that the distributed storage system is in the normal service state, and the capacity reduction node is a registered safe node and has been bound to the original routing information. Specifically, it is detected whether the distributed storage system is in the normal service state, wherein the normal service state indicates that the distributed storage system has no ongoing data migration task, and it is detected whether the capacity reduction node is a registered safe node and has been bound to the original routing information. If the distributed storage system is in the normal service state, and the capacity reduction node is a registered safe node and has been bound to the original routing information, it is determined that the current capacity reduction associated information meets the predetermined capacity reduction condition. In other words, the predetermined capacity reduction condition refers to that the distributed storage system currently has no ongoing data migration task and the nodes to be removed are all legally registered and bound in the routing information. This pre-validation step can effectively avoid performing dangerous operations when the distributed storage system is unstable or the node state is abnormal, and can establish a safe and reliable operation environment for subsequent data redistribution, avoiding the risk of service interruption due to state conflicts.
[0030] For example, two nodes are scaled down, and the legality of the scaling operation is checked, wherein the distributed storage system must be in an Init state, and other state input commands are invalid; meanwhile, the two nodes scaled down are in a registered state, and if the two nodes scaled down are not registered, the input scaling command is invalid, in addition, the two nodes scaled down have bound slot routing information, and otherwise the input scaling command is invalid.
[0031] In step 106, if the current scaling association information meets the predetermined scaling condition, the original routing information of the distributed storage system is acquired.
[0032] The original routing information includes: a standby node of each original node in the distributed storage system, an original slot managed by each original node, and a plurality of hash slots in each original slot. It can be said that the original routing information completely records the data storage distribution of the entire cluster of the distributed storage system before scaling, that is, the original routing information completely acquires the data jurisdiction range of each node as a master node and the data backup jurisdiction range of each node as a standby node, and details the distribution of the hash slots, providing an effective basis for subsequent affinity weight calculation and even new routing generation.
[0033] In step 108, according to a predetermined slot weight setting mode, a slot weight is set for each hash slot.
[0034] By setting a weight for each hash slot, the abstract load content of each hash slot can be quantified as a specific numerical value, thereby facilitating the differentiation of the importance of the data blocks in different hash slots.
[0035] In a possible design, the slot weight of each hash slot is set to 1. In this case, the slot weight of the original slot is equal to the number of hash slots managed by the original slot.
[0036] In another possible design, for each hash slot, the storage space of the hash slot is acquired, and a space ratio of the storage space to a predetermined storage unit is determined, and the slot weight of the hash slot is set to an upward integer value of the space ratio; or the storage spaces of all the hash slots are normalized, and the normalized results are discretized to a first target interval, and the first discrete results corresponding to all the hash slots are taken as the slot weights of all the hash slots, respectively, wherein the lower limit and the upper limit of the first target interval are 1 and one half of the maximum backup number of a single node, respectively.
[0037] That is, the physical storage consumption space of the hash slot can be quantified into a comparable numerical value. The physical storage consumption space of the hash slot reflects the resource occupation characteristics of data storage, can measure the actual volume size of the data managed by each hash slot on the disk, facilitate the identification of data blocks occupying a large amount of space, avoid the centralized allocation of data blocks occupying a large amount of space to the same node in the capacity reduction load balancing process, and thus prevent the node from having a storage performance bottleneck due to insufficient disk space, excessive read-write pressure, and the like, further ensuring the balanced allocation of storage resources. At the same time, the normalization processing maps the storage spaces of different scales into a unified interval for discrete representation, so as to eliminate the dimensional differences between the original data.
[0038] In still another possible design, for each hash slot, the access frequency of the hash slot is obtained, a frequency ratio of the access frequency to a predetermined frequency unit is determined, and the slot weight of the hash slot is set as an upward integer value of the frequency ratio; or the access frequencies of all the hash slots are normalized, and the result of the normalization processing is discretized to a second target interval, so that the respective second discrete results of all the hash slots are taken as the respective slot weights of all the hash slots, where the lower limit and the upper limit of the second target interval are 1 and one-half of the maximum number of node backups, respectively.
[0039] Thus, the access frequency of the hash slot can be quantified into a comparable numerical value. The access frequency of the hash slot reflects the hot spot distribution of business access, can measure the request activity level of the data served by each hash slot in unit time, facilitate the identification of high-frequency access data blocks, avoid the centralized allocation of multiple hot spot data blocks to the same node in the capacity reduction load balancing process, and thus prevent the node from having a service performance bottleneck due to the overload of computing resources or the saturation of network throughput, further ensuring the balanced processing of business requests. At the same time, the normalization processing maps the access frequencies of different magnitudes into a unified interval for discrete representation, which can eliminate the dimensional differences between the original data.
[0040] At this point, different weight setting methods can meet different capacity reduction load balancing needs, so that more targeted resource scheduling can be performed according to actual needs.
[0041] In step 110, the difference between the first number and the second number is obtained as a first capacity reduction slot block number calculation parameter, the difference between the first capacity reduction slot block number calculation parameter and 1 is obtained as a second capacity reduction slot block number calculation parameter, and the product of the first capacity reduction slot block number calculation parameter and the second capacity reduction slot block number calculation parameter is determined as the target slot block number of the distributed storage system after capacity reduction.
[0042] Thus, a clear target slot block number can be provided for the redistribution of hash slots, and a segmentation basis standard is set for subsequent data segmentation and aggregation.
[0043] In the actual scenario of scaling down 6 original nodes to 4 original nodes, that is, the scenario of 6 to 2, each original node originally manages some slot blocks. After scaling down, the target slot block number mean_size = (n - m) × (n - m - 1) is calculated by the distributed storage system, where the original node number n is 6, the scaled-down node number m is 2, the first scaled-down slot block number calculation parameter is n - m = 6 - 2 = 4, the second scaled-down slot block number calculation parameter is 3, and the mean_size is calculated to be 12, which represents the target sub-block number when the entire hash slot space [0..4096) is re-divided in the initial stage of the load balancing algorithm.
[0044] In step 112, based on the original routing information, the slot weight of each hash slot, and the target slot block number, the scaling-down routing information of the distributed storage system is determined according to a predetermined load balancing algorithm.
[0045] The predetermined load balancing algorithm is used to re-determine the routing information according to the target slot block number formed by the hash slot redistribution. The original routing information reflects the data distribution before the system is scaled down and the master-slave dependency relationship between nodes, records the current location distribution of each original slot block, the jurisdiction range of the master node, and the backup node, and constitutes a source relationship graph for data migration. The target slot block number reflects the block target of the cluster architecture after scaling down, and is derived based on the number of nodes to define the block target after scaling down the load balancing. The slot weight of the hash slot reflects the data load characteristics of the hash slot. Through the load balancing algorithm, the three are fused, and the optimal data distribution scheme that meets the load balancing requirements between nodes, fully considers the data locality characteristics, and also meets the cluster size constraint after scaling down can be calculated.
[0046] In step 114, the scaling-down state metadata is determined based on the original routing information and the scaling-down routing information, where the scaling-down state metadata is used to reflect the hash slot distribution in each reserved node and the scaling-down action information of each original node.
[0047] The scaling-down state metadata is generated by comparing the new and old routing information, and specifically describes the slot distribution change of each node and the operation instructions to be executed. These metadata convert the abstract load balancing scheme into an executable action blueprint, and provide a clear operation guide for subsequent data migration and routing switching.
[0048] In step 116, the hash slots managed by all the original nodes are re-allocated to the reserved nodes according to the scaling-down state metadata.
[0049] The hash slots are re-allocated to the reserved nodes according to the guidance of the metadata, and the final conversion from calculation to execution is completed. This step converts the theoretical balancing scheme into the actual system state through ordered data migration and routing update, and finally realizes the load balancing and stable operation of the cluster after scaling down.
[0050] In summary, the present application proposes a technical solution for load balancing of a distributed storage system in a scaling-down scenario. By obtaining a node scaling-down instruction and verifying the scaling-down conditions, based on the original routing information and the fine-grained hash slot weight, the load balancing algorithm is used to calculate the optimized routing considering data locality and load balancing. Finally, data migration and routing switching are realized according to the generated scaling-down state metadata. This solution can realize dynamic redistribution of data when nodes are offline, ensure high availability of the system while reducing unnecessary data migration, effectively avoid performance bottlenecks and even service avalanche risks caused by uneven load, and realize smooth, efficient and stable operation of the distributed storage system during scaling-down.
[0051] Figure 2 A flowchart of the load balancing algorithm in step 112 is shown. As shown in Figure 2 The load balancing algorithm includes: Step 202, based on the slot weight of each hash slot and the target slot block number, the average weight and the remainder of the target slot block number are calculated.
[0052] By calculating the average weight and the remainder of the target slot block number, a clear quantitative benchmark is provided for subsequent slot block aggregation. This step converts the abstract load balancing target into a specific numerical index, so that the data fragmentation process can be carried out around a clear standard, thereby ensuring that the final generated slot block is as close as possible to the ideal state in terms of load.
[0053] The average weight of the target slot block number is gather_size = ∑slot_weight / mean_size, that is, the quotient of the weight sum of all slot blocks and the target slot block number.
[0054] The remainder is remainder = ∑slot_weight-gather_size×mean_size.
[0055] In the 6-to-2 scenario, if the slot weight of each hash slot is 1, the total weight ∑slot_weight = 4096, the target slot block number mean_size is 12, gather_size = 4096 / 12 = 341, and remainder = 4096-341×12 = 4.
[0056] That is, in an ideal shrinkage result, each of the 12 target slots should carry 341 weight units, i.e., 341 hash slots.
[0057] In a possible design, since the total weight 4096 cannot be divided by 12, there will be 4 weight units left, which will be allocated to some slots in subsequent processing, forming 4 slots with a weight of 342 and 8 slots with a weight of 341, so as to complete the accurate load allocation.
[0058] In step 204, the number of original slot divisions and the number of aggregated divided slots are determined based on the number of original slots and the number of target slots.
[0059] The number of divisions and the number of aggregations are determined based on the greatest common divisor of the number of original slots and the number of target slots, which sets a scientific division granularity for data reorganization. This calculation method ensures that the original data blocks can be reasonably divided into appropriate number of sub-blocks, and at the same time provides a reasonable aggregation unit size for subsequent clustering operations, so that the entire data reorganization process has mathematical rigor and operability.
[0060] In the method, the greatest common divisor of the number of original slots and the number of target slots is determined, the number of original slot divisions is the quotient of the number of target slots and the greatest common divisor, indicating the number of divided slots into which each original slot needs to be divided, and the number of aggregated divided slots is the quotient of the number of original slots and the greatest common divisor, indicating the number of divided slots required for a single aggregation operation in the first round of clustering processing.
[0061] In the 6 shrink 2 scenario, the number of original slots old_block_number is 30, and the number of target slots mean_size is 12. First, the greatest common divisor gcd(30, 12) = 6 is calculated, and then the number of original slot divisions denominator = mean_size / gcd(30, 12) = 12 / 6 = 2 is calculated, indicating that each original slot needs to be divided into 2 divided slots. Next, the number of aggregated divided slots numerator = old_block_number / gcd(30, 12) = 30 / 6 = 5 is calculated, indicating that in the first round of clustering processing, a single aggregation operation needs to aggregate 5 divided slots. Through this calculation method, the basic requirement of data reorganization is ensured.
[0062] In a possible design, the original 30 slots are divided into 30x2 = 60 divided slots, and in the first round of clustering, every 5 divided slots are aggregated into a new slot, finally forming 60÷5 = 12 target slots, which is completely consistent with the preset mean_size. This division and aggregation strategy based on the greatest common divisor ensures the balance degree of slot allocation in the data reorganization process.
[0063] The old slot set is evenly divided by denominator for each block, and the divided slot block set is put into the to-be-merged slot block set. In the 6 / 2 scenario, for slots{[0..127]}, the division is performed according to denominator=2 to obtain slots{[0..69), [69..137]}, and finally 60 divided slot block sets are obtained.
[0064] In step 206, each of the original slot blocks is divided according to the original slot block division number, and the divided divided slot block is added to the to-be-merged slot block set as a to-be-merged slot block.
[0065] The original slot block is subdivided into smaller to-be-merged units according to the division number, which creates conditions for subsequent flexible reorganization. By decomposing large blocks of data into finer-grained components, the system can obtain more permutation and combination possibilities when reassigning, thereby providing a basis for finding the optimal load balancing solution.
[0066] In step 208, based on the original routing information and the slot weight of each hash slot, the affinity weight of each to-be-merged slot block and each reserved node is determined.
[0067] By constructing an affinity matrix and calculating a multi-dimensional intersection vector, the historical association degree between each to-be-merged slot block and the reserved node is accurately quantified. This comprehensive weight calculation method considering the master-slave relationship can accurately identify the migration path with the optimal data locality, thereby minimizing the actual data migration amount while ensuring load balancing, significantly improving the downsizing efficiency.
[0068] Specifically, the method for calculating the affinity weight includes: based on each of the to-be-merged slot blocks and each of the reserved nodes, an affinity matrix is constructed, wherein the affinity matrix is used to reflect the distribution position of each of the to-be-merged slot blocks and the respective association relationship of the plurality of reserved nodes; based on the affinity matrix, a master slot intersection vector, a master slot weight coefficient matrix, a backup slot intersection vector, a backup slot weight coefficient matrix, and a no intersection vector of the to-be-merged slot block are determined; based on the master slot intersection vector, the master slot weight coefficient matrix, the backup slot intersection vector, the backup slot weight coefficient matrix, and the no intersection vector, the affinity weight of the to-be-merged slot block is determined, wherein the affinity weight is used to reflect the historical association between the to-be-merged slot block and the reserved node.
[0069] The main slot intersection vector is used to reflect the historical relationship between the to-be-merged slot block and the reserved node when the reserved node is a main node, the backup slot intersection vector is used to reflect the historical relationship between the to-be-merged slot block and the reserved node when the reserved node is a backup node, the main slot weight coefficient matrix is used to reflect the close or distant relationship between the to-be-merged slot block and the reserved node when the reserved node is a main node, the backup slot weight coefficient matrix is used to reflect the close or distant relationship between the to-be-merged slot block and the reserved node when the reserved node is a backup node, and the no-intersection vector is used to reflect the relevance between the to-be-merged slot block and the reserved node, wherein the no-intersection vector is 0 if at least one hash slot in the to-be-merged slot block is managed by the reserved node before the capacity reduction, otherwise, the no-intersection vector is 1.
[0070] The step of determining the affinity weight of the to-be-merged slot block based on the main slot intersection vector, the main slot weight coefficient matrix, the backup slot intersection vector, the backup slot weight coefficient matrix and the no-intersection vector comprises: determining a first product of the main slot intersection vector and the main slot weight coefficient matrix, and determining a second product of the backup slot intersection vector and the backup slot weight coefficient matrix; calculating a product sum of the first product and the second product, and determining a difference value between the product sum and the no-intersection vector as the affinity weight of the to-be-merged slot block.
[0071] In step 210, the to-be-merged slot block set is clustered based on the split slot block aggregation number and the affinity weight of each to-be-merged slot block, to obtain an aggregated slot block.
[0072] The to-be-merged slot blocks are clustered based on the aggregation number and the affinity weight, and the data blocks with similar characteristics and relevance are intelligently grouped. This clustering method not only considers the size weight of the data block, but also fully respects the existing data distribution relationship, so that the generated new slot block not only meets the load requirement but also maintains reasonable data locality.
[0073] In step 212, if the slot block weight of the aggregated slot block is greater than or equal to the average weight, the aggregated slot block is determined as a post-capacity-reduction slot block.
[0074] The slot block weight of the aggregated slot block is the sum of the slot weights of all hash slots in the aggregated slot block. By judging whether the aggregated slot block weight meets the requirement, the final state of the aggregated slot block is determined, so that each generated new slot block meets the basic load requirement. This quality control step prevents small or unbalanced slot blocks from entering the final allocation scheme, thereby guaranteeing the overall load balancing effect from the source.
[0075] Step 214, if the slot weight of the aggregated slot is less than the average weight, the aggregated slot is put back into the set of to-be-merged slots, and the step of determining the affinity weight of each to-be-merged slot and each reserved node is returned for another round of clustering processing until there is no aggregated slot with a slot weight less than the average weight in the clustering result.
[0076] The under-performing aggregated slots are put back into the set of to-be-processed slots for clustering again, forming an effective quality feedback mechanism. This iterative processing method can continuously optimize the grouping result, ensuring that all generated slots eventually meet the load standard, thereby realizing continuous improvement of the overall balanced effect.
[0077] For the set of segmented slots, clustering is performed according to the affinity weight of the nodes reserved after downsizing. For the clustering result with an average weight reaching the target slot number, it can be renumbered as a slot after downsizing. The clustering result with an average weight not reaching the target slot number is put into the to-be-aggregated list, and the clustering operation based on the affinity weight is performed again to finally obtain the set of aggregated new slots.
[0078] In the 6-to-2 scenario, after removing node1 and node3, the following results are obtained: node2: [5, 18, 26, 30, 2, 29, 3, 13, 17, 23], node4: [4, 5, 9, 27, 14, 19, 25, 21, 6, 13], node5: [9, 16, 22, 26, 27, 19, 8, 12, 6, 17], node6: [4, 10, 18, 11, 2, 20, 29, 7, 15, 24]].
[0079] The 12 downsized slots after aggregation are as follows: SlotSetRebalance:1, size:342slots:{[69..137, 479..616, 1846..1983]}; SlotSetRebalance:2, size:342slots:{[1368..1505, 2050..2118, 3210..3347]}; SlotSetRebalance:3, size:341slots:{[2186..2322, 2732..2801, 3891..4027]}; SlotSetRebalance:4, size:341 slots:{[2527..2663, 2663..2731, 3073..3142, 4027..4095]} ; SlotSetRebalance:5, size:341 slots:{[958..1026, 1300..1368, 1778..1846, 2869..3006]} ; SlotSetRebalance:6, size:342 slots:{[137..274, 1505..1642, 3142..3210]} ; SlotSetRebalance:7, size:342 slots:{[684..821, 821..958, 2801..2869]} ; SlotSetRebalance:8, size:341 slots:{[411..479, 1709..1778, 2322..2390, 3006..3072, 3618..3686][2049, 2731]} ; SlotSetRebalance:9, size:341 slots:{[1163..1300, 3414..3550, 3550..3618]} ; SlotSetRebalance:10, size:342 slots:{[342..411, 1026..1163, 3347..3413, 3686..3754][3072, 4095]} ; SlotSetRebalance:11, size:341 slots:{[0..69, 274..342, 616..684, 2391..2527]} ; SlotSetRebalance:12, size:340 slots:{[1642..1709, 1983..2049, 2118..2186, 3755..3891][2390, 3413, 3754]}.
[0080] In step 216, the set of the shrinked slot blocks that each of the reserved nodes can manage is determined from all the shrinked slot blocks by using the permutation and combination algorithm and the pruning optimization method.
[0081] The permutation and combination algorithm is used to determine the management slot block set of each node in combination with pruning optimization, and the optimal solution is quickly found from numerous possible allocation schemes. This method not only guarantees the global optimality of the allocation scheme, but also avoids the combination explosion problem through the pruning strategy, achieving a good balance between efficiency and effectiveness.
[0082] In step 218, based on the set of slot blocks capable of being managed by each of the reserved nodes after the capacity reduction, the primary node and the standby node of each of the slot blocks after the capacity reduction in all the reserved nodes are determined.
[0083] Based on the determined slot block set, appropriate primary nodes and standby nodes are allocated to each slot block after the capacity reduction, and the final decision of data routing is completed. This step ensures that the new data distribution scheme has complete fault tolerance capability and access path, and provides a reliable data architecture foundation for the stable operation of the system.
[0084] At this point, the primary slot routing of each node is determined, and the remaining is the standby slot routing. After obtaining the set of slot blocks belonging to each node by the improved permutation and combination algorithm, the primary slot block responsible by each node is further selected. The permutation and combination algorithm has poor performance due to the need to exhaust all combination cases, and the candidate set can be pruned in advance by restricting the blocks already selected by other nodes from being selected again, and setting the maximum number of attempts to ensure performance.
[0085] In the 6x2 scenario, the primary node is selected for each node's candidate set to obtain the primary slot routing result. Since the result nodes 2 and 4 are not balanced, the post-processing algorithm adjusts the slot block number 12 from node 2 to node 4.
[0086] candidate: [1, 2, 4, 5, 6, 7, 8, 11, 12]; candidate: [1, 2, 3, 4, 6, 8, 9, 10, 11, 12]; candidate: [1, 3, 5, 7, 8, 9, 10, 11, 12]; candidate: [2, 3, 4, 5, 6, 7, 9, 10]; belong_node: 1 size: 3 [1, 5, 8]; belong_node: 2 size: 3 [2, 6, 11]; belong_node: 3 size: 3 [3, 7, 12]; belong_node: 4 size: 3 [4, 9, 10]; rebalance_block: 12 node: 2->4; Finally, the slot routing data of the new and old nodes are compared to generate the metadata of the shrink state, and then the distributed storage system enters the shrink state. The metadata of the shrink state includes the slot routing data used to record how the slot set is divided after shrinkage, the expansion action list data of each node that is not shrunk, and the action list data of the shrunk node.
[0087] In the 6 shrink 2 scenario, the slot set routing metadata is as follows: routers: [Router{id:1weight:342slots:{[69..137,479..616,1846..1983]}node:1backups:{2,3}}, Router{id:2weight:342slots:{[1368..1505,2050..2118,3210..3347]}node:2backups:{1,4}}, Router{id:3weight:341slots:{[2186..2322,2732..2801,3891..4027]}node:3backups:{2,4}}, Router{id:4weight:341slots:{[2527..2663,2663..2731,3073..3142,4027..4095]}node:4backups:{1,2}}, Router{id:5weight:341slots:{[958..1026,1300..1368,1778..1846,2869..3006]}node:1backups:{3,4}}, Router{id:6weight:342slots:{[137..274,1505..1642,3142..3210]}node:2backups:{1,4}}, Router{id:7weight:342slots:{[684..821,821..958,2801..2869]}node:3backups:{1,4}}, Router{id:8weight:341slots:{[411..479,1709..1778,2322..2390,3006..3072,3618..3686][2049,2731]}node:1backups:{2,3}}, Router {id: 9 weight: 341 slots: {[1163..1300, 3414..3550, 3550..3618]} node: 4 backups: {2, 3}}, Router {id: 10 weight: 342 slots: {[342..411, 1026..1163, 3347..3413, 3686..3754] [3072, 4095]} node: 4 backups: {2, 3}}, Router {id: 11 weight: 341 slots: {[0..69, 274..342, 616..684, 2391..2527]} node: 2 backups: {1, 3}}, Router {id: 12 weight: 340 slots: {[1642..1709, 1983..2049, 2118..2186, 3755..3891] [2390, 3413, 3754]} node: 3 backups: {1, 4}}.
[0088] In addition, under this 6 shrink 2 scenario, the action list information each node needs is as follows: node: 2 old_slots: {[0..342, 479..684, 958..1026, 1300..2050, 2390..2663, 2731..3073, 3347..3414] [3754, 4095]} -> new_slots: {[0..342, 411..1026, 1300..2186, 2322..2732, 2801..3072, 3073..3347, 3618..3686, 3754..3891, 4027..4095]
[3413] }, needexpand: 1160 {[411..479, 684..958, 2050..2186, 2322..2390, 2663..2731, 3073..3347, 3618..3686, 3755..3891, 4027..4095]}, needshrink: 137 {[2732..2801, 3347..3413] [3072, 4095]}, node:4 old_slots:{[137..684,1368..1505,1642..2049,2050..2391,3073..3347,3413..3550,3686..3891]} -> new_slots:{[0..684,1026..1300,1368..1642,1709..1778,1846..1983,2049..2118,2186..2390,2391..2801,3006..3413,3414..3754,3891..4096]}, needexpand:1433{[0..137,1026..1300,1505..1642,2391..2801,3006..3073,3347..3413,3550..3686,3891..4096]
[2049] }, needshrink:408{[1642..1709,1778..1846,1983..2049,2118..2186,3754..3891][2390,3413]}, node:5 old_slots:{[684..1026,1163..1368,1505..1642,1846..1983,2050..2390,2732..2869,3073..3210,3414..3754,3755..4027]} -> new_slots:{[0..137,274..1368,1642..2050,2118..2527,2731..3073,3347..4027]
[4095] }, needexpand:1366{[0..137,274..684,1026..1163,1642..1846,1983..2050,2390..2527,2869..3073,3347..3414][2731,3754,4095]}, needshrink:342{[1505..1642,2050..2118,3073..3210]}, node:6 old_slots: {[137..274, 342..479, 684..958, 1026..1163, 1368..1709, 1983..2049, 2390..2731, 2869..3006, 3073..3347, 3891..4095][3413, 3754]} -> new_slots: {[137..274, 342..411, 684..1709, 1778..1846, 1983..2049, 2050..2322, 2527..2731, 2732..3006, 3072..3618, 3686..4096]
[2390] }, needexpand: 1226 {[958..1026, 1163..1368, 1778..1846, 2050..2322, 2732..2869, 3347..3413, 3414..3618, 3686..3754, 3755..3891][3072, 4095]}, needshrink: 204 {[411..479, 2391..2527]}.
[0089] In the 6 shrink 2 scenario, the list of actions needed by the shrinking node is as follows: node: 1 old_slots: {[0..137, 274..479, 616..821, 958..1368, 2391..2732, 3006..3073, 3210..3413, 3550..3686, 3755..4096]
[2049] } -> new_slots: {[]}, needshrink: 2046 {[0..137, 274..479, 616..821, 958..1368, 2391..2732, 3006..3073, 3210..3413, 3550..3686, 3755..4096]
[2049] }, node: 3 old_slots: {[0..137, 479..616, 821..958, 1026..1300, 1709..1846, 2049..2390, 2663..3073, 3347..3413, 3414..3754, 4027..4096]} -> new_slots: {[]}, needshrink: 2048{[0..137, 479..616, 821..958, 1026..1300, 1709..1846, 2049..2390, 2663..3073, 3347..3413, 3414..3754, 4027..4096]}.
[0090] Finally, the broadcast informs the full route change, interacts with the storage nodes involved, drives the action state switching of each node, and until the whole shrink action is completed. The current shrink action of each node must be completed before switching to the next expansion action. No confirmation reply is required when notifying the shrinked node, because the shrinked node may be unable to repair due to failure.
[0091] After all nodes successfully execute the shrink action, the system enters the Init state, at this time, the system can accept the expansion or shrink command again.
[0092] In addition, in the actual scenario of the present application, the case of main slot failure requiring dynamic load balancing may also occur. The main slot failure load balancing mechanism is triggered after the storage node is offline, and the control service uses the slot information reported by each storage node to select the main node route of the hash slot according to the load balancing algorithm and update the associated routing information, and notifies all storage nodes through the broadcast mechanism to restore the system to be available. The specific process is as follows: Step 1, each storage node independently reports its own slot information, the specific format is {slot, seq, space, freq} tuple set. Wherein seq represents the latest sequence number of slot slot storage data, which has the properties of self-increment and uniqueness. Space represents the occupied storage space, and freq represents the access frequency.
[0093] Step 2, the control service center records the latest reported slot information of each node in slot slot granularity. The subsequent load balancing algorithm will use this part of data information.
[0094] Step 3, the heartbeat system senses the fault of a node after the heartbeat timeout and notifies the fault node information to drive the control system to perform fault load balancing processing.
[0095] Step 4, calculate the candidate position of the main slot responsible for by the fault node, the candidate position refers to the backup node corresponding to each slot; and filter out the candidate slot position with the latest sequence number value according to the sequence number value in the reported slot information. At this time, the candidate position list corresponding to the main slot set borne by the fault node is obtained. Taking a 4-node system as an example: BlockRouter::Init{clients:[70002, 70005, 70008, 70011], blocks:[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]}.
[0096] Single fault 70002 node corresponding to the number 1 candidate list is: [Candidate {id: 1 slots: {[0..342]} backups: {2, 4}}, Candidate {id: 2 slots: {[1368..1709]} backups: {2, 3}}, Candidate {id: 3 slots: {[2732..3073]} backups: {3, 4}}].
[0097] Simultaneous fault 70002, 70008 node corresponding to the number 1, 3, then the candidate list is: [Candidate {id: 1 slots: {[0..342]} backups: {2, 4}}, Candidate {id: 2 slots: {[1368..1709]} backups: {2}}, Candidate {id: 3 slots: {[2732..3073]} backups: {4}}, Candidate {id: 7 slots: {[684..1026]} backups: {4}}, Candidate {id: 8 slots: {[2050..2391]} backups: {2}}, Candidate {id: 9 slots: {[3414..3755]} backups: {2, 4}}].
[0098] Step 5, the load balancing algorithm selects the unique candidate position corresponding to the main slot of the fault node according to the candidate list, and if it cannot be selected, it is considered that the slot routing is faulty. The fault load balancing algorithm selection diagram, first select the slot with only one candidate position, refresh the weight of the candidate position, then preferentially select the position with the smallest weight and refresh the weight, until all slots are selected. Candidate position.
[0099] Single fault 70002 node after reselection corresponding to the routing situation is as follows: BlockRouter::Init{clients: [70002, 70005, 70008, 70011], blocks: [[], [1, 4, 5, 6], [2, 7, 8, 9], [3, 10, 11, 12]]}.
[0100] Corresponding routing situation of re-election of 70002, 70008 after simultaneous failure: BlockRouter::Init{clients: [70002, 70005, 70008, 70011], blocks: [[], [1, 2, 4, 5, 6, 8], [], [3, 7, 9, 10, 11, 12]]}.
[0101] Step 5, update slot routing, calculate the master position and backup position of the changed slot, and broadcast the incremental routing change.
[0102] After the single failure of 70002 node, the notification information is as follows: UpdataEvent: [slots: {[0..342]} node: 70005 backups: {70002, 70011}, slots: {[0..342]} node: 70005 backups: {70002, 70011}, slots: {[1368..1709]} node: 70008 backups: {70002, 70005}, slots: {[2732..3073]} node: 70011 backups: {70002, 70008}].
[0103] The above, the application proposes a dynamic load balancing mechanism for master slot failure, by collecting node slot state information in real time, and automatically triggering the rebalancing process when the heartbeat system detects node failure. Therefore, based on the backup node candidate list and the serial number filtering mechanism, the load balancing algorithm is used to re-elect the master node for the failed master slot and update the routing information, and finally the incremental broadcast is used to realize the rapid switching of the routing. This technical scheme can automatically, quickly and accurately restore data availability and service continuity when node failure occurs, effectively avoids the data unavailability and service interruption problem of the distributed storage system caused by single point or multiple point failure, and improves the fault tolerance and overall reliability of the distributed storage system.
[0104] Figure 3 A scaling state machine working schematic diagram according to an embodiment of the application is shown.
[0105] As Figure 3As shown, the trigger condition of the empty state to the initial state is the Init (initialization) command. When the distributed storage system is in the empty state, after receiving the Init command, it enters the initial state. This is the state transition process of starting or initializing the distributed storage system, indicating that the system starts to enter the initial preparation state of performing operations such as capacity expansion and capacity reduction.
[0106] The trigger condition of the initial state to the capacity expansion state is the capacity expansion command. When the distributed storage system is in the initial state, after receiving the capacity expansion command, it enters the capacity expansion state. At this time, the distributed storage system will perform related operations of resource expansion, such as adding server nodes.
[0107] The trigger condition of the capacity expansion state to the initial state is capacity expansion success. When the distributed storage system completes the capacity expansion operation in the capacity expansion state and the capacity expansion is successful, it returns to the initial state, which indicates that the capacity expansion operation is completed, and the distributed storage system returns to the initial state that can receive new commands.
[0108] The trigger condition of the initial state to the capacity reduction state is the capacity reduction command. After receiving the capacity reduction command in the initial state, the distributed storage system enters the capacity reduction state and starts to perform resource reduction operations, such as reducing server nodes.
[0109] The trigger condition of the capacity reduction state to the initial state is capacity reduction success. When the distributed storage system completes the capacity reduction operation in the capacity reduction state and the capacity reduction is successful, it returns to the initial state, which indicates that the capacity reduction operation is completed, and the distributed storage system again enters the initial state that can receive new commands.
[0110] Figure 4 A capacity expansion and reduction action list diagram is shown according to an embodiment of the present application.
[0111] As shown, Figure 4 Node to capacity expansion slot refers to that the node enters the capacity expansion slot stage. This stage is related to resource expansion processing of the node and prepares for subsequent operations, which is the first step of state transition in the resource adjustment process. Capacity expansion slot to capacity reduction slot refers to that from the capacity expansion slot to the capacity reduction slot, which means that after completing the capacity expansion operation, the capacity reduction operation stage can be entered, and the node resource is processed for capacity reduction, which is an intermediate link in the resource adjustment process. Capacity reduction slot to master upgrade slot refers to that from the capacity reduction slot to the master upgrade slot, which indicates that after the capacity reduction operation is completed, the related operation of node master upgrade is performed, which indicates the adjustment of the node master and slave roles, and is a key step of the node state to serviceable. Master upgrade slot to ready refers to that from the master upgrade slot to the ready state, which indicates that the node has completed the master upgrade operation and reaches a state that can normally provide services, which is the final stage of the entire process, and the node can participate in business processing at this time.
[0112] In the above, in the state machine, the distributed storage system is from the empty state to the initial state by the Init command, and then enters the corresponding state according to the expansion and contraction commands, and returns to the initial state after the operation is successful. In the action list of the node, the node can experience three stages of expansion slot, contraction slot and master slot, and finally enters the ready state to provide services.
[0113] In addition, in an embodiment, the present application provides a computer device which can be a server, and an internal structure diagram of the computer device can be as shown in Figure 5 The computer device includes a processor, a memory, a network interface and a database connected through a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium, an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client through a network connection. The computer program is executed by the processor to implement the method described in any of the above embodiments.
[0114] In an embodiment, the present application also provides a computer device which can be a client, and an internal structure diagram of the computer device can be as shown in Figure 6 The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. The computer program is executed by the processor to implement the method described in any of the above embodiments.
[0115] Any computer device described in the above embodiments of the present application exists in various forms, including but not limited to: (1) Mobile communication device: This type of device is characterized by having mobile communication function and providing voice and data communication as the main target. This type of terminal includes smart phones, multimedia phones, functional phones, and low-end phones.
[0116] (2) Ultra-mobile personal computer device: This type of device belongs to the category of personal computers and has computing and processing functions, and generally also has the characteristics of mobile Internet. This type of terminal includes PDA, MID and UMPC devices.
[0117] (3) Portable entertainment device: This kind of device can display and play multimedia content. This kind of device includes: audio, video player, palm game machine, electronic book, and smart toy, wearable device and portable car navigation device.
[0118] (4) Server: A device that provides computing services, the composition of the server includes processor, hard disk, memory, system bus, etc. The server and the general computer architecture are similar, but because it needs to provide high-reliable services, it has higher requirements in processing capacity, stability, reliability, security, scalability, manageability, etc.
[0119] (5) Other electronic devices with data interaction function.
[0120] In addition, the embodiment of the application provides a computer readable storage medium, which stores computer executable instructions, and the computer executable instructions are used for executing the following steps: Obtaining a node capacity reduction instruction, wherein the node capacity reduction instruction is used to indicate that a second number of capacity reduction nodes is reduced from a first number of original nodes in a distributed storage system, and a third number of reserved nodes is reserved; In response to the acquisition of the node capacity reduction instruction, it is detected whether the current capacity reduction association information meets a predetermined capacity reduction condition, wherein the current capacity reduction association information includes the current state of the distributed storage system and the real-time state of the capacity reduction node; If the current capacity reduction association information meets the predetermined capacity reduction condition, the original routing information of the distributed storage system is obtained, wherein the original routing information includes: the standby node of each original node in the distributed storage system, the original slot block managed by each original node and a plurality of hash slots in each original slot block; According to a predetermined slot weight setting mode, a slot weight is set for each hash slot; The difference between the first number and the second number is obtained as a first capacity reduction slot block number calculation parameter, and the difference between the first capacity reduction slot block number calculation parameter and 1 is obtained as a second capacity reduction slot block number calculation parameter, and the product of the first capacity reduction slot block number calculation parameter and the second capacity reduction slot block number calculation parameter is determined as the target slot block number of the distributed storage system after capacity reduction; Based on the original routing information, the slot weight of each hash slot and the target slot block number, the capacity reduction routing information of the distributed storage system is determined according to a predetermined load balancing algorithm; Based on the original routing information and the capacity reduction routing information, capacity reduction state metadata is determined, wherein the capacity reduction state metadata is used to reflect the hash slot distribution in each reserved node and the capacity reduction action information of each original node; According to the shrinkage state metadata, all the original node managed hash slots are re-allocated to each of the reserved nodes.
[0121] It should be noted that the functions or steps described above with respect to the computer readable storage medium or the computer device can correspond to the related description in the foregoing method embodiments, and to avoid repetition, they will not be described one by one here.
[0122] The technical solution of the present application is described in detail above in combination with the drawings. The technical solution of the present application, by acquiring a node shrinkage instruction and verifying a shrinkage condition, based on original routing information and fine set hash slot weights, using a load balancing algorithm to calculate an optimized route considering data locality and load balancing, and finally guiding data migration and route switching according to generated shrinkage state metadata, the scheme can realize dynamic redistribution of data when a node is offline, while ensuring high availability of the system and reducing unnecessary data migration, effectively avoiding the risk of performance bottleneck or even service avalanche caused by uneven load, and realizing smooth, efficient and stable operation of the distributed storage system during the shrinkage process.
[0123] It should be understood that although the terms first, second, etc. can be used in the embodiments of the present application to describe quantities, these quantities should not be limited to these terms. These terms are only used to distinguish one quantity from another. For example, the first quantity can also be referred to as the second quantity without departing from the scope of the embodiments of the present application, and similarly, the second quantity can also be referred to as the first quantity.
[0124] Depending on the context, the word "if" as used herein can be interpreted as meaning "when" or "while" or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if it is determined" or "if (a stated condition or event) is detected" can be interpreted as meaning "when it is determined" or "in response to determining" or "when (a stated condition or event) is detected" or "in response to detecting (a stated condition or event)".
[0125] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise.
[0126] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented by other manners. For example, the above-described device embodiments are merely illustrative, for example, the division of the units is merely a logical function division, and in actual implementation, another division manner can be adopted, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0127] In addition, each functional unit in each embodiment of the present application can be integrated into one processing unit, or each unit can be physically present separately, or two or more units can be integrated into one unit. The integrated unit can be realized in the form of hardware or in the form of hardware plus software functional unit.
[0128] A person of ordinary skill in the art can understand that all or part of the processes in the above-described embodiments can be completed by a computer program instructing related hardware, and the computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-described embodiments. In each embodiment provided in the present application, any reference to memory, storage, database or other medium can include non-volatile and / or volatile memory. The non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. The volatile memory can include random access memory (RAM) or external cache memory. As an illustration but not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM) and memory bus dynamic RAM (RDRAM).
[0129] The above-described embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit the present application; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.
Claims
1. A method for load balancing a distributed storage system in a scaling-down scenario, characterized in that, include: Obtain a node shrinkage instruction, wherein the node shrinkage instruction is used to instruct a second number of shrinkage nodes to be reduced from a first number of original nodes in the distributed storage system, and a third number of reserved nodes to be retained. In response to the acquisition of the node scaling down instruction, it is detected whether the current scaling down association information meets the predetermined scaling down conditions, wherein the current scaling down association information includes the current state of the distributed storage system and the real-time state of the scaling down node. If the current scaling-down association information meets the predetermined scaling-down condition, the original routing information of the distributed storage system is obtained, wherein the original routing information includes: the backup node of each original node in the distributed storage system, the original slot block managed by each original node, and multiple hash slots in each original slot block; According to the predetermined slot weight setting method, set the slot weight for each hash slot; The difference between the first quantity and the second quantity is obtained as a first reduction slot number calculation parameter, and the difference between the first reduction slot number calculation parameter and 1 is obtained as a second reduction slot number calculation parameter. The product of the first reduction slot number calculation parameter and the second reduction slot number calculation parameter is determined as the target number of slots after the distributed storage system is reduced in size. Based on the original routing information, the slot weight of each hash slot, and the target number of slot blocks, the scaling-down routing information of the distributed storage system is determined according to a predetermined load balancing algorithm. Based on the original routing information and the scaling-down routing information, scaling-down state metadata is determined, wherein the scaling-down state metadata is used to reflect the hash slot distribution in each of the reserved nodes and the scaling-down action information of each of the original nodes; According to the reduced-scale metadata, all hash slots managed by the original nodes are redistributed to the reserved nodes.
2. The method according to claim 1, characterized in that, The step of detecting whether the current scaling-down association information meets the predetermined scaling-down conditions includes: The system detects whether the distributed storage system is in a normal service state, wherein the normal service state indicates that the distributed storage system has no ongoing data migration tasks, and... Check whether the scaled-down node is a registered secure node and has been bound to the original routing information. If the distributed storage system is in the normal service state, and the scaling-down node is a registered secure node and has been bound to the original routing information, then the current scaling-down association information is determined to meet the predetermined scaling-down conditions.
3. The method according to claim 1, characterized in that, The step of setting a slot weight for each hash slot according to a predetermined slot weight setting method includes: Set the slot weight of each hash slot to 1; or, For each hash slot, obtain the storage space of the hash slot, determine the space ratio of the storage space to a predetermined storage unit, and set the slot weight of the hash slot to the rounded-up value of the space ratio; or normalize the storage space of all hash slots, and discretize the result of the normalization process to a first target interval, using the first discrete result corresponding to each of the hash slots as the slot weight of each of the hash slots, wherein the lower limit and upper limit of the first target interval are 1 and half of the maximum number of backups per node, respectively.
4. The method according to claim 1, characterized in that, The step of setting a slot weight for each hash slot according to a predetermined slot weight setting method includes: For each hash slot, obtain the access frequency of the hash slot; Determine the frequency ratio of the accessed frequency to a predetermined frequency unit, and set the slot weight of the hash slot to the rounded-up value of the frequency ratio; or, The access frequency of all hash slots is normalized, and the result of the normalization is discretized into a second target interval. The second discrete result corresponding to each of the hash slots is used as the slot weight of each of the hash slots. The lower limit and upper limit of the second target interval are 1 and half of the maximum number of backups per node, respectively.
5. The method according to claim 1, characterized in that, The step of determining the scaling-down routing information of the distributed storage system based on the original routing information, the slot weight of each hash slot, and the target number of slot blocks, according to a predetermined load balancing algorithm, includes: Based on the slot weight of each hash slot and the target number of slot blocks, calculate the average weight and remainder of the target number of slot blocks; Based on the original number of slots and the target number of slots of all the original nodes, the number of original slot splits and the number of split slot aggregations are determined. The greatest common divisor of the original number of slots and the target number of slots is determined. The original slot split number is the quotient of the target number of slots and the greatest common divisor, representing the number of split slots that each original slot needs to be split into. The number of split slot aggregations is the quotient of the original number of slots and the greatest common divisor, representing the number of split slots required for a single aggregation operation in the first round of clustering. According to the original number of slots, each original slot is divided, and the divided slots are added to the set of slots to be merged as slots to be merged. Based on the original routing information and the slot weight of each hash slot, the affinity weight between each slot block to be merged and each retained node is determined; Based on the number of aggregated slots and the affinity weight of each slot to be merged, the entire set of slots to be merged is clustered to obtain aggregated slots. If the slot weight of the aggregated slot is greater than or equal to the average weight, the aggregated slot is determined to be a scaled-down slot, wherein the slot weight of the aggregated slot is the sum of the slot weights of all hash slots in the aggregated slot; If the weight of the aggregated slot is less than the average weight, the aggregated slot is put back into the set of slots to be merged, and the step of determining the affinity weight between each slot to be merged and each retained node is returned to perform another round of clustering processing until there are no aggregated slots with a weight less than the average weight in the clustering results.
6. The method according to claim 5, characterized in that, The determination of the affinity weight between each of the slot blocks to be merged and each of the retained nodes includes: Based on each of the slot blocks to be merged and each of the retained nodes, an affinity matrix is constructed, wherein the affinity matrix is used to reflect the distribution location of each of the slot blocks to be merged and the respective association relationships of the multiple retained nodes; Based on the affinity matrix, the main slot intersection vector, main slot weight coefficient matrix, spare slot intersection vector, spare slot weight coefficient matrix, and vector with no intersection are determined for the slot blocks to be merged. The primary slot intersection vector reflects the historical relationship between the slot to be merged and the primary node when the primary node is the primary node. The backup slot intersection vector reflects the historical relationship between the slot to be merged and the primary node when the primary node is the backup node. The primary slot weight coefficient matrix reflects the affinity between the primary node and the slot to be merged when the primary node is the primary node. The backup slot weight coefficient matrix reflects the affinity between the primary node and the slot to be merged when the primary node is the backup node. The vector with no intersection reflects the correlation between the slot to be merged and the primary node. If at least one hash slot in the slot to be merged is managed by the primary node before shrinking, the vector with no intersection is 0; otherwise, the vector with no intersection is 1. Based on the main slot intersection vector, the main slot weight coefficient matrix, the backup slot intersection vector, the backup slot weight coefficient matrix, and the vector with no intersection, the affinity weight of the slot block to be merged is determined, wherein the affinity weight is used to reflect the historical correlation between the slot block to be merged and the reserved node.
7. The method according to claim 6, characterized in that, The process of determining the affinity weight of the slot block to be merged based on the intersection vector of the main slots, the weight coefficient matrix of the main slots, the intersection vector of the backup slots, the weight coefficient matrix of the backup slots, and the vector with no intersection includes: Determine the first product of the intersection vector of the main slots and the weight coefficient matrix of the main slots, and determine the second product of the intersection vector of the spare slots and the weight coefficient matrix of the spare slots; Calculate the sum of the products of the first product and the second product, and determine the difference between the sum of the products and the vectors that have no intersection, as the affinity weight of the slot blocks to be merged.
8. The method according to claim 5, characterized in that, The step of determining the scaling-down routing information of the distributed storage system based on the original routing information, the slot weight of each hash slot, and the target number of slot blocks according to a predetermined load balancing algorithm further includes: By using permutation and combination algorithms and pruning optimization methods, the set of reduced-size slots that each retained node can manage is determined from all the reduced-size slots. Based on the set of scaled-down slots that each of the reserved nodes can manage, determine the primary node and backup node for each scaled-down slot among all the reserved nodes.
9. A computer device, characterized in that, include: At least one processor; And, a memory communicatively connected to the at least one processor; The memory stores instructions executable by the at least one processor, the instructions being configured to cause the processor to perform the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions configured to perform the method as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Method, device and system for expanding and shrinking capacity of database cluster
CN110874384A
Automatic load balancing distribution method and system
CN116069489A
Hash distribution method and system without data migration during system capacity expansion
CN116361299A
Storage cluster capacity expansion method and device, computer equipment and storage medium
CN117435129A
Multi-scene access control dynamic verification method and system based on permission tree
CN120528709A