Method for load balancing of distributed storage system in shrinkage scenario

By obtaining node scaling-down instructions, detecting conditions, setting hash slot weights, and using load balancing algorithms to calculate routing information in a distributed storage system, the risk of hotspot overload after scaling-down is resolved, and the system achieves efficient and stable operation.

CN121397006BActive Publication Date: 2026-05-01BANK OF CHINA INSURANCE INFORMATION TECH MANAGEMENT
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BANK OF CHINA INSURANCE INFORMATION TECH MANAGEMENT
Filing Date
2025-10-27
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

During the scaling down of a distributed storage system, existing static load balancing strategies cannot adapt to dynamic business changes, leading to increased risk of hotspot overload and deterioration of system performance.

Method used

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.

Benefits of technology

It effectively avoids performance bottlenecks and service avalanche risks caused by uneven load, ensuring smooth, efficient and stable operation of the system during the scaling-down process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121397006B_ABST
    Figure CN121397006B_ABST
Patent Text Reader

Abstract

The application provides a method for load balancing of a distributed storage system in a capacity reduction scenario, comprising: obtaining original routing information of the distributed storage system; setting a slot weight for each hash slot according to a predetermined slot weight setting mode; determining a target number of slot blocks after capacity reduction of the distributed storage system; determining capacity-reduced 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 hash slot and the target number of slot blocks; determining capacity-reduced metadata based on the original routing information and the capacity-reduced routing information; and reassigning all hash slots managed by original nodes to reserved nodes according to the capacity-reduced metadata. The technical scheme of the application realizes dynamic load balancing of the distributed storage system in the capacity reduction process.
Need to check novelty before this filing date? Find Prior Art

Description

Methods for load balancing distributed storage systems in scaling-down scenarios Technical Field

[0001] This application relates to the field of distributed storage technology, and in particular to a method for load balancing of distributed storage systems in a shrinking scenario. Background Technology

[0002] In current distributed storage system applications, if a faulty node occurs or there is a need to optimize resource allocation, it is often necessary to reduce the number of nodes in the distributed storage system.

[0003] However, the scaling down process of distributed storage systems faces significant technical challenges. Because data distribution is tightly bound to node routing, deleting a node without proper data redistribution will lead to uneven load distribution on the remaining nodes, potentially causing a global service collapse due to localized overload. Furthermore, during data migration, related technologies often calculate based on a static situation just before scaling down, and these calculations remain unchanged once the migration is complete. However, in reality, real-time business access patterns are dynamically changing, and scaling down may create new, unpredictable overload hotspots. Existing static load balancing strategies cannot adaptively adjust to the real-time load of distributed storage.

[0004] Therefore, how to avoid the risk of hotspot overload caused by the inability of static scaling-down load balancing strategies to adapt to dynamic business loads has become an urgent technical problem to be solved. Summary of the Invention

[0005] This application provides a method for load balancing a distributed storage system in a scaling-down scenario, aiming to solve the technical problem in related technologies where static scaling-down load balancing strategies cannot adapt to dynamic business changes, leading to increased risk of hotspot overload and deterioration of system performance after scaling down.

[0006] In a first aspect, embodiments of this application provide a method for load balancing a distributed storage system in a scaling-down scenario, including:

[0007] 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.

[0008] 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.

[0009] 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;

[0010] According to the predetermined slot weight setting method, set the slot weight for each hash slot;

[0011] 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.

[0012] 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.

[0013] 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;

[0014] According to the reduced-scale metadata, all hash slots managed by the original nodes are redistributed to the reserved nodes.

[0015] Optionally, in one embodiment of this application, detecting whether the current scaling-down association information meets the predetermined scaling-down conditions includes:

[0016] The system detects whether the distributed storage system is in a normal service state, wherein a normal service state indicates that the distributed storage system has no ongoing data migration tasks, and

[0017] Check whether the scaled-down node is a registered secure node and has been bound to the original routing information.

[0018] 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.

[0019] Optionally, in one embodiment of this application, setting a slot weight for each hash slot according to a predetermined slot weight setting method includes:

[0020] Set the slot weight of each hash slot to 1; or

[0021] 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.

[0022] Optionally, in one embodiment of this application, setting a slot weight for each hash slot according to a predetermined slot weight setting method includes:

[0023] For each hash slot, obtain the access frequency of the hash slot;

[0024] 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

[0025] 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.

[0026] In one embodiment of this application, optionally, 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:

[0027] 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;

[0028] 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.

[0029] 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.

[0030] 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;

[0031] 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.

[0032] 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;

[0033] 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.

[0034] In one embodiment of this application, optionally, determining the affinity weight between each of the slot blocks to be merged and each of the retained nodes includes:

[0035] 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;

[0036] 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.

[0037] 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.

[0038] 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.

[0039] In one embodiment of this application, optionally, determining the affinity weight of the slot block to be merged based on the main slot intersection vector, the main slot weight coefficient matrix, the spare slot intersection vector, the spare slot weight coefficient matrix, and the vector with no intersection includes:

[0040] 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;

[0041] 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.

[0042] In one embodiment of this application, optionally, 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:

[0043] 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.

[0044] 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.

[0045] In a second aspect, embodiments of this application provide a computer device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to perform the method described in the first aspect above.

[0046] Thirdly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions for performing the method described in the first aspect above.

[0047] The above technical solutions address the technical problem in related technologies where static scaling-down load balancing strategies cannot adapt to dynamic business changes, leading to increased risk of hotspot overload and system performance degradation after scaling down. This application proposes a technical solution for load balancing of distributed storage systems in scaling-down scenarios. By obtaining node scaling-down instructions and verifying scaling-down conditions, and based on the original routing information and finely configured hash slot weights, an optimized route that considers data locality and load balancing is calculated using a load balancing algorithm. Finally, data migration and route switching are guided based on the generated scaling-down state metadata. This solution enables dynamic redistribution of data when nodes go offline, ensuring high system availability while reducing unnecessary data migration, effectively avoiding performance bottlenecks or even service avalanche risks caused by uneven load, and achieving smooth, efficient, and stable operation of the distributed storage system during the scaling-down process. Attached Figure Description

[0048] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0049] Figure 1 shows a flowchart of a method for load balancing a distributed storage system in a scaling-down scenario according to an embodiment of this application;

[0050] Figure 2 shows a flowchart of a load balancing algorithm according to an embodiment of this application;

[0051] Figure 3 shows a schematic diagram of the operation of a scaling state machine according to an embodiment of this application;

[0052] Figure 4 shows a schematic diagram of a list of expansion and contraction actions according to an embodiment of this application;

[0053] Figure 5 shows a block diagram of a computer device according to an embodiment of this application;

[0054] Figure 6 shows a block diagram of a computer device according to another embodiment of this application. Detailed Implementation

[0055] 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.

[0056] Figure 1 shows a flowchart of a method for load balancing a distributed storage system in a scaling-down scenario according to an embodiment of this application.

[0057] As shown in Figure 1, a method for load balancing a distributed storage system in a scaling-down scenario according to an embodiment of this application includes:

[0058] 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.

[0059] 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.

[0060] 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.

[0061] Optionally, when upgrading or iterating the hardware of a distributed storage system, the old version or old model nodes must be safely taken offline first. This will also trigger targeted scaling down of these specific old version or old model nodes.

[0062] Optionally, when performance bottlenecks are detected in some nodes, or when resource configurations of some nodes are found to be unreasonable, the node distribution of the distributed storage system can be re-planned by scaling down, in order to improve the overall performance of the distributed storage system.

[0063] In summary, the node shrinkage command specifies which nodes need to be removed from the original node cluster and which nodes need to be retained, providing a clear target for subsequent data migration. This enables the distributed storage system to respond to various practical operation and maintenance needs. Whether it is dealing with faulty nodes, optimizing resource costs, or upgrading the system, a standardized shrinkage process can be triggered through a unified command, thereby ensuring that the distributed storage system can achieve dynamic load balancing in different scenarios.

[0064] It should be noted that in any of the technical solutions mentioned in the context, the implementing entity can be a distributed storage system or a third-party system specifically designed to manage the data storage of the distributed storage system.

[0065] Step 104: In response to the acquisition of the node scaling down instruction, detect 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.

[0066] In one possible design, the predetermined scaling-down condition refers to the distributed storage system being in a normal service state and the scaling-down node being a registered secure node bound to the original routing information. Specifically, it involves detecting whether the distributed storage system is in a normal service state, where a normal service state indicates that the distributed storage system has no ongoing data migration tasks, and detecting whether the scaling-down node is a registered secure node bound to the original routing information. If the distributed storage system is in a normal service state and the scaling-down node is a registered secure node bound to the original routing information, it is determined that the current scaling-down association information meets the predetermined scaling-down condition. In other words, the predetermined scaling-down condition means that the distributed storage system currently has no ongoing data migration tasks and all nodes to be removed are legally registered and bound to the routing information. This pre-verification step effectively avoids performing dangerous operations when the distributed storage system is unstable or the node state is abnormal, establishing a safe and reliable operating environment for subsequent data redistribution and avoiding the risk of service interruption due to state conflicts.

[0067] For example, to scale down two nodes and perform a validity check on this scaling-down operation, the distributed storage system must be in the Init state; commands entered in other states are invalid. Additionally, the two nodes to be scaled down must be registered; if the two nodes are not registered, the scaling-down command is invalid. Furthermore, the two nodes to be scaled down must have bound slot routing information; otherwise, the scaling-down command is invalid.

[0068] Step 106: If the current scaling-down association information meets the predetermined scaling-down conditions, obtain the original routing information of the distributed storage system.

[0069] The original routing information includes: the backup node of each original node in the distributed storage system, the original slots managed by each original node, and multiple hash slots in each original slot. In short, the original routing information completely records the data storage distribution of the entire distributed storage system cluster before scaling down. That is, the original routing information fully obtains the data jurisdiction of each node as a master node and its backup data jurisdiction as a backup node, and records the distribution of hash slots in detail, providing a valid basis for subsequent affinity weight calculation and even the generation of new routes.

[0070] Step 108: Set the slot weight for each hash slot according to the predetermined slot weight setting method.

[0071] By assigning weights to each hash slot, the abstract payload content of each hash slot can be quantified into specific values, making it easier to distinguish the importance of data blocks within different hash slots.

[0072] In one possible design, the slot weight of each hash slot is set to 1. In this case, the slot weight of the original slot block is equal to the number of hash slots it manages.

[0073] In another possible design, for each hash slot, the storage space of the hash slot is obtained, and the ratio of the storage space to a predetermined storage unit is determined. The slot weight of the hash slot is set to the rounded-up value of the ratio. Alternatively, the storage space of all hash slots is normalized, and the result of the normalization is discretized to a first target interval. The first 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 first target interval are 1 and half of the maximum number of backups per node, respectively.

[0074] In other words, the physical storage consumption of a hash slot can be quantified into a comparable value. The physical storage consumption of a hash slot reflects the resource usage characteristics of data storage, measuring the actual volume of data managed by each hash slot on the disk. This facilitates the identification of data blocks that consume large amounts of space, preventing the concentration of such blocks on the same node during load balancing during scaling down. This prevents storage performance bottlenecks caused by insufficient disk space or excessive read / write pressure, further ensuring a balanced allocation of storage resources. Simultaneously, normalization mapping maps storage spaces of different sizes to a unified interval for discretization eliminates dimensional differences between the original data.

[0075] In another possible design, for each hash slot, the access frequency of the hash slot is obtained, the frequency ratio of the access frequency to a predetermined frequency unit is determined, and the slot weight of the hash slot is set 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 to a second target interval, and the second discrete result corresponding to each of the hash slots is used as the slot weight of each of the hash slots, wherein the lower limit and the upper limit of the second target interval are 1 and half of the maximum number of backups per node, respectively.

[0076] Therefore, the access frequency of hash slots can be quantified into a comparable value. The access frequency of hash slots reflects the hotspot distribution of business access, and can measure the request activity of the data served by each hash slot within a unit of time. This facilitates the identification of frequently accessed data blocks, avoids the concentration of multiple hot data blocks on the same node during scaling down and load balancing, and prevents service performance bottlenecks caused by node overload or network throughput saturation, further ensuring balanced processing of business requests. At the same time, by normalizing the access frequencies of different magnitudes to a unified interval for discretization, the dimensional differences between the original data can be eliminated.

[0077] Thus, different weight settings can meet different scaling-up load balancing needs, thereby enabling more targeted resource scheduling based on actual requirements.

[0078] Step 110: Obtain the difference between the first quantity and the second quantity as a first reduction slot number calculation parameter, and obtain the difference between the first reduction slot number calculation parameter and 1 as a second reduction slot number calculation parameter, and determine the product of the first reduction slot number calculation parameter and the second reduction slot number calculation parameter as the target number of slots after the distributed storage system is reduced.

[0079] This provides a clear target number of hash slots for redistribution, setting a basic standard for subsequent data partitioning and aggregation.

[0080] In a real-world scenario where 6 original nodes are reduced to 4 (i.e., a 6-to-2 reduction), each original node was originally responsible for some slots. The target number of slots after the distributed storage system is reduced is mean_size = (n - m) × (n - m - 1), where the number of original nodes n is 6, the number of reduced nodes m is 2, the first reduction slot number calculation parameter is nm = 6 - 2 = 4, the second reduction slot number calculation parameter is 3, and the calculated mean_size is 12. This parameter represents the number of target sub-blocks that the entire hash slot space [0..4096) is planned to be re-divided into in the initial stage of the load balancing algorithm.

[0081] Step 112: Based on the original routing information, the slot weight of each hash slot, and the target number of slot blocks, determine the scaling-down routing information of the distributed storage system according to a predetermined load balancing algorithm.

[0082] The predetermined load balancing algorithm is used to redetermine routing information based on the target number of hash slots redistributed. The original routing information reflects the data distribution before system downsizing and the master-slave dependencies between nodes, recording the current location distribution of each original slot, the master node's jurisdiction, and backup nodes, forming a source relationship graph for data migration. The target number of slots reflects the block distribution target of the cluster architecture after downsizing; the target number of slots is derived based on the number of nodes, allowing the definition of the target number of blocks after load balancing. The slot weight of the hash slot reflects the data load characteristics of the hash slot. By integrating these three factors through the load balancing algorithm, the optimal data distribution scheme can be calculated that satisfies the load balancing requirements between nodes, fully considers data locality characteristics, and also meets the constraints of the cluster size after downsizing.

[0083] Step 114: Based on the original routing information and the scaling-down routing information, determine the scaling-down state metadata, 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.

[0084] By comparing old and new routing information, scaling-down metadata is generated, which details the changes in slot distribution for each node and the operational instructions that need to be executed. This metadata transforms the abstract load balancing scheme into an executable action blueprint, providing clear operational guidelines for subsequent data migration and route switching.

[0085] Step 116: According to the reduced-scale metadata, all hash slots managed by the original nodes are redistributed to the reserved nodes.

[0086] Following the guidance of metadata, hash slots are redistributed to reserved nodes, completing the final transformation from computation to execution. This step, through orderly data migration and routing updates, transforms the theoretical load balancing scheme into a practical system state, ultimately achieving load balancing and stable operation of the scaled-down cluster.

[0087] In summary, this application proposes a technical solution for load balancing of a distributed storage system in a scaling-down scenario. By obtaining node scaling-down instructions and verifying scaling-down conditions, and based on the original routing information and finely configured hash slot weights, an optimized route that considers data locality and load balancing is calculated using a load balancing algorithm. Finally, data migration and route switching are achieved based on the generated scaling-down state metadata. This solution enables dynamic redistribution of data when nodes go offline, ensuring high system availability while reducing unnecessary data migration. It effectively avoids performance bottlenecks or even service avalanche risks caused by uneven load, achieving smooth, efficient, and stable operation of the distributed storage system during the scaling-down process.

[0088] Figure 2 shows a flowchart of the load balancing algorithm in step 112. As shown in Figure 2, the load balancing algorithm includes:

[0089] Step 202: Calculate the average weight and remainder of the target number of slots based on the slot weight of each hash slot and the target number of slots.

[0090] By calculating the average weight and remainder of the target number of slots, a clear quantitative benchmark is provided for subsequent slot aggregation. This step transforms the abstract load balancing objective into a concrete numerical metric, enabling the data sharding process to unfold around a clear standard, thereby ensuring that the final generated slots are as close as possible to the ideal load.

[0091] The average weight of the target slot number is given by `gather_size = ∑slot_weight / mean_size`, which is the sum of the weights of all slots and the quotient of the target slot number.

[0092] Remainder=∑slot_weight-gather_size×mean_size.

[0093] In the 6-slot-2 scenario, if the slot weight of each hash slot is 1, then 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.

[0094] In other words, in the ideal shrinking result, each of the 12 target slots should carry 341 weight units, that is, 341 hash slots.

[0095] In one possible design, since the total weight 4096 is not divisible by 12, there will be 4 weight units remaining. These 4 remaining weight units 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, thereby completing the accurate load distribution.

[0096] Step 204: Based on the original number of slots of all the original nodes and the target number of slots, determine the original number of slot segments and the number of slot aggregations.

[0097] The number of partitions and aggregations is determined by using the greatest common divisor of the original number of slots and the target number of slots, thus setting a scientific granularity for data reorganization. This calculation method ensures that the original data blocks can be reasonably divided into an appropriate number of sub-blocks, while providing a reasonable aggregation unit size for subsequent clustering operations, making the entire data reorganization process mathematically rigorous and operable.

[0098] Specifically, the greatest common divisor of the original number of slots and the target number of slots is determined. The original number of slot divisions is the quotient of the target number of slots and the greatest common divisor, representing the number of slots that each original slot needs to be divided into. The number of slot aggregations is the quotient of the original number of slots and the greatest common divisor, representing the number of slots required for a single aggregation operation in the first round of clustering.

[0099] In the 6-to-2 clustering scenario, the original number of slots (old_block_number) is 30, and the target number of slots (mean_size) is 12. First, the greatest common divisor (GCD) of the two is calculated as gcd(30, 12) = 6. Then, the original slot partitioning number (denominator) is calculated as mean_size / gcd(30, 12) = 12 / 6 = 2, indicating that each original slot needs to be partitioned into 2 partitioned slots. Next, the partitioned slot aggregation number (numerator) is calculated as old_block_number / gcd(30, 12) = 30 / 6 = 5, indicating that in the first round of clustering, a single aggregation operation requires aggregating 5 partitioned slots. This calculation method ensures the basic requirements for data reorganization are met.

[0100] In one possible design, the original 30 slots are divided into 30 × 2 = 60 sub-slots. In the first round of clustering, every 5 sub-slots are aggregated into a new slot, ultimately forming 60 ÷ 5 = 12 target slots, which perfectly matches the preset mean_size. This partitioning and aggregation strategy based on the greatest common divisor ensures a balanced distribution of slots during the data reorganization process.

[0101] Each block of the old slot set is divided equally according to the denominator and placed into the slot block set to be merged. In the 6-fold 2 scenario, for slots{[0..127]}, it is divided according to denominator=2 to obtain slots{[0..69),[69..137]}, and finally a set of 60 divided slot blocks is obtained.

[0102] Step 206: Divide each original slot block according to the original number of slot block divisions, and add the divided slot blocks as slot blocks to be merged to the set of slot blocks to be merged.

[0103] The original slots are subdivided into smaller units to be merged based on the number of partitions, creating conditions for flexible reorganization later. By decomposing large blocks of data into finer-grained components, the system can obtain more permutation and combination possibilities during redistribution, thus providing a basis for finding the optimal load balancing solution.

[0104] Step 208: Based on the original routing information and the slot weight of each hash slot, determine the affinity weight between each slot block to be merged and each reserved node.

[0105] By constructing an affinity matrix and calculating multi-dimensional intersection vectors, the historical correlation between each slot to be merged and the retained nodes is precisely quantified. This weighted calculation method, which comprehensively considers the master-slave relationship, can accurately identify the migration path with optimal data locality, thereby minimizing the actual data migration volume while ensuring load balancing and significantly improving scaling efficiency.

[0106] Specifically, the method for calculating affinity weights includes: constructing an affinity matrix based on each slot block to be merged and each retained node, wherein the affinity matrix is ​​used to reflect the distribution location of each slot block to be merged and the respective association relationships of the multiple retained nodes; based on the affinity matrix, determining the main slot intersection vector, main slot weight coefficient matrix, spare slot intersection vector, spare slot weight coefficient matrix, and no-intersection vector of the slot block to be merged; and determining the affinity weight of the slot block to be merged based on the main slot intersection vector, the main slot weight coefficient matrix, the spare slot intersection vector, the spare slot weight coefficient matrix, and the no-intersection vector, wherein the affinity weight is used to reflect the historical association between the slot block to be merged and the retained nodes.

[0107] Wherein, the primary slot intersection vector is used to reflect 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 is used to reflect 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 is ​​used to reflect 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 is ​​used to reflect the affinity between the primary node and the slot to be merged when the primary node is the backup node; and the vector with no intersection is used to reflect the correlation between the slot to be merged and the primary node. Wherein, 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.

[0108] The step of determining the affinity weight of the slot block to be merged 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 includes: 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 the sum of the first product and the second product, and determining the difference between the sum of the products and the vector with no intersection as the affinity weight of the slot block to be merged.

[0109] Step 210: Based on the number of aggregated segments and the affinity weight of each segment to be merged, cluster all segments to be merged to obtain aggregated segments.

[0110] Clustering is performed on the slots to be merged based on the aggregation number and affinity weights, intelligently grouping data blocks with similar characteristics and correlations. This clustering method not only considers the size weight of the data blocks, but also fully respects the existing data distribution relationships, so that the generated new slots meet the load requirements while maintaining reasonable data locality.

[0111] Step 212: If the weight of the aggregated tank is greater than or equal to the average weight, the aggregated tank is determined to be a reduced-capacity tank.

[0112] The weight of the aggregated slot block is the sum of the weights of all hash slots within it. By determining whether the aggregated slot block's weight meets the required standard, its final state is determined, ensuring that each newly generated slot block satisfies basic load requirements. This quality control step prevents excessively small or unbalanced slot blocks from entering the final allocation scheme, guaranteeing overall load balancing effectiveness from the outset.

[0113] Step 214: If the weight of the aggregated slot is less than the average weight, put the aggregated slot back into the set of slots to be merged, and return to the step of determining the affinity weight between each slot to be merged and each retained node, and perform another round of clustering processing until there are no aggregated slots with a weight less than the average weight in the clustering results.

[0114] Substandard aggregated slots are returned to the processing set for re-clustering, forming an effective quality feedback mechanism. This iterative processing method continuously optimizes the grouping results, ensuring that all generated slots eventually meet the load criteria, thereby achieving continuous improvement in the overall load balancing effect.

[0115] For the already segmented set of slots, cluster them according to the affinity weights of the nodes retained after scaling down. For clustering results with average weights that reach the target number of slots after scaling down, renumber them and use them as the scaled-down slots. Clustering results with average weights that do not reach the target number of slots after scaling down are placed in the list to be aggregated, and the clustering operation based on affinity weights is performed again to finally obtain the new aggregated set of slots.

[0116] In the 6-to-2 scenario, after removing node1 and node3, the following result is obtained:

[0117] node2: [5, 18, 26, 30, 2, 29, 3, 13, 17, 23],

[0118] node4: [4, 5, 9, 27, 14, 19, 25, 21, 6, 13],

[0119] node5: [9, 16, 22, 26, 27, 19, 8, 12, 6, 17],

[0120] node6: [4, 10, 18, 11, 2, 20, 29, 7, 15, 24]].

[0121] The 12 reduced-capacity slots after aggregation are as follows:

[0122] SlotSetRebalance:1, size:342slots:{[69..137, 479..616, 1846..1983]};

[0123] SlotSetRebalance:2, size:342slots:{[1368..1505, 2050..2118, 3210..3347]};

[0124] SlotSetRebalance:3,size:341slots:{[2186..2322,2732..2801,3891..4027]};

[0125] SlotSetRebalance:4,size:341slots:{[2527..2663,2663..2731,3073..3142,4027..4095]};

[0126] SlotSetRebalance:5,size:341slots:{[958..1026,1300..1368,1778..1846,2869..3006]};

[0127] SlotSetRebalance:6,size:342slots:{[137..274,1505..1642,3142..3210]};

[0128] SlotSetRebalance:7,size:342slots:{[684..821,821..958,2801..2869]};

[0129] SlotSetRebalance:8,size:341slots:{[411..479,1709..1778,2322..2390,3006..3072,3618..3686][2049,2731]};

[0130] SlotSetRebalance:9,size:341slots:{[1163..1300,3414..3550,3550..3618]};

[0131] SlotSetRebalance:10,size:342slots:{[342..411,1026..1163,3347..3413,3686..3754][3072,4095]};

[0132] SlotSetRebalance:11,size:341slots:{[0..69,274..342,616..684,2391..2527]};

[0133] SlotSetRebalance: 12, size: 340 slots: {[1642..1709, 1983..2049, 2118..2186, 3755..3891][2390, 3413, 3754]}.

[0134] Step 216: Using a permutation and combination algorithm and a pruning optimization method, determine the set of scaled-down slots that each of the retained nodes can manage from all the scaled-down slots.

[0135] This method employs a combination of permutation and combination algorithms with pruning optimization to determine the set of management slots for each node, quickly finding the optimal solution among numerous possible allocation schemes. This approach ensures both the global optimality of the allocation scheme and avoids combinatorial explosion through pruning strategies, achieving a good balance between efficiency and effectiveness.

[0136] Step 218: Based on the set of scaled-down slots that each of the reserved nodes can manage, determine the primary node and backup node of each scaled-down slot among all the reserved nodes.

[0137] Based on the determined set of slots, appropriate master and backup nodes are assigned to each scaled-down slot, completing the final decision on data routing. This step ensures that the new data distribution scheme has complete fault tolerance and access paths, providing a reliable data architecture foundation for the subsequent stable operation of the system.

[0138] At this point, the primary slot route for each node is determined, and the remaining slot routes are backup slot routes. Using an improved permutation and combination algorithm, after obtaining the set of slot blocks belonging to each node, the primary slot block responsible for each node is further selected. The permutation and combination algorithm has poor performance due to exhaustively searching all combinations. This can be improved by constraining blocks already selected by other nodes to prevent further selection, pruning the candidate set in advance, and setting a maximum number of combination attempts.

[0139] In the 6-to-2 scenario, a master is selected from the candidate set of each node to obtain the master slot routing result. Since the result nodes 2 and 4 are unbalanced, the post-processing algorithm adjusts the slot block number 12 from node 2 to node 4.

[0140] candidate:[1,2,4,5,6,7,8,11,12];

[0141] candidate:[1, 2, 3, 4, 6, 8, 9, 10, 11, 12];

[0142] candidate:[1, 3, 5, 7, 8, 9, 10, 11, 12];

[0143] candidate:[2, 3, 4, 5, 6, 7, 9, 10];

[0144] belong_node:1size:3[1, 5, 8];

[0145] belong_node:2size:3[2, 6, 11];

[0146] belong_node:3size:3[3, 7, 12];

[0147] belong_node:4size:3[4, 9, 10];

[0148] rebalance_block:12node:2->4;

[0149] Finally, by comparing the slot routing data of the old and new nodes, the scale-down state metadata is generated. Then, the distributed storage system enters the scale-down state. The scale-down state metadata includes slot routing data that records how the slot set is divided after scaling down, a list of scaling-up actions for each node that was not scaled down, and a list of actions for the nodes that were scaled down.

[0150] In a 6-to-2 scenario, the slot set routing metadata is as follows:

[0151] routers:

[0152] [Router{id:1weight:342slots:{[69..137,479..616,1846..1983]}node:1backups:{2,3}},

[0153] Router{id:2weight:342slots:{[1368..1505,2050..2118,3210..3347]}node:2backups:{1,4}},

[0154] Router{id:3weight:341slots:{[2186..2322,2732..2801,3891..4027]}node:3backups:{2,4}},

[0155] Router{id:4weight:341slots:{[2527..2663,2663..2731,3073..3142,4027..4095]}node:4backups:{1,2}},

[0156] Router{id:5weight:341slots:{[958..1026,1300..1368,1778..1846,2869..3006]}node:1backups:{3,4}},

[0157] Router{id:6weight:342slots:{[137..274,1505..1642,3142..3210]}node:2backups:{1,4}},

[0158] Router{id:7weight:342slots:{[684..821,821..958,2801..2869]}node:3backups:{1,4}},

[0159] Router{id:8weight:341slots:{[411..479,1709..1778,2322..2390,3006..3072,3618..3686][2049,2731]}node:1backups:{2,3}},

[0160] Router{id:9weight:341slots:{[1163..1300,3414..3550,3550..3618]}node:4backups:{2,3}},

[0161] Router{id:10weight:342slots:{[342..411,1026..1163,3347..3413,3686..3754][3072,4095]}node:4backups:{2,3}},

[0162] Router{id:11weight:341slots:{[0..69,274..342,616..684,2391..2527]}node:2backups:{1,3}},

[0163] Router{id:12weight:340slots:{[1642..1709,1983..2049,2118..2186,3755..3891][2390,3413,3754]}node:3backups:{1,4}},].

[0164] In addition, in this 6-to-2 scenario, the action list information required for each node is as follows:

[0165] node:2old_slots:{[0..342,479..684,958..1026,1300..2050,2390..2663,2731..3073,3347..3414][3754,4095]}->

[0166] new_slots:{[0..342,411..1026,1300..2186,2322..2732,2801..3072,3073..3347,3618..3686,3754..3891,4027..4095]

[3413] },

[0167] needexpand:1160{[411..479,684..958,2050..2186,2322..2390,2663..2731,3073..3347,3618..3686,3755..3891,4027..4095]},

[0168] needshrink:137{[2732..2801,3347..3413][3072,4095]},

[0169] node:4old_slots:{[137..684,1368..1505,1642..2049,2050..2391,3073..3347,3413..3550,3686..3891]}->

[0170] new_slots:{[0..684,1026..1300,1368..1642,1709..1778,1846..1983,2049..2118,2186..2390,2391..2801,3006..3413,3414..3754,3891..4096]},

[0171] needexpand:1433{[0..137,1026..1300,1505..1642,2391..2801,3006..3073,3347..3413,3550..3686,3891..4096]

[2049] },

[0172] needshrink:408{[1642..1709,1778..1846,1983..2049,2118..2186,3754..3891][2390,3413]},

[0173] node:5old_slots:{[684..1026,1163..1368,1505..1642,1846..1983,2050..2390,2732..2869,3073..3210,3414..3754,3755..4027]}->

[0174] new_slots:{[0..137,274..1368,1642..2050,2118..2527,2731..3073,3347..4027]

[4095] },

[0175] needexpand:1366{[0..137,274..684,1026..1163,1642..1846,1983..2050,2390..2527,2869..3073,3347..3414][2731,3754,4095]},

[0176] needshrink:342{[1505..1642,2050..2118,3073..3210]},

[0177] node:6old_slots:{[137..274,342..479,684..958,1026..1163,1368..1709,1983..2049,2390..2731,2869..3006,3073..3347,3891..4095][3413,3754]}->

[0178] new_slots:{[137..274,342..411,684..1709,1778..1846,1983..2049,2050..2322,2527..2731,2732..3006,3072..3618,3686..4096]

[2390] },

[0179] needexpand:1226{[958..1026,1163..1368,1778..1846,2050..2322,2732 ..2869,3347..3413,3414..3618,3686..3754,3755..3891][3072,4095]},

[0180] needshrink:204{[411..479,2391..2527]}.

[0181] In a 6-to-2 scaling-down scenario, the list of actions required by the scaled-down node is as follows:

[0182] node:1old_slots:{[0..137,274..479,616..821,958..1368,2391..2732,30 06..3073,3210..3413,3550..3686,3755..4096]

[2049] }->new_slots:{[]},

[0183] needshrink:2046{[0..137,274..479,616..821,958..1368,2391..2732,3006..3073,3210..3413,3550..3686,3755..4096]

[2049] },

[0184] node:3old_slots:{[0..137,479..616,821..958,1026..1300,1709..1846,2049 ..2390,2663..3073,3347..3413,3414..3754,4027..4096]}->new_slots:{[]},

[0185] needshrink:2048{[0..137,479..616,821..958,1026..1300,1709..1846,2049..2390,2663..3073,3347..3413,3414..3754,4027..4096]}.

[0186] Finally, a broadcast notification of the full routing change is sent, interacting with the affected storage nodes and driving the state transitions of each node until all scaling-down actions are completed. Each node must complete its current scaling-down action before switching to the next scaling-up action. No confirmation response is required when notifying the nodes being scaled down, as the scaling-down might be due to an unrecoverable failure.

[0187] After all nodes have successfully completed the scaling down operation, the system enters the Init state. At this point, the system can accept scaling up or scaling down commands again.

[0188] Furthermore, in the actual scenario described in this application, a primary slot failure may occur, requiring dynamic load balancing. The primary slot failure load balancing mechanism is triggered after a storage node fails and goes offline. The control service uses the slot information reported by each storage node, and based on the load balancing algorithm, reselects the primary node route for the hash slot and updates the associated routing information. This information is then broadcast to all storage nodes, restoring system availability. The specific process is as follows:

[0189] Step 1: Each storage node independently reports its own slot information, specifically in the format of a set of tuples: {slot, seq, space, freq}. Here, seq represents the latest sequence number of the data stored in the slot, which has an auto-incrementing unique attribute. space represents the occupied storage space, and freq represents the access frequency.

[0190] Step 2: The control service center records the latest slot information reported by each node at the slot level. This data will be used by subsequent load balancing algorithms.

[0191] Step 3: After the heartbeat system detects a heartbeat timeout fault at a certain node, it notifies the faulty node and drives the control system to perform fault load balancing.

[0192] Step 4: Calculate the candidate locations of the primary slots responsible for the failed node. Candidate locations refer to the backup nodes corresponding to each slot. Then, filter the candidate slot locations based on the sequence number values ​​in the reported slot information, selecting the slot location with the latest sequence number. At this point, a list of candidate locations corresponding to the set of primary slots undertaken by the failed node is obtained. Taking a 4-node system as an example:

[0193] BlockRouter::Init{clients:[70002, 70005, 70008, 70011], blocks: [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]}.

[0194] If the single-fault node 70002 corresponds to node number 1, then the candidate list is as follows:

[0195] [Candidate{id:1slots:{[0..342]}backups:{2, 4}},

[0196] Candidate{id:2slots:{[1368..1709]}backups:{2,3}},

[0197] Candidate{id:3slots:{[2732..3073]}backups:{3, 4}},].

[0198] Meanwhile, faulty nodes 70002 and 70008 correspond to numbers 1 and 3, respectively. Therefore, the candidate list is as follows:

[0199] [Candidate{id:1slots:{[0..342]}backups:{2, 4}},

[0200] Candidate{id:2slots:{[1368..1709]}backups:{2}},

[0201] Candidate{id:3slots:{[2732..3073]}backups:{4}},

[0202] Candidate{id:7slots:{[684..1026]}backups:{4}},

[0203] Candidate{id:8slots:{[2050..2391]}backups:{2}},

[0204] Candidate{id:9slots:{[3414..3755]}backups:{2, 4}},].

[0205] Step 5: The load balancing algorithm selects a unique candidate position for the primary slot corresponding to the faulty node based on the candidate list. If no candidate position can be selected, the slot is considered to be routing faulty. The fault load balancing algorithm first selects the slot with only one candidate position, refreshes the weight of the candidate position, then prioritizes selecting the position with the smallest weight and refreshes its weight, until all slots have selected candidate positions.

[0206] The route selected after the single failure of node 70002 is as follows:

[0207] BlockRouter::Init{clients:[70002, 70005, 70008, 70011], blocks: [[], [1, 4, 5, 6], [2, 7, 8, 9], [3, 10, 11, 12]]}.

[0208] Meanwhile, the corresponding routes reselected for faults 70002 and 70008 are as follows:

[0209] BlockRouter::Init{clients:[70002, 70005, 70008, 70011], blocks: [[], [1, 2, 4, 5, 6, 8], [], [3, 7, 9, 10, 11, 12]]}.

[0210] Step 5: Update the slot route, calculate the primary and backup locations of the changed slot, and broadcast the incremental route change notification.

[0211] The notification information after a single failure at node 70002 is as follows:

[0212] UpdataEvent:[slots:{[0..342]}node:70005backups:{70002, 70011},

[0213] slots:{[0..342]}node:70005backups:{70002, 70011},

[0214] slots:{[1368..1709]}node:70008backups:{70002, 70005},

[0215] slots:{[2732..3073]}node:70011backups:{70002, 70008}].

[0216] In summary, this application proposes a dynamic load balancing mechanism for primary slot failures. By collecting node slot status information in real time, it automatically triggers a rebalancing process when the heartbeat system detects a node failure. Based on a backup node candidate list and a sequence number filtering mechanism, a load balancing algorithm is used to re-elect a primary node for the failed primary slot and update routing information. Finally, rapid route switching is achieved through incremental broadcasting. This technical solution can automatically, quickly, and accurately restore data availability and service continuity in the event of a sudden node failure, effectively avoiding data unavailability and service interruptions in distributed storage systems caused by single or multiple points of failure, thus improving the fault tolerance and overall reliability of the distributed storage system.

[0217] Figure 3 shows a schematic diagram of the expansion / shrinkage state machine according to an embodiment of this application.

[0218] As shown in Figure 3, the trigger condition for the transition from the empty state to the initial state is the Init (initialization) command. When the distributed storage system is in the empty state, it enters the initial state after receiving the Init command. This is the state transition process of the distributed storage system starting or initializing, indicating that the system begins to enter the initial preparation state in which it can perform operations such as expansion and contraction.

[0219] The trigger condition for the transition from the initial state to the expansion state is an expansion command. When the distributed storage system is in the initial state, it receives an expansion command and enters the expansion state. At this time, the distributed storage system will perform resource expansion-related operations, such as adding server nodes.

[0220] The condition for transitioning from the expansion state to the initial state is successful expansion. Once the distributed storage system completes the expansion operation in the expansion state and the expansion is successful, it will return to the initial state. This indicates that the expansion operation is over and the distributed storage system returns to its initial state where it can receive new commands.

[0221] The condition for transitioning from the initial state to the shrinking state is a shrinking command. When a shrinking command is received in the initial state, the distributed storage system enters the shrinking state and begins to execute resource shrinking operations, such as reducing the number of server nodes.

[0222] The trigger condition for the transition from the shrinking state to the initial state is successful shrinking. After the distributed storage system completes the shrinking operation in the shrinking state and the shrinking is successful, it returns to the initial state. This indicates that the shrinking operation is complete and the distributed storage system is once again in the initial state where it can receive new commands.

[0223] Figure 4 shows a schematic diagram of a list of scaling operations according to an embodiment of this application.

[0224] As shown in Figure 4, "Node → Expansion Slot" refers to the node entering the expansion slot stage. This stage involves resource expansion processing to prepare for subsequent operations and is the first state transition in the resource adjustment process. "Expansion Slot → Shrinkage Slot" means moving from the expansion slot to the shrinkage slot, indicating that after completing expansion operations, the node can enter the shrinkage operation stage to reduce its resource size. This is an intermediate step in the resource adjustment process. "Shrinkage Slot → Promotion Slot" indicates moving from the shrinkage slot to the promotion slot, signifying that after the shrinkage operation, node promotion operations are performed. This represents the adjustment of the node's master-slave role and is a crucial step towards a serviceable state. "Promotion Slot → Ready" indicates moving from the promotion slot to the ready state, signifying that the node has completed the promotion operation and is ready to provide services. This is the final stage of the entire process, and the node can now participate in business processing.

[0225] In the state machine, the distributed storage system transitions from an empty state to the initial state via the `Init` command, and then enters the corresponding states according to the expansion and contraction commands. After a successful operation, it returns to the initial state. In the node's action list, the node can go through three stages: expansion slot, contraction slot, and promotion slot, and finally enters the ready state to provide services.

[0226] In one embodiment, this application provides a computer device, which can be a server, and its internal structure diagram is shown in Figure 5. The computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface of the computer device is used to communicate with external clients via a network connection. When the computer program is executed by the processor, it can implement the methods described in any of the above embodiments.

[0227] In one embodiment, this application also provides a computer device, which can be a client, and its internal structure diagram can be as shown in Figure 6. The computer device includes a processor, memory, network interface, display screen, and input device connected via a system bus. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it can implement the methods described in any of the above embodiments.

[0228] Any of the computer devices described in the embodiments of this application exist in various forms, including but not limited to:

[0229] (1) Mobile communication devices: These devices are characterized by their mobile communication capabilities and primarily aim to provide voice and data communication. These terminals include smartphones, multimedia phones, feature phones, and low-end phones.

[0230] (2) Ultra-mobile personal computer devices: These devices fall under the category of personal computers, possessing computing and processing capabilities, and generally also have mobile internet access features. These terminals include PDAs, MIDs, and UMPCs, etc.

[0231] (3) Portable entertainment devices: These devices can display and play multimedia content. This category includes: audio and video players, handheld game consoles, e-books, as well as smart toys, wearable devices, and portable car navigation devices.

[0232] (4) Server: A device that provides computing services. The components of a server include a processor, hard disk, memory, system bus, etc. Servers are similar to general computer architectures, but because they need to provide highly reliable services, they have higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.

[0233] (5) Other electronic devices with data interaction functions.

[0234] Additionally, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which are used to perform the following steps:

[0235] 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.

[0236] 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.

[0237] 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;

[0238] According to the predetermined slot weight setting method, set the slot weight for each hash slot;

[0239] 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.

[0240] 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.

[0241] 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;

[0242] According to the reduced-scale metadata, all hash slots managed by the original nodes are redistributed to the reserved nodes.

[0243] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.

[0244] The technical solution of this application has been described in detail above with reference to the accompanying drawings. The technical solution of this application obtains node scaling-down instructions and verifies scaling-down conditions. Based on the original routing information and finely configured hash slot weights, it uses a load balancing algorithm to calculate an optimized route that considers data locality and load balancing. Finally, it guides data migration and route switching based on the generated scaling-down state metadata. This solution can realize dynamic redistribution of data when nodes go offline. While ensuring high system availability, it reduces unnecessary data migration and effectively avoids performance bottlenecks or even service avalanche risks caused by uneven load. It achieves smooth, efficient and stable operation of the distributed storage system during the scaling-down process.

[0245] It should be understood that although the terms "first," "second," etc., may be used to describe quantities in the embodiments of this application, these quantities should not be limited to these terms. These terms are only used to distinguish quantities from each other. For example, without departing from the scope of the embodiments of this application, a first quantity may also be referred to as a second quantity, and similarly, a second quantity may also be referred to as a first quantity.

[0246] Depending on the context, the word "if" as used here can be interpreted as "when," "when," "in response to determination," or "in response to detection." Similarly, depending on the context, the phrase "if determination" or "if detection (of the stated condition or event)" can be interpreted as "when determination," "in response to determination," "when detection (of the stated condition or event)," or "in response to detection (of the stated condition or event)."

[0247] The terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. The singular forms “a,” “the,” and “the” used in the embodiments of this application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise.

[0248] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0249] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in a combination of hardware and software functional units.

[0250] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0251] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A method for load balancing a distributed storage system in a scaling-down scenario, characterized in that, include: Obtain a node scaling-down instruction, wherein the node scaling-down instruction is used to instruct the reduction of a second number of scaling-down nodes and the retention of a third number of reserved nodes from a first number of original nodes in the distributed storage system; in response to the acquisition of the node scaling-down instruction, detect 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 nodes; if the current scaling-down association information meets the predetermined scaling-down conditions, obtain the original routing information of the distributed storage system, wherein the original routing information includes: the backup nodes of each original node in the distributed storage system, the original slots managed by each original node, and multiple hash slots in each original slot; set a slot weight for each hash slot according to a predetermined slot weight setting method; obtain the first number and the second number of nodes... The difference in quantity is used as the first shrinking slot block number calculation parameter, and the difference between the first shrinking slot block number calculation parameter and 1 is used as the second shrinking slot block number calculation parameter. The product of the first shrinking slot block number calculation parameter and the second shrinking slot block number calculation parameter is determined as the target number of slot blocks after the distributed storage system is shrunk. Based on the original routing information, the slot weight of each hash slot, and the target number of slot blocks, the shrinking routing information of the distributed storage system is determined according to a predetermined load balancing algorithm. Based on the original routing information and the shrinking routing information, shrinking state metadata is determined, wherein the shrinking state metadata is used to reflect the hash slot distribution in each reserved node and the shrinking action information of each original node. According to the shrinking state metadata, all hash slots managed by the original nodes are redistributed to each reserved node.

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: 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 tasks; and detecting whether the scaling-down node is a registered security 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 security node and has been bound to the original routing information, it is determined that the current scaling-down association information meets 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: setting the slot weight of each hash slot to 1; or, for each hash slot, obtaining the storage space of the hash slot, determining the space ratio of the storage space to a predetermined storage unit, and setting the slot weight of the hash slot to the rounded-up value of the space ratio; or normalizing the storage space of all hash slots, and discretizing 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, 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 to the rounded-up value of the frequency ratio; or, normalizing the access frequency of all hash slots, and discretizing the result of the normalization process to a second target interval, using the second 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 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: calculating the average weight and remainder of the target number of slot blocks based on the slot weight of each hash slot and the target number of slot blocks; determining the number of original slot block splits and the number of split slot block aggregations based on the number of original slot blocks of all original nodes and the number of target slot blocks, wherein the greatest common divisor of the number of original slot blocks and the number of target slot blocks is determined, the number of original slot block splits is the quotient of the number of target slot blocks and the greatest common divisor, representing the number of split slot blocks that each original slot block needs to be split into, and the number of split slot block aggregations is the quotient of the number of original slot blocks and the greatest common divisor, representing the number of split slot blocks required for a single aggregation operation in the first round of clustering processing; splitting each original slot block according to the number of original slot block splits, and dividing the splits... The split 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 to be merged and each reserved 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 slot 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 reserved node is returned for another round of clustering, until there are no aggregated slots with slot weights 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 slot to be merged and each reserved node includes: constructing an affinity matrix based on each slot to be merged and each reserved node, wherein the affinity matrix reflects the distribution location of each slot to be merged and the respective association relationships of the multiple reserved nodes; and determining, based on the affinity matrix, the primary slot intersection vector, the primary slot weight coefficient matrix, the backup slot intersection vector, the backup slot weight coefficient matrix, and the vector with no intersection for each slot to be merged, wherein the primary slot intersection vector reflects the historical relationship between the slot to be merged and the reserved node when the reserved node is the primary node, the backup slot intersection vector reflects the historical relationship between the slot to be merged and the reserved node when the reserved node is the backup node, and the primary slot weight coefficient... The matrix reflects the affinity between the reserved node as the primary node and the slot to be merged. The backup slot weight coefficient matrix reflects the affinity between the reserved node as the backup node and the slot to be merged. The vector with no intersection reflects the association between the slot to be merged and the reserved node. If at least one hash slot in the slot to be merged was managed by the reserved node before scaling down, the vector with no intersection is 0; otherwise, the vector with no intersection is 1. Based on the primary slot intersection vector, the primary 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 to be merged is determined. The affinity weight reflects the historical association between the slot to be merged and the reserved node.

7. The method according to claim 6, characterized in that, The step of determining the affinity weight of the slot block to be merged 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 includes: 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 the sum of the first product and the second product, and determining the difference between the sum of the products and the vector with no intersection as the affinity weight of the slot block 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: determining the set of scaled-down slot blocks that each reserved node can manage from all the scaled-down slot blocks through a permutation and combination algorithm and a pruning optimization method; and determining the primary node and backup node of each scaled-down slot block among all the reserved nodes based on the set of scaled-down slot blocks that each reserved node can manage.

9. A computer device, characterized in that, include: At least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being configured to cause the processor to perform the method of 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