A database management method and related products
By dividing the first-level cluster and selecting the first-level master node in the database cluster, then combining it into the second-level cluster and selecting the second-level master node, the problem of data negotiation and synchronization performance bottlenecks between cross-regional database nodes is solved, and the availability and performance of the database are improved.
Patent Information
- Application Number
- CN202411780679.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-05
- Publication Date
- 2025-04-08
AI Technical Summary
In a database cluster, there are performance bottlenecks in data negotiation and data synchronization between master and slave nodes across regions, resulting in reduced database availability.
The database nodes are divided into multiple first-level clusters through a preset partition algorithm, and a first-level master node is selected from each first-level cluster, and the first-level master node is combined into a second-level cluster, and the second-level master node is selected. This method reduces the network bandwidth requirements of the secondary master node and optimizes the data transmission path.
It improves the efficiency of data negotiation and data synchronization among database nodes, reduces the amount of data synchronized across regions, and improves the performance and availability of databases.
Smart Images

Figure CN119782416A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a database management method, a computer-readable storage medium, and a computer program product. Background Art
[0002] In a database cluster, database nodes are usually distributed in different computer rooms. To ensure data consistency, the cluster usually sets only one node as the master node to provide business services to the outside world, and the other nodes are set as slave nodes. The master node and the slave node need to negotiate and synchronize data through a network connection. When the master and slave nodes are distributed in different computer rooms in different regions, there are often performance bottlenecks when transmitting data across regions due to factors such as geographical location and hardware performance. For example, when the master node is in region A and multiple slave nodes are in region B, for each business data, the master node needs to transmit it over a long distance to each slave node in region B, which will bring great performance loss and affect the availability of the database. With the increase of the physical distance between the master and slave nodes, the decrease of network bandwidth, and the increase of the number of slave nodes, the performance and availability of the database will be further reduced. Summary of the invention
[0003] An object of the present invention is to provide a database management method, a computer-readable storage medium and a computer program product, so as to improve the efficiency of data negotiation and data synchronization between nodes of the database and improve the availability of the database.
[0004] A further object of the present invention is to improve the efficiency of data negotiation and data synchronization between nodes in different regions and to improve the availability of the database.
[0005] Specifically, according to one aspect of the present invention, the present invention provides a method for managing a database.
[0006] It includes:
[0007] According to a preset partitioning algorithm, all nodes of the database are divided into at least two first-level clusters, each of the first-level clusters includes at least one of the nodes;
[0008] Executing a first master election algorithm in each of the first-level clusters to determine a first-level master node of the first-level cluster from all the nodes contained therein;
[0009] Combining all the primary master nodes into a secondary cluster;
[0010] A second master election algorithm is executed in the secondary cluster to determine a secondary master node as the secondary cluster from all the primary master nodes contained therein.
[0011] Optionally, the preset partitioning algorithm includes:
[0012] Obtaining a communication speed factor between each pair of all the nodes; wherein the communication speed factor is calculated based on the physical distance between the two nodes and is configured to be negatively correlated with the physical distance;
[0013] The two nodes whose communication speed factor is greater than a preset communication speed threshold are grouped into the same primary cluster, and the two nodes whose communication speed factor is less than or equal to the preset communication speed threshold are grouped into different primary clusters.
[0014] Optionally, the communication speed factor is calculated based on the network bandwidth between the two nodes and is configured to be positively correlated with the network bandwidth.
[0015] Optionally, the communication speed factor is calculated based on the physical distance between the two nodes and the network bandwidth, and is configured to be negatively correlated with the physical distance and positively correlated with the network bandwidth.
[0016] Optionally, the first master election algorithm includes:
[0017] The nodes within the primary cluster are communicatively connected according to a first heartbeat mechanism;
[0018] In each heartbeat cycle of the first heartbeat mechanism, each of the nodes within the first-level cluster performs a vote;
[0019] According to the voting situation, one of the nodes in the first-level cluster is determined as the first-level master node, and the remaining nodes in the first-level cluster are set as first-level slave nodes.
[0020] Optionally, the second master selection algorithm includes:
[0021] The primary master nodes of the secondary cluster are communicatively connected according to a second heartbeat mechanism;
[0022] In each heartbeat cycle of the second heartbeat mechanism, each of the first-level master nodes performs a vote;
[0023] According to the voting situation, one of the first-level master nodes is determined as the second-level master node, and the remaining first-level master nodes are set as second-level slave nodes.
[0024] Optionally, after all the first-level master nodes are combined into a second-level cluster, the management method includes:
[0025] Periodically determining whether the primary master node of each primary cluster has changed at a preset time interval;
[0026] If so, update the secondary cluster to the combination of all current primary master nodes.
[0027] Optionally, after the second-level cluster is updated to a combination of all current first-level master nodes, the management method further includes:
[0028] Determine whether the primary master node that has been changed is the secondary master node before the change;
[0029] If so, immediately execute the second main algorithm.
[0030] Optionally, after executing the second master election algorithm in the secondary cluster, the management method further includes:
[0031] In response to the secondary master node executing a write operation, the secondary master node synchronizes the service data formed by executing the write operation to each secondary slave node; the secondary slave node is each of the other primary master nodes in the secondary cluster except the secondary master node;
[0032] Each of the first-level master nodes synchronizes the business data to each of the first-level slave nodes; the first-level slave nodes are the other nodes in the same first-level cluster except the first-level master node.
[0033] Optionally, after executing the second master election algorithm in the secondary cluster, the management method further includes:
[0034] In response to the secondary master node executing a write operation, the secondary master node synchronizes the service data formed by executing the write operation to each secondary slave node, and synchronizes the service data to each primary slave node of the primary cluster to which the secondary master node belongs; the secondary slave nodes are each other primary master node in the secondary cluster except the secondary master node, and the primary slave nodes are each other node in the same primary cluster except the primary master node;
[0035] Each of the second-level slave nodes synchronizes the service data to each of the first-level slave nodes of the first-level cluster to which it belongs.
[0036] According to another aspect of the present invention, there is further provided a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned database management methods are implemented.
[0037] According to yet another aspect of the present invention, a computer program product is provided, which includes a computer program, and when the computer program is executed by a processor, the steps of any of the above-mentioned database management methods are implemented.
[0038] The database management method of the present invention divides all nodes into multiple first-level clusters, and combines the first-level master nodes of each first-level cluster into a second-level cluster, so that the second-level master node is directly connected to each first-level master node, but not directly connected to the slave nodes of each first-level cluster. During data negotiation and data synchronization, data transmission can be performed first in the second-level cluster, and then in each first-level cluster. For example, the second-level master node first negotiates and synchronizes data with other first-level master nodes, and then each first-level master node negotiates and synchronizes data with its own slave node. Since the number of first-level master nodes is less than the total number of all nodes, this solution greatly reduces the network bandwidth demand of the second-level master nodes, improves the efficiency of data negotiation and data synchronization between the nodes of the database, and improves the availability of the database.
[0039] Furthermore, the management method of the present invention divides all nodes into primary clusters according to physical distance, and divides nodes in different regions into different primary clusters, thereby greatly reducing the amount of data synchronized across regions and improving the performance and availability of the database.
[0040] On the other hand, the management method of the present invention divides all nodes into primary clusters according to network bandwidth, and divides nodes with lower network bandwidth into different primary clusters, thereby significantly reducing the amount of data transmitted by low network bandwidth and improving the performance and availability of the database.
[0041] Based on the following detailed description of specific embodiments of the present invention in conjunction with the accompanying drawings, those skilled in the art will become more aware of the above and other objects, advantages and features of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Hereinafter, some specific embodiments of the present invention will be described in detail in an exemplary and non-limiting manner with reference to the accompanying drawings. The same reference numerals in the accompanying drawings indicate the same or similar components or parts. It should be understood by those skilled in the art that these drawings are not necessarily drawn to scale. In the accompanying drawings:
[0043] Figure 1 is a flow chart of a management method according to an embodiment of the present invention;
[0044] Figure 2 is a schematic diagram of a process of dividing a primary cluster according to a management method of an embodiment of the present invention;
[0045] Figure 3 is a flowchart of a first master selection algorithm of a management method according to an embodiment of the present invention;
[0046] Figure 4 is a flow chart of a second master selection algorithm of a management method according to an embodiment of the present invention;
[0047] Figure 5 is a flow chart of a management method according to an embodiment of the present invention;
[0048] Figure 6 is a schematic diagram of a data synchronization process of a management method according to an embodiment of the present invention;
[0049] Figure 7 is a schematic diagram of a data synchronization process of a management method according to an embodiment of the present invention;
[0050] Figure 8 is a schematic block diagram of a database cluster of a management method according to an embodiment of the present invention;
[0051] Fig. 9 is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and
[0052] Fig.10 is a schematic diagram of a computer program product according to an embodiment of the present invention. DETAILED DESCRIPTION
[0053] The purpose of the database management method of this embodiment is to improve the efficiency of data negotiation and data synchronization between nodes of the database and to improve the availability of the database.
[0054] Figure 1 FIG. 1 is a flow chart of a management method according to an embodiment of the present invention. The method may generally include:
[0055] S100, dividing all nodes of the database into at least two first-level clusters according to a preset partitioning algorithm, each first-level cluster including at least one node;
[0056] S200, executing a first master election algorithm in each primary cluster to determine a primary master node of the primary cluster from all nodes contained therein;
[0057] S300, combines all primary master nodes into a secondary cluster;
[0058] S400, executing a second master election algorithm in the secondary cluster to determine a secondary master node as the secondary cluster from all primary master nodes contained therein.
[0059] The preset partitioning algorithm can divide all nodes according to factors such as the physical distance between nodes, the network bandwidth between nodes, the total number of nodes, the physical read and write performance of each node, etc. The preset partitioning algorithm can also determine the number of primary clusters based on the above factors.
[0060] The first master election algorithm is used to select the first-level master node from each node of the first-level cluster. The first-level master election algorithm can be a bully algorithm (Bully Algorithm), a Raft algorithm (Raft Consensus Algorithm), a ZAB algorithm (ZooKeeper Atomic Broadcast), etc. The first-level master node is used to connect with the second-level master node on behalf of the first-level cluster to which it belongs, and synchronize the data synchronized by the second-level master node to other nodes of the first-level cluster (which can be called first-level slave nodes). The first-level master node can be a pseudo master node, which does not directly provide services to the outside world, and is mainly used for data negotiation and data synchronization with the second-level master node in the second-level cluster.
[0061] The second master election algorithm is used to select the second master node from each first-level master node of the second-level cluster. The second master election algorithm can be a bully algorithm, a Raft algorithm, a ZAB algorithm, etc. The second master node is used to represent the second-level cluster (that is, the entire database cluster) to provide services to the outside world, perform read operations and write operations, and synchronize the business data generated by the write operation to other first-level master nodes (which can be called second-level slave nodes), and then the first-level master node synchronizes the business data to the first-level slave nodes of the first-level cluster to which it belongs.
[0062] It should be noted that in actual use, the first master selection algorithm and the second master selection algorithm are run periodically at their respective preset intervals to dynamically adjust the first-level master nodes of each first-level cluster and the second-level master nodes of the second-level cluster, so as to detect faulty nodes in a timely manner and maintain the high availability and consistency of the cluster.
[0063] For example, Figure 8 As shown, the database cluster has 7 nodes, including node 1 to node 7, and is divided into 3 first-level clusters (region A, region B, region C) according to region (physical distance). The 3 first-level clusters respectively select their own first-level master nodes (node 1, node 4 and node 7) through the first master selection algorithm. The 3 first-level master nodes are combined into a second-level cluster, and the second-level master node node 1 is selected through the second master selection algorithm. When in use, node 1 can provide services to the outside as a second-level master node, and can synchronize business data to the second-level slave nodes (node 4 and node 7). Each first-level master node can synchronize business data with the corresponding first-level slave node, that is, node 1 synchronizes to node 2 and node 3, and node 4 synchronizes to node 5 and node 6.
[0064] The management method of this embodiment divides all nodes into multiple first-level clusters, and divides the first-level master nodes of each first-level cluster into a second-level cluster, so that the second-level master node is directly connected to the remaining first-level master nodes, but not directly connected to the first-level slave nodes of each first-level cluster. During data negotiation and data synchronization, data transmission can be performed first within the second-level cluster, and then within each first-level cluster. For example, the second-level master node first negotiates and synchronizes data with the second-level slave node, and then each first-level master node negotiates and synchronizes data with its own first-level slave node. Compared with the prior art, since the number of second-level slave nodes is less than the total number of all nodes, the network bandwidth demand of the second-level master node is greatly reduced, thereby improving the efficiency of data negotiation and data synchronization between the nodes of the database, and improving the availability of the database.
[0065] In some embodiments of the management method of the present invention, the number of nodes in each primary cluster is an odd number, and the total number of primary clusters is an odd number.
[0066] The number of nodes in the primary cluster is an odd number, which to a certain extent prevents the two nodes in the primary cluster from getting the same number of votes when executing the first election algorithm. The total number of primary clusters is an odd number, which to a certain extent prevents the two nodes in the secondary cluster from getting the same number of votes when executing the second election algorithm.
[0067] In some embodiments of the management method of the present invention, the total number of primary clusters is less than or equal to 1 / 3 of the total number of all nodes in the database. In this way, the number of nodes directly connected to the secondary master node can be greatly reduced, further reducing the network bandwidth requirements of the secondary master node, thereby improving the efficiency of data negotiation and data synchronization between the nodes of the database and improving the availability of the database.
[0068] In some embodiments of the management methods of the present invention, Figure 2 As shown, the preset partitioning algorithms include:
[0069] S111, obtaining a communication speed factor between each pair of all nodes; wherein the communication speed factor is calculated according to the physical distance and / or network bandwidth between the two nodes, and is configured to be negatively correlated with the physical distance and / or positively correlated with the network bandwidth;
[0070] S112, obtaining a preset communication speed threshold;
[0071] S113, dividing two nodes whose communication speed factors are greater than a preset communication speed threshold into the same first-level cluster, and dividing two nodes whose communication speed factors are less than or equal to the preset communication speed threshold into different first-level clusters.
[0072] The greater the physical distance between two nodes, the lower the efficiency of data negotiation and data synchronization, and the smaller the communication speed factor. If multiple nodes with long physical distances are divided into the same first-level cluster, the first-level master node and multiple first-level slave nodes will need to perform multiple long-distance transmissions during data negotiation and data synchronization, which will affect the performance and availability of the database.
[0073] The smaller the network bandwidth between two nodes, the lower the efficiency of data negotiation and data synchronization, and the smaller the communication speed factor. If multiple nodes with smaller network bandwidth are divided into the same first-level cluster, the first-level master node and multiple first-level slave nodes will need to perform multiple transmissions at a slower speed during data negotiation and data synchronization, which will affect the performance and availability of the database.
[0074] For example, it can be set
[0075] Communication speed factor = k1*network bandwidth / physical distance, or communication speed factor = k2*network bandwidth-k3*physical distance,
[0076] In the two formulas, k1, k2, and k3 are all positive numbers and preset parameters, which can be flexibly set according to actual needs.
[0077] In particular, when the network bandwidth between nodes is consistent, the nodes can be directly divided according to the physical distance between them. For example, nodes with a physical distance less than 100 kilometers are divided into the same first-level cluster, and nodes with a physical distance greater than or equal to 100 kilometers are divided into different clusters, so that nodes belonging to the same region (such as the same city) are divided into the same first-level cluster, and nodes belonging to different regions (such as different cities) are divided into different clusters. In this way, data negotiation and data synchronization are only performed between the first-level master nodes in different regions, which greatly reduces the amount of data synchronized across regions and greatly improves the performance and availability of the database.
[0078] In some embodiments of the management methods of the present invention, Figure 3 As shown, the first selection algorithm includes:
[0079] S211, communicating and connecting the nodes in the first-level cluster according to the first heartbeat mechanism;
[0080] S212, in each heartbeat cycle of the first heartbeat mechanism, each node in the first-level cluster performs a vote;
[0081] S213, according to the voting situation, determine a node in the first-level cluster as the first-level master node, and set the remaining nodes in the first-level cluster as first-level slave nodes.
[0082] In this embodiment, the nodes in the same first-level cluster periodically vote with each other, and a first-level master node can be selected based on the majority principle (most votes) and / or data age (latest voting data). The first-level master node is used to connect with the second-level master node on behalf of the first-level cluster to which it belongs, and synchronize the data synchronized by the second-level master node to the first-level slave node of the first-level cluster. The first-level master node can be a pseudo-master node, which does not directly provide services to the outside world, and is mainly used for data negotiation and data synchronization with the second-level master node within the second-level cluster. In actual use, the master election principle and its heartbeat period of the first master election algorithm can be set as needed.
[0083] In some embodiments of the management methods of the present invention, Figure 4 As shown, the second main algorithm includes:
[0084] S411, communicating and connecting the primary master nodes of the secondary cluster according to the second heartbeat mechanism;
[0085] S412, in each heartbeat cycle of the second heartbeat mechanism, each primary master node performs a vote;
[0086] S413, according to the voting situation, determine a primary master node as a secondary master node, and set the remaining primary master nodes as secondary slave nodes.
[0087] In this embodiment, each primary master node in the secondary cluster periodically votes, and a secondary master node can be selected based on the majority principle and / or the data freshness. The secondary master node is used to represent the entire database cluster to provide services to the outside world, perform read operations and write operations, and synchronize the business data generated by the write operation to the secondary slave node, and the primary master node then synchronizes the business data to the primary slave nodes of the primary cluster to which it belongs. In actual use, the second master election algorithm can be set according to the needs of the master election principle and its heartbeat cycle.
[0088] In some embodiments of the management methods of the present invention, Figure 5 As shown, after all the primary master nodes are combined into a secondary cluster, the management method includes:
[0089] S511, periodically determining whether a primary master node of each primary cluster has changed at a preset time interval;
[0090] S512: If yes, update the secondary cluster to the combination of all current primary master nodes.
[0091] In this embodiment, the secondary cluster periodically updates the primary master nodes it contains, thereby maintaining high availability and consistency of database data and preventing the secondary master nodes from losing connection with a primary cluster. The preset time interval can be equal to the heartbeat period of the first master selection algorithm, that is, each time the first master selection algorithm maintains the original primary master node or changes the primary master node, it confirms once and updates the latest primary master node to the secondary cluster in time.
[0092] In some embodiments of the management methods of the present invention, Figure 5 As shown, after the secondary cluster is updated to a combination of all current primary master nodes, the management method further includes:
[0093] S531, determining whether there is a primary master node that has been changed and was a secondary master node before the change;
[0094] S532: If yes, immediately execute the second main algorithm.
[0095] In this embodiment, when the original secondary master node fails and is exempted from the primary master node by the primary cluster to which it belongs, the secondary cluster will be without a secondary master node, which may cause the external service of the database to be interrupted. At this time, regardless of whether the heartbeat cycle time node of the second master selection algorithm is reached, the second master selection algorithm is immediately executed to determine the secondary master node as soon as possible, thereby maintaining the high availability of the cluster.
[0096] In some embodiments of the management method of the present invention, after executing the second master election algorithm in the secondary cluster, the management method further includes:
[0097] Determine whether the secondary master node has changed;
[0098] If so, immediately execute the first master election algorithm in the first-level cluster to which the second-level master node before the change belongs.
[0099] In this embodiment, when the original secondary master node fails and is exempted from the secondary master node by the secondary cluster, it means that the original secondary master node is no longer qualified to be a primary master node. At this time, regardless of whether the heartbeat cycle time node of the first master selection algorithm is reached, the first master selection algorithm is immediately executed to determine the primary master node of the primary cluster as soon as possible, thereby maintaining the high availability of the cluster.
[0100] In some embodiments of the management methods of the present invention, Figure 6 As shown, after executing the second master selection algorithm in the secondary cluster, the management method further includes:
[0101] S611, in response to the secondary master node executing a write operation, the secondary master node synchronizes the service data generated by executing the write operation to each secondary slave node; the secondary slave node is each primary master node other than the secondary master node in the secondary cluster;
[0102] S612, each first-level master node synchronizes the business data to each first-level slave node; the first-level slave node is each node other than the first-level master node in the same first-level cluster.
[0103] The secondary master node has a dual identity, being both the master node of the secondary cluster and the pseudo master node of the primary cluster to which it belongs. In this embodiment, the secondary master node can first synchronize the business data to each secondary slave node, and then synchronize the business data to the primary slave node of the primary cluster to which it belongs. At the same time, the primary master nodes of other secondary clusters synchronize the business data to the primary slave nodes of the primary cluster to which they belong. This embodiment is suitable for situations where the network bandwidth of the secondary master node is relatively small, and the business data can be synchronized to each primary cluster as quickly as possible to prevent affecting the performance of the secondary master node.
[0104] In some embodiments of the management methods of the present invention, Figure 7 As shown, after executing the second master selection algorithm in the secondary cluster, the management method further includes:
[0105] S711, in response to the secondary master node executing a write operation, the secondary master node synchronizes the business data generated by executing the write operation to each secondary slave node, and synchronizes the business data to each primary slave node of the primary cluster to which the secondary master node belongs; the secondary slave nodes are each primary master node other than the secondary master node in the secondary cluster, and the primary slave nodes are each node other than the primary master node in the same primary cluster;
[0106] S712, each secondary slave node synchronizes the business data to each primary slave node of the primary cluster to which it belongs.
[0107] The difference between this embodiment and the previous embodiment is that the secondary master node synchronizes the business data to each secondary slave node and each primary slave node of the primary cluster to which the secondary master node belongs at the same time, and then each secondary slave node synchronizes the business data to each primary slave node of the primary cluster to which it belongs. This embodiment is suitable for the case where the network bandwidth of the secondary master node is relatively large, and the business data can be synchronized to all primary clusters as quickly as possible.
[0108] The flow chart provided by the present embodiment is not intended to indicate that the operation of the method will be performed in any particular order, or that all operations of the method are included in all every case. In addition, the method may include additional operations. Within the scope of the technical thinking provided by the present embodiment method, additional changes may be made to the above method.
[0109] It should be understood that in some embodiments, each part can be implemented by hardware, software, firmware or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system.
[0110] This embodiment also provides a computer program product 10 and a computer readable storage medium 20 . Fig.10 is a schematic diagram of a computer program product 10 according to an embodiment of the present invention, Fig. 9 is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which implements the steps of any of the above-mentioned management methods when the computer program 11 is executed by the processor 32. The computer-readable storage medium 20 stores the above-mentioned computer program 11 thereon, and the computer program 11 implements the steps of the management method of any of the above-mentioned embodiments when the computer program 11 is executed by the processor 32.
[0111] The computer program 11 for performing the operation of the present invention may be an assembly instruction, an instruction set architecture (ISA) instruction, a machine instruction, a machine-related instruction, a microcode, a firmware instruction, a state setting data, a configuration data of an integrated circuit, or a source code or an object code written in any combination of one or more programming languages and process programming languages. The computer program 11 may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network (including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider via the Internet). In some embodiments, in order to perform various aspects of the present invention, an electronic circuit including, for example, a programmable logic circuit, a field programmable gate array (FPGA) or a programmable logic array (PLA) may execute computer-readable program instructions by utilizing the state information of the computer-readable program instructions to personalize the electronic circuit.
[0112] In the description of this embodiment, the computer program product 10 is a related product including the computer program 11 .
[0113] For the purpose of the description of the present embodiment, the computer readable storage medium 20 is a tangible device capable of retaining and storing the computer program 11, which can be any device that can contain, store, communicate, propagate or transmit the computer program 11 for use with an instruction execution system, device or apparatus or in conjunction with these instruction execution systems, devices or apparatuses. More specific examples (a non-exhaustive list) of the computer readable storage medium 20 include the following: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, and any suitable combination of the above.
[0114] The computer program product 10 can be run on a computer device. The computer device may include a memory, a processor 32, and a computer program 11 stored in the memory and running on the processor 32. The computer device may be, for example, a server, a desktop computer, a notebook computer, a tablet computer, or a smart phone. In some examples, the computer device may be a cloud computing node. The computer device may be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, a program module may include routines, programs, target programs, components, logic, data structures, etc. that perform specific tasks or implement specific abstract data types. The computer device may be implemented in a distributed cloud computing environment where remote processing devices linked through a communication network perform tasks. In a distributed cloud computing environment, program modules may be located on a local or remote computing system storage medium including a storage device.
[0115] The computer device may include a processor 32 adapted to execute stored instructions, and a memory that provides temporary storage space for the operation of the instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any number of other configurations. The memory may include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.
[0116] The computer device may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows input and output of data with external devices that may be connected to the computer device. The network adapter / interface may provide communication between the computer device and a network, which is usually shown as a communication network.
[0117] At this point, those skilled in the art should recognize that, although multiple exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that conform to the principles of the present invention can still be directly determined or derived based on the content disclosed in the present invention without departing from the spirit and scope of the present invention. Therefore, the scope of the present invention should be understood and recognized as covering all these other variations or modifications.
Claims
1. A database management method, characterized in that: include: According to a preset partitioning algorithm, all nodes of the database are divided into at least two first-level clusters, each of the first-level clusters includes at least one of the nodes; Executing a first master election algorithm in each of the first-level clusters to determine a first-level master node of the first-level cluster from all the nodes contained therein; Combining all the primary master nodes into a secondary cluster; A second master election algorithm is executed in the secondary cluster to determine a secondary master node as the secondary cluster from all the primary master nodes contained therein.
2. The management method according to claim 1, characterized in that: The preset partitioning algorithm includes: Obtaining a communication speed factor between each pair of all the nodes; wherein the communication speed factor is calculated based on the physical distance and / or network bandwidth between the two nodes, and is configured to be negatively correlated with the physical distance and / or positively correlated with the network bandwidth; The two nodes whose communication speed factor is greater than a preset communication speed threshold are grouped into the same primary cluster, and the two nodes whose communication speed factor is less than or equal to the preset communication speed threshold are grouped into different primary clusters.
3. The management method according to claim 1, characterized in that: The first master selection algorithm includes: The nodes within the primary cluster are communicatively connected according to a first heartbeat mechanism; In each heartbeat cycle of the first heartbeat mechanism, each of the nodes within the first-level cluster performs a vote; According to the voting situation, one of the nodes in the first-level cluster is determined as the first-level master node, and the remaining nodes in the first-level cluster are set as first-level slave nodes.
4. The management method according to claim 1, characterized in that: The second master selection algorithm includes: The primary master nodes of the secondary cluster are communicatively connected according to a second heartbeat mechanism; In each heartbeat cycle of the second heartbeat mechanism, each of the first-level master nodes performs a vote; According to the voting situation, one of the first-level master nodes is determined as the second-level master node, and the remaining first-level master nodes are set as second-level slave nodes.
5. The management method according to claim 1, characterized in that: After all the primary master nodes are combined into a secondary cluster, the management method includes: Periodically determining whether the primary master node of each primary cluster has changed at a preset time interval; If so, update the secondary cluster to the combination of all current primary master nodes.
6. The management method according to claim 5, characterized in that: After the second-level cluster is updated to a combination of all current first-level master nodes, the management method further includes: Determine whether the primary master node that has been changed is the secondary master node before the change; If so, immediately execute the second main selection algorithm.
7. The management method according to claim 1, characterized in that: After executing the second master election algorithm in the secondary cluster, the management method further includes: In response to the secondary master node executing a write operation, the secondary master node synchronizes the service data formed by executing the write operation to each secondary slave node; the secondary slave node is each of the other primary master nodes in the secondary cluster except the secondary master node; Each of the first-level master nodes synchronizes the business data to each of the first-level slave nodes; the first-level slave nodes are the other nodes in the same first-level cluster except the first-level master node.
8. The management method according to claim 1, characterized in that: After executing the second master election algorithm in the secondary cluster, the management method further includes: In response to the secondary master node executing a write operation, the secondary master node synchronizes the service data formed by executing the write operation to each secondary slave node, and synchronizes the service data to each primary slave node of the primary cluster to which the secondary master node belongs; the secondary slave nodes are each other primary master node in the secondary cluster except the secondary master node, and the primary slave nodes are each other node in the same primary cluster except the primary master node; Each of the second-level slave nodes synchronizes the service data to each of the first-level slave nodes of the first-level cluster to which it belongs.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed by a processor, the steps of the database management method according to any one of claims 1 to 8 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the database management method according to any one of claims 1 to 8 are implemented.