CN113254167B - Distributed transaction processing method, device and system and electronic equipment - Google Patents
Distributed transaction processing method, device and system and electronic equipment Download PDFInfo
- Publication number
- CN113254167B CN113254167B CN202110628823.9A CN202110628823A CN113254167B CN 113254167 B CN113254167 B CN 113254167B CN 202110628823 A CN202110628823 A CN 202110628823A CN 113254167 B CN113254167 B CN 113254167B
- Authority
- CN
- China
- Prior art keywords
- transaction
- information
- server
- global
- item information
- 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.)
- Active
Links
- 238000003672 processing method Methods 0.000 title claims abstract description 22
- 238000000034 method Methods 0.000 claims abstract description 69
- 238000012545 processing Methods 0.000 claims abstract description 58
- 230000000977 initiatory effect Effects 0.000 claims abstract description 35
- 238000004891 communication Methods 0.000 claims description 11
- 238000004590 computer program Methods 0.000 claims description 9
- 230000010365 information processing Effects 0.000 claims description 4
- 230000008569 process Effects 0.000 abstract description 34
- 230000008859 change Effects 0.000 description 14
- 239000003999 initiator Substances 0.000 description 14
- 238000012217 deletion Methods 0.000 description 10
- 230000037430 deletion Effects 0.000 description 10
- 238000010586 diagram Methods 0.000 description 6
- 230000006870 function Effects 0.000 description 5
- 239000002699 waste material Substances 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012544 monitoring process Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
- 230000001960 triggered effect Effects 0.000 description 1
Images
Classifications
-
- 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/466—Transaction processing
-
- 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/23—Updating
-
- 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/24—Querying
- G06F16/245—Query processing
- G06F16/2458—Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
- G06F16/2471—Distributed queries
-
- 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
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Software Systems (AREA)
- Fuzzy Systems (AREA)
- Computational Linguistics (AREA)
- Probability & Statistics with Applications (AREA)
- Mathematical Physics (AREA)
- Computing Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention provides a distributed transaction processing method, a device, a system and electronic equipment. Wherein, the method comprises the following steps: the central server responds to a transaction initiating request of the first transaction server and distributes global transaction information for a transaction corresponding to the transaction initiating request; the global transaction information is distributed to a second transaction server participating in the transaction through the first transaction server, so that the second transaction server feeds back to-be-operated item information corresponding to the transaction according to the global transaction information; storing the to-be-operated item information corresponding to the global transaction information to a storage server; when the execution state of the first transaction server for executing the transaction is monitored to be successful, the to-be-operated item information corresponding to the global transaction information in the storage server is processed, so that the consistency and concurrency of data in the distributed transaction processing process are realized, and the processing efficiency of the distributed transaction is improved.
Description
Technical Field
The present invention relates to the field of network technologies, and in particular, to a distributed transaction processing method, apparatus, system, and electronic device.
Background
With the development of the internet and the continuous change of user requirements, various application businesses become more and more complex, especially, transactions related to business in the financial industry are mostly realized by adopting a distributed architecture to realize effective services. In a distributed architecture, the same transaction may need to access across multiple databases, such as read and/or write operations, and in order to ensure consistency of data access across multiple databases, distributed transactions are mostly used to process financial transactions.
In practical applications, the distributed transaction has final consistency, for example, the distributed transaction modifies a certain data from a to B, then the data may be A, B or other data during the execution of the distributed transaction, but after the distributed transaction is finished, the data can only be a (transaction rollback) or B (transaction commit).
The current distributed transactions are classified into strong and weak consistency; the strong consistency can ensure the strong consistency of data under the distributed transaction, but the method needs to keep the occupation time of the transaction long, problems such as deadlock and the like can be caused, the performance is low, and the use scene is limited, therefore, the existing distributed transaction mostly adopts weak consistency, although the method can ensure the final data consistency of the transaction, dirty data reading can occur, namely, a distributed transaction can read the data which is accessed by the unfinished distributed transaction, so that the consistency and the concurrency performance of the data can not be ensured in the distributed transaction processing process, and the processing efficiency of the distributed transaction is influenced.
Disclosure of Invention
In view of this, the present invention provides a method, an apparatus, a system and an electronic device for distributed transaction processing, so as to alleviate the above problems, improve the consistency and concurrency of data in the process of distributed transaction processing, and thus improve the processing efficiency of distributed transaction.
In a first aspect, an embodiment of the present invention provides a distributed transaction processing method, which is applied to a central server, where the central server is in communication connection with a plurality of transaction servers and storage servers, respectively; the method comprises the following steps: responding to a transaction initiating request of a first transaction server, and generating global transaction information for a transaction corresponding to the transaction initiating request; the global transaction information is distributed to a second transaction server participating in the transaction through the first transaction server, so that the second transaction server feeds back to-be-operated item information corresponding to the transaction according to the global transaction information; storing the to-be-operated item information corresponding to the global transaction information to a storage server; and when the execution state of the transaction executed by the first transaction server is monitored to be successful, processing the to-be-operated item information corresponding to the global transaction information in the storage server.
With reference to the first aspect, an embodiment of the present invention provides a first possible implementation manner of the first aspect, where the storing, to the storage server, the to-be-operated item information corresponding to the global transaction information includes: and storing the to-be-operated item information corresponding to the global transaction information to a storage server according to a locking state.
With reference to the first possible implementation manner of the first aspect, an embodiment of the present invention provides a second possible implementation manner of the first aspect, where the step of processing the to-be-operated item information corresponding to the global transaction information in the storage server includes: and generating change instruction information, and sending the change instruction information to the storage server so that the storage server changes the to-be-operated item information corresponding to the global transaction information from a locking state to an unlocking state according to the change instruction information.
With reference to the second possible implementation manner of the first aspect, an embodiment of the present invention provides a third possible implementation manner of the first aspect, where the method further includes: and if the execution state is the execution failure state, generating deletion instruction information, and sending the deletion instruction information to the storage server so that the storage server deletes the to-be-operated item information corresponding to the global transaction information according to the deletion instruction information.
With reference to the first possible implementation manner of the first aspect, an embodiment of the present invention provides a fourth possible implementation manner of the first aspect, where the storing, in a locked state, to-be-operated item information corresponding to the global transaction information in a storage server includes: when it is monitored that the feedback operation of all second transaction servers participating in the transaction is completed, storing the to-be-operated item information fed back by all second transaction servers corresponding to the global transaction information to a storage server according to a locking state; or when the feedback operation of the current second transaction server is monitored to be completed, storing the to-be-operated item information fed back by the current second transaction server corresponding to the global transaction information to the storage server according to the locking state.
With reference to the first aspect, an embodiment of the present invention provides a fifth possible implementation manner of the first aspect, where after the step of storing the to-be-operated item information corresponding to the global transaction information in the storage server, the method further includes: when the storage operation of the to-be-operated item information corresponding to the global transaction information is monitored to be completed, a storage completion identifier is generated; and sending the storage completion identifier to the first transaction server to trigger the first transaction server to execute the transaction according to the global transaction information.
In a second aspect, an embodiment of the present invention further provides a distributed transaction processing apparatus, which is applied to a central server, where the central server is respectively in communication connection with a plurality of transaction servers and a storage server; the device includes: the global transaction information generating module is used for responding to a transaction initiating request of the first transaction server and generating global transaction information for a transaction corresponding to the transaction initiating request; the to-be-operated item information acquisition module is used for distributing the global transaction information to a second transaction server participating in the transaction through the first transaction server so that the second transaction server feeds back the to-be-operated item information corresponding to the transaction according to the global transaction information; the to-be-operated item information storage module is used for storing the to-be-operated item information corresponding to the global transaction information to the storage server; and the to-be-operated item information processing module is used for processing the to-be-operated item information corresponding to the global transaction information in the storage server when the execution state that the first transaction server executes the transaction is monitored to be successful.
In a third aspect, an embodiment of the present invention further provides a distributed transaction processing system, which is applied to the distributed transaction processing method in the first aspect; the system comprises a central server and a plurality of transaction servers which are respectively in communication connection with the central server.
In a fourth aspect, an embodiment of the present invention further provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the steps of the method in the first aspect when executing the computer program.
In a fifth aspect, the present invention further provides a computer-readable storage medium, on which a computer program is stored, where the computer program is executed by a processor to perform the steps of the method in the first aspect.
The embodiment of the invention has the following beneficial effects:
the embodiment of the invention provides a distributed transaction processing method, a device, a system and electronic equipment, for a transaction corresponding to a transaction initiation request of a first transaction server, a central server distributes global transaction information for the transaction, and receives to-be-operated transaction information corresponding to the transaction fed back by a second transaction server participating in the transaction according to the global transaction information so as to store the to-be-operated transaction information in a storage server and process the to-be-operated transaction information until the fact that the transaction is successfully executed by the first transaction server is monitored, compared with the existing transaction servers which respectively process the to-be-operated transaction information, the to-be-operated transaction information corresponding to the transaction is stored in the storage server, and when the execution state of the first transaction server is successful, the to-be-operated transaction information in the storage server is processed simultaneously, so that dirty reading in the processing process is avoided, the consistency and concurrency of data in the distributed transaction processing process are realized, and the processing efficiency of the distributed transaction is improved.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and drawings.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a schematic structural diagram of a distributed transaction processing system according to an embodiment of the present invention;
fig. 2 is a flowchart of a distributed transaction processing method according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of another distributed transaction processing system according to an embodiment of the present invention;
FIG. 4 is a flow chart of another distributed transaction processing method provided by an embodiment of the invention;
fig. 5 is an interaction diagram of a distributed transaction processing method according to an embodiment of the present invention;
fig. 6 is a schematic diagram of a distributed transaction processing apparatus according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Aiming at the problem that dirty reading occurs in the existing distributed transaction processing process, the embodiment of the invention provides a distributed transaction processing method, a device, a system and electronic equipment.
To facilitate understanding of the embodiment, first, a detailed description is given below of a distributed transaction processing system provided in the embodiment of the present invention, where the system may be used to implement the distributed transaction processing function of the embodiment of the present invention.
Fig. 1 is a schematic structural diagram of a distributed transaction processing system, where the distributed transaction processing system 1 includes a central server 10, and a plurality of transaction servers 20 and storage servers 30 respectively connected to the central server 10 in communication; wherein the storage server 30 is configured with a message queue 31, which components are interconnected by a bus system 40 and/or other form of connection mechanism (not shown). It should be noted that the components and structure of the distributed transaction system 1 shown in fig. 1 are exemplary only and not limiting, and that the distributed transaction system described above may have other components and structures as desired.
The central server 10, the transaction server 20 and the storage server 30 may also be configured as intelligent terminals, or devices or apparatuses including a Central Processing Unit (CPU) or other forms of processing units with data processing capability and/or instruction execution capability to implement the functions of distributed transaction processing. It should be noted that in practical applications, the central server 10 and the storage server 30 may also be one or more, for example, different central servers and corresponding storage servers are set according to different application scenarios of distributed transactions, and the setting may be specifically performed according to practical situations.
It should be noted that, in practical applications, for the plurality of transaction servers 20, in practical applications, the transaction servers are communicatively connected to each other, and in different transactions, the transaction server may be a transaction initiator, that is, a first transaction server, and may also be a transaction participant, that is, a second transaction server, for example, the transaction server a initiates a first transaction, that is, the transaction server a is the first transaction server in the first transaction; meanwhile, for a second transaction initiated by the transaction server B, the transaction server a participates in the second transaction, that is, the transaction server a is a second transaction server in the second transaction, and therefore, the specific function of each transaction server is set according to the specific transaction processing condition, which is not described in the embodiment of the present invention.
Based on the distributed transaction processing system, an embodiment of the present invention provides a distributed transaction processing method, where an execution subject is a central server, and as shown in fig. 2, the method includes the following steps:
step S202, responding to a transaction initiating request of a first transaction server, and generating global transaction information for a transaction corresponding to the transaction initiating request;
specifically, a first transaction server is a transaction initiator in a plurality of transaction servers, and before starting a distributed transaction, when a central server monitors a transaction initiation request of the first transaction server, global transaction information is generated for a transaction corresponding to the transaction initiation request; the global transaction information comprises global transaction identification information and global transaction attribute information; the global transaction identification information may be a distributed transaction ID (Identity Document) corresponding to the transaction or other identification information for characterizing the transaction, and may be specifically set according to an actual situation; the global transaction attribute information includes attribute information to which a transaction corresponding to the transaction initiation request belongs, and various operation information included in the transaction corresponding to the transaction initiation request, so that the transaction corresponding to the transaction initiation request can be distinguished from other transactions through the global transaction information, and it can be ensured that a second transaction server participating in the transaction determines corresponding to-be-operated item information according to the global transaction information, and the setting can be specifically performed according to actual conditions. For example, as shown in fig. 3, before starting the distributed transaction, when the central server 10 monitors the transaction initiation request sent by the first transaction server 21, the global transaction information of the transaction corresponding to the transaction initiation request is generated for the first transaction server 21.
In practical application, one possible allocation manner is as follows: the central server generates global transaction information for a transaction corresponding to a transaction initiation request according to the transaction initiation request of the first transaction server, and sends the generated global transaction information to the first transaction server; another possible allocation is: the method comprises the steps that a global transaction information set is stored in a central server, wherein each piece of global transaction information in the global transaction information set is different, when the central server monitors a transaction initiation request of a first transaction server, one piece of global transaction information is selected from the global transaction information set to serve as the global transaction information of a transaction corresponding to the transaction initiation request, and the selected global transaction information is sent to the first transaction server; the specific allocation mode of the global transaction information can be set according to actual situations.
Step S204, global transaction information is distributed to a second transaction server participating in the transaction through the first transaction server, so that the second transaction server feeds back to-be-operated item information corresponding to the transaction according to the global transaction information;
after the first transaction server acquires the global transaction information, the global transaction information is distributed to all second transaction servers participating in the transaction, so that the second transaction servers feed back to-be-operated item information corresponding to the transaction according to the global transaction information, wherein the second transaction servers can also be called transaction participants. After receiving the global transaction information, the second transaction server determines a corresponding local transaction according to the global transaction information, that is, in the transaction corresponding to the transaction initiation request, a distributed sub-transaction corresponding to the second transaction server, and operation information corresponding to the local transaction, such as an SQL (Structured Query Language) set for operation, and combines the second transaction and the corresponding operation information into to-be-operated item information corresponding to the second transaction server.
Therefore, the central server can obtain the local transaction and the corresponding operation information corresponding to each second transaction server in the transaction according to the information of the to-be-operated items fed back by each second transaction server. For example, as shown in fig. 3, the first transaction server 21 distributes the global transaction information to the second transaction server 22 participating in the transaction, so that the second transaction server 22 feeds back the corresponding to-be-operated item information to the central server 10; it should be noted that, only one second transaction server 22 is shown here, and the number of the second transaction servers participating in the transaction in particular may be set according to practical situations.
Step S206, storing the to-be-operated item information corresponding to the global transaction information to a storage server;
specifically, as shown in fig. 3, the central server 10 stores the to-be-operated item information corresponding to the global transaction information fed back by the second transaction server 22 in the message queue 31 according to the locked state; in the message queue, each to-be-operated item information carries corresponding global transaction information or global transaction identification information of the global transaction information, and is distinguished through the global transaction identification information; the locking state can also be called a half message state, that is, in the sending process, the to-be-operated item information corresponding to the global transaction information cannot be consumed, so that the problem that the final data cannot keep consistency due to the change of part of the to-be-operated item information in the storage process is solved.
In the storage process, one possible storage mode is as follows: when it is monitored that the feedback operation of all second transaction servers participating in the transaction is completed, storing the to-be-operated item information fed back by all second transaction servers corresponding to the global transaction information into a message queue according to a locking state; specifically, when all the second transaction servers participating in the transaction complete the feedback, at this time, the central server stores the to-be-operated item information fed back by all the second transaction servers to the message queue according to the locking state, so that the central server is prevented from executing multiple storage operations, the storage efficiency is improved, and the consistency and concurrency of the to-be-operated item information corresponding to the global transaction information in the storage process are ensured.
Another possible storage manner is: and when the feedback operation of the current second transaction server is monitored to be completed, storing the to-be-operated item information fed back by the current second transaction server corresponding to the global transaction information into a message queue according to a locking state. Specifically, when the central server listens to the feedback operation of the current second transaction server in the plurality of second transaction servers participating in the transaction, directly storing the information of the to-be-operated items fed back by the current second transaction server corresponding to the global transaction information into a message queue according to a locking state without waiting, that is, the central server directly stores the information of the to-be-operated items fed back by the second transaction server according to the first-come first-serve principle, the storage mode avoids the resource waste caused by the waiting process of the central server, meanwhile, when the to-be-operated item information fed back by a certain second transaction server needs to be changed, the first-come first-processing principle also avoids processing all the to-be-operated item information corresponding to the global transaction information, and only the to-be-operated item information needing to be changed needs to be searched in the message queue, so that various processing requirements are met.
It should be noted that the specific storage process of the to-be-operated item information may be set according to actual requirements, and this is not limited in the embodiment of the present invention.
Step S208, when it is monitored that the execution state of the transaction executed by the first transaction server is successful, processing the to-be-operated item information corresponding to the global transaction information in the storage server.
Specifically, after the storing is completed, when the central server monitors that the execution state of the transaction initiator, that is, the first transaction server, for executing the transaction is successful, and if the execution state of the first transaction server, after executing the local operation corresponding to the transaction, is successful, the central server processes the to-be-operated item information corresponding to the global transaction information in the message queue according to the execution state, so that the to-be-operated item information of each transaction participant is separately stored in the message queue, and is uniformly processed after the transaction initiator completes the local operation, thereby avoiding the problem of dirty reading in the distributed transaction processing process.
Compared with the existing transaction servers which respectively process the transaction information, the distributed transaction processing method provided by the embodiment of the invention stores the transaction information corresponding to the transaction into the storage server by storing the transaction information corresponding to the transaction into the storage server, and simultaneously processes the transaction information in the storage server when the execution state of the first transaction server is monitored to be successful, avoids dirty reading in the processing process and realizes the consistency and concurrency of data in the distributed transaction processing process, the processing efficiency of the distributed transaction is improved.
Optionally, after the information of the to-be-operated item corresponding to the global transaction information is stored in the storage server, the method further includes: when the storage operation of the to-be-operated item information corresponding to the global transaction information is monitored to be completed, a storage completion identifier is generated; and sending the storage completion identifier to the first transaction server to trigger the first transaction server to execute the transaction according to the global transaction information. Specifically, after the central server completes storage of all pieces of to-be-operated transaction information corresponding to the global transaction information, a storage completion identifier is further generated, so that a transaction initiator, that is, a first transaction server, is triggered to start executing a local operation corresponding to a transaction through the storage completion identifier, and the to-be-operated transaction information in the message queue is processed according to an execution state.
On the basis of fig. 2, another distributed transaction processing method is further provided in the embodiments of the present invention, where an execution subject is a central server, and the method mainly describes a process of processing to-be-operated item information corresponding to global transaction information in a storage server according to an execution state. As shown in fig. 4, the method comprises the steps of:
step S402, responding to the transaction initiation request of the first transaction server, and generating global transaction information for the transaction corresponding to the transaction initiation request;
step S404, global transaction information is distributed to a second transaction server participating in the transaction through the first transaction server, so that the second transaction server feeds back to-be-operated item information corresponding to the transaction according to the global transaction information;
step S406, storing the to-be-operated item information corresponding to the global transaction information to a storage server;
step S408, monitoring the execution state of the first transaction server for executing the transaction;
the aforementioned method embodiments can be referred to in the aforementioned steps S402 to S408, and the embodiments of the present invention are not described in detail herein.
Step S410, judging whether the execution state is the execution success state; if so, go to step S412; otherwise, step S414 is executed.
Step S412, generating change instruction information, and sending the change instruction information to a storage server, so that the storage server changes the to-be-operated item information corresponding to the global transaction information from a locking state to an unlocking state according to the change instruction information;
specifically, when the central server monitors that the local operation executed by the transaction initiator, that is, the first transaction server, is successful, the central server generates change instruction information at this time to change the to-be-operated item information corresponding to the global transaction information in the message queue from the locked state to the unlocked state, where the unlocked state may also be referred to as a consumption state, so as to execute the to-be-operated item information corresponding to the global transaction information in the message queue, for example, a distributed sub-transaction in each to-be-operated item information is processed according to the corresponding operation information, where the operation information includes a change operation, an add operation, a delete operation, a commit operation, and the like, and may be specifically set according to an actual situation.
Therefore, the to-be-operated transaction information corresponding to the global transaction information is stored in the message queue and is simultaneously processed, so that the dirty reading phenomenon in the distributed transaction processing process is avoided, the consistency and concurrency of data in the distributed transaction processing process are realized, and the processing efficiency of the distributed transaction is improved.
And step S414, generating deletion instruction information, and sending the deletion instruction information to the storage server, so that the storage server deletes the to-be-operated item information corresponding to the global transaction information according to the deletion instruction information.
In addition, when the central server monitors that the local operation executed by the transaction initiator, namely the first transaction server, fails, the transaction execution fails, the to-be-operated item information of each corresponding transaction participant does not need to be executed, namely, the central server generates deletion instruction information to delete the to-be-operated item information corresponding to the global transaction information in the message queue, so that the situation of resource waste caused by too much useless to-be-operated item information stored in the message queue is avoided, and the storage space of the message queue is saved.
Optionally, on the basis of the foregoing method embodiment, another distributed transaction processing method is further provided in the embodiments of the present invention, where an execution subject is a distributed transaction processing system, where the distributed transaction processing system includes a transaction coordinator (i.e., a central server), and a transaction initiator (i.e., a first transaction server), a transaction participant (i.e., a second transaction server), and a storage server configured with a message queue, which are respectively connected to the transaction coordinator, and as shown in fig. 5, the method includes the following steps:
step S502, the transaction initiating side sends a transaction initiating request to the transaction coordinating side;
step S504, the transaction coordinator distributes global transaction information for the transaction corresponding to the transaction initiation request; for example, global transaction information is generated for a transaction corresponding to a transaction initiation request, or global transaction information is allocated for the transaction corresponding to the transaction initiation request from a pre-stored global transaction information set;
step S506, the transaction coordinator sends the global transaction information to the transaction initiator;
step S508, the transaction initiator distributes the global transaction information to the transaction participants participating in the transaction; the number of the transaction participants can be set according to actual conditions, and only one transaction participant is shown in the embodiment of the invention;
step S510, the transaction participant generates corresponding to-be-operated item information according to the global transaction information; if the transaction participant determines the distributed sub-transactions in the transaction corresponding to the transaction initiation request and the operation information corresponding to the distributed sub-transactions according to the global transaction information, and the distributed sub-transactions and the operation information form the to-be-operated item information corresponding to the global transaction information;
step S512, the transaction participant feeds back the information of the to-be-operated items corresponding to the global transaction information to the transaction coordinator;
step S514, the transaction coordinator stores the information of the to-be-operated items corresponding to the global transaction information into a message queue;
step S516, the transaction coordinator generates a storage completion identifier; when the information of the to-be-operated items corresponding to the global transaction information is completely stored, the transaction coordinator generates a storage completion identifier;
step S518, the transaction coordinator sends the storage completion identifier to the transaction initiator;
step S520, the transaction initiator executes the local operation corresponding to the transaction according to the storage completion identifier;
step S522, the transaction initiator sends the execution state to the transaction coordinator;
step S524, the transaction coordinator processes the to-be-operated item information corresponding to the global transaction information in the message queue according to the execution state.
The above steps can be seen in detail in the foregoing embodiments, and the embodiments of the present invention are not described in detail herein. Therefore, according to the distributed transaction processing method, the to-be-operated item information corresponding to the transaction participant is stored in the message queue, and then the to-be-operated item information in the message queue is processed by the transaction coordinator according to the execution state of the local operation corresponding to the transaction executed by the transaction initiator, so that dirty reading in the processing process is avoided, the consistency and concurrency of data in the distributed transaction processing process are realized, and the processing efficiency of the distributed transaction is improved.
Corresponding to the above method embodiment, the embodiment of the present invention further provides a distributed transaction processing apparatus, which is applied to a central server, and the central server is respectively in communication connection with a plurality of transaction servers and a storage server; as shown in fig. 6, the apparatus comprises, connected in sequence: a global transaction information generating module 61, a to-be-operated item information acquiring module 62, a to-be-operated item information storing module 63 and a to-be-operated item information processing module 64; the functions of each module are as follows:
a global transaction information generating module 61, configured to respond to a transaction initiation request of a first transaction server, and generate global transaction information for a transaction corresponding to the transaction initiation request;
a to-be-operated item information obtaining module 62, configured to distribute, by the first transaction server, the global transaction information to a second transaction server participating in the transaction, so that the second transaction server feeds back, according to the global transaction information, to-be-operated item information corresponding to the transaction;
a to-be-operated item information storage module 63, configured to store to-be-operated item information corresponding to the global transaction information to a storage server;
and the to-be-operated item information processing module 64 is configured to process the to-be-operated item information corresponding to the global transaction information in the storage server when it is monitored that the execution state of the transaction executed by the first transaction server is successful.
Compared with the existing transaction servers which respectively process the to-be-operated item information, the distributed transaction processing device provided by the embodiment of the invention stores the to-be-operated item information corresponding to the transaction to the storage server, and simultaneously processes the to-be-operated item information in the storage server when the execution state of the first transaction server is successfully monitored, so that dirty reading in the processing process is avoided, the consistency and concurrency of data in the distributed transaction processing process are realized, and the processing efficiency of the distributed transaction is improved.
In one possible embodiment, the backlog information storage module 63 is further configured to: and storing the to-be-operated item information corresponding to the global transaction information to a storage server according to a locking state.
In another possible embodiment, the processing the to-be-operated item information corresponding to the global transaction information in the storage server includes: and generating change instruction information, and sending the change instruction information to the storage server so that the storage server changes the to-be-operated item information corresponding to the global transaction information from a locking state to an unlocking state according to the change instruction information.
In another possible embodiment, the apparatus further comprises: and if the execution state is the execution failure state, generating deletion instruction information, and sending the deletion instruction information to the storage server so that the storage server deletes the to-be-operated item information corresponding to the global transaction information according to the deletion instruction information.
In another possible embodiment, the backlog information storage module 63 is further configured to: when it is monitored that the feedback operation of all second transaction servers participating in the transaction is completed, storing the to-be-operated item information fed back by all second transaction servers corresponding to the global transaction information to a storage server according to a locking state; or when the feedback operation of the current second transaction server is monitored to be completed, storing the to-be-operated item information fed back by the current second transaction server corresponding to the global transaction information to the storage server according to the locking state.
In another possible embodiment, after the backlog information storage module 63, the apparatus further includes: when the storage operation of the to-be-operated item information corresponding to the global transaction information is monitored to be completed, a storage completion identifier is generated; and sending the storage completion identifier to the first transaction server to trigger the first transaction server to execute the transaction according to the global transaction information.
The distributed transaction processing apparatus provided in the embodiment of the present invention has the same technical features as the distributed transaction processing method provided in the above embodiment, so that the same technical problems can be solved, and the same technical effects can be achieved.
The embodiment of the present invention further provides an electronic device, which includes a processor and a memory, where the memory stores machine executable instructions capable of being executed by the processor, and the processor executes the machine executable instructions to implement the distributed transaction processing method.
Referring to fig. 7, the electronic device comprises a processor 70 and a memory 71, the memory 71 stores machine executable instructions capable of being executed by the processor 70, and the processor 70 executes the machine executable instructions to implement the distributed transaction processing method described above.
Further, the electronic device shown in fig. 7 further includes a bus 72 and a communication interface 73, and the processor 70, the communication interface 73 and the memory 71 are connected through the bus 72.
The Memory 71 may include a high-speed Random Access Memory (RAM) and may further include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 73 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used. The bus 72 may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Enhanced Industry Standard Architecture) bus, or the like. The above-mentioned bus may be classified into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one double-headed arrow is shown in FIG. 7, but this does not indicate only one bus or one type of bus.
The processor 70 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 70. The Processor 70 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, a discrete Gate or transistor logic device, or a discrete hardware component. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 71, and the processor 70 reads the information in the memory 71 and completes the steps of the method of the foregoing embodiment in combination with the hardware thereof.
The present embodiments also provide a machine-readable storage medium having stored thereon machine-executable instructions that, when invoked and executed by a processor, cause the processor to implement the distributed transaction processing method described above.
The distributed transaction processing method, apparatus, system, and computer program product of the electronic device provided in the embodiments of the present invention include a computer-readable storage medium storing a program code, where instructions included in the program code may be used to execute the method described in the foregoing method embodiments, and specific implementation may refer to the method embodiments, and will not be described herein again.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In addition, in the description of the embodiments of the present invention, unless otherwise explicitly specified or limited, the terms "mounted," "connected," and "connected" are to be construed broadly, e.g., as meaning either a fixed connection, a removable connection, or an integral connection; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. The specific meanings of the above terms in the present invention can be understood in specific cases to those skilled in the art.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims (8)
1. A method of distributed transaction processing, the method comprising:
acquiring a transaction initiation request sent by a first transaction server, and generating global transaction information for a transaction corresponding to the transaction initiation request;
sending the global transaction information to the first transaction server to cause the first transaction server to distribute the global transaction information to a second transaction server participating in the transaction;
obtaining to-be-operated item information corresponding to the transaction and fed back by the second transaction server according to the global transaction information;
storing the to-be-operated item information corresponding to the global transaction information according to a locking state;
when the execution state of the transaction executed by the first transaction server is monitored to be successful, unlocking the to-be-operated item information corresponding to the global transaction information;
storing the to-be-operated item information corresponding to the global transaction information according to a locking state, wherein the step comprises the following steps of:
when it is monitored that the feedback operation of all second transaction servers participating in the transaction is completed, storing the to-be-operated item information fed back by all second transaction servers corresponding to the global transaction information according to a locking state; or,
when the fact that the feedback operation of the current second transaction server is completed is monitored, storing the to-be-operated item information fed back by the current second transaction server corresponding to the global transaction information according to a locking state;
each piece of to-be-operated item information is also configured with a weight, and the step of storing the to-be-operated item information fed back by all the second transaction servers corresponding to the global transaction information according to a locking state comprises the following steps:
when the weight of the current to-be-operated item information in the to-be-operated item information fed back by all the second transaction servers is smaller than a preset weight threshold, determining the current to-be-operated item information as target to-be-operated item information corresponding to the global transaction information;
and storing the target to-be-operated item information according to a locking state.
2. The method of claim 1, further comprising:
and if the execution state is failure, deleting the to-be-operated item information corresponding to the global transaction information.
3. The method according to claim 1, wherein the to-be-operated item information carries priority information, and the step of storing the to-be-operated item information fed back by all the second transaction servers corresponding to the global transaction information according to a locked state includes:
and locking the to-be-operated item information fed back by all the second transaction servers corresponding to the global transaction information according to the priority information, and storing the to-be-operated item information fed back by all the second transaction servers according to a locking state after the locking is completed.
4. The method according to claim 1, wherein after the step of storing the backlog information corresponding to the global transaction information according to a locked state, the method further comprises:
when the storage operation of the to-be-operated item information corresponding to the global transaction information is monitored to be completed, a storage completion identifier is generated;
and sending the storage completion identifier to the first transaction server to trigger the first transaction server to execute the transaction according to the global transaction information.
5. A distributed transaction processing device is applied to a central server, and the central server is respectively in communication connection with a plurality of transaction servers; the device comprises:
the global transaction information generating module is used for responding to a transaction initiating request of a first transaction server and generating global transaction information for a transaction corresponding to the transaction initiating request;
a to-be-operated item information obtaining module, configured to distribute, by the first transaction server, the global transaction information to a second transaction server participating in the transaction, so that the second transaction server feeds back, according to the global transaction information, to-be-operated item information corresponding to the transaction;
the to-be-operated item information storage module is used for storing the to-be-operated item information corresponding to the global transaction information according to a locking state;
the to-be-operated item information processing module is used for unlocking the to-be-operated item information corresponding to the global transaction information when the execution state that the first transaction server executes the transaction is monitored to be successful;
the to-be-operated item information storage module is further configured to store, when it is monitored that feedback operations of all second transaction servers participating in the transaction are completed, to-be-operated item information fed back by all second transaction servers corresponding to the global transaction information according to a locking state; or,
when the fact that the feedback operation of the current second transaction server is completed is monitored, storing the to-be-operated item information fed back by the current second transaction server corresponding to the global transaction information according to a locking state;
each piece of to-be-operated event information is also configured with a weight, and the to-be-operated event information storage module is further configured to determine the current to-be-operated event information as target to-be-operated event information corresponding to the global event information when the weight of the current to-be-operated event information in the to-be-operated event information fed back by all the second transaction servers is smaller than a preset weight threshold;
and storing the target to-be-operated item information according to a locking state.
6. A distributed transaction processing system, characterized in that, applied to the distributed transaction processing method of any one of the above claims 1-4; the system comprises a central server and a plurality of transaction servers which are respectively in communication connection with the central server.
7. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the steps of the method of any of the preceding claims 1-4 are implemented when the computer program is executed by the processor.
8. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when being executed by a processor, performs the steps of the method of any of the preceding claims 1-4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110628823.9A CN113254167B (en) | 2021-06-07 | 2021-06-07 | Distributed transaction processing method, device and system and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110628823.9A CN113254167B (en) | 2021-06-07 | 2021-06-07 | Distributed transaction processing method, device and system and electronic equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113254167A CN113254167A (en) | 2021-08-13 |
CN113254167B true CN113254167B (en) | 2021-11-16 |
Family
ID=77186607
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110628823.9A Active CN113254167B (en) | 2021-06-07 | 2021-06-07 | Distributed transaction processing method, device and system and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113254167B (en) |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115271736B (en) * | 2022-07-11 | 2023-06-16 | 中电金信软件有限公司 | Method, device, equipment and storage medium for verifying transaction consistency |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US6671686B2 (en) * | 2000-11-02 | 2003-12-30 | Guy Pardon | Decentralized, distributed internet data management |
CN107045454B (en) * | 2016-02-06 | 2020-06-26 | 华为技术有限公司 | Cross-process distributed transaction control method and related system |
CN108279986B (en) * | 2017-12-29 | 2023-10-03 | 亿阳安全技术有限公司 | Distributed transaction processing method and device |
CN109408203B (en) * | 2018-11-01 | 2019-10-18 | 无锡华云数据技术服务有限公司 | A kind of implementation method, device, the computing system of queue message consistency |
CN111651244B (en) * | 2020-07-01 | 2023-08-18 | 中国银行股份有限公司 | Distributed transaction processing system |
-
2021
- 2021-06-07 CN CN202110628823.9A patent/CN113254167B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN113254167A (en) | 2021-08-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11336451B2 (en) | Cross-blockchain resource transmission | |
EP3934162B1 (en) | Blockchain consensus method and device and electronic equipment | |
CN112052264B (en) | Business data query method and device, electronic equipment and readable storage medium | |
CN110471746B (en) | Distributed transaction callback method, device and system | |
CN110188110B (en) | Method and device for constructing distributed lock | |
CN111638972B (en) | Request response method, system, equipment and storage medium based on micro-service | |
CN109379398B (en) | Data synchronization method and device | |
CN110943934A (en) | Service request processing method, system, terminal and readable storage medium | |
CN110880147B (en) | Transaction processing method, related equipment and computer storage medium | |
CN113254167B (en) | Distributed transaction processing method, device and system and electronic equipment | |
CN112650812A (en) | Data fragment storage method and device, computer equipment and storage medium | |
CN112799791A (en) | Method and device for calling distributed lock, electronic equipment and storage medium | |
CN109684048B (en) | Method and device for processing transaction in transaction submitting system | |
CN110908968B (en) | Method, device, equipment and storage medium for avoiding frightened groups during file lock unlocking | |
CN112084068A (en) | Database remote backup method and device and cloud server | |
CN114489956A (en) | Instance starting method and device based on cloud platform | |
CN113902415A (en) | Financial data checking method and device, computer equipment and storage medium | |
CN111475306B (en) | Micro service node, asynchronous task processing method, system and storage medium | |
CN109901933B (en) | Operation method and device of business system, storage medium and electronic device | |
CN110175182B (en) | Data checking method and device | |
CN107967181B (en) | Method and device for controlling critical section | |
CN113268327A (en) | Transaction request processing method and device and electronic equipment | |
CN111984424A (en) | Task processing method, device, equipment and computer readable storage medium | |
CN113516476B (en) | Account reconciliation processing method and device | |
CN113168323B (en) | Resource adding method, management device and computer storage medium |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |