Methods for configuring nodes in distributed database, methods for synchronizing transaction logs in the distributed database, and nodes in distributed database
Embodiments of this specification provide methods for configuring nodes in a distributed database, methods for synchronizing transaction logs in the distributed database, and the nodes in the distributed database. One method for configuring nodes includes: determining a first quantity of first nodes from N nodes in the distributed database, wherein the first nodes comprise a master node configured to synchronize transactions, the first quantity is an integer greater than N/2, and the first nodes determine a first transaction based on a distributed consistency protocol, and determining one or more of remaining nodes other than the first nodes in the N nodes as asynchronous nodes or election nodes, wherein the asynchronous nodes are configured to asynchronously receive the first transaction from the master node, and the election nodes are configured to modify at least the master node.
1 . A computer-implemented method for configuring nodes in a distributed database, comprising:
determining a first quantity of first nodes from N nodes in the distributed database, wherein N is a positive integer, wherein the first nodes comprise a master node configured to synchronize transactions, the first quantity is an integer greater than N/2, and the first nodes determine a first transaction based on a distributed consistency protocol; and
determining one or more of remaining nodes other than the first nodes in the N nodes as election nodes, wherein the election nodes are configured to determine the master node without receiving the first transaction from the master node.
2 . The computer-implemented method according to claim 1 , wherein the determining a first quantity of first nodes from N nodes in the distributed database comprises:
determining the first quantity of first nodes from the N nodes based on a network bandwidth between the N nodes.
3 . The computer-implemented method according to claim 2 , wherein determining the first quantity of first nodes from the N nodes based on the network bandwidth between the N nodes comprises:
determining that a first pairwise network bandwidth between a first particular node and each of one or more of the N nodes in the distributed database is above a network bandwidth threshold; and
in response to determining that the first pairwise network bandwidth is above the network bandwidth threshold, determining the first particular node as a first node.
4 . The computer-implemented method according to claim 3 , further comprising:
determining that a second pairwise network bandwidth between a second particular node and each of one or more of the N nodes in the distributed database is below the network bandwidth threshold; and
in response to determining that the second pairwise network bandwidth is below the network bandwidth threshold, determining the second particular node as an asynchronous node that is configured to receive the first transaction from the master node after the first transaction is determined by the first nodes.
5 . The computer-implemented method according to claim 1 , wherein the N nodes are N valid nodes in the distributed database, and wherein the election nodes are configured to determine the N valid nodes in the distributed database.
6 . The computer-implemented method according to claim 1 , wherein the determining a first quantity of first nodes from N nodes in the distributed database comprises:
determining the first quantity of first nodes from the N nodes based on a network topology of the distributed database.
7 . The computer-implemented method according to claim 1 , wherein determining one or more of the remaining nodes as the election nodes comprises:
determining one or more of the remaining nodes as the election nodes based on a computing resource of each of one or more of the remaining nodes.
8 . The computer-implemented method according to claim 7 , wherein the computing resource of each of one or more of the remaining nodes comprises: a CPU, memory, or a disk of each of one or more of the remaining nodes.
9 . The computer-implemented method according to claim 1 , wherein determining one or more of the remaining nodes as the election nodes comprises:
determining one or more of the remaining nodes as the election nodes based on a geographic distance between each of one or more of the remaining nodes and each first node.
10 . A distributed database, wherein the distributed database comprises N nodes, and the N nodes comprise:
a first quantity of first nodes, wherein the first nodes comprise a master node configured to synchronize transactions, the first nodes determine a first transaction based on a distributed consistency protocol, and the first quantity is an integer greater than N/2, where N is a positive integer; and
an election node configured to determine the master node in the first nodes without receiving the first transaction from the master node.
11 . The distributed database according to claim 10 , wherein the N nodes are N valid nodes in the distributed database; and
the election node is configured to redetermine the N valid nodes in the distributed database.
12 . A non-transitory, computer-readable medium storing one or more instructions executable by a computer system to perform operations for configuring nodes in a distributed database, the operations comprising:
determining a first quantity of first nodes from N nodes in the distributed database, wherein N is a positive integer, wherein the first nodes comprise a master node configured to synchronize transactions, the first quantity is an integer greater than N/2, and the first nodes determine a first transaction based on a distributed consistency protocol; and
determining one or more of remaining nodes other than the first nodes in the N nodes as election nodes, wherein the election nodes are configured to determine the master node without receiving the first transaction from the master node.
13 . The non-transitory, computer-readable medium according to claim 12 , wherein the determining a first quantity of first nodes from N nodes in the distributed database comprises:
determining the first quantity of first nodes from the N nodes based on a network bandwidth between the N nodes.
14 . The non-transitory, computer-readable medium according to claim 13 , wherein determining the first quantity of first nodes from the N nodes based on the network bandwidth between the N nodes comprises:
determining that a first pairwise network bandwidth between a first particular node and each of one or more of the N nodes in the distributed database is above a network bandwidth threshold; and
in response to determining that the first pairwise network bandwidth is above the network bandwidth threshold, determining the first particular node as a first node.
15 . The non-transitory, computer-readable medium according to claim 14 , wherein the operations further comprise:
determining that a second pairwise network bandwidth between a second particular node and each of one or more of the N nodes in the distributed database is below the network bandwidth threshold; and
in response to determining that the second pairwise network bandwidth is below the network bandwidth threshold, determining the second particular node as an asynchronous node that is configured to receive the first transaction from the master node after the first transaction is determined by the first nodes.
16 . The non-transitory, computer-readable medium according to claim 12 , wherein the N nodes are N valid nodes in the distributed database, and wherein the election nodes are configured to determine the N valid nodes in the distributed database.
17 . The non-transitory, computer-readable medium according to claim 12 , wherein the determining a first quantity of first nodes from N nodes in the distributed database comprises:
determining the first quantity of first nodes from the N nodes based on a network topology of the distributed database.
18 . The non-transitory, computer-readable medium according to claim 12 , wherein determining one or more of the remaining nodes as the election nodes comprises:
determining one or more of the remaining nodes as the election nodes based on a computing resource of each of one or more of the remaining nodes.
19 . The non-transitory, computer-readable medium according to claim 18 , wherein the computing resource of each of one or more of the remaining nodes comprises: a CPU, memory, or a disk of each of one or more of the remaining nodes.
20 . The non-transitory, computer-readable medium according to claim 12 , wherein determining one or more of the remaining nodes as the election nodes comprises:
determining one or more of the remaining nodes as the election nodes based on a geographic distance between each of one or more of the remaining nodes and each first node.