CN114647701A - Load balancing method and device for distributed database, electronic equipment and medium - Google Patents
Load balancing method and device for distributed database, electronic equipment and medium Download PDFInfo
- Publication number
- CN114647701A CN114647701A CN202210287080.8A CN202210287080A CN114647701A CN 114647701 A CN114647701 A CN 114647701A CN 202210287080 A CN202210287080 A CN 202210287080A CN 114647701 A CN114647701 A CN 114647701A
- Authority
- CN
- China
- Prior art keywords
- storage module
- user
- copy
- copies
- fragment
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 65
- 239000012634 fragment Substances 0.000 claims abstract description 267
- 238000012546 transfer Methods 0.000 claims abstract description 20
- 238000005192 partition Methods 0.000 claims description 19
- 238000004364 calculation method Methods 0.000 claims description 18
- 238000004590 computer program Methods 0.000 claims description 11
- 230000004044 response Effects 0.000 claims description 8
- 238000009825 accumulation Methods 0.000 claims description 4
- 238000013500 data storage Methods 0.000 abstract description 2
- 238000004891 communication Methods 0.000 description 9
- 238000012545 processing Methods 0.000 description 8
- 238000010586 diagram Methods 0.000 description 6
- 238000009826 distribution Methods 0.000 description 5
- 230000008859 change Effects 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 230000006870 function Effects 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 238000013467 fragmentation Methods 0.000 description 2
- 238000006062 fragmentation reaction Methods 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000013473 artificial intelligence Methods 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 239000004973 liquid crystal related substance Substances 0.000 description 1
- 238000010801 machine learning Methods 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 230000010076 replication Effects 0.000 description 1
- 239000004065 semiconductor Substances 0.000 description 1
- 230000001953 sensory effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
- 238000009827 uniform distribution Methods 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
- G06F16/278—Data partitioning, e.g. horizontal or vertical partitioning
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5083—Techniques for rebalancing the load in a distributed system
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Software Systems (AREA)
- Computing Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The disclosure provides a load balancing method and device for a distributed database, electronic equipment and a medium, and relates to the technical field of big data and cloud computing, in particular to the technical field of data storage. The specific implementation scheme is as follows: and receiving the heartbeat message sent by the first storage module. And then, for each fragment copy in the first storage module, determining a user to which the fragment copy belongs and whether the fragment copy is a main fragment copy according to the attribute information of the fragment copy. And for each determined user, if the number of the main fragmented copies of the user stored in the first storage module is greater than a preset first threshold, sending a first notification message to the first storage module, wherein the first notification message is used for notifying the first storage module to transfer part of the main fragmented copies of the user to the second storage module, and the number of the main fragmented copies of the user stored in the second storage module is less than that of the first storage module. Thereby ensuring the access performance of the table owner data.
Description
Technical Field
The disclosure relates to the technical field of big data and cloud computing, in particular to the technical field of data storage.
Background
In a distributed database, a data table is generally divided into a plurality of parts for storage, each part is called a fragment, each fragment comprises a part of data of the data table, and each fragment has a plurality of fragment copies, so that data reliability is ensured.
Disclosure of Invention
The disclosure provides a load balancing method and device for a distributed database, electronic equipment and a medium.
In a first aspect of the embodiments of the present disclosure, a load balancing method for a distributed database is provided, including:
receiving heartbeat messages sent by a first storage module in a storage cluster, wherein the heartbeat messages comprise attribute information of each fragment copy stored in the first storage module;
for each fragment copy in the first storage module, determining a user to which the fragment copy belongs and whether the fragment copy is a main fragment copy according to the attribute information of the fragment copy;
for each determined user, if the number of the main fragment copies of the user stored in the first storage module is greater than a preset first threshold, sending a first notification message to the first storage module; wherein the first notification message is used to notify the first storage module to transfer the user portion primary split copy to a second storage module; the second storage module stores a number of primary fragmented copies of the user that is less than the number of primary fragmented copies of the user stored by the first storage module.
In a second aspect of the embodiments of the present disclosure, a load balancing apparatus for a distributed database is provided, including:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving heartbeat messages sent by a first storage module in a storage cluster, and the heartbeat messages comprise attribute information of each fragment copy stored in the first storage module;
a determining module, configured to determine, for each fragmented copy in the first storage module, according to attribute information of the fragmented copy, a user to which the fragmented copy belongs and whether the fragmented copy is a main fragmented copy;
a sending module, configured to send, for each user determined by the determining module, a first notification message to the first storage module if the number of primary split copies of the user stored in the first storage module is greater than a preset first threshold; wherein the first notification message is used to notify the first storage module to transfer the user's partial primary fragmented copy to a second storage module; the second storage module stores a number of primary fragmented copies of the user that is less than the number of primary fragmented copies of the user stored by the first storage module.
In a third aspect of the embodiments of the present disclosure, an electronic device is provided, including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of the first aspect.
In a fourth aspect of the disclosed embodiments, there is provided a non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of the first aspect.
In a fifth aspect of the embodiments of the present disclosure, a computer program product is provided, comprising a computer program, which when executed by a processor, implements the method of the first aspect.
It should be understood that the statements in this section do not necessarily identify key or critical features of the embodiments of the present disclosure, nor do they limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description.
Drawings
The drawings are included to provide a better understanding of the present solution and are not to be construed as limiting the present disclosure. Wherein:
FIG. 1 is an exemplary diagram of a distributed database architecture provided by embodiments of the present disclosure;
fig. 2 is a flowchart of a load balancing method for a distributed database according to an embodiment of the present disclosure;
fig. 3 is a flowchart of a method for determining an identifier of a storage module corresponding to a primary shard copy according to an embodiment of the present disclosure;
fig. 4 is a flowchart of a method for determining an identifier of a storage module corresponding to a fragmented copy according to an embodiment of the present disclosure;
FIG. 5 is a flowchart of a method for determining an average value of a fragmented copy and an average value of a master fragmented copy provided by an embodiment of the present disclosure;
fig. 6 is an exemplary schematic diagram of a load balancing process of a distributed database according to an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of a load balancing apparatus for a distributed database according to an embodiment of the present disclosure;
fig. 8 is a block diagram of an electronic device for implementing a load balancing method for a distributed database according to an embodiment of the present disclosure.
Detailed Description
Exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings, in which various details of the embodiments of the disclosure are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In the distributed database, the shard copies ensure consistency of the shard copies of the same shard through a distributed consistency protocol, for example, the distributed consistency protocol is a common knowledge (raft) protocol. Based on the requirement of the distributed consistency protocol, in each fragment copy of the same fragment, there are one master fragment copy and one or more slave fragment copies, the master fragment copy may be referred to as a leader (leader), and the slave fragment copies may be referred to as followers (followers). Wherein, reading and writing the data in the fragments are carried out in the primary fragment copy. When the data volume of each fragment exceeds a threshold value, fragment splitting is triggered, namely, one fragment is split into two new fragments, and each new fragment corresponds to a part of row data of the original fragment. For example, a slice includes more than 200 ten thousand rows of data, or the slice size exceeds 500 Megabytes (MB), the slice is split into two sub-slices of equal data size.
As shown in fig. 1, the distributed database of the spinner-like architecture includes 3 modules: a database (db) module 101, a metadata (meta) module 102 and a store (store) module 103. Wherein the spanner is a scalable, multi-version, globally distributed, synchronous replication database.
The db module 101 is configured to read data from or write data to the store module 103.
The meta module 102 is configured to manage metadata of the fragmented copies and perform storage location scheduling of the fragmented copies.
The store module 103 is configured to store a fragmented copy of the data table.
It should be noted that fig. 1 is only one example of a partial deployment database structure provided by the embodiment of the present disclosure, and the number of modules in the distributed database is not limited thereto.
If multiple rows of data in the data table belong to the same user, the user is called a table owner. Because the row data of the table owner is more, the data of the table owner is distributed on a plurality of sub-slices, and if the main sub-slice copies of the table owner are all concentrated in a few storage modules, such as one or two storage modules, the access load of the two storage modules is increased, the response is slow, the time consumption for responding to the user request is increased and even overtime is caused, the access performance of the data of the table owner is difficult to guarantee, and the storage resources of the whole storage cluster are not fully utilized.
The traditional load balancing method for the distributed database is divided into the following three types: sharding load balancing, raft loader load balancing, and access hotspot load balancing.
In the fragmentation load balancing method, the data volume borne by each store module is more balanced by balancing the number of fragmentation copies stored in each store module.
In the method for load balancing of the raft leader, the leader is distributed among the storage modules in a scattered manner by balancing the leader data stored in the storage modules.
In the method for balancing access hotspot load, a store module reports information of current access load, such as read-write speed, to a meta module. And then, the meta detects the access hotspot readers according to the current access load information of each store module, and distributes the access hotspot readers among the store modules in a scattered way.
However, in the three ways, load balancing is not realized from the user dimension, and the access performance of data of the table owner cannot be guaranteed.
In order to ensure the access performance of data of each user, the embodiment of the present disclosure provides a load balancing method for a distributed database, which is applied to the meta module in fig. 1. As shown in fig. 2, the method comprises the steps of:
s201, receiving a heartbeat message sent by a first storage module in the storage cluster.
The first storage module is any storage module in the storage cluster, and for convenience of description, the storage module that sends the heartbeat message is referred to as the first storage module. For example, the first storage module is any one of the three storage modules shown in fig. 1, and the storage cluster is a cluster formed by 3 storage modules in fig. 1.
The heartbeat message comprises attribute information of each fragment copy stored in the first storage module. The attribute information may indicate a user to which the data in the fragmented copy belongs and whether the fragmented copy is a primary fragmented copy. In addition, the attribute information may also indicate information of other aspects, for example, the attribute information may also indicate a size of the fragmented copy, which is not specifically limited in this disclosure.
S202, aiming at each fragment copy in the first storage module, determining a user to which the fragment copy belongs and whether the fragment copy is a main fragment copy according to the attribute information of the fragment copy.
In one implementation, the meta module may sequentially determine, according to an arrangement order of the fragmented copies in the first storage module, a user to which each fragmented copy belongs and whether the fragmented copy is a master fragmented copy.
And S203, aiming at each determined user, if the number of the main fragment copies of the user stored in the first storage module is greater than a preset first threshold value, sending a first notification message to the first storage module.
The first notification message is used for notifying the first storage module to transfer the partial main fragment copies of the user to the second storage module, and the number of the main fragment copies of the user stored by the second storage module is less than the number of the main fragment copies of the user stored by the first storage module.
In one implementation manner, for each user determined in S202, the number of main fragmented copies of the user stored in the first storage module is counted, and it is determined whether the number of main fragmented copies of the user stored in the first storage module is greater than a preset first threshold. And if so, sending a first notification message to the first storage module. If not, the storage position of the main fragment copy of the user stored in the first storage module is not adjusted.
Alternatively, the number of primary split copies transferred by the first storage module to the other storage modules may be a fixed value, for example, a fixed value of 1. Alternatively, the number of primary split copies transferred by the first storage module to the other storage modules may be a value determined by the meta module based on the number of primary split copies of the user stored in the first storage module. For example, if the ratio of the number of main split copies of the user stored in the first storage module to the first preset threshold exceeds a preset ratio, it is determined that the number of main split copies to be transferred is 2; otherwise, determining the number of main fragment copies needing to be transferred to be 1. The specific determination method can be further referred to as described later.
After the first storage module receives the first notification message, for each main fragment copy needing to be transferred, if the second storage module stores a slave fragment copy of the main fragment copy, the first storage module may change the main fragment copy stored by itself into the slave fragment copy, and notify the second storage module to change the slave fragment copy of the main fragment copy stored by itself into the main fragment copy, thereby implementing the transfer of the storage location of the main fragment copy.
Alternatively, if a slave shard copy of the master shard copy is not stored in the second storage module, the first storage module may send the master shard copy to the second storage module, thereby transferring the master shard copy to the second storage module for storage.
In the embodiment of the present disclosure, the meta module may determine, through the heartbeat message reported by the storage module, a user to which each piece copy stored by the storage module belongs, and whether each piece copy is a main piece copy. And then when the storage module stores more main fragment copies of the same user, transferring part of the main fragment copies to the storage module storing the user fragment copies, thereby achieving the purpose of realizing the load balance of the main fragment copies in the user dimension, namely realizing the dispersed distribution of the main fragment copies of the same user in each storage module. Thereby ensuring the access performance of data of each user.
In an embodiment of the present disclosure, the attribute information of each fragment copy in the heartbeat message includes a primary key prefix and identity information of the fragment copy. The main key prefix of the fragment copy comprises a user identifier, and the user identifier represents a user to which the line data included in the fragment copy belongs. The identity information is used for indicating that the identity of the fragment copy is a master fragment copy or a slave fragment copy, that is, the identity information indicates whether the fragment copy is a leader or a follower of the fragment.
When the data table is split, a main key (key) is set for the data table, and the data table is split according to the main key to obtain a plurality of fragments. For example, the primary key is int type, the value of the primary key in the data table is in the range of [0,200], when the data table is split, the row data with the primary key range of [0,100] is taken as the fragment 1, and the row data with the primary key range of [101,200] is taken as the fragment 2.
In the embodiment of the present disclosure, the primary key of the data table is preset manually, and the primary key includes a user identification field. Optionally, the primary key in the embodiments of the present disclosure may further include other fields.
For example, fields in a shopping information table include: user number (userid), order number (orderid), product number (produced), cost (cost), discount (count), and purchase time (purchase _ time), etc.
In the case where the primary key includes only the user identification field, the primary key of the shopping information table is userid. In the case where the primary key includes the user identification field and other fields, the primary key of the shopping information table may be userid + orderid.
Setting multiple primary keys to a data table enables finer granularity of splitting of the data table. For example, line data with userid of 1 and orderid in the range of [0,5] is taken as slice 1, and line data with userid of 1 and orderid in the range of [6,10] is taken as slice 2.
As can be seen, each fragmented copy corresponds to a segment of primary key range of the data table, and the primary key prefix in the embodiment of the present disclosure may include a maximum value, a minimum value, or an intermediate value of the primary key range of the line data stored in the fragmented copy in the data table. For example, the primary key of the data table is userid + orderid, in the row data stored in the segment 1, userid is 1 and orderid is in the range of [0,5], and the primary key prefix of the segment 1 is: userid:1 and orderid: 0. Alternatively, when the setting of the primary key prefix includes that the line data stored in the sliced copy has the minimum value of the primary key range in the data table, the primary key prefix may be referred to as a start key (start _ key).
On this basis, the manner of determining the user to which the fragmented copy belongs and whether the fragmented copy is the primary fragmented copy in S202 may be implemented as follows: and determining a user to which the fragment copy belongs according to the primary key prefix of the fragment copy, and determining whether the fragment copy is a main fragment copy according to the identity information of the fragment copy.
For example, when the identity information is a leader, determining that the fragment copy is a main fragment copy; and when the identity information is a follower, determining that the fragment copy is a slave fragment copy. Or when the identity information is 1, determining the fragment copy as a main fragment copy; and when the identity information is 0, determining that the fragment copy is a slave fragment copy.
Optionally, since there may be one or more primary keys of the data table, the purpose of the embodiment of the present disclosure is to perform load balancing based on the user to which the fragmented copy belongs, that is, the meta module performs load balancing not according to all primary keys, but according to only the primary key of the user dimension. Therefore, the primary key prefix load balancing dimension is preset to be 1, wherein the primary key prefix load balancing dimension refers to the number of primary keys on which load balancing is based. When the meta module determines the user to which the fragment copy belongs, the dimension is load balanced based on the prefix of the primary key, that is, 1, only the primary key of the user dimension in the prefix of the primary key is considered.
Specifically, the meta module may determine a value of a user dimension in the primary key prefix, that is, a user identifier in the primary key prefix, based on a preset primary key prefix load balancing dimension, and then use a user represented by the user identifier as a user to which the fragmented copy belongs.
For example, when the primary key prefix in the heartbeat message only includes userid:1, the meta module takes the value of userid, i.e., 1, as the user to which the fragmented copy belongs.
Or, when the primary key prefix in the heartbeat message includes userid:1 and orderid:0, the meta module ignores the value of orderid and takes the value of userid, namely 1, as the user to which the fragmented copy belongs because the preset load balancing dimension of the primary key prefix is 1.
By adopting the method, the embodiment of the disclosure can obtain the user to which the fragment copy belongs according to the primary key prefix of the fragment copy, and determine whether the fragment copy is the primary fragment copy according to the identity information, thereby obtaining the number of the fragment copies of each user and the number of the primary fragment copies stored in the first storage module, facilitating the subsequent determination of whether the number of the primary fragment copies and the number of the fragment copies of the same user stored in the first storage module are excessive, and thus performing load balancing of user dimensions.
In one embodiment of the disclosure, the first notification message includes an identification of the second storage module to which each of the first specified number of primary partition copies to be transferred corresponds. After the first storage module receives the first notification message, the first specified number of primary partition copies can be respectively transferred to the respective corresponding second storage modules according to the identifiers of the respective corresponding second storage modules of the first specified number of primary partition copies.
Before the above S203 sends the first notification message to the first storage module, referring to fig. 3, the meta module may further determine the identifier of the second storage module corresponding to each of the first specified number of primary partition copies by:
s301, selecting a main fragment copy of the user stored in the first storage module according to a preset sequence.
The preset sequence may be an arrangement sequence or a random sequence of the primary split copies of the user stored in the first storage module, which is not specifically limited in this disclosure. And selecting the main fragment copies according to a preset sequence so as not to repeatedly determine the identifier of the second storage module corresponding to the same main fragment copy.
S302, determining storage modules where the slave fragment copies of the selected master fragment copy are located, and selecting the storage module with the least number of the master fragment copies currently storing the user from the determined storage modules.
The meta module obtains the fragments to which the fragment copies stored in the storage modules belong, the users to which the fragment copies belong and whether the fragment copies are main fragment copies through the heartbeat messages reported by the storage modules, so that the meta module can screen out the storage module in which the slave fragment copies included in the fragments to which the main fragment copies belong are located for a selected main fragment copy. And then selecting the storage module with the least main fragment copy number for storing the user currently from the screened storage modules, so that the main fragment copy of the user is more uniformly distributed in the storage module.
The main fragment copy and the slave fragment copy belong to the same fragment, and the main fragment copy and the slave fragment copy are different fragment copies of the fragment, so that the stored line data are the same. The method comprises the steps of selecting a second storage module from storage modules of slave fragment copies in which master fragment copies are stored, enabling the first storage module and the second storage module to store the fragment copies of the same fragment, and transferring the master fragment copies among the fragment copies in which the same fragment is stored, namely changing the master fragment copies in the first storage module into slave fragment copies and changing the slave fragment copies in the second storage module into master fragment copies, so that master fragment copy transfer is realized without actually transferring the fragment copies, and communication resources consumed by fragment copy transfer can be reduced while the master fragment copies of the same user are distributed in the storage modules in a scattered manner.
Optionally, when more than one storage module currently storing the user with the least number of main split copies is used, one storage module may be randomly selected from the storage modules currently storing the user with the least number of main split copies.
And S303, adding 1 to the number of the main fragment copies of the user stored in the selected storage module, taking the identifier of the selected storage module as the identifier of the second storage module corresponding to the main fragment copy, returning to S301, and selecting one main fragment copy of the user stored in the first storage module according to a preset sequence until the identifiers of the second storage modules corresponding to the main fragment copies of the first specified number are determined.
For example, the leaders storing user 1 in the first storage module include leader1, leader2, leader3, leader4 and leader 5. When the first specified number is 2, firstly selecting leader1, determining that the storage modules where the folrowers of leader1 are located are storeA and storeB, and assuming that the number of leaders of the user stored in storeA is 0 and the number of leaders of the user stored in storeB is 3, determining that leader1 corresponds to storeA. And updates the number of leader of the user stored in storeA to 1+0 to 1. And selecting leader2, determining that the store in which the follower of leader1 is located is both storeA and storeB, and determining that leader2 corresponds to storeA if the number of leaders of the user stored in storeA is 1 and the number of leaders of the user stored in storeB is 3.
Through the method, in the embodiment of the present disclosure, the meta module may determine the transferred storage module for each main fragmented copy to be scheduled, so that the main fragmented copies of the same user are distributed on the storage module in a dispersed manner after the transfer. In addition, in the embodiment of the present disclosure, since the secondary segment copy of the primary segment copy is stored in the second storage module, and the primary segment copy and the secondary segment copy belong to the same segment, the stored line data is the same, so that when the primary segment copy is transferred, only identity change of the segment copy can be completed without transferring the storage location of the segment copy, thereby improving the efficiency of load balancing.
In an embodiment of the present disclosure, the first preset threshold in S203 may be a main partition copy average corresponding to the user. And the average value of the main fragmented copies corresponding to the user is the quotient between the total number of the main fragmented copies of the user and the number of the storage modules in the storage cluster.
For example, the total number of main split copies of user 1 is 5, the number of storage modules in the storage cluster is 3, and the average value of the main split copies corresponding to user 1 is 5/3. Accordingly, when the meta module executes S203, it is assumed that the first storage module includes slice 1, slice 2, and slice 3. The partition 1, the partition 2 and the partition 3 all belong to the user 1, and the partition 1 and the partition 3 are main partition copies, at this time 2>5/3, that is, the number of main partition copies of the user 1 stored in the first storage module is greater than the average value of the main partition copies corresponding to the user 1.
On this basis, before sending the first notification message to the first storage module in S203, the meta module may further calculate a first specified number, including: and calculating the difference value between the number of the main fragment copies of the user stored in the first storage module and the average value of the main fragment copies corresponding to the user, and taking the calculation result as a first specified number.
For example, the leaders of the user 2 stored in the first storage module include the leader1, the leader2 and the leader3, the average value of the leaders corresponding to the user 2 is 2, and the first specified number is determined to be 3-2-1.
By adopting the method, in the embodiment of the present disclosure, the meta module may determine the number of the main fragmented copies which are stored in the first storage module and exceed the average value of the main fragmented copies corresponding to the user, so as to transfer the main fragmented copies which exceed the average value to other storage modules in the following process, thereby implementing uniform distribution of the main fragmented copies of the same user on the storage modules.
Because the frequency of the memory module reporting the heartbeat messages is high, if the load balancing is performed every time the heartbeat messages are received, the load balancing operation is too frequent, and the calculation pressure of the meta module is increased.
In one embodiment of the present disclosure, in order to reduce the calculation pressure of the meta module, after receiving the heartbeat message sent by the first storage module in S201, the meta module may further perform: the number of times that the first storage module sends the heartbeat message is increased by 1, and then in response to the increased number of times reaching the designated number of times, the above-described S202 is performed. Otherwise, waiting for the next heartbeat message sent by the first storage module.
The specified times can be preset according to actual conditions. For example, the number of designation times is a multiple of 50, that is, the number of designation times is 50, 100, 150, and the like. If the number of times that the current first storage module sends the heartbeat message is 49, after receiving the heartbeat message sent by the first storage module, calculating that 49+1 is 50, at this time, the number of times that the first storage module sends the heartbeat message reaches the specified number, and executing the above S202 to perform the load balancing operation. If the current number of times that the first storage module sends the heartbeat message is 29, after the heartbeat message sent by the first storage module is received, calculating that 29+1 is 30, at this time, the number of times that the first storage module sends the heartbeat message does not reach the specified number of times, so the above S202 is not executed.
Through the method, the load balancing operation is executed only when the number of times that the meta module receives the heartbeat message reported by the first storage module reaches the designated number, so that the frequency of the meta module executing the load balancing operation is reduced, and the calculation pressure of the meta module is reduced.
In an embodiment of the present disclosure, the scheduling policy in S203 is a primary shard copy scheduling policy, that is, the primary shard copy of the same user is scheduled in the storage module, so that the primary shard copy of the same user is uniformly distributed in the storage module.
In addition, the embodiment of the present disclosure further provides a copy scheduling policy, that is, a storage module schedules the fragmented copies of the same user, so that the fragmented copies of the same user are distributed in the storage module in a distributed manner. The user's sharded copies include a master sharded copy and a slave sharded copy of the user.
The meta module may choose to adopt the leader scheduling policy or the replica scheduling policy. That is, after determining the user to which the fragmented copy belongs and whether the fragmented copy is a main fragmented copy in S202, the meta module may further perform the following steps:
and in response to the preset scheduling policy corresponding to the designated times being the primary fragment copy scheduling policy, executing the step S203. And responding to the preset scheduling policy corresponding to the specified times as a copy scheduling policy, executing the copy scheduling policy, namely, if the number of the fragmented copies of the user stored in the first storage module is greater than a preset second threshold value, sending a second notification message to the first storage module for each determined user.
The second notification message is used for notifying the first storage module to transfer the partial fragment copy of the user to the third storage module; the number of the user's fragmented copies stored by the third storage module is less than the number of the user's fragmented copies stored by the first storage module.
The scheduling policy corresponding to the specified times can be preset according to the actual situation. For example, when the specified number of times is a multiple of 50 and is not a multiple of 100, the corresponding copy scheduling policy is applied; and when the specified times are multiples of 50 and multiples of 100, the specified times correspond to the leader scheduling strategy. That is, when the specified times are 50, 150, 250, and the like, the copy scheduling policy is corresponded; and when the specified times are 100, 200, 300 and the like, corresponding to the leader scheduling policy.
In the copy scheduling policy, for each user determined in S202, the number of fragmented copies of the user stored in the first storage module is counted. And judging whether the number of the user's fragmented copies stored in the first storage module is greater than a preset second threshold. And if so, sending a second notification message to the first storage module. If not, the storage position of the user's fragment copy stored in the first storage module is not adjusted.
By adopting the method, the meta module in the embodiment of the disclosure can select the leader scheduling policy and the replica scheduling policy, so that the sharded replica of the user is scheduled in the leader dimension or the replica sharding dimension. In the copy scheduling policy, the fragmented copies of the same user can be distributed in each storage module in a scattered manner, so that the access performance of the data of the user is ensured.
In one embodiment of the disclosure, the second notification message includes an identification of a third storage module corresponding to each of the second specified number of fragmented copies to be transferred. After the first storage module receives the second notification message, the second specified number of fragment copies can be transferred to the respective corresponding third storage modules according to the identifiers of the respective corresponding third storage modules of the second specified number of fragment copies.
Thus, before sending the second notification message to the first storage module, referring to fig. 4, the meta module may further determine the identity of the third storage module corresponding to each of the second specified number of fragmented copies by:
s401, acquiring the number of the user' S fragmented copies stored in each storage module in the storage cluster.
The meta module obtains the user to which the fragment copy stored in each storage module belongs through the heartbeat message reported by each storage module in the storage cluster, so as to obtain the number of the fragment copies of the user stored in each storage module in the storage cluster.
S402, according to a preset sequence, selecting one fragment copy of the user stored by the first storage module, and determining the storage module which currently stores the least number of fragment copies of the user.
The preset sequence may be an arrangement sequence or a random sequence of the fragmented copies of the user stored in the first storage module, which is not specifically limited in this embodiment of the present disclosure. And selecting the fragment copies according to a preset sequence so as not to repeatedly determine the identifier of the third storage module corresponding to the same fragment copy.
Optionally, when more than one storage module currently storing the user with the smallest number of fragmented copies is used, one storage module is randomly selected from the storage modules currently storing the user with the smallest number of fragmented copies.
And S403, adding 1 to the determined number of the user' S fragmented copies stored in the storage module, taking the determined identifier of the storage module as the identifier of a third storage module corresponding to the fragmented copy, and returning to S402 to select one fragmented copy of the user stored in the first storage module according to a preset sequence until the identifiers of the third storage modules corresponding to the second specified number of fragmented copies are determined.
For example, the shard copies stored in the first storage module for user 1 include shard copy 1, shard copy 2, and shard copy 3. And when the second specified quantity is 1, selecting the fragment copy 1, and determining that the fragment copy 1 corresponds to the storeA under the assumption that the quantity of the fragment copies of the storeA user 1 in the storage cluster is 0 and the quantity of the fragment copies of the storeA user 1 in the storeB is 1.
Through the method, in the embodiment of the present disclosure, the meta module may determine the transferred storage module for each fragmented copy to be scheduled, so that fragmented copies of the same user are distributed on the storage module in a dispersed manner after transfer.
In an embodiment of the present disclosure, the second preset threshold in the copy scheduling policy is a sliced copy average value corresponding to the user. And the average value of the fragment copies corresponding to the user is the quotient of the total number of the fragment copies of the user and the number of the storage modules in the storage cluster.
For example, suppose that the total number of fragmented copies of user 1 is 5, and the number of storage modules in the storage cluster is 2, i.e. the average value of the fragmented copies corresponding to the user is 5/2. Assume that the first storage module includes segment 1, segment 2, and segment 3, and segment 1, segment 2, and segment 3 all belong to user 1. At this time 3>5/2, that is, the number of the fragmented copies of user 1 stored in the first storage module is greater than the average value of the fragmented copies corresponding to user 1.
The meta module may also calculate a second specified quantity before sending the second notification message to the first storage module, including: and calculating the difference value between the number of the user's fragment copies stored in the first storage module and the average value of the user's corresponding fragment copies, and taking the calculation result as a second specified number.
For example, the fragmented copies of the user 2 stored by the first storage module include a fragmented copy 1, a fragmented copy 2, and a fragmented copy 3, the average value of the fragmented copies corresponding to the user 2 is 2, and it is determined that the second specified number is 3-2 — 1.
By adopting the method, in the embodiment of the present disclosure, the meta module may determine the number of the fragmented copies which are stored in the first storage module and exceed the average value of the fragmented copies corresponding to the user, so as to transfer the fragmented copies which exceed the average value to other storage modules in the following process, thereby realizing that the fragmented copies of the same user are uniformly distributed on the storage modules.
In an embodiment of the present disclosure, since the leader scheduling policy shown in fig. 1 needs to use the main shard copy average value corresponding to the user, and the replica scheduling policy needs to use the shard copy average value, before the meta module executes the load balancing method shown in fig. 1, the main shard copy average value and the shard copy average value corresponding to the user may also be calculated in the manner shown in fig. 5. Or, the meta module may also update the main slice copy average value and the slice copy average value corresponding to the user at intervals in the manner shown in fig. 5. The embodiment of the present disclosure does not specifically limit the timing of executing the meta module in fig. 5.
Optionally, after the meta module collects the heartbeat messages sent by each storage module for a period of time in S501, the meta module performs S502 to S504, so as to ensure that the meta module sufficiently obtains the condition of the slice copies stored by all storage modules of the storage cluster.
Referring to fig. 5, the following describes a manner in which the meta module calculates the average value of the main slice copy and the average value of the slice copy corresponding to the user:
s501, receiving heartbeat messages sent by each storage module in the storage cluster.
The heartbeat message sent by each storage module comprises the primary key prefix and the identity information of each fragment copy stored in the storage module.
S502, aiming at each storage module, determining a user to which each fragment copy in the storage module belongs according to a main key prefix of each fragment copy included in a heartbeat message sent by the storage module, and determining whether each fragment copy is a main fragment copy according to identity information of each fragment copy.
The specific implementation manner of S502 is the same as that of S202, and reference may be made to the related description of S202, which is not repeated herein.
S503, aiming at each user, taking the sum of the number of the user 'S fragmented copies stored by each storage module in the storage cluster as the total number of the user' S fragmented copies, calculating the quotient between the total number of the user 'S fragmented copies and the number of the storage modules in the storage cluster, and taking the calculation result as the average value of the user' S corresponding fragmented copies.
For example, the store cluster includes store1, store2, and store3, and for each user, the number of sharded copies of the user stored in store1 is determined to be 2, the number of sharded copies of the user stored in store2 is determined to be 1, the number of sharded copies of the user stored in store3 is determined to be 0, and therefore the sum of the number of sharded copies of the user is 3. The average value of the slice copy corresponding to the user is (2+1)/3 is 1.
Optionally, the upper integer of the quotient between the total number of the fragmented copies of the user and the number of the storage modules in the storage cluster may be calculated, so that the calculated average value of the fragmented copies corresponding to the user is an integer.
S504, the sum of the number of the main split copies of the user stored by each storage module in the storage cluster is used as the total number of the main split copies of the user, the quotient of the total number of the main split copies of the user and the number of the storage modules in the storage cluster is calculated, and the calculation result is used as the average value of the main split copies corresponding to the user.
For example, the storage cluster includes store1, store2, and store3, and for each user, the number of primary shard copies of the user stored by store1 is determined to be 2, the number of primary shard copies of the user stored by store2 is determined to be 1, the number of primary shard copies of the user stored by store3 is determined to be 0, and thus the total number of primary shard copies of the user is 3. The average value of the main slice copy corresponding to the user is (2+1)/3 is 1.
Optionally, an upper integer of a quotient between the total number of the main fragmented copies of the user and the number of the storage modules in the storage cluster may be calculated, so that the calculated average value of the main fragmented copies corresponding to the user is an integer.
By adopting the method, in the embodiment of the present disclosure, the meta module may collect the user to which the fragment copy stored by each storage module in the storage cluster belongs, and whether the fragment copy is a main fragment copy, thereby determining the average value of the fragment copy corresponding to each user and the average value of the main fragment copy corresponding to each user, so as to be used in subsequent load balancing.
Referring to fig. 6, the following description illustrates a load balancing method for a distributed database according to an embodiment of the present disclosure in combination with an application scenario:
the store cluster includes store1, store2, store3, store4, store5, and store6, where the rectangle within each store module in fig. 6 represents one shard copy stored, and the shard sequence number within the shard copy represents the shard to which the shard copy belongs. When the fragment copy is marked with a "leader", the fragment copy is the master fragment copy, and when the fragment copy is not marked with a "leader", the fragment copy is the slave fragment copy.
And the store module reports the main key prefix and the identity information of the fragment copy stored by the store module to the meta module through the heartbeat message. For example, in the heartbeat message reported by store1, the primary key prefix start _ key of the fragment copy of fragment 1 is: 1, userid, 3, and the identity information is leader; the primary key prefix start _ key of the fragment copy of fragment 2 is: 1, userid, 5 and the identity information is follower; the primary key prefix start _ key of the fragment copy of fragment 3 is: userid:1, orderid:9, and identity information is leader.
Because the load balancing dimension of the main key prefix is 1, the meta module only considers userid in the main key prefix, ignores orderid, and obtains the segment corresponding to the user with userid of 1, which includes segment 1, segment 2 and segment 3. And the meta module determines, through the heartbeat message, that the store1 stores the fragmented copy of the user includes: the shard copy of shard 1, the shard copy of shard 2, and the shard copy of shard 3 are denoted as userid 1, store1: [1,2,3].
store2 stores the fragmented copy of the user including: the shard copy of shard 1 and the shard copy of shard 3 are denoted as userid 1, store 2: [1,3].
store3 stores the fragmented copy of the user including: the shard copy of shard 1 and the shard copy of shard 2 are denoted as userid 1, store3: [1,2].
store4 stores the fragmented copy of the user including: the slice copy of slice 2, denoted as userid 1, store 4: [2].
store5 does not store a fragmented copy of the user.
store6 stores the fragmented copy of the user including: the copy of slice 3, denoted as userid 1, store 6: [3].
Obtaining the distribution condition of the fragment copies of the user dimension: userid is 1, and the shard list (regionlist) is { store1: [1,2,3], store 2: [1,3], store3: [1,2], store 4: [2] store 6: [3]}. And the number distribution condition of the leader of the user dimension: userid is 1, and leader list (leader) { store1:2, store3:1 }. And counting the distribution situation of the fragment copies of other users and the distribution situation of the leader according to the same method.
Thereby calculating the average value of the corresponding fragment copy of the user asAnd the average value of the main fragment copy corresponding to the user is
When a subsequent meta module receives a heartbeat message sent by the store1, and when the scheduling policy corresponding to the number of times that the heartbeat message is sent by the store1 is a leader scheduling policy, because the number of leaders of the user is 2, which is stored in the store1, and the average value 1 of the main slice copy corresponding to the user is 1, that is, 1 leader needs to be transferred. Randomly selecting one leader of the user from the store1, assuming that the leader of segment 3 is selected, the followers of segment 3 are stored in the store2 and the store6, and the number of leaders of the user stored in the store2 and the store6 are both 0, at this time, randomly selecting one store module from the store2 and the store6, assuming that the store6 is selected. A first notification message is sent to the store1, the first notification message being used to notify the store1 to schedule the leader of segment 3 into the store 6. When receiving the first notification message, store1 changes the segment copy of segment 3 stored by itself to folower, and notifies store6 to change the segment copy of segment 3 stored by itself to leader.
Then, when the meta module receives the heartbeat message sent by the store1, and when the scheduling policy corresponding to the number of times that the store1 sends the heartbeat message is the copy scheduling policy, since the store1 stores that the number of the shard copies of the user is 3 — the average value 2 of the shard copies corresponding to the user is 1, that is, 1 shard copy needs to be transferred. A shard copy is randomly selected from store1, assuming that the shard copy of shard 2 is selected. store5 in the store cluster stores the least number of sharded copies of the user, and therefore store5 is selected. A second notification message is sent to store1, notifying store1 to transfer the shard copy of shard 2 into store 5. store1, upon receiving the second notification message, transfers its own stored shard copy of shard 2 to store 5.
After the shard copies and the leaders of the user with the userid of 1 are uniformly distributed in the store cluster by the method, the access operation to the user data is uniformly distributed on each store module, so that the access performance of the user data is guaranteed.
The scheduling of only the sharded copy and the leader for the user with userid of 1 is shown in fig. 6, and the sharded copies and the leader for other users are scheduled in the same way.
Based on the same inventive concept, corresponding to the above method embodiments, the disclosed embodiments provide a load balancing apparatus for a distributed database, which is applied to a meta module. As shown in fig. 7, the apparatus includes: a receiving module 701, a determining module 702 and a sending module 703;
a receiving module 701, configured to receive a heartbeat message sent by a first storage module in a storage cluster, where the heartbeat message includes attribute information of each slice copy stored in the first storage module;
a determining module 702, configured to determine, according to attribute information of each fragment copy in the first storage module, a user to which the fragment copy belongs and whether the fragment copy is a primary fragment copy;
a sending module 703, configured to send, for each user determined by the determining module 702, a first notification message to the first storage module if the number of the main split copies of the user stored in the first storage module is greater than the average value of the main split copies corresponding to the user; wherein the first notification message is used for notifying the first storage module to transfer the partial main fragmented copy of the user to the second storage module; the second storage module stores a fewer number of copies of the user's primary partition than the number of copies of the user's primary partition stored by the first storage module.
In an embodiment of the present disclosure, the attribute information of each fragmented copy includes a primary key prefix and identity information of the fragmented copy, and the primary key prefix of the fragmented copy includes a user identifier; the determining module 702 is specifically configured to:
determining a user to which the fragment copy belongs according to the primary key prefix of the fragment copy;
and determining whether the fragment copy is a main fragment copy according to the identity information of the fragment copy.
In one embodiment of the present disclosure, the apparatus further comprises: an accumulation module;
the accumulation module is used for adding 1 to the number of times of sending the heartbeat message by the first storage module after receiving the heartbeat message sent by the first storage module in the storage cluster, calling the determination module 702 to execute the steps of aiming at each fragment copy in the first storage module, and determining the user to which the fragment copy belongs and whether the fragment copy is a main fragment copy according to the attribute information of the fragment copy in response to the increased number of times reaching the specified number of times; otherwise, waiting for the next heartbeat message sent by the first storage module.
In one embodiment of the present disclosure, the apparatus may further include: calling a module;
a calling module, configured to, after determining, for each fragmented copy in the first storage module, a user to which the fragmented copy belongs and whether the fragmented copy is a primary fragmented copy according to attribute information of the fragmented copy, in response to a preset scheduling policy corresponding to a specified number of times being a primary fragmented copy scheduling policy, call the sending module 703 to execute a step of sending a first notification message to the first storage module if the number of primary fragmented copies of the user stored in the first storage module is greater than a preset first threshold;
the sending module 703 is further configured to respond to that the preset scheduling policy corresponding to the specified number of times is a copy scheduling policy, and send, for each determined user, a second notification message to the first storage module if the number of the fragmented copies of the user stored in the first storage module is greater than a preset second threshold; the second notification message is used for notifying the first storage module to transfer the partial fragment copies of the user to the third storage module, and the number of the fragment copies of the user stored by the third storage module is less than that of the fragment copies of the user stored by the first storage module.
In one embodiment of the disclosure, the first notification message includes an identification of the second storage module to which each of the first specified number of primary split copies to be transferred corresponds; the apparatus may further include: a selection module;
the selection module is used for selecting one main fragment copy of the user stored in the first storage module according to a preset sequence before the first notification message is sent to the first storage module; determining storage modules where slave fragment copies of the selected master fragment copy are located, and selecting the storage module with the least number of master fragment copies currently storing the user from the determined storage modules;
the determining module 702 is further configured to add 1 to the number of the main split copies of the user stored in the storage module selected by the selecting module, use the identifier of the selected storage module as an identifier of a second storage module corresponding to the main split copy, and return to the step of selecting one main split copy of the user stored in the first storage module according to the preset sequence until determining the identifiers of the second storage modules corresponding to the main split copies of the first specified number.
In an embodiment of the present disclosure, the first preset threshold is an average value of the main fragmented copies corresponding to the user, and the average value of the main fragmented copies corresponding to the user is a quotient between the total number of the main fragmented copies of the user and the number of storage modules in the storage cluster; the apparatus may further include: a calculation module;
and the calculating module is used for calculating the difference between the number of the main partition copies of the user stored by the first storage module and the average value of the main partition copies corresponding to the user before the first notification message is sent to the first storage module, and taking the calculation result as the first designated number.
In an embodiment of the present disclosure, the second notification message includes an identifier of a third storage module corresponding to each of the second specified number of fragmented copies to be transferred; the apparatus may further include: an acquisition module;
the acquisition module is used for acquiring the number of the fragment copies of the user stored by each storage module in the storage cluster before sending the second notification message to the first storage module;
the determining module 702 is further configured to select, according to a preset sequence, one fragmented copy of the user stored in the first storage module, and determine the storage module that currently stores the smallest number of fragmented copies of the user; adding 1 to the determined number of the user's fragmented copies stored by the storage module, taking the determined identifier of the storage module as the identifier of a third storage module corresponding to the fragmented copies, and returning to the step of selecting one fragmented copy of the user stored by the first storage module according to the preset sequence until the identifier of the third storage module corresponding to each of the first specified number of fragmented copies is determined.
In an embodiment of the present disclosure, the second preset threshold is a sliced copy average value corresponding to the user, and the sliced copy average value corresponding to the user is a quotient between the total number of sliced copies of the user and the number of storage modules in the storage cluster; the apparatus may further include: a calculation module;
and the calculating module is used for calculating the difference value between the number of the user's fragment copies stored in the first storage module and the average value of the corresponding fragment copies of the user before sending the second notification message to the first storage module, and taking the calculation result as a second specified number.
In the technical scheme of the disclosure, the collection, storage, use, processing, transmission, provision, disclosure and other processing of the related fragment information all meet the regulations of related laws and regulations and do not violate the good customs of the public order.
The present disclosure also provides an electronic device, a readable storage medium, and a computer program product according to embodiments of the present disclosure.
FIG. 8 illustrates a schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 8, the electronic device 800 includes a computing unit 801 that can perform various appropriate actions and processes according to a computer program stored in a Read Only Memory (ROM)802 or a computer program loaded from a storage unit 808 into a Random Access Memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The calculation unit 801, the ROM 802, and the RAM 803 are connected to each other by a bus 804. An input/output (I/O) interface 805 is also connected to bus 804.
A number of components in the electronic device 800 are connected to the I/O interface 805, including: an input unit 806, such as a keyboard, a mouse, or the like; an output unit 807 such as various types of displays, speakers, and the like; a storage unit 808, such as a magnetic disk, optical disk, or the like; and a communication unit 809 such as a network card, modem, wireless communication transceiver, etc. The communication unit 809 allows the electronic device 800 to exchange information/data with other devices through a computer network such as the internet and/or various telecommunication networks.
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuitry, Field Programmable Gate Arrays (FPGAs), Application Specific Integrated Circuits (ASICs), Application Specific Standard Products (ASSPs), system on a chip (SOCs), Complex Programmable Logic Devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be special or general purpose, receiving data and instructions from, and transmitting data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for implementing the methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program code, when executed by the processor or controller, causes the functions/acts specified in the flowchart and/or block diagram to be performed. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which a user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic, speech, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a back-end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back-end, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), Wide Area Networks (WANs), and the Internet.
The computer system may include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server combining a blockchain.
It should be understood that various forms of the flows shown above may be used, with steps reordered, added, or deleted. For example, the steps described in the present disclosure may be executed in parallel or sequentially or in different orders, and are not limited herein as long as the desired results of the technical solutions disclosed in the present disclosure can be achieved.
The above detailed description should not be construed as limiting the scope of the disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may be made in accordance with design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present disclosure should be included in the scope of protection of the present disclosure.
Claims (19)
1. A load balancing method for a distributed database comprises the following steps:
receiving a heartbeat message sent by a first storage module in a storage cluster, wherein the heartbeat message comprises attribute information of each fragment copy stored in the first storage module;
for each fragment copy in the first storage module, determining a user to which the fragment copy belongs and whether the fragment copy is a main fragment copy according to the attribute information of the fragment copy;
for each determined user, if the number of the main fragment copies of the user stored in the first storage module is greater than a preset first threshold, sending a first notification message to the first storage module; wherein the first notification message is used to notify the first storage module to transfer the user portion primary split copy to a second storage module; the number of primary fragmented copies of the user stored by the second storage module is less than the number of primary fragmented copies of the user stored by the first storage module.
2. The method of claim 1, wherein the attribute information of each fragmented copy includes a primary key prefix and identity information of the fragmented copy, and the primary key prefix of the fragmented copy includes a user identification; the determining, according to the attribute information of the fragmented copy, whether the user to which the fragmented copy belongs and the fragmented copy are the main fragmented copy includes:
determining a user to which the fragment copy belongs according to the primary key prefix of the fragment copy;
and determining whether the fragment copy is a main fragment copy according to the identity information of the fragment copy.
3. The method of claim 1, after receiving a heartbeat message sent by a first storage module in a storage cluster, the method further comprising:
adding 1 to the number of times of sending heartbeat messages by the first storage module, executing the step of aiming at each fragment copy in the first storage module in response to the increased number of times reaching the specified number of times, and determining a user to which the fragment copy belongs and whether the fragment copy is a main fragment copy according to the attribute information of the fragment copy; otherwise, waiting for the first storage module to send the heartbeat message next time.
4. The method of claim 3, after determining, for each shard copy in the first storage module, a user to which the shard copy belongs and whether the shard copy is a primary shard copy according to the attribute information of the shard copy, the method further comprising:
responding to a preset scheduling policy corresponding to the specified times as a primary fragment copy scheduling policy, executing the step of sending a first notification message to the first storage module for each determined user if the number of primary fragment copies of the user stored in the first storage module is greater than a preset first threshold;
responding to that the preset scheduling policy corresponding to the specified times is a copy scheduling policy, and if the number of the fragmented copies of the user stored in the first storage module is greater than a preset second threshold value, sending a second notification message to the first storage module for each determined user; the second notification message is used for notifying the first storage module to transfer the partial fragment copies of the user to a third storage module, and the number of the fragment copies of the user stored by the third storage module is less than the number of the fragment copies of the user stored by the first storage module.
5. The method of any of claims 1-4, the first notification message including an identification of the second storage module to which each of the first specified number of primary partition copies to be transferred corresponds; before the sending the first notification message to the first storage module, the method further includes:
selecting one main fragment copy of the user stored in the first storage module according to a preset sequence;
determining storage modules where slave fragment copies of the selected master fragment copy are located, and selecting the storage module with the least number of master fragment copies currently storing the user from the determined storage modules;
and adding 1 to the number of the main fragment copies of the user stored in the selected storage module, taking the identifier of the selected storage module as the identifier of the second storage module corresponding to the main fragment copy, and returning to the step of selecting one main fragment copy of the user stored in the first storage module according to the preset sequence until the identifiers of the second storage modules corresponding to the main fragment copies of the first specified number are determined.
6. The method of claim 5, wherein the first preset threshold is an average value of the primary split copies corresponding to the user, and the average value of the primary split copies corresponding to the user is a quotient between the total number of the primary split copies of the user and the number of storage modules in the storage cluster; prior to the sending the first notification message to the first storage module, the method further comprises:
and calculating the difference value between the number of the main fragment copies of the user stored in the first storage module and the average value of the main fragment copies corresponding to the user, and taking the calculation result as the first specified number.
7. The method of claim 4, wherein the second notification message includes an identification of a third storage module corresponding to each of a second specified number of shard copies to be transferred; before the sending the second notification message to the first storage module, the method further includes:
acquiring the number of the fragmented copies of the user stored by each storage module in the storage cluster;
according to a preset sequence, selecting one fragment copy of the user stored by the first storage module, and determining the storage module which currently stores the least number of fragment copies of the user;
adding 1 to the determined number of the user's fragmented copies stored by the storage module, taking the determined identifier of the storage module as the identifier of a third storage module corresponding to the fragmented copy, and returning to the step of selecting one of the user's fragmented copies stored by the first storage module according to the preset sequence until the identifiers of the third storage modules corresponding to the first specified number of fragmented copies are determined.
8. The method according to claim 7, wherein the second preset threshold is an average value of the fragmented copies corresponding to the user, and the average value of the fragmented copies corresponding to the user is a quotient between a total number of fragmented copies of the user and a number of storage modules in the storage cluster; prior to said sending the second notification message to the first storage module, the method further comprises:
and calculating the difference value between the number of the user's fragment copies stored in the first storage module and the average value of the user's corresponding fragment copies, and taking the calculation result as the second designated number.
9. A load balancing apparatus for a distributed database, comprising:
the system comprises a receiving module, a sending module and a receiving module, wherein the receiving module is used for receiving heartbeat messages sent by a first storage module in a storage cluster, and the heartbeat messages comprise attribute information of each fragment copy stored in the first storage module;
a determining module, configured to determine, for each fragmented copy in the first storage module, according to attribute information of the fragmented copy, a user to which the fragmented copy belongs and whether the fragmented copy is a main fragmented copy;
a sending module, configured to send, for each user determined by the determining module, a first notification message to the first storage module if the number of primary partition copies of the user stored in the first storage module is greater than a preset first threshold; wherein the first notification message is used to notify the first storage module to transfer the user's partial primary fragmented copy to a second storage module; the second storage module stores a number of primary fragmented copies of the user that is less than the number of primary fragmented copies of the user stored by the first storage module.
10. The apparatus according to claim 9, wherein the attribute information of each fragmented copy includes a primary key prefix and identity information of the fragmented copy, and the primary key prefix of the fragmented copy includes a user identifier; the determining module is specifically configured to:
determining a user to which the fragment copy belongs according to the primary key prefix of the fragment copy;
and determining whether the fragment copy is a main fragment copy according to the identity information of the fragment copy.
11. The apparatus of claim 9, the apparatus further comprising: an accumulation module;
the accumulation module is used for adding 1 to the number of times of sending the heartbeat message by the first storage module after receiving the heartbeat message sent by the first storage module in the storage cluster, calling the determination module to execute the steps of aiming at each fragment copy in the first storage module, and determining a user to which the fragment copy belongs and whether the fragment copy is a main fragment copy according to the attribute information of the fragment copy in response to the increased number of times reaching the specified number of times; otherwise, waiting for the first storage module to send the heartbeat message next time.
12. The apparatus of claim 11, the apparatus further comprising: calling a module;
the calling module is configured to, after determining, according to the attribute information of each fragment copy in the first storage module, whether a user to which the fragment copy belongs and the fragment copy are primary fragment copies, and in response to a preset scheduling policy corresponding to the specified times being a primary fragment copy scheduling policy, call a sending module to execute the step of sending a first notification message to the first storage module if the number of primary fragment copies of the user stored in the first storage module is greater than a preset first threshold;
the sending module is further configured to respond to that the preset scheduling policy corresponding to the specified number of times is a copy scheduling policy, and send, for each determined user, a second notification message to the first storage module if the number of the fragmented copies of the user stored in the first storage module is greater than a preset second threshold; the second notification message is used for notifying the first storage module to transfer the partial fragment copies of the user to a third storage module, and the number of the fragment copies of the user stored by the third storage module is less than the number of the fragment copies of the user stored by the first storage module.
13. The apparatus of any of claims 9-12, the first notification message to include an identification of the second storage module to which each of the first specified number of primary split copies to be transferred corresponds; the device further comprises: a selection module;
the selection module is configured to select, according to a preset order, one primary fragmented copy of the user stored in the first storage module before the first notification message is sent to the first storage module; determining storage modules where slave fragment copies of the selected master fragment copy are located, and selecting the storage module with the least number of master fragment copies currently storing the user from the determined storage modules;
the determining module is further configured to add 1 to the number of the main fragmented copies of the user stored in the storage module selected by the selecting module, use the identifier of the selected storage module as an identifier of a second storage module corresponding to the main fragmented copy, and return to the step of selecting one main fragmented copy of the user stored in the first storage module according to the preset sequence until the identifiers of the second storage modules corresponding to the main fragmented copies of the first specified number are determined.
14. The apparatus of claim 13, wherein the first preset threshold is an average value of the primary split copies corresponding to the user, and the average value of the primary split copies corresponding to the user is a quotient between a total number of the primary split copies of the user and a number of storage modules in the storage cluster; the device further comprises: a calculation module;
the calculating module is configured to calculate, before the first notification message is sent to the first storage module, a difference between the number of main split copies of the user stored in the first storage module and an average value of the main split copies corresponding to the user, and use a calculation result as the first specified number.
15. The apparatus of claim 12, the second notification message comprising an identification of a third storage module to which each of a second specified number of fragmented copies to be transferred corresponds; the device further comprises: an acquisition module;
the obtaining module is configured to obtain the number of the fragmented copies of the user stored by each storage module in the storage cluster before the second notification message is sent to the first storage module;
the determining module is further configured to select one of the fragmented copies of the user stored in the first storage module according to a preset sequence, and determine the storage module that currently stores the smallest number of fragmented copies of the user; adding 1 to the determined number of the user's fragmented copies stored by the storage module, taking the determined identifier of the storage module as the identifier of a third storage module corresponding to the fragmented copy, and returning to the step of selecting one of the user's fragmented copies stored by the first storage module according to the preset sequence until the identifiers of the third storage modules corresponding to the first specified number of fragmented copies are determined.
16. The apparatus according to claim 15, wherein the second preset threshold is an average value of fragmented copies corresponding to the user, and the average value of fragmented copies corresponding to the user is a quotient between a total number of fragmented copies of the user and a number of storage modules in the storage cluster; the device further comprises: a calculation module;
the calculating module is configured to calculate a difference between the number of the user's fragmented copies stored in the first storage module and an average value of the fragmented copies corresponding to the user before the second notification message is sent to the first storage module, and use a calculation result as the second specified number.
17. An electronic device, comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-8.
18. A non-transitory computer readable storage medium having stored thereon computer instructions for causing the computer to perform the method of any one of claims 1-8.
19. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 1-8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210287080.8A CN114647701A (en) | 2022-03-22 | 2022-03-22 | Load balancing method and device for distributed database, electronic equipment and medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210287080.8A CN114647701A (en) | 2022-03-22 | 2022-03-22 | Load balancing method and device for distributed database, electronic equipment and medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114647701A true CN114647701A (en) | 2022-06-21 |
Family
ID=81996201
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210287080.8A Pending CN114647701A (en) | 2022-03-22 | 2022-03-22 | Load balancing method and device for distributed database, electronic equipment and medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114647701A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117478699A (en) * | 2023-10-31 | 2024-01-30 | 北京中元易尚科技有限公司 | Data writing method based on multi-network fusion Internet of things card and computer equipment |
-
2022
- 2022-03-22 CN CN202210287080.8A patent/CN114647701A/en active Pending
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117478699A (en) * | 2023-10-31 | 2024-01-30 | 北京中元易尚科技有限公司 | Data writing method based on multi-network fusion Internet of things card and computer equipment |
CN117478699B (en) * | 2023-10-31 | 2024-07-12 | 北京中元易尚科技有限公司 | Data writing method based on multi-network fusion Internet of things card and computer equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108388479B (en) | Delayed message pushing method and device, computer equipment and storage medium | |
CN109947668B (en) | Method and device for storing data | |
US9934263B1 (en) | Big-fast data connector between in-memory database system and data warehouse system | |
CN112650576A (en) | Resource scheduling method, device, equipment, storage medium and computer program product | |
US8751446B2 (en) | Transference control method, transference control apparatus and recording medium of transference control program | |
CN107346270B (en) | Method and system for real-time computation based radix estimation | |
CN113127564B (en) | Parameter synchronization method and device | |
CN109413125A (en) | The method and apparatus of dynamic regulation distributed system resource | |
CN113553179A (en) | Distributed key value storage load balancing method and system | |
CN110909978A (en) | Resource processing method, device, server and computer readable storage medium | |
WO2017114180A1 (en) | Component logical threads quantity adjustment method and device | |
CN113014608A (en) | Flow distribution control method and device, electronic equipment and storage medium | |
CN115291806A (en) | Processing method, processing device, electronic equipment and storage medium | |
CN114647701A (en) | Load balancing method and device for distributed database, electronic equipment and medium | |
CN107203437B (en) | Method, device and system for preventing memory data from being lost | |
CN115237595A (en) | Data processing method, data processing device, distribution server, data processing system, and storage medium | |
CN113347238A (en) | Message partitioning method, system, device and storage medium based on block chain | |
CN115543416A (en) | Configuration updating method and device, electronic equipment and storage medium | |
CN107229424B (en) | Data writing method for distributed storage system and distributed storage system | |
CN113360689B (en) | Image retrieval system, method, related device and computer program product | |
CN113641670B (en) | Data storage and data retrieval method and device, electronic equipment and storage medium | |
CN114612212A (en) | Business processing method, device and system based on risk control | |
CN113641688A (en) | Node updating method, related device and computer program product | |
CN116991882B (en) | Query optimization method and device based on service priority and electronic equipment | |
CN113495888B (en) | Identification management method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |