Method for controlling data node, electronic equipment and readable storage medium
By dividing data nodes by domain in distributed data storage and using dynamic adjustment algorithms, the traditional low-efficiency operation by node is solved, and efficient data management and load balancing are achieved.
Patent Information
- Application Number
- CN202510755045.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-06
- Publication Date
- 2025-08-08
AI Technical Summary
The traditional node-by-node operation method is less efficient in distributed data storage scenarios and cannot meet the needs of large-scale data storage and efficient access.
By controlling the data nodes in the first and second domains divided by data shards, performing operations uniformly and providing data services, ensuring that the number of data nodes in each domain is balanced, and a dynamic adjustment algorithm is used to optimize the distribution of data shards.
It improves operational execution efficiency, ensures that the access to data shard content does not affect the data storage process, and realizes load balancing and efficient data management.
Smart Images

Figure CN120455478A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and in particular to a method for controlling a data node, an electronic device, and a readable storage medium. Background Art
[0002] With the continuous development of the internet and big data technologies, data volumes are exploding. Traditional methods of using a single node for data storage can no longer meet the demands of large-scale data storage and efficient access. To address this challenge, multiple data nodes are now widely used for data storage.
[0003] In some scenarios where unified operations need to be performed on multiple data nodes (such as software upgrade operations), related technologies generally adopt a node-by-node rolling operation (such as node-by-node rolling upgrade), which has the problem of low processing efficiency. Summary of the Invention
[0004] The embodiments of the present application provide a method for controlling a data node, an electronic device, and a readable storage medium, which can solve the problem of low operational execution efficiency in the related art in a distributed data storage scenario.
[0005] In a first aspect, an embodiment of the present application provides a method for controlling a data node, including: Controlling a plurality of first data nodes in the first domain to perform a first operation; controlling a plurality of second data nodes in the second domain to provide data services; The first domain and the second domain are both domains divided by data shards, the data shards in the first domain are distributed on the multiple first data nodes, and the data shards in the second domain are distributed on the multiple second data nodes; The first domain contains the content of any data slice in the second domain, and the second domain contains the content of any data slice in the first domain.
[0006] In a second aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, wherein the memory stores a program or instruction, and when the program or instruction is executed by the processor, the method described in the first aspect is implemented.
[0007] In a third aspect, an embodiment of the present application provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the method described in the first aspect is implemented.
[0008] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program, which implements the method described in the first aspect when executed by a processor.
[0009] In an embodiment of the present application, multiple first data nodes in the first domain are controlled to perform a first operation, and multiple second data nodes in the second domain are controlled to provide data services; wherein, the first domain and the second domain are both domains divided according to data shards, and the data shards on the first domain are distributed on the multiple first data nodes, and the data shards on the second domain are distributed on the multiple second data nodes; the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain. In this way, multiple first data nodes are controlled to uniformly perform the first operation according to the first domain, and there is no need to perform the first operation node by node. In the scenario of distributed data storage, the execution efficiency of the first operation can be greatly improved. Moreover, the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain, which can ensure that access to the content of the data shards will not be affected during the execution of the operation. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 This is a flow chart of a method for controlling a data node provided by an embodiment of the present application; Figure 2 This is a schematic diagram of an implementation environment of a method for controlling a data node provided in an embodiment of the present application; Figure 3 This is a schematic diagram of a copy of a data shard accessed according to an embodiment of the present application; Figure 4 This is a flowchart of another method for controlling a data node provided by an embodiment of the present application; Figure 5 This is a schematic diagram of a data node scaling process provided by an embodiment of the present application; Figure 6 This is a schematic diagram of replica distribution before shard migration provided by an embodiment of the present application; Figure 7-1 A schematic diagram of replica distribution during shard migration provided in an embodiment of the present application; Figure 7-2 A schematic diagram of replica priority setting during shard migration provided in an embodiment of the present application; Figure 8 This is a schematic diagram of replica distribution after shard migration provided by an embodiment of the present application; Figure 9 This is a flow chart of a data node elastic expansion process provided by an embodiment of the present application; Figure 10 This is an example schematic diagram of a shard splitting provided in an embodiment of the present application; Figure 11 This is a schematic diagram of a shard splitting process provided in an embodiment of the present application; Figure 12 This is a specific flow chart of a method for controlling a data node provided by an embodiment of the present application; Figure 13 This is a structural block diagram of a device for controlling a data node provided in an embodiment of the present application; Figure 14 This is a structural block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0011] The following will be combined with the accompanying drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the embodiments described are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field are within the scope of protection of this application.
[0012] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.
[0013] The method for controlling data nodes provided in the embodiment of the present application can be applied to the control technology of data nodes. Multiple first data nodes are controlled according to the first domain to uniformly perform the first operation without having to execute the first operation node by node. In the scenario of distributed data storage, the execution efficiency of the first operation can be greatly improved.
[0014] The method for controlling a data node provided in an embodiment of the present application can be executed by a management node, wherein the management node can be a server, such as an independent physical server, a server cluster composed of multiple servers, or a cloud server capable of cloud computing. For example, the data node in an embodiment of the present application can be a data storage node in a distributed database, and the management node can be a node device in the distributed database used to control and manage the data node.
[0015] The method for controlling a data node provided by the embodiment of the present application is described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.
[0016] Please refer to Figure 1 , Figure 1This is a flow chart of a method for controlling a data node provided by an embodiment of the present application, which can be executed by a management node. Figure 1 As shown, the method includes: Step 110: Control multiple first data nodes in the first domain to perform a first operation.
[0017] In an embodiment of the present application, multiple domains may be obtained according to data sharding, and the first domain is any one of the multiple domains. The first domain includes multiple first data nodes, and a first operation may be uniformly performed on the multiple first data nodes within the first domain according to the first domain control. The first data node may be a node device for storing data in a distributed database, and the first operation may be a data operation applicable to the multiple first data nodes, such as a data update operation or a software upgrade operation.
[0018] Step 120: Control multiple second data nodes in the second domain to provide data services; The first domain and the second domain are both domains divided by data shards, the data shards on the first domain are distributed on the multiple first data nodes, and the data shards on the second domain are distributed on the multiple second data nodes; the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain.
[0019] In an embodiment of the present application, similar to the first domain, the second domain may also be any one of the multiple domains, and the second domain includes multiple second data nodes, and the second data nodes may be node devices for storing data in a distributed database. The number of second data nodes included in the second domain may be the same as or different from the number of first data nodes included in the first domain. While controlling the execution of the first operation on the multiple first data nodes in the first domain, the multiple second data nodes in the second domain may be controlled to provide data services, and the data services may be services supported by the second data nodes, such as data access, data query or data storage services. In this way, even if the multiple first data nodes in the first domain are unable to provide data services when performing the first operation, the multiple second data nodes in the second domain may provide data services.
[0020] In one embodiment of the present application, after the multiple first data nodes in the first domain complete the execution of the first operation, the multiple second data nodes in the second domain can be controlled to execute the second operation; and the multiple first data nodes in the first domain can be controlled to provide data services.
[0021] In an embodiment of the present application, the second operation may be a data operation applicable to the plurality of second data nodes, such as a data update operation or a software upgrade operation. The second operation and the first operation may be the same type of operation, for example, the second operation and the first operation both include a software upgrade operation, and the second operation and the first operation may be the same operation. In addition, the second operation and the first operation may also be different types of operations, for example, the first operation may be a data update operation, and the second operation may be a software upgrade operation.
[0022] After the multiple first data nodes in the first domain complete the first operation, they can continue to control the multiple second data nodes in the second domain to perform the second operation, thereby ensuring that data nodes in domains other than the first domain perform the relevant operation. While controlling the multiple second data nodes in the second domain to perform the second operation, the multiple first data nodes in the first domain can also be controlled to provide data services. In this way, even if the multiple second data nodes in the second domain are unable to provide data services while performing the second operation, the multiple first data nodes in the first domain can still provide data services.
[0023] After controlling multiple second data nodes in the second domain to perform the second operation, the other domains except the first domain and the second domain can continue to be controlled to perform related operations, thereby enabling multiple data nodes to perform operations by domain, which can improve processing efficiency and ensure that access to the data shard content will not be affected during the operation execution.
[0024] In one embodiment of the present application, the number of data nodes in different domains can be balanced, such that the difference in the number of data nodes in different domains is less than or equal to a fixed value. For example, if the fixed value is 1, the first domain may include 4 data nodes, and the second domain may include 3 nodes. Furthermore, the number of the plurality of first data nodes and the number of the plurality of second data nodes can be the same. In other words, when dividing multiple domains, the number of data nodes in each domain can be the same, thereby ensuring load balancing within each domain.
[0025] In one embodiment of the present application, the same data shard contains multiple copies, and the multiple copies are distributed on different target nodes. One of the target nodes contains one copy of the multiple copies, and the target node is the first data node or the second data node.
[0026] In an embodiment of the present application, data sharding is a technology that divides a large database or data set into smaller, more manageable shards, and the same data shard can be distributed on multiple data nodes, and the multiple data nodes can include both the first data node on the first domain and the second data node on the second domain. The same data shard can include multiple copies, and the multiple copies can be the same copies or different copies. The multiple copies can be distributed on different data nodes among the multiple data nodes, and the same data node may not have multiple copies of the same data shard distributed. For example, data shard A includes copy 1, copy 2, and copy 3, then copy 1, copy 2, and copy 3 need to be distributed on 3 different data nodes respectively, for example, copy 1 is distributed on data node 1, copy 2 is distributed on data node 2, and copy 3 is distributed on data node 3, where data node 1, data node 2, and data node 3 can be from different domains.
[0027] In one embodiment of the present application, the multiple replicas may include a primary replica and a backup replica. For example, the multiple replicas contained in the same data shard may include a primary replica and one or more backup replicas corresponding to the primary replica.
[0028] The primary replica and backup replica of the same data shard can be distributed in different domains, with the primary replica distributed in a first designated domain and the backup replica distributed in a second designated domain. The first designated domain is one of the first and second domains, and the second designated domain is the other of the first and second domains.
[0029] Through the above-mentioned distribution method, multiple primary copies from different data shards can be distributed on any data node in the first designated domain, and the multiple backup copies corresponding to the multiple primary copies can be distributed on other domains except the first designated domain, for example, the multiple backup copies corresponding to the multiple primary copies are distributed on multiple data nodes in the second designated domain. In order to ensure the load balancing of the multiple backup copies on the multiple data nodes in the second designated domain. In one embodiment of the present application, any data node in the first designated domain contains multiple primary copies of multiple different data shards, and the multiple backup copies corresponding to the multiple primary copies are evenly distributed on all data nodes in the second designated domain. Among them, the multiple primary copies and the multiple backup copies are all copies of the multiple different data shards.
[0030] The balanced distribution here is used to ensure that the difference in the number of backup replicas distributed on any two data nodes in the second designated domain is less than a preset threshold, which may be, for example, 1 or 2. Specifically, the balanced distribution may be, for example, an even distribution, where the multiple backup replicas corresponding to the multiple primary replicas are evenly distributed across all data nodes in the second designated domain, such that the same number of backup replicas is distributed on each data node in the second designated domain. The backup replicas in this section are the backup replicas among the multiple backup replicas corresponding to the multiple primary replicas.
[0031] In addition, it can ensure that the number of primary replicas distributed on each data node in the same domain is similar, and the number of backup replicas distributed on each data node in the same domain is similar, thereby ensuring load balancing of data nodes in the domain.
[0032] Specifically, in one embodiment of the present application, any one data node in the first designated domain contains multiple primary copies of multiple different data shards and multiple backup copies of multiple different data shards, the difference in the number of primary copies on any two data nodes in the first designated domain is less than a first preset value, and the difference in the number of backup copies on any two data nodes in the first designated domain is less than a second preset value. The first preset value and the second preset value can be adaptively adjusted, and the first preset value and the second preset value can be the same, for example, the first preset value and the second preset value are both 1. Alternatively, the first preset value and the second preset value can be different, for example, the first preset value is 1 and the second preset value is 2.
[0033] In an embodiment of the present application, multiple first data nodes in the first domain are controlled to perform a first operation, and multiple second data nodes in the second domain are controlled to provide data services; wherein, the first domain and the second domain are both domains divided according to data shards, and the data shards on the first domain are distributed on the multiple first data nodes, and the data shards on the second domain are distributed on the multiple second data nodes; the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain. In this way, multiple first data nodes are controlled to uniformly perform the first operation according to the first domain, and there is no need to perform the first operation node by node. In the scenario of distributed data storage, the execution efficiency of the first operation can be greatly improved. Moreover, the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain, which can ensure that access to the content of the data shards will not be affected during the execution of the operation.
[0034] Please refer to Figure 2 , Figure 2 Schematic diagram of an implementation environment of a method for controlling data nodes provided in an embodiment of the present application. Figure 2 As shown, the method for controlling data nodes provided in an embodiment of the present application involves a management node, a client and a data node.
[0035] The management node is responsible for data node management, shard distribution calculation, shard copy status management, and data migration. The management node can directly control the data node. The data node is used to store document data, which can be divided according to multiple tenants. Data of different business functions can be physically isolated by tenants. The client can be used to obtain topology information from the management node, and can determine the corresponding data shard based on the topology information, thereby selecting a shard copy with normal access status from the multiple copies of the data shard contained in the data node. The topology information may include the hash key range contained in the data shard, the data nodes corresponding to the multiple copies of the data shard, and the access status of the multiple copies of the data shard.
[0036] Please refer to Figure 3 , Figure 3 This is a schematic diagram of a copy of a data shard provided by an embodiment of the present application. Figure 3 As shown, the client can calculate the corresponding hash key range (such as Figure 3 At the same time, the client can obtain topology information from the management node, which includes the hash key range contained in the data shards, thereby obtaining the mapping relationship between the hash key and the data shards, such as Figure 2 Data shard 1 corresponds to hash keys 1 and 2, data shard 2 corresponds to hash keys 3 and 4, data shard 3 corresponds to hash key 5, data shard 4 corresponds to hash key 6, and data shard M corresponds to hash key N. The multiple replicas contained in each data shard are distributed on different data nodes, so that a shard replica with normal access status can be selected from the data node for data access.
[0037] See Figure 4 , Figure 4 This is a flow chart of another method for controlling data nodes provided by an embodiment of the present application. Figure 4 As shown, the method includes the following steps: Step 410: Distribute data shards to the first domain and the second domain.
[0038] In an embodiment of the present application, data shards may be initially distributed to the first domain and the second domain. Specifically, the data shards may be distributed to the first domain and the second domain using a random allocation method, or the data shards may be distributed to the first domain and the second domain using a distribution algorithm, such as a hash algorithm or a consistent hash algorithm.
[0039] Taking the consistent hashing algorithm as an example, the maximum number of copies of the same data shard distributed on a domain can be predetermined. Specifically, the maximum number of copies of the same data shard distributed on a domain must meet the following conditions: ,in, It is used to indicate the maximum number of copies of data shard A distributed on a domain, and ceiling() is used to indicate rounding up. Then, the consistent hashing algorithm can be used to calculate the data node to which the copy of each data shard belongs. If other copies of the data shard are already distributed on the belonging data node, or the number of copies distributed on the belonging data node is greater than or equal to the maximum number corresponding to the data shard, the next data node of the belonging data node on the hash ring can be selected, and the judgment of whether the next data node meets the condition can be continued. Until the selected data node does not meet the condition, the copy of the data shard can be distributed on the data node.
[0040] Step 420: Dynamically adjust the distribution of target data shards; wherein the target data shards include at least one of data shards located on the first domain and data shards located on the second domain.
[0041] In an embodiment of the present application, to further ensure that data shards are evenly distributed across the first and second domains, the distribution of the data shards can be dynamically adjusted. The dynamic adjustment of the distribution of the target data shards can be an inter-domain adjustment, such as migrating a data shard from the first domain to the second domain, or migrating a data shard from the second domain to the first domain. Alternatively, the dynamic adjustment of the distribution of the target data shards can be an intra-domain adjustment, such as migrating a data shard located on a data node to another data node.
[0042] In one embodiment of the present application, the target data shards include data shards located in a first set; and the dynamically adjusting the distribution of the target data shards includes controlling the migration of the data shards in the first set to a second set. The first set and the second set are located in the same target domain, which is either the first domain or the second domain; and the number of data shards in the first set is greater than the number of data shards in the second set.
[0043] Because the number of data shards on the data nodes in the first set is greater than the number of data shards on the data nodes in the second set, a data node with the largest number of data shards can be selected from the first set. Any data shard on this data node can be migrated from this data node to any data node in the second set. This approach ensures a balanced distribution of data shards in the first and second sets to a certain extent.
[0044] In one embodiment of the present application, the first set and the second set may also be located in different domains. That is, the first set may be located in the first domain, and the second set may be located in the second domain. The same method can be used to ensure balanced distribution of data shards between the first set located in the first domain and the second set located in the second domain. In fact, the first set may be one of the first and second domains, and the second set may be the other of the first and second domains.
[0045] In one embodiment of the present application, the number of data shards contained in any data node in the first set is greater than a preset average, and the number of data shards contained in any data node in the second set is less than the preset average, wherein the preset average is obtained based on the total number of data shards and the total number of data nodes.
[0046] In an embodiment of the present application, the preset average value may be the theoretical capacity of data shards distributed on any data node, and the quotient of the total number of data shards and the total number of data nodes may be determined as the preset average value. Data nodes among the multiple data nodes having a number of data shards greater than the average shard capacity may be grouped into a first set, and data nodes among the multiple data nodes having a number of data shards less than or equal to the average shard capacity may be grouped into a second set. Data shards located in the first set may be controlled to be migrated to the second set.
[0047] In the embodiments of this application, two algorithms are provided for dynamically adjusting the distribution of target data shards. The first algorithm is an improved consistent hashing algorithm, and the second algorithm is a dynamic weighted shard distribution algorithm. The following describes the first algorithm first.
[0048] In one embodiment of the present application, controlling the migration of data shards from the first set to the second set includes controlling the migration of a specified data shard from the first set to a specified data node in the second set. Each data shard in the first set has a shard hash value, and each data node in the second set has a node hash value. The difference between the shard hash value of the specified data shard and the node hash value of the specified data node is minimized.
[0049] In an embodiment of the present application, the shard hash value of each data shard in the first set can be determined, and the node hash value of each data node in the second set can be determined. For any data shard in the first set and any data node in the second set, the difference between the shard hash value of the data shard and the node hash value of the data node can be determined, and sorted from large to small. The data shard-data node pair with the smallest difference can be selected to determine whether the data node in the data shard-data node pair has been distributed with other copies of the data shard in the data shard-data node pair, and whether the maximum number of distributed copies on the target domain has been reached. If the above conditions are met, the next data shard-data node pair is selected based on the sorting of the difference, until a shard-data node pair that does not meet the above conditions is selected, the data node in the shard-data node pair is determined as the designated data node, the data shard in the shard-data node pair is determined as the designated data shard, and the designated data shard is migrated to the second set.
[0050] The following describes the second algorithm, the dynamic weighted sharding distribution algorithm. The dynamic weighted sharding distribution algorithm migrates a copy of a data shard from one data node to another, where both data nodes are located in the same domain.
[0051] Specifically, in one embodiment of the present application, the dynamic adjustment of the distribution of the target data shards includes: controlling the migration of the target data shards located on the first designated node to the second designated node. The first designated node and the second designated node are located in the same target domain; the first designated node is the data node with the largest weight in the target domain, and the second designated node is the data node with the smallest weight in the target domain; the target domain is the first domain or the second domain. The weight of the data node is positively correlated with the number of data shards on the data node, and the data node is the first data node or the second data node.
[0052] In an embodiment of the present application, in the process of dynamically adjusting the distribution of data shards, dynamic adjustments can be made domain by domain. For example, the distribution of data shards in the first domain can be adjusted first, and then the distribution of data shards in the second domain can be adjusted. Regarding the weight calculation of data nodes, the weight of a data node is positively correlated with the number of data shards on the data node. That is to say, the core idea of this algorithm is to select data shards from data nodes with a larger number of data shards and migrate the data shards to data nodes with a smaller number of data shards. At the same time, in the process of data shard migration, the hashing characteristics of the data shard distribution can also be guaranteed to ensure that when a data node in a domain fails, the load can be hashed and shared to all data nodes in another domain. The calculation formula for the weight of a data node is slightly different according to different migration strategies. For example, the weight of a data node is positively correlated with the number of primary copies on the data node, or the weight of a data node is positively correlated with the number of backup copies on the data node.
[0053] In one embodiment of the present application, the same data shard may contain multiple replicas. When controlling the migration of a target data shard, migration may be performed for one or more replicas within the data shard. Where the same data shard contains multiple replicas, and the multiple replicas include a primary replica and a backup replica, the target data shard is at least one of the primary replica and the backup replica. In other words, migration may be performed for the primary replica within a data shard, for the backup replica within a data shard, or for both the primary and backup replicas within a data shard.
[0054] In one embodiment of the present application, the controlling of migrating the target data shard located on the first designated node to the second designated node is performed after the number of data nodes in the target domain is expanded from the first number to the second number.
[0055] In fact, when the business access volume of the data node increases or the amount of data increases, the data node may reach a performance bottleneck. At this time, new data nodes can be expanded, that is, the data nodes in the target domain can be expanded from the first number to the second number. When the data nodes in the target domain are expanded from the first number to the second number, there are new data nodes in the target domain, and the original first number of data nodes in the target domain can be recorded as old data nodes. There are no copies of the data shards distributed on the new data nodes for the time being. At this time, the distribution of data shards on the old and new data nodes is uneven. The data shards on the old data nodes can be migrated to the new data nodes to ensure that the distribution of data shards on the old and new data nodes is balanced. The dynamic weight shard distribution algorithm provided in the embodiment of the present application can be applied to this scenario. The following will be introduced by taking the distribution adjustment of data shards in this scenario as an example. However, it should be noted that the dynamic weight shard distribution algorithm is not only used in this scenario, but can be used in any scenario where the distribution of data shards needs to be adjusted.
[0056] Correspondingly, when the business access volume of the data node decreases, the data volume decreases, the data node load and the memory usage are low, the data node can be scaled in and out, that is, the data nodes in the target domain can be reduced from the first number to the third number, and the third number is smaller than the first number. After the data node is reduced, the copy of the data shard on the reduced data node can be migrated to the non-reduced data node, and the reduced data node is the offline node. Figure 5 , Figure 5 This is a flow chart of a data node scaling process provided by an embodiment of the present application. Figure 5 As shown, after scaling data nodes, the data shard distribution can be recalculated and migrated. The data shard distribution method after scaling data nodes is similar to the data shard distribution method after scaling data nodes. The scaled-down data nodes can be grouped into a first set, and the non-scaled data nodes can be grouped into a second set. The data shard distribution after scaling data nodes is recalculated using this method.
[0057] The dynamic weight sharding distribution algorithm can be implemented based on a quantization matrix. The idea is to quantize the distribution relationship between replicas between domains through the matrix, calculate the weight of each data node in the target domain according to the quantization matrix, sort all data nodes in the target domain by weight, select data shards from the data node with the largest weight, and migrate the selected data shards to the data node with the smallest weight. Repeat the above process until the quantization matrix is balanced.
[0058] Specifically, in one embodiment of the present application, before the control migrates the target data shard located on the first designated node to the second designated node, a first matrix may be constructed for the first designated domain, and a second matrix may be constructed for the second designated domain; the elements L in the first matrix areij The number of backup copies of the primary replica on the i-th node of the first specified domain on the j-th node of the second specified domain is represented by the element R in the second matrix. ij represents the number of backup replicas on the jth node of the first designated domain for the primary replica on the i-th node of the second designated domain; i and j are both positive integers less than the second number. The first designated domain is one of the first and second domains, and the second designated domain is the other of the first and second domains. The first and second designated nodes are obtained based on the first matrix or the second matrix.
[0059] In an embodiment of the present application, after the data shards are initially distributed to the first domain and the second domain, matrices can be constructed for the first domain and the second domain, respectively, to obtain a first matrix corresponding to the first designated domain and a second matrix corresponding to the second designated domain. Taking the example of expanding the number of data nodes in the first designated domain and the second designated domain from 3 to 5, and a total of 256 data shards distributed in the first designated domain and the second designated domain, the following first matrix and second matrix can be obtained for the first designated domain and the second designated domain: ; in, is the first matrix, is the second matrix, and the element L in the first matrix ij The number of backup copies of the primary replica on the i-th node of the first specified domain on the j-th node of the second specified domain is represented by the element R in the second matrix. ij Indicates the number of standby replicas on the j-th node of the first specified domain for the primary replica on the i-th node of the second specified domain. Both i and j are positive integers less than the second number (5 in the above example).
[0060] Using the first matrix and the second matrix, we can obtain the number of primary replicas on the i-th node of the first designated domain, the number of backup replicas on the i-th node of the first designated domain, the total number of primary replicas and backup replicas on the i-th node of the first designated domain, the number of primary replicas on the j-th node of the second designated domain, the number of backup replicas on the j-th node of the second designated domain, and the total number of primary replicas and backup replicas on the j-th node of the second designated domain. The specific calculation process is as follows: ; ; ; ; ; ; in, Used to indicate the second quantity, is the number of primary replicas on the i-th node of the first specified domain, The number of standby replicas on the i-th node of the first specified domain, is the total number of primary and standby replicas on the i-th node of the first specified domain, The number of primary replicas on the j-th node of the second specified domain, Specifies the number of standby replicas on the jth node of the second domain, Specifies the total number of primary and standby replicas on the j-th node of the second domain.
[0061] In one embodiment of the present application, after the first matrix and the second matrix are constructed, the element L with the largest weight can be selected from the first matrix. xy and the element with the smallest weight L mn . Wherein, 1≤x,y≤N1, N1<m≤N2, 1≤n≤N2, N1 is the first number, and N2 is the second number. The control migrates the target data shard located on the first designated node to the second designated node, including: for the target data shard with the primary copy on the xth node on the first designated domain and the backup copy on the yth node on the second designated domain, controlling the migration of the primary copy of the xth node on the first designated domain to the mth node on the first designated domain, and controlling the migration of the backup copy of the yth node on the second designated domain to the nth node on the second designated domain.
[0062] In an embodiment of the present application, a target data shard can be selected from an old data node in a first designated domain, and the target data shard can be migrated to a new data node in the first designated domain. The first goal of this migration is that the difference between the number of master copies distributed on the new data node in the first designated domain and the number of master copies distributed on the old data node is less than a first preset value. This migration can ensure that: the number of master copies of the new data node and the old data node in the first designated domain is balanced, the backup copies corresponding to the master copies on the new data node in the first designated domain are evenly distributed on the second designated domain, and the backup copies of the old data nodes in the first designated domain are evenly distributed on the new data nodes in the second designated domain. The first designated domain is any one of the first and second domains. In actual implementation, the distribution of data shards in the first domain can be adjusted using the above method with the first designated domain as the first domain, and then the distribution of data shards in the second domain can be adjusted using the above method with the first designated domain as the second domain, so as to achieve a uniform distribution of data shards in the first and second domains.
[0063] In order to achieve the above first goal, the data node with the most distributed master copies (i.e. The data node with the largest number of backup copies distributed on any data node in the second designated domain is selected from the first designated domain with the second priority (i.e., L ij The data node with the largest number of primary and backup copies (i.e. Under this priority setting, the weight of each element in the first matrix can be calculated by the following formula: ; Among them, << is used to represent the left shift operation in binary. is used to represent the weight of the element in the i-th row and j-th column of the first matrix, is the number of primary replicas on the i-th node of the first specified domain, L ij Indicates the number of standby replicas of the primary replica on the i-th node of the first specified domain on the j-th node of the second specified domain, Specifies the number of standby replicas on the j-th node for the second domain.
[0064] In the above formula, Left shift 16 bits to indicate The weight ratio is the largest, L ij Left shift 8 bits is used to indicate L ij The second largest weight ratio is The weight ratio of (1 in the above formula) is the smallest. Shift left 16 bits and L ij Left shift 8 bits is just an example, you can also use Shift left 8 bits and L ij This is accomplished by shifting left by 4 bits.
[0065] In this case, the element L with the largest weight can be determined from the first matrix xy and the element with the smallest weight L mn. Then, for one or more data shards whose primary copy is at the xth node on the first designated domain and whose backup copy is at the yth node on the second designated domain, any one data shard can be selected from the one or more data shards as the target data shard, and the primary copy of the target data shard can be controlled to be migrated to the mth node on the first designated domain, and the backup copy of the target data shard at the yth node on the second designated domain can be controlled to be migrated to the nth node on the second designated domain. Wherein, x and y are both positive integers less than or equal to the first number, and m and n are both positive integers greater than the first number and less than or equal to the second number. If the element L with the smallest weight is calculated mn Make n less than or equal to the first number, and n is not equal to y. To avoid data shards from migrating between old data nodes, the next element can be selected from the first matrix in descending order of weight until the selected element does not meet the above conditions.
[0066] With the first matrix above For example, it can be calculated that the element with the largest weight in the first matrix is L 13 , the element with the smallest weight is L 44 、L 45 、L 54 and L 55 , where the four elements have the same weight, one can be randomly selected as the element with the smallest weight, for example, L 44 As the element with the smallest weight, for any data shard whose primary copy is on the first node of the first designated domain and whose backup copy is on the third node of the second designated domain, the primary copy of the data shard on the first node of the first designated domain can be migrated to the fourth node of the first designated domain, and the backup copy of the data shard on the third data node of the first designated domain can be migrated to the fourth node of the first designated domain.
[0067] In an embodiment of the present application, during the data shard migration process, the first matrix and the second matrix can be updated synchronously. The above migration process can be repeated until the above first goal is achieved, that is, the difference between the number of primary replicas distributed on the new data nodes in the first designated domain and the number of primary replicas distributed on the old data nodes is less than a first preset value. At this time, the following first matrix and second matrix can be obtained: .
[0068] In one embodiment of the present application, after the first matrix and the second matrix are constructed, the element L with the largest weight can be selected from the elements in the i-th row of the first matrix. iy and the element with the smallest weight L in; wherein, 1≤i≤N1, 1≤y≤N1, N1<n≤N2, N1 is a first number, and N2 is a second number. The control of migrating a target data shard located on a first designated node to a second designated node includes: for a target data shard whose primary copy is located on the i-th node of the first designated domain and whose backup copy is located on the y-th node of the second designated domain, controlling the migration of the backup copy on the y-th node of the second designated domain to the n-th node of the second designated domain.
[0069] In an embodiment of the present application, the first designated node includes the yth node on the second designated domain, and the second designated node includes the nth node on the second designated domain. To ensure that the backup replicas corresponding to the primary replica on the i-th data node on the first designated domain are evenly distributed across all nodes on the second designated domain, the backup replicas distributed on the second designated domain can be migrated between domains. The second goal of this migration is that the difference between the number of backup replicas on any data node on the first designated domain and any two data nodes on the second designated domain is less than a third preset value, which can be 1. In other words, this migration ensures that the backup replicas corresponding to the primary replicas distributed on the old data nodes on the first designated domain are evenly distributed across the second designated domain.
[0070] To achieve the second goal, the data node with the largest total number of primary and backup copies (i.e. The data node with the largest number of backup copies (i.e. The data node with the largest number of backup copies corresponding to the primary copy of the same data node in the first specified domain is selected from the second specified domain with the third priority (i.e., L ij Under this priority setting, the weight of each element in the first matrix can be calculated by the following formula: ; Among them, << is used to represent the left shift operation in binary. is used to represent the weight of the element in the i-th row and j-th column of the first matrix, is the total number of primary and standby replicas on the j-th node of the second specified domain, The number of standby replicas on the jth node of the second specified domain, L ij Indicates the number of standby replicas of the primary replica on the i-th node of the first specified domain on the j-th node of the second specified domain.
[0071] In the above formula, Left shift 16 bits to indicate The weight ratio is the largest. Left shift 8 bits to indicate The weight ratio is the second largest, L ij The weight ratio of (1 in the above formula) is the smallest. Left shift 16 bits and Left shift 8 bits is just an example, you can also use Left shift 8 bits and This is accomplished by shifting left by 4 bits.
[0072] The weights of the elements in the first matrix can be calculated row by row, and the element with the largest weight L can be determined for the elements in the i-th row of the first matrix. iy and the element with the smallest weight L in Then, for one or more data shards whose primary copy is on the i-th node of the first designated domain and whose backup copy is on the y-th node of the second designated domain, any one data shard can be selected from the one or more data shards as the target data shard, and the backup copy of the target data shard on the y-th node of the second designated domain can be controlled to be migrated to the n-th node of the second designated domain. Here, i and y are both positive integers less than or equal to the first number, and n is a positive integer greater than the first number and less than or equal to the second number.
[0073] In the embodiment of the present application, the migration process for achieving the second goal can be performed after the migration process for achieving the first goal is completed, or the migration process for achieving the second goal can be performed independently. Here, taking the migration process for achieving the second goal after the migration process for achieving the first goal as an example, for the first matrix and the second matrix obtained after the migration process for achieving the first goal is completed, the above formula can be used to determine the element with the largest weight from the first row elements of the first matrix as L 12 and L 13 , where the weights of the two elements are the same, one can be randomly selected as the element with the largest weight, for example, select L 12 As the element with the largest weight. The element with the smallest weight can be determined from the elements in the first row of the first matrix as L 14 and L 15 , where the two elements have the same weight, one of them can be randomly selected as the element with the smallest weight, for example, L 14 As the element with the smallest weight, for any data shard whose primary copy is on the first node of the first designated domain and whose backup copy is on the second node of the second designated domain, the backup copy of the data shard on the second node of the second designated domain can be migrated to the third node of the second designated domain.
[0074] In this embodiment of the present application, during the data shard migration process, the first matrix and the second matrix can be updated synchronously. The above migration process can be repeated until the above second goal is achieved, that is, the difference in the number of primary replicas on any data node in the first designated domain and the number of backup replicas on any two data nodes in the second designated domain is less than a third preset value. At this time, the following first matrix and second matrix can be obtained: .
[0075] In one embodiment of the present application, after the first matrix and the second matrix are constructed, the node y with the largest weight and the node n with the smallest weight can be selected from the first matrix. The control of migrating the target data shard located on the first designated node to the second designated node includes: if the node i exists in the second designated domain, making R iy -R in ≥ a fixed value. For a target data shard with a primary replica on the i-th node in the second designated domain and a backup replica on the y-th node in the first designated domain, control the migration of the backup replica on the y-th node in the first designated domain to the n-th node in the first designated domain. Where 1≤i≤N2, 1≤y≤N2, 1<n≤N2, and N2 is the second number.
[0076] In this embodiment of the present application, the first designated node includes the yth node in the first designated domain, and the second designated node includes the nth node in the first designated domain. To ensure a balanced number of distributed standby replicas across all nodes in the first designated domain, inter-domain migration can be performed on the distributed standby replicas in the first designated domain. A third migration goal is to ensure that the difference in the number of distributed standby replicas between any two data nodes in the first designated domain is less than a second preset value.
[0077] This migration process can be used to achieve a balanced distribution of backup replicas across the first designated domain, provided that the distribution of primary replicas across the first designated domain is already balanced, thereby achieving a balanced total number of primary and backup replicas across the first designated domain. In fact, the migration process used to achieve the third goal can be performed after the migration process used to achieve the first goal. In this way, the difference in the total number of primary and backup replicas distributed across any two data nodes in the first designated domain can be less than a fourth preset value, which can be 1 or 2.
[0078] To achieve the third goal, the data node with the largest total number of primary and backup copies (i.e. The data node with the largest number of backup copies (i.e. The first designated domain is migrated based on the number of data nodes with the largest number of primary and backup replicas. Specifically, the first designated domain contains multiple data nodes with the largest number of primary and backup replicas. The data node with the largest number of backup replicas is selected from these nodes. Under this priority setting, the weight of each data node in the first designated domain can be calculated using the following formula: ; in, is the weight of the ith node in the first specified domain, is the total number of primary and standby replicas on the i-th node of the first specified domain, Specifies the number of standby replicas on the i-th node for the first domain.
[0079] After calculating the weight of each node in the first designated domain, the node y with the largest weight and the node n with the smallest weight can be selected from the data nodes in the first designated domain. For the i-th node in the second designated domain, it can be determined whether the following conditions are met: . If the i-th node meets the condition, then for any data shard with the primary copy on the i-th node on the second designated domain and the backup copy on the y-th node on the first designated domain, the backup copy of the data shard on the y-th node of the first designated domain is migrated to the n-th node of the first designated domain. If each data node in the second designated domain does not meet the above condition, skip this process. Repeat the above process until the difference in the number of backup copies distributed on any two nodes on the first designated domain is less than the second preset value, which means that the backup copies distributed on the first designated domain are now balanced.
[0080] Taking the first matrix and the second matrix obtained after the migration process to achieve the second goal as an example, the weights of the five nodes in the first designated domain can be determined based on the first matrix and the second matrix, and the data node with the largest weight among the five nodes is determined to be the third node, and the data nodes with the smallest weight are the fourth and fifth nodes. Here, the fourth node is taken as the data node with the smallest weight. At this time, there is node 1 in the second designated domain, such that , then for any data shard whose primary copy is on the first node in the second designated domain and whose backup copy is on the third node in the first designated domain, the backup copy of the data shard on the third node in the first designated domain can be migrated to the fourth node in the first designated domain.
[0081] Repeat the above process until the difference in the number of standby replicas distributed on any two nodes in the first designated domain is less than a second preset value. The migration process is completed, and the following first matrix and second matrix can be obtained: .
[0082] Step 430: Control multiple first data nodes in the first domain to perform a first operation.
[0083] Step 440: Control multiple second data nodes in the second domain to provide data services.
[0084] In an embodiment of the present application, after the data shards are initially distributed to the first domain and the second domain, the data shards located on the first domain or the data shards located on the second domain can be dynamically adjusted to ensure that the data shards are evenly distributed on the first domain and the second domain.
[0085] The above examples illustrate how to determine which data shards need to be migrated and which data nodes they need to be migrated from. The following describes the specific process of migrating a data shard from one data node to another, using intra-domain replica migration as an example to illustrate the shard migration process.
[0086] Please refer to Figure 6 、 Figure 7-1 、 Figure 7-2 and Figure 8 , Figure 6 This is a schematic diagram of replica distribution before shard migration provided by an embodiment of the present application. Figure 7-1 A schematic diagram of replica distribution during shard migration provided in an embodiment of the present application is provided. Figure 7-2 A schematic diagram of replica priority setting during shard migration provided in an embodiment of the present application is provided. Figure 8 This is a schematic diagram of replica distribution after shard migration provided in an embodiment of the present application.
[0087] Before shard migration, Figure 6 As shown, the same domain contains data nodes 1 and 2. Data node 1 contains primary replicas s1-1, s2-1, and s3-2, while data node 2 contains primary replicas s4-1, s5-2, and s6-2. Primary replicas s1-1, s2-1, and s4-1 are all first replicas, while primary replicas s3-2, s5-2, and s6-2 are all second replicas. Both the first and second replicas are accessible to clients.
[0088] After adding data node 3 to the domain, we will take the migration of the primary replica s2-1 on data node 1 and the primary replica s6-2 on data node 2 to data node 3 as an example. The management node can create a third replica of the shard to be migrated on data node 3, that is, Figure 7-1The primary replica S6-3 and the primary replica S2-3 on data node 3, the third replica is used to represent a replica with low priority that does not allow client access, and then the data of the primary replica s2-1 on data node 1 and the primary replica s6-2 on data node 2 can be copied to the primary replica S6-3 and the primary replica S2-3 on data node 3.
[0089] like Figure 7-2 As shown in the figure, after the management node determines that all the third replicas have been copied, the third replica can be switched to the replica accessible to the client (i.e., the first and second replicas), and the original replica on data node 1 (i.e., the primary replica s2-1) and the original replica on data node 2 (i.e., the primary replica s6-2) can be switched to the fourth replica, i.e. Figure 7-1 The primary replica s2-4 on data node 1 and the primary replica s6-4 on data node 2 are used. The fourth replica is used to represent a replica with low priority that is not allowed to be accessed by clients. The fourth replica cannot copy data from other replicas and only allows other replicas to copy data from the fourth replica.
[0090] After the management node determines that all data of the fourth replica in the domain has been copied to the newly added replica in data node 3, the fourth replica in the domain can be deleted, that is, the primary replica s2-4 on data node 1 and the primary replica s6-4 on data node 2, completing the migration process. The replica distribution diagram after the migration process is completed in the domain is as follows Figure 8 As shown, the same domain contains data nodes 1, 2, and 3. Data node 1 contains the primary replica s1-1 and s3-2. Data node 2 contains the primary replica s4-1 and s5-2. Data node 3 contains the primary replica s2-1 and s6-2.
[0091] In one embodiment of the present application, the target data shard in the above embodiment may be a shard obtained by performing a splitting operation on the shard to be split. The splitting operation may split the shard to be split into multiple shards, and the target data shard may be one of the multiple shards. For the splitting process of the plurality of shards to be split, the data of the shard to be split may be divided according to a certain division rule to obtain multiple shards. The division rule is not limited and may be random division or even distribution.
[0092] In an embodiment of the present application, the split operation may be triggered based on the expansion of the data nodes in the target domain from the first number to the second number. Figure 9 , Figure 9 This is a flow chart of a data node elastic expansion process provided by an embodiment of the present application. Figure 9As shown in the figure, after the data node is expanded, the average number of primary replicas on each data node in the target domain after the expansion can be calculated. Specifically, the average value can be calculated using the following formula: ; Wherein, avg is used to represent the average value, S is used to represent the number of primary replicas in the target domain, is the second number. If the average value is less than the preset balance ratio, a splitting operation may be performed on the shards to be split within the target domain. If the average value is greater than or equal to the preset balance ratio, the splitting operation may not be performed. Then, since the number of data nodes within the target domain has expanded from the first number to the second number, the distribution of the data shards may be recalculated, and a migration operation may be performed on the replicas of the target shards. The distribution and migration of data shards can be referred to above; this section mainly introduces the splitting of data shards.
[0093] In the process of performing a split operation on the shards to be split within the target domain, the split operation may be performed on the shards to be split based on a split number. The split number may be a preset value, or the split number may be determined based on the second number, the number of shards to be split, and the preset balancing ratio. Specifically, the split number may be determined using the following formula: ; Wherein, n is used to represent the number of splits, is the second number, and IF is used to represent the preset balancing ratio. That is, each shard to be split in the target domain can be split into n shards, and each of the n shards contains the same number of hash keys.
[0094] Please refer to Figure 10 , Figure 10 This is an example diagram of a shard split provided by an embodiment of the present application. Figure 10 In the example, the split operation can be performed on both the first domain and the second domain, splitting each data shard into two shards. It should be noted that the same data shard contains multiple copies, and splitting the same data shard means splitting the multiple copies separately. For example, data shard 1 contains Figure 10 The primary copy 1 and the backup copy 1 in the data shard 1 are distributed on the data node 1 of the first domain, and the backup copy 1 is distributed on the data node 3 of the second domain. When the split operation is performed on the data shard 1, the primary copy 1 of the data shard 1 can be split into two primary copies, namely Figure 10 The primary replica 1 in a and primary replica 1 b , the backup copy 1 of the data shard 1 can be split into two backup copies, namely Figure 10 Backup copy 1 in aand standby replica 1 b .
[0095] In an embodiment of the present application, considering that the data shard splitting process should not affect the business operations of the data node, and that the data shard splitting process will occupy additional resources, multiple data shards on the same data node can be split serially.
[0096] In one embodiment of the present application, a splitting operation can be performed on the shard to be split in the following manner. Before dynamically adjusting the distribution of the target data shard, the shard to be split can be determined, and the shard to be split includes a first part and a second part; the data of the second part of the shard to be split is controlled to be copied to a blank shard to obtain a duplicate shard containing the data of the second part; after the data of the second part is copied, the first target operation on the first part of the shard to be split is controlled to access the shard to be split, and the second target operation on the second part of the shard to be split is controlled to access the duplicate shard. The first target operation includes at least one of a read operation and a write operation, and the second target operation includes at least one of a read operation and a write operation.
[0097] In an embodiment of the present application, the first part includes a portion of the hash keys in the shard to be split, and the second part includes another portion of the hash keys in the shard to be split, and there is no overlap between the first part and the second part. The number of hash keys contained in the first part and the number of hash keys contained in the second part can be the same, and the hash keys of the shard to be split can be evenly divided to obtain the first part and the second part. Figure 11 , Figure 11 This is a schematic diagram of a shard splitting process provided by an embodiment of the present application. Figure 11 The splitting process of shard X in is introduced as an example. The shard to be split can be Figure 11 In the process of splitting the shard X in the shard X, a blank shard can be created first, that is, Figure 11 Then, the hash key range (rangeX) of shard X to be split can be evenly divided into the first part (rangeX') and the second part (rangeN), and the data of the second part of shard X can be copied to shard N.
[0098] After the data of the second part is copied, a duplicate shard containing the data of the second part is obtained, and the hash key range associated with shard X and shard N can be adjusted, that is, the hash key range of the adjusted shard X only contains the first part, and the hash key range of shard N contains the second part. At this time, the first target operation on the first part of the shard to be split is controlled to access the shard to be split, and the second target operation on the second part of the shard to be split is controlled to access the duplicate shard. The first target operation includes at least one of a read operation and a write operation, and the second target operation includes at least one of a read operation and a write operation. That is to say, shard N is accessed for the addition, deletion, query, and modification of the data of the second part in shard X. Then, the data belonging to the second part in shard X can be deleted to complete the splitting operation of shard X.
[0099] By performing a split operation on the shard to be split, a remaining shard and a duplicate shard are obtained. The remaining shard may contain only the first portion of data, while the duplicate shard contains the second portion of data. Both the remaining shard and the duplicate shard can serve as the target data shards for the aforementioned migration process.
[0100] In one embodiment of the present application, during the data replication process of the second part, the query operation on the replicated shard is controlled to access the second part of the shard to be split, and the write operation on the replicated shard or the second part is controlled to access the replicated shard and the second part at the same time.
[0101] During the data replication process of the second part, the data on the replicated shard is incomplete. For query operations on the replicated shard, the second part of the shard to be split can be accessed to query the complete data. For write operations on the replicated shard, the replicated shard and the second part can be accessed at the same time to ensure that the data in the replicated shard is accurate. Figure 11 As shown in the figure, during the replication process of shard N, read operations (queries) on the second part of the data in shard X can access shard X. Write operations (such as add, delete, and modify operations) on the second part of the data in the blank shard X can be controlled simultaneously on shard X and the blank shard N. If the data does not exist in the blank shard N, a success response can be directly returned.
[0102] See Figure 12 , Figure 12 This is a specific flow chart of a method for controlling data nodes provided by an embodiment of the present application. Figure 12 As shown, the method includes the following steps: Step 1210: Distribute data shards to the first domain and the second domain.
[0103] Step 1220: Dynamically adjust the distribution of target data shards; wherein the target data shards include at least one of data shards located on the first domain and data shards located on the second domain.
[0104] In an embodiment of the present application, two methods for dynamically adjusting the distribution of target data shards are provided. In the first method, the target data shards include data shards located on a first set; the dynamic adjustment of the distribution of the target data shards includes: controlling the migration of the data shards on the first set to the second set. Wherein, the first set and the second set are located in the same target domain, and the target domain is the first domain or the second domain; the number of data shards on the first set is greater than the number of data shards on the second set. Wherein, the number of data shards contained in any data node in the first set is greater than a preset average value, and the number of data shards contained in any data node in the second set is less than the preset average value. Wherein, the preset average value is obtained based on the total number of data shards and the total number of data nodes.
[0105] In controlling the migration of data shards from the first set to the second set, the following method may be employed: controlling the migration of a specified data shard from the first set to a specified data node in the second set, wherein each data shard in the first set has a shard hash value, each data node in the second set has a node hash value, and the difference between the shard hash value of the specified data shard and the node hash value of the specified data node is minimized.
[0106] In the second method, the dynamic adjustment of the distribution of the target data shards includes: controlling the migration of the target data shards located on a first designated node to a second designated node. The first designated node and the second designated node are located in the same target domain; the first designated node is the data node with the highest weight in the target domain, and the second designated node is the data node with the lowest weight in the target domain; the target domain is the first domain or the second domain. The weight of the data node is positively correlated with the number of data shards on the data node, and the data node is the first data node or the second data node.
[0107] Wherein, if the same data shard includes multiple replicas, and the multiple replicas include a primary replica and a backup replica, the target data shard is at least one of the primary replica and the backup replica. Controlling the migration of the target data shard located on the first designated node to the second designated node is performed after the number of data nodes in the target domain is expanded from the first number to the second number.
[0108] Before the control migrates the target data slice located on the first designated node to the second designated node, a first matrix may be constructed for the first designated domain, and a second matrix may be constructed for the second designated domain; the elements L in the first matrix ij The number of backup copies of the primary replica on the i-th node of the first specified domain on the j-th node of the second specified domain is represented by the element R in the second matrix. ij represents the number of backup replicas on the jth node of the first designated domain for the primary replica on the i-th node of the second designated domain; i and j are both positive integers less than the second number. The first designated domain is one of the first and second domains, and the second designated domain is the other of the first and second domains. The first and second designated nodes are obtained based on the first matrix or the second matrix.
[0109] After the first matrix and the second matrix are constructed, the data shard distribution in the first designated domain and the second designated domain may be dynamically adjusted using at least one of the following three migration strategies.
[0110] The first migration strategy: select the element L with the largest weight from the first matrix xy and the element with the smallest weight L mn ; Wherein, 1≤x,y≤N1, N1<m≤N2, 1≤n≤N2, N1 is the first number, and N2 is the second number. In the process of controlling the migration of the target data shard located on the first designated node to the second designated node, for the target data shard with the primary copy on the xth node of the first designated domain and the backup copy on the yth node of the second designated domain, the primary copy on the xth node of the first designated domain can be controlled to be migrated to the mth node of the first designated domain, and the backup copy on the yth node of the second designated domain can be controlled to be migrated to the nth node of the second designated domain.
[0111] The second migration strategy: select the element with the largest weight L from the i-th row of the first matrix iy and the element with the smallest weight L in Wherein, 1≤i≤N1, 1≤y≤N1, N1<n≤N2, N1 is the first number, and N2 is the second number. In the process of controlling the migration of a target data shard located on a first designated node to a second designated node, for a target data shard with a primary replica on the i-th node of the first designated domain and a backup replica on the y-th node of the second designated domain, the backup replica on the y-th node of the second designated domain may be controlled to be migrated to the n-th node of the second designated domain.
[0112] The third migration strategy: select the node y with the largest weight and the node n with the smallest weight from the first matrix. In the process of controlling the migration of the target data shard located on the first designated node to the second designated node, the following method can be used: if there is a node i in the second designated domain, make R iy -R in ≥ a fixed value. For a target data shard with a primary replica on the i-th node in the second designated domain and a backup replica on the y-th node in the first designated domain, control the migration of the backup replica on the y-th node in the first designated domain to the n-th node in the first designated domain. Where 1≤i≤N2, 1≤y≤N2, 1<n≤N2, and N2 is the second number.
[0113] In addition, the target data shard in the above-mentioned migration process may be a shard obtained by performing a splitting operation on the shard to be split. Before dynamically adjusting the distribution of the target data shard, the shard to be split may be determined, and the shard to be split includes a first part and a second part; the data of the second part of the shard to be split is controlled to be copied to a blank shard to obtain a copy shard containing the data of the second part. After the data of the second part is copied, the first target operation on the first part of the shard to be split is controlled to access the shard to be split, and the second target operation on the second part of the shard to be split is controlled to access the copy shard. The first target operation includes at least one of a read operation and a write operation, and the second target operation includes at least one of a read operation and a write operation.
[0114] During the data replication process of the second part, the query operation on the replicated shard is controlled to access the second part of the shard to be split, and the write operation on the replicated shard or the second part is controlled to access the replicated shard and the second part at the same time.
[0115] Step 1230: Control multiple first data nodes in the first domain to perform a first operation; control multiple second data nodes in the second domain to provide data services.
[0116] Step 1240: Control the multiple second data nodes in the second domain to perform a second operation; control the multiple first data nodes in the first domain to provide data services.
[0117] In an embodiment of the present application, the number of the multiple first data nodes is the same as the number of the multiple second data nodes. The same data shard contains multiple copies, and the multiple copies are distributed on different target nodes. One target node contains one copy of the multiple copies, and the target node is the first data node or the second data node. The multiple copies include a primary copy and a backup copy. The primary copy can be, for example, a readable and writable copy, and the backup copy can be, for example, a read-only copy. The primary copy is distributed in a first designated domain, and the backup copy is distributed in a second designated domain; the first designated domain is one of the first and second domains, and the second designated domain is the other of the first and second domains.
[0118] In this embodiment of the present application, any data node in the first designated domain contains multiple primary replicas of multiple different data shards, and multiple backup replicas corresponding to the multiple primary replicas are evenly distributed across all data nodes in the second designated domain. The multiple primary replicas and the multiple backup replicas are all replicas of the multiple different data shards.
[0119] In an embodiment of the present application, any data node in the first designated domain includes multiple primary copies of multiple different data shards and multiple backup copies of multiple different data shards, the difference in the number of primary copies on any two data nodes in the first designated domain is less than a first preset value, and the difference in the number of backup copies on any two data nodes in the first designated domain is less than a second preset value.
[0120] In an embodiment of the present application, multiple first data nodes in the first domain are controlled to perform a first operation, and multiple second data nodes in the second domain are controlled to provide data services; wherein, the first domain and the second domain are both domains divided according to data shards, and the data shards on the first domain are distributed on the multiple first data nodes, and the data shards on the second domain are distributed on the multiple second data nodes; the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain. In this way, multiple first data nodes are controlled to uniformly perform the first operation according to the first domain, and there is no need to perform the first operation node by node. In the scenario of distributed data storage, the execution efficiency of the first operation can be greatly improved. Moreover, the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain, which can ensure that access to the content of the data shards will not be affected during the execution of the operation.
[0121] It should be noted that the method for controlling data nodes provided in the embodiment of the present application may have the beneficial effects shown in Table 1 below.
[0122]
[0123] Table 1 See Figure 13 , Figure 13 This is a structural block diagram of a device for controlling data nodes provided in an embodiment of the present application. Figure 13 As shown, an embodiment of the present application provides a device 1300 for controlling a data node, and the device 1300 for controlling a data node includes: a first control module 1310 and a second control module 1320.
[0124] The first control module 1310 is configured to control a plurality of first data nodes in the first domain to perform a first operation; The second control module 1320 is configured to control the plurality of second data nodes in the second domain to provide data services; The first domain and the second domain are both domains divided by data shards, the data shards on the first domain are distributed on the multiple first data nodes, and the data shards on the second domain are distributed on the multiple second data nodes; the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain.
[0125] In an embodiment of the present application, a plurality of first data nodes in a first domain are controlled to perform a first operation; a plurality of second data nodes in a second domain are controlled to provide data services; wherein, the first domain and the second domain are domains divided according to data shards, the data shards on the first domain are distributed on the plurality of first data nodes, and the data shards on the second domain are distributed on the plurality of second data nodes; the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain. In this way, the first domain controls the plurality of first data nodes to uniformly perform the first operation, and there is no need to perform the first operation node by node. In the scenario of distributed data storage, the execution efficiency of the first operation can be greatly improved. Moreover, the first domain contains the content of any data shard in the second domain, and the second domain contains the content of any data shard in the first domain, which can ensure that access to the content of the data shards will not be affected during the execution of the operation.
[0126] The device for controlling a data node provided in the embodiment of the present application can implement each process implemented in the above method embodiment. To avoid repetition, it will not be described here.
[0127] See Figure 14 , Figure 14 This is a structural block diagram of an electronic device provided in an embodiment of the present application. Figure 14As shown, an embodiment of the present application also provides an electronic device 1400. The electronic device 1400 includes: a processor 1410 and a memory 1420, and the memory 1420 stores a program or instruction, and when the program or instruction is executed by the processor 1410, it implements the steps of any of the methods described above. For example, when the program is executed by the processor 1410, it implements the following process: controlling multiple first data nodes in the first domain to perform a first operation; controlling multiple second data nodes in the second domain to provide data services; wherein, the first domain and the second domain are domains divided by data shards, the data shards on the first domain are distributed on the multiple first data nodes, and the data shards on the second domain are distributed on the multiple second data nodes; the first domain contains the content of any one data shard in the second domain, and the second domain contains the content of any one data shard in the first domain. In this way, multiple first data nodes are controlled according to the first domain to uniformly perform the first operation, without having to perform the first operation node by node, which can greatly improve the execution efficiency of the first operation in the scenario of distributed data storage. Moreover, the first domain contains the content of any data slice in the second domain, and the second domain contains the content of any data slice in the first domain, which can ensure that access to the data slice content will not be affected during the operation execution.
[0128] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of each embodiment of the method for controlling a data node are implemented and the same technical effect can be achieved. To avoid repetition, they are not repeated here.
[0129] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0130] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned method embodiment and achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0131] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0132] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element. In addition, it should be noted that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in the opposite order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0133] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better embodiment. Based on this understanding, the technical solution of this application, or the part that contributes to the existing technology, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of this application.
[0134] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.
Claims
1. A method for controlling a data node, characterized in that: include: Controlling a plurality of first data nodes in the first domain to perform a first operation; controlling a plurality of second data nodes in the second domain to provide data services; The first domain and the second domain are both domains divided by data shards, the data shards in the first domain are distributed on the multiple first data nodes, and the data shards in the second domain are distributed on the multiple second data nodes; The first domain contains the content of any data slice in the second domain, and the second domain contains the content of any data slice in the first domain.
2. The method according to claim 1, characterized in that After the multiple first data nodes in the first domain complete executing the first operation, the method further includes: controlling the plurality of second data nodes in the second domain to perform a second operation; The plurality of first data nodes in the first domain are controlled to provide data services.
3. The method according to claim 1, characterized in that The number of the plurality of first data nodes is the same as the number of the plurality of second data nodes.
4. The method according to claim 1, wherein The same data shard contains multiple copies, and the multiple copies are distributed on different target nodes. One target node contains one copy of the multiple copies, and the target node is the first data node or the second data node.
5. The method according to claim 4, characterized in that The multiple replicas include primary replicas and backup replicas, the primary replicas are distributed in a first designated domain, and the backup replicas are distributed in a second designated domain; the first designated domain is one of the first domain and the second domain, and the second designated domain is the other of the first domain and the second domain.
6. The method according to claim 5, characterized in that Any data node in the first designated domain includes multiple primary replicas of multiple different data shards, and multiple backup replicas corresponding to the multiple primary replicas are evenly distributed on all data nodes in the second designated domain; Among them, the multiple primary copies and the multiple backup copies are all copies of the multiple different data shards.
7. The method according to claim 5, characterized in that Any data node in the first specified domain contains multiple primary copies of multiple different data shards and multiple backup copies of multiple different data shards. The difference in the number of primary copies on any two data nodes in the first specified domain is less than a first preset value, and the difference in the number of backup copies on any two data nodes in the first specified domain is less than a second preset value.
8. The method according to any one of claims 1 to 4, characterized in that Before controlling the plurality of first data nodes in the first domain to perform the first operation, the method further includes: Distributing data shards to the first domain and the second domain; Dynamically adjust the distribution of target data shards; The target data slice includes at least one of a data slice located on the first domain and a data slice located on the second domain.
9. The method according to claim 8, characterized in that The target data shards include data shards located in the first set; and the dynamically adjusting the distribution of the target data shards includes: Control the migration of data shards on the first set to the second set; The first set and the second set are located in the same target domain, which is the first domain or the second domain; and the number of data shards on the first set is greater than the number of data shards on the second set.
10. The method according to claim 9, characterized in that The number of data shards contained in any data node in the first set is greater than a preset average value, and the number of data shards contained in any data node in the second set is less than the preset average value; The preset average value is obtained based on the total number of data shards and the total number of data nodes.
11. The method according to claim 9 or 10, characterized in that The controlling the migration of the data shards on the first set to the second set includes: Control the migration of specified data shards in the first set to specified data nodes in the second set; Each data shard on the first set has a shard hash value, each data node in the second set has a node hash value; and the difference between the shard hash value of the specified data shard and the node hash value of the specified data node is the smallest.
12. The method according to claim 8, characterized in that The dynamic adjustment of the distribution of target data shards includes: Control the migration of the target data shard located on the first designated node to the second designated node; The first designated node and the second designated node are located in the same target domain; the first designated node is the data node with the largest weight in the target domain, and the second designated node is the data node with the smallest weight in the target domain; the target domain is the first domain or the second domain; The weight of the data node is positively correlated with the number of data shards on the data node, and the data node is the first data node or the second data node.
13. The method according to claim 12, characterized in that In the case where the same data shard contains multiple copies, and the multiple copies include a primary copy and a backup copy, the target data shard is at least one of the primary copy and the backup copy.
14. The method according to claim 13, characterized in that Before controlling the migration of the target data shard located on the first designated node to the second designated node, the method further includes: Construct a first matrix for a first specified domain, and construct a second matrix for a second specified domain; the elements L in the first matrix ij The number of backup copies of the primary replica on the i-th node of the first specified domain on the j-th node of the second specified domain is represented by the element R in the second matrix. ij Indicates the number of backup copies of the primary replica on the i-th node of the second specified domain on the j-th node of the first specified domain; i and j are both positive integers less than the second number; The first designated domain is one of the first domain and the second domain, and the second designated domain is the other of the first domain and the second domain; the first designated node and the second designated node are obtained based on the first matrix or the second matrix.
15. The method according to claim 14, characterized in that After the first matrix and the second matrix are constructed, the method further includes: Select the element L with the largest weight from the first matrix xy and the element with the smallest weight L mn ; Wherein, 1≤x,y≤N1, N1<m≤N2, 1≤n≤N2, N1 is the first number, and N2 is the second number; The controlling the migration of the target data shard located on the first designated node to the second designated node includes: For the target data shard with the primary copy at the xth node on the first designated domain and the backup copy at the yth node on the second designated domain, control the migration of the primary copy at the xth node on the first designated domain to the mth node on the first designated domain, and control the migration of the backup copy at the yth node on the second designated domain to the nth node on the second designated domain.
16. The method according to claim 14, characterized in that After the first matrix and the second matrix are constructed, the method further includes: Select the element with the largest weight L from the i-th row elements of the first matrix iy and the element with the smallest weight L in ; Wherein, 1≤i≤N1, 1≤y≤N1, N1<n≤N2, N1 is the first number, and N2 is the second number; The controlling the migration of the target data shard located on the first designated node to the second designated node includes: For the target data shard where the primary copy is on the i-th node on the first designated domain and the backup copy is on the y-th node on the second designated domain, control the migration of the backup copy on the y-th node on the second designated domain to the n-th node on the second designated domain.
17. The method according to claim 14, characterized in that After the first matrix and the second matrix are constructed, the method further includes: Selecting the node y with the largest weight and the node n with the smallest weight from the first matrix; The controlling the migration of the target data shard located on the first designated node to the second designated node includes: If there is a node i in the second specified domain, let R iy -R in ≥ a fixed value, for a target data shard with a primary replica on the i-th node in the second designated domain and a backup replica on the y-th node in the first designated domain, control the migration of the backup replica on the y-th node in the first designated domain to the n-th node in the first designated domain; Wherein, 1≤i≤N2, 1≤y≤N2, 1<n≤N2, and N2 is the second number.
18. The method according to claim 8, characterized in that The target data shard is a shard obtained by performing a split operation on the shard to be split; Before dynamically adjusting the distribution of the target data shards, the method further includes: Determine a shard to be split, where the shard to be split includes a first part and a second part; Controlling the copying of the second portion of the data of the shard to be split to a blank shard, to obtain a copy shard containing the second portion of the data; After the data of the second portion is copied, controlling a first target operation on the first portion of the shard to be split to access the shard to be split, and controlling a second target operation on the second portion of the shard to be split to access the copied shard; The first target operation includes at least one of a read operation and a write operation, and the second target operation includes at least one of a read operation and a write operation.
19. The method according to claim 18, characterized in that The method further comprises: During the data replication process of the second part, the query operation on the replicated shard is controlled to access the second part of the shard to be split, and the write operation on the replicated shard or the second part is controlled to access the replicated shard and the second part at the same time.
20. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program or an instruction, and when the program or the instruction is executed by the processor, the method according to any one of claims 1 to 19 is implemented.
21. A readable storage medium, characterized in that The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the method according to any one of claims 1 to 19 is implemented.
22. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 19 when being executed by a processor.