Distributed transaction processing method, system, and related device
View Patent ↗A method includes a first lock server in a lock server cluster sending, based on a transaction coordinator list, a request for obtaining lock data to each transaction coordinator in a transaction coordinator list. If the lock data sent by each transaction coordinator in the transaction coordinator list is obtained, the first lock server processes a lock request sent by the transaction coordinator in the transaction coordinator cluster.
1 . A method, comprising:
sending, by a first lock server in a lock server cluster of a distributed system, to transaction coordinators in a transaction coordinator cluster of the distributed system, and based on a transaction coordinator list comprising the transaction coordinators, requests for obtaining lock data;
processing, by the first lock server, lock requests from the transaction coordinators when obtaining the lock data from the transaction coordinators;
sending, by the first lock server to a third transaction coordinator in the transaction coordinator list, an obtaining request when not receiving, from a second transaction coordinator in the transaction coordinator list, the lock data, wherein the third transaction coordinator comprises a backup of the lock data in the second transaction coordinator; and
receiving, by the first lock server and from the third transaction coordinator, the lock data.
2 . The method of claim 1 , wherein the transaction coordinator list records a first transaction coordinator of the transaction coordinators actively performing a lock operation.
3 . The method of claim 1 , wherein processing the lock requests comprises:
receiving, by the first lock server and from a first transaction coordinator of the transaction coordinators, an acquire lock request;
adding, by the first lock server, an identifier (ID) of the first transaction coordinator to the transaction coordinator list to obtain an updated transaction coordinator list when the transaction coordinator list does not comprise the ID;
synchronizing, by the first lock server and to second lock servers in the lock server cluster, the updated transaction coordinator list; and
when the updated transaction coordinator list is successfully synchronized to a preset proportion of the second lock servers:
performing, by the first lock server and based on the acquire lock request, an acquire lock operation to obtain the lock data; and
storing, by the first lock server and to a storage area of the first lock server, the lock data.
4 . The method of claim 3 , wherein when the updated transaction coordinator list is not synchronized to the preset proportion, the method further comprises:
sending, by the first lock server and to the first transaction coordinator, an acquire lock failure message; and
deleting the ID from the updated transaction coordinator list.
5 . The method of claim 3 , wherein when the transaction coordinator list comprises the ID, the method further comprises:
performing, based on the acquire lock request, the acquire lock operation to obtain the lock data; and
storing, to the storage area, the lock data.
6 . The method of claim 3 , wherein the preset proportion of the second lock servers is 0.5.
7 . The method of claim 3 , wherein the preset proportion of the second lock servers is 1.0.
8 . The method of claim 1 , wherein before processing the lock requests, the method further comprises sending, by the first lock server and to the transaction coordinators, a first message instructing the transaction coordinators to send the lock requests to the first lock server.
9 . The method of claim 1 , wherein before sending the requests, the method further comprises not receiving, by the first lock server, from a second lock server, and within a preset duration, a heartbeat packet.
10 . The method of claim 1 , wherein the first lock server is a candidate primary lock server from the lock server cluster.
11 . A system, comprising:
a transaction coordinator cluster comprising transaction coordinators configured to:
control a distributed transaction processing process, wherein the distributed transaction processing process comprises a first lock operation on a database related to a distributed transaction;
send stored lock data; and
send a lock request; and
a lock server cluster comprising a first lock server configured to:
send, based on a transaction coordinator list comprising the transaction coordinators, a request for obtaining lock data to the transaction coordinators;
obtain, from the transaction coordinators, the stored lock data;
process the lock request after obtaining the stored lock data;
send, to a third transaction coordinator in the transaction coordinator list, an obtaining request when not receiving, from a second transaction coordinator in the transaction coordinator list, the lock data, wherein the third transaction coordinator comprises a backup of the lock data in the second transaction coordinator; and
receive, by the first lock server and from the third transaction coordinator, the lock data.
12 . The system of claim 11 , wherein the lock server cluster further comprises a second lock server configured to synchronize, to the first lock server, the transaction coordinator list, wherein the transaction coordinator list records one of the transaction coordinators actively performing a second lock operation, and wherein before the first lock server sends the request, the second lock server is configured to be a primary lock server that processes the lock request.
13 . The system of claim 11 , wherein the first lock server is further configured to process the lock request by:
receiving, from a first transaction coordinator of the transaction coordinators, an acquire lock request;
adding an identifier (ID) of the first transaction coordinator to the transaction coordinator list to obtain an updated transaction coordinator list when the transaction coordinator list does not comprise the ID;
synchronizing, to second lock servers in the lock server cluster, the updated transaction coordinator list; and
when the updated transaction coordinator list is successfully synchronized to a preset proportion of the second lock servers:
performing, based on the acquire lock request, an acquire lock operation to obtain the lock data; and
storing, to a storage area of the first lock server, the lock data.
14 . The system of claim 13 , wherein when the updated transaction coordinator list is not synchronized to the preset proportion, the first lock server is further configured to:
send, to the first transaction coordinator, an acquire lock failure message; and
delete the ID from the updated transaction coordinator list.
15 . The system of claim 13 , wherein when the transaction coordinator list comprises the ID, the first lock server is further configured to:
perform, based on the acquire lock request, the acquire lock operation to obtain the lock data; and
store, to the storage area, the lock data.
16 . The system of claim 11 , wherein before the first lock server processes the lock request, the first lock server is further configured to send, to the transaction coordinators, a first message instructing the transaction coordinators to send the lock request to the first lock server.
17 . The system of claim 11 , wherein before sending the request, the first lock server is further configured to not receive, from a second lock server and within a preset duration, a heartbeat packet.
18 . The system of claim 11 , wherein the first lock server is a candidate primary lock server selected, based on a preset algorithm, from the lock server cluster.
19 . A computer program product comprising instructions stored on a non-transitory computer-readable medium that, when executed by one or more processors, cause an apparatus to:
send, by a first lock server in a lock server cluster of a distributed system, to transaction coordinators in a transaction coordinator cluster of the distributed system, and based on a transaction coordinator list comprising the transaction coordinators, requests for obtaining lock data;
process, by the first lock server, lock requests from the transaction coordinators when obtaining the lock data from the transaction coordinators;
send, by the first lock server to a third transaction coordinator in the transaction coordinator list, an obtaining request when not receiving, from a second transaction coordinator in the transaction coordinator list, the lock data, wherein the third transaction coordinator comprises a backup of the lock data in the second transaction coordinator; and
receive, by the first lock server and from the third transaction coordinator, the lock data.
20 . The computer program product of claim 19 , wherein before processing the lock requests, the one or more processors further cause the apparatus to send, by the first lock server and to the transaction coordinators, a first message instructing the transaction coordinators to send the lock requests to the first lock server.