CN108415758B - Distributed transaction coordination method and device - Google Patents

Distributed transaction coordination method and device Download PDF

Info

Publication number
CN108415758B
CN108415758B CN201810259145.1A CN201810259145A CN108415758B CN 108415758 B CN108415758 B CN 108415758B CN 201810259145 A CN201810259145 A CN 201810259145A CN 108415758 B CN108415758 B CN 108415758B
Authority
CN
China
Prior art keywords
transaction
message
coordination
result
sending
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.)
Expired - Fee Related
Application number
CN201810259145.1A
Other languages
Chinese (zh)
Other versions
CN108415758A (en
Inventor
黄兴
殷林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Rongyimai Information Technology Co ltd
Original Assignee
Shenzhen Rongyimai Information Technology Co ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Shenzhen Rongyimai Information Technology Co ltd filed Critical Shenzhen Rongyimai Information Technology Co ltd
Priority to CN201810259145.1A priority Critical patent/CN108415758B/en
Publication of CN108415758A publication Critical patent/CN108415758A/en
Application granted granted Critical
Publication of CN108415758B publication Critical patent/CN108415758B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Financial Or Insurance-Related Operations Such As Payment And Settlement (AREA)

Abstract

The invention is suitable for the field of distributed technology, and provides a distributed transaction coordination method and a device, wherein the method comprises the steps of receiving a first transaction registration request sent by a first micro-service, registering the first transaction according to the first transaction registration request, returning a first transaction registration response, receiving a coordination message sent by a second micro-service, wherein the coordination message is a confirmation message or a rollback message, calling the first micro-service by the second micro-service, and sending the coordination message to the first micro-service.

Description

Distributed transaction coordination method and device
Technical Field
The invention belongs to the technical field of distribution, and particularly relates to a distributed transaction coordination method and device.
Background
With the development of micro services, the services are more and more finely divided, different micro services often use different databases, so that data access becomes complicated, and the requirement of ensuring consistency among multiple micro services cannot be met due to the defects of strong coupling and difficult expansion of the traditional distributed transaction.
In the prior art, in order to ensure consistency among a plurality of micro services, two methods are mainly adopted: TCC (Try, Confirm, Cancel) model and message queue transactions. Both methods need to write rollback codes for specific transactions, have the defect of poor universality, or need manual intervention to perform manual rollback, and are complex to operate. And the message queue transaction has poor flexibility, is difficult to upgrade and expand, and has long intermediate process and high time complexity.
Disclosure of Invention
In view of this, embodiments of the present invention provide a distributed transaction coordination method and apparatus, so as to solve the problems of poor flexibility and low efficiency in implementing final consistency of a micro service architecture in the prior art.
A first aspect of an embodiment of the present invention provides a distributed transaction coordination method, including:
receiving a first transaction registration request sent by a first micro service, registering a first transaction according to the first transaction registration request, and returning a first transaction registration response;
receiving a coordination message sent by a second micro service, wherein the coordination message is a confirmation message or a rollback message, and the second micro service calls the first micro service;
sending the coordination message to the first microservice.
In a possible implementation manner, the sending the coordination message to the first microservice specifically includes:
when the coordination message is the confirmation message, sending the confirmation message to the first microservice so that the first microservice coordinates a first transaction submission;
and when the coordination message is the rollback message, sending the rollback message to the first micro service so that the first micro service coordinates a first transaction rollback.
A second aspect of an embodiment of the present invention provides a distributed transaction coordination method, including:
sending a registration first transaction request to a transaction coordinator, and receiving a registration first transaction response sent by the transaction coordinator;
receiving a coordination message sent by the transaction coordinator, wherein the coordination message is an acknowledgement message or a rollback message;
and coordinating and processing the first transaction according to the coordination message.
In a possible implementation manner, before sending the register first transaction request to the transaction coordinator, the method further includes:
receiving a first transaction calling request sent by a second micro service, and creating a first transaction connection;
sending a first transaction executing message to a first database, and receiving an executing result of the first transaction returned by the first database.
In a possible implementation manner, after receiving the first transaction response for registering sent by the transaction coordinator, the method further includes:
and sending a first transaction response to the second micro service according to the first transaction response.
In a possible implementation manner, the coordinating, according to the coordination message, processing the first transaction specifically includes:
when the coordination message is the confirmation message, sending a first transaction submitting request to the first database so that the first database stores the execution result, and receiving a submitting result returned by the first database;
and when the coordination message is the rollback message, sending a rollback first transaction request to the first database so that the first database deletes the execution result, and receiving a rollback result returned by the first database.
A third aspect of an embodiment of the present invention provides a distributed transaction coordination method, including:
sending a first transaction calling request to a first micro service, and receiving a first transaction calling response returned by the first micro service, wherein the first transaction calling response carries a calling result;
sending a second transaction submitting request to a second database, and receiving a submitting result sent by the second database;
determining a coordination message according to the calling result and the submitting result, wherein the coordination message is a confirmation message or a rollback message, if the calling result is consistent with the submitting result, the coordination message is determined to be the confirmation message, otherwise, the coordination message is determined to be the rollback message;
and sending the coordination message to a transaction coordinator.
A fourth aspect of the present invention provides a distributed transaction coordination apparatus, including:
the receiving module is used for receiving a first transaction registration request sent by a first micro service;
the registration module is used for registering the first transaction according to the registration first transaction request;
a sending module, configured to send a register first transaction response to the first microservice;
the receiving module is further configured to receive a coordination message sent by a second microservice, where the coordination message is an acknowledgement message or a rollback message, and the second microservice invokes the first microservice;
the sending module is further configured to send the coordination message to the first microservice.
A fifth aspect of an embodiment of the present invention provides a distributed transaction coordination apparatus, including:
a sending module, configured to send a register first transaction request to a transaction coordinator;
a receiving module, configured to receive a first transaction response for registration sent by the transaction coordinator;
the receiving module is further configured to receive a coordination message sent by the transaction coordinator, where the coordination message is an acknowledgement message or a rollback message;
and the coordination processing module is used for coordinating and processing the first transaction according to the coordination message.
A sixth aspect of the present invention provides a distributed transaction coordination apparatus, including:
the sending module is used for sending a first transaction calling request to the first microservice;
the receiving module is used for receiving a first transaction calling response returned by the first micro-service, wherein the first transaction calling response carries a calling result;
the sending module is further configured to send a commit second transaction request to the second database;
the receiving module is further configured to receive a submission result sent by the second database;
the judging module is used for determining a coordination message according to the calling result and the submitting result, wherein the coordination message is a confirmation message or a rollback message, if the calling result is consistent with the submitting result, the coordination message is determined to be the confirmation message, otherwise, the coordination message is determined to be the rollback message;
the sending module is further configured to send the coordination message to a transaction coordinator.
A seventh aspect of the present invention provides a distributed transaction coordination apparatus, including:
a memory, a processor and a computer program stored in the memory and executable on the processor, the processor implementing the steps of the method as described above when executing the computer program.
An eighth aspect of an embodiment of the present invention provides a computer-readable storage medium, including:
the computer-readable storage medium stores a computer program which, when executed by a processor, implements the steps of the method as described above.
The distributed transaction coordination method and device provided by the invention receive the first transaction registration request sent by the first micro service through the distributed transaction coordination device, register the first transaction according to the first transaction registration request, return the first transaction registration response, receive the coordination message sent by the second micro service, the coordination message is a confirmation message or a rollback message, the second micro service calls the first micro service and sends the coordination message to the first micro service, the problems of poor flexibility and low efficiency in the realization of final consistency of a micro service architecture in the prior art are solved, the flexible upgrade and expansion of the transaction are realized, the intermediate process is shortened, and the time complexity is reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic flow chart of an implementation flow of a distributed transaction coordination method according to an embodiment of the present invention;
fig. 2 is a schematic flow chart of an implementation flow of the distributed transaction coordination method according to the second embodiment of the present invention;
fig. 3 is a schematic flow chart of an implementation flow of a distributed transaction coordination method according to a third embodiment of the present invention;
fig. 4 is a schematic flow chart of an implementation flow of a distributed transaction coordination method according to a fourth embodiment of the present invention;
fig. 5 is a schematic flow chart of an implementation flow of the distributed transaction coordination method according to the fifth embodiment of the present invention;
fig. 6 is a schematic diagram of a distributed transaction coordination apparatus according to a sixth embodiment of the present invention;
fig. 7 is a schematic diagram of a distributed transaction coordination apparatus according to a seventh embodiment of the present invention;
fig. 8 is a schematic diagram of a distributed transaction coordination apparatus according to an eighth embodiment of the present invention;
FIG. 9 is a diagram of a distributed transaction coordination apparatus according to a ninth embodiment of the present invention;
fig. 10 is a schematic flow chart of an implementation of a distributed transaction coordination system according to a tenth embodiment of the present invention;
fig. 11 is an interaction diagram of the distributed transaction coordination system according to an eleventh embodiment of the present invention.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
Micro-services are an emerging software architecture, that is, a large single application program or service is split into multiple supporting micro-services, which are generally split according to functions, so that each micro-service realizes a specific function. Each microservice initiates a separate process and provides a standard scheduling interface to invoke or be scheduled by other microservices.
A transaction, a specific operation that implements microservice execution, refers in computer terminology to a program execution unit that accesses and possibly updates various data items in a database, typically caused by the execution of a user program written in a high level database manipulation or programming language. A transaction consists of a collective of operations that are performed between a transaction start (begin transaction) and a transaction end (end transaction), the main operations between which are transaction execution and transaction commit, where transaction commit includes commit and rollback.
In order to explain the technical means of the present invention, the following description will be given by way of specific examples.
Fig. 1 is a schematic diagram of an implementation flow of a distributed transaction coordination method according to an embodiment of the present invention, and as shown in fig. 1, an execution subject of this embodiment is a distributed transaction coordination device, which may specifically be a transaction coordinator, where the transaction coordinator is disposed in a local terminal, and each local terminal has a unique transaction coordinator, and when a certain transaction spans multiple terminals, the respective transaction coordinators of each terminal interact according to a predetermined protocol to implement consistency management of transactions across terminals. The method of the embodiment may include:
and step 11, receiving a registration first transaction request sent by the first micro service.
In this embodiment, the first microservice is a microservice that implements a specific function, and the first transaction is a program execution unit that implements the first microservice, and executes the first transaction, so as to implement the function of the first microservice. After the first transaction is executed, the first micro service sends a first transaction registration request to the transaction coordinator, wherein the first transaction registration request carries first transaction information. The transaction information may include information such as the function, interface, database, etc. of the transaction. The first micro service in this embodiment may be invoked by the second micro service.
Step 12, registering the first transaction according to the registration first transaction request.
And step 13, returning a registration first transaction response.
And the distributed transaction coordination device such as a transaction coordinator finishes registering the first transaction according to the first transaction information carried by the first transaction registration request and stores the first transaction information. After the registration is successful, the transaction coordinator returns a registration first transaction response to the first micro-service, namely a registration result is returned. Thereby completing the registration of the first microservice with the transaction coordinator.
And step 14, receiving a coordination message sent by the second micro service, wherein the coordination message is a confirmation message or a rollback message, and the second micro service calls the first micro service.
In this embodiment, the second microservice calls the first microservice through a standard scheduling interface of the first microservice.
And step 15, sending a coordination message to the first micro service.
And when the service coordinator receives the coordination message sent by the second micro service, sending the coordination message to the first micro service registering the first transaction according to the stored first transaction information, thereby realizing the coordination processing of the first micro service. Wherein the coordination message is an acknowledgement message or a rollback message.
The number of the first micro services can be any number. Taking a bank cash-withdrawal service as an example, as an embodiment of the present invention, the split micro service is used for implementing a cash-withdrawal function, and as another embodiment of the present invention, the split micro service is used for implementing two functions of identity authentication and cash-withdrawal. Taking the first microservice as two examples (for convenience of description, the microservice implementing the cash-out function is referred to as the first microservice, and the microservice implementing the identity verification function is referred to as the third microservice): and when the identity authentication needs to be added to the cash-out function, the third micro service is called by the first micro service or the second micro service. By adopting the method of the embodiment, the function of the third micro-service can be realized by registering new transaction information in the transaction coordinator, and the flexible upgrade or expansion of the transaction coordinator is realized without writing specific codes aiming at the new function, thereby ensuring the overall performance. In addition, by adopting the method of the embodiment, the coupling and time complexity between the transaction and the container are reduced, and the transaction processing efficiency is improved.
The embodiment provides a distributed transaction coordination method, which includes receiving a first transaction registration request sent by a first micro service, registering the first transaction according to the first transaction registration request, returning a first transaction registration response, receiving a coordination message sent by a second micro service, wherein the coordination message is an acknowledgement message or a rollback message, the second micro service calls the first micro service, and sends the coordination message to the first micro service.
Fig. 2 is a schematic flow chart of an implementation of a distributed transaction coordination method according to a second embodiment of the present invention, and as shown in fig. 2, this embodiment is an implementation of the first embodiment shown in fig. 1, and specifically relates to an implementation of the step 15 in the embodiment. The method of the embodiment may include:
and step 21, receiving a registration first transaction request sent by the first micro service.
Step 22 registers the first transaction according to the register first transaction request.
And step 23, returning a registration first transaction response.
And 24, receiving a coordination message sent by the second micro service, wherein the coordination message is a confirmation message or a rollback message, and the second micro service calls the first micro service.
Wherein, steps 21 to 24 refer to steps 11 to 14 of the first embodiment, which are not described herein again.
And 25, when the coordination message is a confirmation message, sending the confirmation message to the first micro service so that the first micro service coordinates the submission of the first transaction.
And step 26, when the coordination message is a rollback message, sending the rollback message to the first microservice so that the first microservice coordinates the rollback of the first transaction.
In an embodiment of the present invention, the coordination message received by the transaction coordinator from the second microservice is an acknowledgement message or a rollback message.
When the coordination message is an acknowledgement message, the indication is that all transactions meet the requirement standard of final consistency, that is, all transactions are successfully executed or all transactions are failed to be executed, at this time, the transaction coordinator sends the received acknowledgement message to the first microservice, so that the first microservice coordinates the commit of the first transaction.
When the coordination message is a rollback message, it indicates that all transactions do not meet the requirement standard of final consistency, that is, a part of transactions are successfully executed and a part of transactions are failed to be executed, and in order to ensure the final consistency of the transactions, the successfully executed part of transactions needs to be restored to the initial state before execution.
Fig. 3 is a schematic flow chart of an implementation process of a distributed transaction coordination method according to a third embodiment of the present invention, as shown in fig. 3, an execution subject of this embodiment is a distributed transaction coordination apparatus, which may specifically be a first microservice, and the method of this embodiment may include:
step 31, a register first transaction request is sent to the transaction coordinator.
Step 32, receiving a registration first transaction response sent by the transaction coordinator.
And step 33, receiving a coordination message sent by the transaction coordinator, wherein the coordination message is an acknowledgement message or a rollback message.
And step 34, coordinating and processing the first transaction according to the coordination message.
The first micro service sends a registration first transaction request to the transaction coordinator, wherein the registration first transaction request carries first transaction information. The transaction coordinator returns a register first transaction response according to the register first transaction request. Thereby completing the registration of the first transaction.
When the service coordinator sends the coordination message, the first micro-service coordinates and processes the first transaction according to the coordination message. Wherein the coordination message is an acknowledgement message or a rollback message.
The embodiment provides a distributed transaction coordination method, which includes sending a registration first transaction request to a transaction coordinator, receiving a registration first transaction response sent by the transaction coordinator, receiving a coordination message sent by the transaction coordinator, wherein the coordination message is a confirmation message or a rollback message, and coordinating and processing a first transaction according to the coordination message, so that the problems of poor flexibility and low efficiency in the prior art for achieving final consistency of a micro-service architecture are solved, flexible upgrading and expanding of the transaction are achieved, a middle process is shortened, and time complexity is reduced.
Optionally, in order to avoid that the concurrent intermediate state of the transaction is modified, which causes the final consistency of the transaction to be affected, an Optimistic Locking (Optimistic Locking) is introduced in the embodiment, and further, the final consistency of the implementation of the micro service architecture is ensured.
Specifically, optimistic locks are typically implemented based on a data Version (Version) record mechanism, i.e., a Version number is recorded for each transaction call to ensure that the intermediate state is not modified. Compared with pessimistic locks, optimistic locks adopt a looser locking mechanism. Pessimistic locks are mostly realized by a lock mechanism of a database to ensure the maximum degree of independence of operation, so that the overhead of the database is increased, the overall performance of the system is reduced, and the pessimistic lock is particularly obvious for long transactions. The optimistic locking mechanism avoids the database locking expense in long transactions, and greatly improves the overall performance of the system with higher expense. For example, in the first transaction execution or submission process of this embodiment, locking of the first database data is not required, and time complexity is reduced while final consistency of the micro-service architecture is further ensured.
Fig. 4 is a schematic flow chart of an implementation process of a distributed transaction coordination method according to a fourth embodiment of the present invention, as shown in fig. 4, this embodiment is a distributed transaction coordination method based on the third embodiment shown in fig. 3, and the method of this embodiment may include:
step 401, receiving a first transaction invoking request sent by a second micro service.
Step 402, create a first transaction connection.
Step 403, send execute first transaction message to first database.
Step 404, receiving an execution result of executing the first transaction returned by the first database.
Executing the first transaction performs a particular function, e.g., executing the process of the first transaction, implementing the cash-out function in the above-described embodiment. When the cash withdrawal function needs to be realized, the second micro service calls the first micro service, and specifically, the second micro service may be a micro service for realizing a bank transaction function. The second micro service sends a request for calling the first transaction to the first micro service, the first micro service starts the first transaction, creates a first transaction connection, sends a message for executing the first transaction to the first database, the first database executes the first transaction, and returns an execution result to the first micro service. Thereby completing execution of the first transaction.
Step 405, send register first transaction request to transaction coordinator.
Step 406, receive a register first transaction response sent by the transaction coordinator.
Step 407, according to the registered first transaction response, sending an invoke first transaction response to the second microservice.
The first micro service sends a registration first transaction request to the transaction coordinator, wherein the registration first transaction request carries first transaction information. The transaction coordinator returns a register first transaction response according to the register first transaction request. Thereby completing the registration of the first transaction. Meanwhile, the first micro service responds to the second micro service by calling the first transaction so as to inform the second micro service of the calling result.
And step 408, receiving a coordination message sent by the transaction coordinator, wherein the coordination message is an acknowledgement message or a rollback message.
When the service coordinator sends the coordination message, the first micro-service coordinates and processes the first transaction according to the coordination message. Wherein the coordination message is an acknowledgement message or a rollback message.
Step 409, when the coordination message is a confirmation message, sending a commit first transaction request to the first database, so that the first database stores the execution result, and receiving a commit result returned by the first database.
And step 410, when the coordination message is a rollback message, sending a rollback first transaction request to the first database so that the first database deletes the execution result, and receiving a rollback result returned by the first database.
When the coordination message is a confirmation message, it indicates that all transactions meet the requirement standard of final consistency, that is, all transactions are successfully executed or all transactions are failed to be executed, at this time, the first micro service receives the confirmation message sent by the transaction coordinator, and the first micro service sends a commit first transaction request to the first database, so that the first database stores the execution result of the first transaction, and returns the commit result to the first micro service, so as to coordinate the commit of the first transaction.
When the coordination message is a rollback message, it indicates that all transactions do not meet the requirement criteria of final consistency, that is, a part of transactions are successfully executed and a part of transactions are unsuccessfully executed, and in order to ensure the final consistency of the transactions, it is necessary to restore the successfully executed part of transactions to the initial state before execution, so that the first microserver receives the rollback message sent by the transaction coordinator according to the saved first transaction information, and the first microserver sends a rollback first transaction request to the first database, so that the first transaction is rolled back and restored to the initial state before execution of the transactions.
Optionally, the first database may be any database supporting JDBC, such as MySQL, SQL Server, and Oracle, which is not limited in this application.
And when the first transaction coordination process is completed, releasing the first transaction connection.
Fig. 5 is a schematic flow chart of an implementation process of a distributed transaction coordination method according to a fifth embodiment of the present invention, as shown in fig. 5, an execution subject of this embodiment is a distributed transaction coordination apparatus, which may specifically be a second microservice, and the method of this embodiment may include:
step 51, send a call first transaction request to the first microservice.
Before sending a request for calling the first transaction to the first micro-service, the second micro-service initiates a second transaction by a user or other applications, creates a second transaction connection, sends a message for executing the second transaction to a second database, the second database executes the second transaction, and returns an execution result to the second micro-service, thereby completing the execution of the second transaction.
And step 52, receiving a first transaction response for calling returned by the first micro service, wherein the first transaction response for calling carries a calling result.
When the second micro service needs to complete a certain specific function of the first transaction, a request for calling the first transaction is sent to the first micro service to call the first micro service, and after the first micro service is registered, a call result returned by the first micro service is received, so that the call of the second micro service is completed.
Step 53, send commit second transaction request to second database.
And step 54, receiving the submission result sent by the second database.
And step 55, determining the coordination message according to the calling result and the submitting result, wherein the coordination message is a confirmation message or a rollback message, if the calling result is consistent with the submitting result, the coordination message is determined to be the confirmation message, otherwise, the coordination message is determined to be the rollback message.
Step 56, sending a coordination message to the transaction coordinator.
And after receiving the calling result, the second transaction submits the second transaction to the second database, and receives a submission result returned by the second database. And the second micro-service determines the coordination message according to the submission result. Specifically, if the calling result is consistent with the submitting result, the coordination message is determined to be a confirmation message, otherwise, the coordination message is determined to be a rollback message. And the second micro service sends the determined coordination message to the transaction coordinator to realize the coordination processing of other micro services.
And when the second transaction coordination processing is completed, releasing the second transaction connection.
The embodiment provides a distributed transaction coordination method, which includes sending a first transaction calling request to a first microservice, receiving a first transaction calling response returned by the first microservice, sending a second transaction submitting request to a second database, receiving a submitting result sent by the second database, wherein the first transaction calling response carries a calling result, and determining a coordination message according to the calling result and the submitting result, wherein the coordination message is a confirmation message or a rollback message, if the calling result is consistent with the submitting result, the coordination message is determined to be the confirmation message, otherwise, the coordination message is determined to be the rollback message, and the coordination message is sent to the transaction coordinator, so that the problems of poor flexibility and low efficiency in the prior art for realizing the final consistency of the micro-service architecture are solved, the flexible upgrading and expanding of the transaction are realized, the intermediate process is shortened, and the time complexity is reduced.
Fig. 6 is a schematic diagram of a distributed transaction coordination apparatus according to a sixth embodiment of the present invention, as shown in fig. 6, an execution subject of this embodiment is the distributed transaction coordination apparatus, which may specifically be a transaction coordinator, and the apparatus of this embodiment may include:
the receiving module 61 is configured to receive a register first transaction request sent by the first microservice.
A registration module 62 for registering the first transaction in accordance with the register first transaction request.
A sending module 63, configured to send a register first transaction response to the first microservice.
The receiving module 61 is further configured to receive a coordination message sent by the second micro service, where the coordination message is an acknowledgement message or a rollback message, and the second micro service invokes the first micro service.
The sending module 63 is further configured to send a coordination message to the first microservice.
The distributed transaction coordination apparatus provided in this embodiment is used to implement the distributed transaction coordination method described in the first embodiment, where the functions of each module may refer to corresponding descriptions in the method embodiment, and the implementation principle and technical effect thereof are similar, and are not described herein again.
Fig. 7 is a schematic diagram of a distributed transaction coordination apparatus according to a seventh embodiment of the present invention, as shown in fig. 7, an execution subject of the present embodiment is the distributed transaction coordination apparatus, which may specifically be a first microservice, and the apparatus of the present embodiment may include:
a sending module 71, configured to send a register first transaction request to the transaction coordinator.
A receiving module 72, configured to receive a register first transaction response sent by the transaction coordinator.
The receiving module 72 is further configured to receive a coordination message sent by the transaction coordinator, where the coordination message is an acknowledgement message or a rollback message.
And a coordination processing module 73, configured to coordinate processing of the first transaction according to the coordination message.
The distributed transaction coordination apparatus provided in this embodiment is configured to implement the distributed transaction coordination method described in the third embodiment, where functions of each module may refer to corresponding descriptions in the method embodiment, and implementation principles and technical effects thereof are similar, and are not described herein again.
Fig. 8 is a schematic diagram of a distributed transaction coordination apparatus according to an eighth embodiment of the present invention, as shown in fig. 8, an execution subject of this embodiment is the distributed transaction coordination apparatus, and specifically may be a second microservice, and the apparatus of this embodiment may include:
the sending module 81 is configured to send a request for invoking the first transaction to the first microservice.
The receiving module 82 is configured to receive a first transaction response to be called returned by the first micro service, where the first transaction response is called to carry a calling result.
The sending module 81 is further configured to send a commit second transaction request to the second database.
The receiving module 82 is further configured to receive the submission result sent by the second database.
And a determining module 83, configured to determine, according to the call result and the submission result, a coordination message, where the coordination message is a confirmation message or a rollback message, and if the call result is consistent with the submission result, the coordination message is determined to be the confirmation message, otherwise, the coordination message is determined to be the rollback message.
The sending module 81 is further configured to send a coordination message to the transaction coordinator.
The distributed transaction coordination apparatus provided in this embodiment is configured to implement the distributed transaction coordination method described in the fifth embodiment, where functions of each module may refer to corresponding descriptions in the method embodiment, and implementation principles and technical effects thereof are similar, and are not described herein again.
Fig. 9 is a schematic diagram of a distributed transaction coordination apparatus according to a ninth embodiment of the present invention, and as shown in fig. 9, an execution subject of the present embodiment is the distributed transaction coordination apparatus, which may specifically be a second microservice, and the apparatus of the present embodiment may include: a memory 91, a processor 92, and a computer program 93, such as a distributed transaction coordination program, stored in the memory 91 and executable on the processor 92. The processor 92 executes the computer program 93 to implement the steps in each of the embodiments of the distributed transaction coordination method described above, such as the steps 11 to 15 shown in fig. 1. Alternatively, the processor 92, when executing the computer program 93, implements the functions of the modules in the various embodiments of the distributed transaction coordination apparatus, such as the functions of the modules 61 to 63 shown in fig. 6.
Illustratively, the computer program 93 may be divided into one or more modules, which are stored in the memory 91 and executed by the processor 92 to implement the present invention. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used for describing the execution process of the computer program 93 in the distributed transaction coordination apparatus 9. For example, the computer program 93 may be divided into a receiving module, a registering module, and a transmitting module (a module in a virtual device), and the specific functions of the modules are as follows:
the receiving module is used for receiving a first transaction registration request sent by a first micro service;
the registration module is used for registering the first transaction according to the registration first transaction request;
the sending module is used for sending a registration first transaction response to the first microservice;
the receiving module is further configured to receive a coordination message sent by the second microservice;
the sending module is further configured to send a coordination message to the first microservice.
It will be understood by those skilled in the art that fig. 9 is merely an example of the distributed transaction coordination apparatus 9, and does not constitute a limitation on the distributed transaction coordination apparatus 9, and may include more or less components than those shown, or combine some components, or different components, for example, the distributed transaction coordination apparatus may further include an input/output device, a network access device, a bus, etc.
The Processor 92 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 91 may be an internal storage unit of the distributed transaction coordination apparatus 9, such as a hard disk or a memory of the distributed transaction coordination apparatus 9. The memory 91 may also be an external storage device of the distributed transaction coordination apparatus 9, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the distributed transaction coordination apparatus 9. Further, the memory 91 may include both an internal storage unit and an external storage device of the distributed transaction coordination apparatus 9. The memory 91 is used for storing the computer program 93 and other programs and data required by the distributed transaction coordination apparatus 9. The above-mentioned memory 91 can also be used to temporarily store data that has been output or is to be output.
Therefore, the method and the device solve the problems of poor flexibility and low efficiency in the prior art in the realization of final consistency of the micro-service architecture, realize flexible upgrading and expansion of the affairs, shorten the intermediate process and reduce the time complexity.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned functions may be distributed as different functional units and modules according to needs, that is, the internal structure of the apparatus may be divided into different functional units or modules to implement all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described embodiments of the apparatus are merely illustrative, and for example, the division of the above-described modules or units is only one type of division of logical functions, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated module may be stored in a computer-readable storage medium if it is implemented in the form of a software functional unit and sold or used as a separate product. Based on such understanding, all or part of the flow in the method according to the above embodiments may be implemented by a computer program, which may be stored in a computer-readable storage medium and can implement the steps of the above embodiments when executed by a processor. The computer program includes computer program code, and the computer program code may be in a source code form, an object code form, an executable file or some intermediate form. The computer readable medium may include: any entity or device capable of carrying the above-mentioned computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signal, telecommunication signal, software distribution medium, etc. It should be noted that the computer readable medium described above may be suitably increased or decreased as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media excludes electrical carrier signals and telecommunications signals in accordance with legislation and patent practice.
Fig. 10 is a schematic flow chart of an implementation flow of a distributed transaction coordination system provided in a tenth embodiment of the present invention, and as shown in fig. 10, the system of this embodiment may include:
step 101, the local transaction manager opens the transaction.
Step 102, local transactions are executed.
Step 103, registering to the transaction coordinator.
Step 104, coordinating transaction commit or rollback.
And step 105, releasing the database.
The distributed transaction coordination system provided in this embodiment is used to implement the technical solutions executed by the corresponding method embodiments, and the implementation principles and technical effects are similar, and are not described herein again.
Fig. 11 is an interaction schematic diagram of a distributed transaction coordination system according to an eleventh embodiment of the present invention, and as shown in fig. 11, the system of this embodiment is a system composed of a transaction coordinator, a first microservice and a second microservice, and an implementation principle and a technical effect thereof are similar to those of the technical solutions executed by the embodiments of the foregoing apparatuses, and details are not repeated here.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.

Claims (10)

1. A distributed transaction coordination method, comprising:
receiving a first transaction registration request sent by a first micro service, registering a first transaction according to the first transaction registration request, and returning a first transaction registration response; the register first transaction response is used for indicating the first micro service to send a call first transaction response to the second micro service, and the call first transaction response comprises a call result;
receiving a coordination message sent by a second micro service, wherein the coordination message is a confirmation message or a rollback message, and the second micro service calls the first micro service; the coordination message is determined by the second micro-service according to the calling result and the submitting result of the second transaction request;
sending the coordination message to the first microservice.
2. The method of claim 1, wherein said sending the coordination message to the first microservice comprises:
when the coordination message is the confirmation message, sending the confirmation message to the first microservice so that the first microservice coordinates a first transaction submission;
and when the coordination message is the rollback message, sending the rollback message to the first micro service so that the first micro service coordinates a first transaction rollback.
3. A distributed transaction coordination method, comprising:
sending a registration first transaction request to a transaction coordinator, and receiving a registration first transaction response sent by the transaction coordinator;
receiving a coordination message sent by the transaction coordinator, wherein the coordination message is an acknowledgement message or a rollback message;
coordinating processing of the first transaction according to the coordination message;
before sending the register first transaction request to the transaction coordinator, the method further includes:
receiving a first transaction calling request sent by a second micro service, and creating a first transaction connection;
sending a first transaction executing message to a first database, and receiving an executing result of the first transaction executed and returned by the first database;
after receiving the first transaction response sent by the transaction coordinator to register, the method further includes:
sending a first transaction response to be called to the second micro service according to the first transaction response; the call first transaction response comprises a call result; and the first transaction response is used for indicating the second microserver to determine the coordination message according to the calling result and the submission result of the second transaction request, and the coordination message is sent to the transaction coordinator.
4. The method according to claim 3, wherein the coordinating processing the first transaction according to the coordination message specifically comprises:
when the coordination message is the confirmation message, sending a first transaction submitting request to the first database so that the first database stores the execution result, and receiving a submitting result returned by the first database;
and when the coordination message is the rollback message, sending a rollback first transaction request to the first database so that the first database deletes the execution result, and receiving a rollback result returned by the first database.
5. A distributed transaction coordination method, comprising:
sending a first transaction calling request to a first micro service, and receiving a first transaction calling response returned by the first micro service, wherein the first transaction calling response carries a calling result;
sending a second transaction submitting request to a second database, and receiving a submitting result sent by the second database;
determining a coordination message according to the calling result and the submitting result, wherein the coordination message is a confirmation message or a rollback message, if the calling result is consistent with the submitting result, the coordination message is determined to be the confirmation message, otherwise, the coordination message is determined to be the rollback message;
and sending the coordination message to a transaction coordinator.
6. A distributed transaction coordination apparatus, comprising:
the receiving module is used for receiving a first transaction registration request sent by a first micro service; the registration module is used for registering the first transaction according to the registration first transaction request;
a sending module, configured to send a register first transaction response to the first microservice; the register first transaction response is used for indicating the first micro service to send a call first transaction response to the second micro service, and the call first transaction response comprises a call result;
the receiving module is further configured to receive a coordination message sent by a second microservice, where the coordination message is an acknowledgement message or a rollback message, and the second microservice invokes the first microservice; the coordination message is determined by the second micro-service according to the calling result;
the sending module is further configured to send the coordination message to the first microservice.
7. A distributed transaction coordination apparatus, comprising:
a sending module, configured to send a register first transaction request to a transaction coordinator;
a receiving module, configured to receive a first transaction response for registration sent by the transaction coordinator;
the receiving module is further configured to receive a coordination message sent by the transaction coordinator, where the coordination message is an acknowledgement message or a rollback message;
the coordination processing module is used for coordinating and processing the first transaction according to the coordination message;
the distributed transaction coordination device is also used for receiving a first transaction calling request sent by the second micro service and creating a first transaction connection; sending a first transaction executing message to a first database, and receiving an executing result of the first transaction executed and returned by the first database;
the distributed transaction coordination device is further used for sending a first transaction response to be called to the second microservice according to the registered first transaction response; the call first transaction response comprises a call result; and the first transaction response is used for indicating the second micro-service to determine the coordination message according to the calling result and the second transaction request submission result, and the coordination message is sent to the transaction coordinator.
8. A distributed transaction coordination apparatus, comprising:
the sending module is used for sending a first transaction calling request to the first microservice;
the receiving module is used for receiving a first transaction calling response returned by the first micro-service, wherein the first transaction calling response carries a calling result;
the sending module is further configured to send a commit second transaction request to the second database;
the receiving module is further configured to receive a submission result sent by the second database;
the judging module is used for determining a coordination message according to the calling result and the submitting result, wherein the coordination message is a confirmation message or a rollback message, if the calling result is consistent with the submitting result, the coordination message is determined to be the confirmation message, otherwise, the coordination message is determined to be the rollback message;
the sending module is further configured to send the coordination message to a transaction coordinator.
9. A distributed transaction coordination device comprising a memory, a processor and a computer program stored in said memory and executable on said processor, wherein said processor implements the steps of the method according to any of claims 1 to 5 when executing said computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 5.
CN201810259145.1A 2018-03-27 2018-03-27 Distributed transaction coordination method and device Expired - Fee Related CN108415758B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810259145.1A CN108415758B (en) 2018-03-27 2018-03-27 Distributed transaction coordination method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810259145.1A CN108415758B (en) 2018-03-27 2018-03-27 Distributed transaction coordination method and device

Publications (2)

Publication Number Publication Date
CN108415758A CN108415758A (en) 2018-08-17
CN108415758B true CN108415758B (en) 2020-11-27

Family

ID=63133652

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810259145.1A Expired - Fee Related CN108415758B (en) 2018-03-27 2018-03-27 Distributed transaction coordination method and device

Country Status (1)

Country Link
CN (1) CN108415758B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110876852B (en) * 2018-09-06 2023-09-26 深圳市贰陆陆科技有限公司 Network game data processing method and system for micro-service
CN109714319A (en) * 2018-12-06 2019-05-03 深圳市中农网有限公司 Management system, method, apparatus, computer equipment and the storage medium of micro services
US10963324B2 (en) * 2018-12-12 2021-03-30 Citrix Systems, Inc. Predictive microservice systems and methods
CN111385361B (en) * 2020-03-10 2023-04-07 创新奇智(广州)科技有限公司 Cloth inspecting machine communication method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20160002623A (en) * 2015-12-16 2016-01-08 김우진 Method for managing payment between mobile terminal
CN106156119A (en) * 2015-04-07 2016-11-23 阿里巴巴集团控股有限公司 A kind of distributed transaction communication means, system and device
CN106503132A (en) * 2016-10-19 2017-03-15 广州快塑电子商务有限公司 A kind of distributed transaction management method and system
CN106874130A (en) * 2017-02-06 2017-06-20 西多多信息科技(北京)有限公司 The processing method of distributed transaction in a kind of micro services framework

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106156119A (en) * 2015-04-07 2016-11-23 阿里巴巴集团控股有限公司 A kind of distributed transaction communication means, system and device
KR20160002623A (en) * 2015-12-16 2016-01-08 김우진 Method for managing payment between mobile terminal
CN106503132A (en) * 2016-10-19 2017-03-15 广州快塑电子商务有限公司 A kind of distributed transaction management method and system
CN106874130A (en) * 2017-02-06 2017-06-20 西多多信息科技(北京)有限公司 The processing method of distributed transaction in a kind of micro services framework

Also Published As

Publication number Publication date
CN108415758A (en) 2018-08-17

Similar Documents

Publication Publication Date Title
CN108415758B (en) Distributed transaction coordination method and device
CN111045794B (en) Distributed transaction processing method, device, system, computer equipment and storage medium
CN107113341B (en) System for high throughput processing of transactions in a distributed relational database management system for data partitioning
CN102971711A (en) An apparatus for processing a batched unit of work
CN107436799B (en) Method and device for realizing consistency of distributed transactions
CN110188110B (en) Method and device for constructing distributed lock
CN110471746B (en) Distributed transaction callback method, device and system
CN110888718A (en) Method and device for realizing distributed transaction
CN110430257A (en) Information processing method, device, system and readable storage medium storing program for executing
CN112667600A (en) Inventory solution method combining redis and MySQL
CN109376165A (en) The implementation method and device and computer readable storage medium of memory database lock
CN111444199B (en) Data processing method and device, storage medium and processor
CN107195144B (en) The method, apparatus and computer readable storage medium of managing payment terminal hardware module
CN112559496A (en) Distributed database transaction atomicity realization method and device
CN111984379A (en) Read-write transaction control method, system, terminal device and storage medium
CN113342481B (en) Transaction state confirmation method and device
CN112988775B (en) Method, computing device and storage medium for processing batch transactions
CN109710629A (en) Data access method, device, server and storage medium
CN111367694B (en) Event processing method, server and computer storage medium
CN114816684A (en) Business processing method, device, equipment, readable storage medium and product
CN112162988A (en) Distributed transaction processing method and device and electronic equipment
CN111897822A (en) Account state information processing method and device, electronic equipment and storage medium
CN111309521A (en) FPGA reloading method, FPGA card type equipment and host
CN109559240A (en) Prevent premium from repeating method, apparatus, equipment and the readable storage medium storing program for executing of withholding
CN111292028A (en) Inventory information processing method and system, computer system and readable 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
CB02 Change of applicant information

Address after: Room 201, Building A, No. 1 Qianwan Road, Qianhai Shenzhen-Hong Kong Cooperation Zone, Shenzhen, Guangdong 518000:No. 1701, 1702B, A, New Hao one town, No. 7018 Cai Tian Road, Futian, Shenzhen 518000 Room 201, No. 1 A (Qianhai business secretary, Shenzhen, Shenzhen City, Qianhai Shenzhen Hong Kong cooperation zone, Shenzhen City, Guangdong)

Applicant after: Shenzhen Rongyimai Information Technology Co., Ltd.

Address before: Room 201, Building A, No. 1 Qianwan Road, Qianhai Shenzhen-Hong Kong Cooperation Zone, Shenzhen, Guangdong 518000:No. 1701, 1702B, A, New Hao one town, No. 7018 Cai Tian Road, Futian, Shenzhen 518000 Room 201, No. 1 A (Qianhai business secretary, Shenzhen, Shenzhen City, Qianhai Shenzhen Hong Kong cooperation zone, Shenzhen City, Guangdong)

Applicant before: Maimaiti Mdt InfoTech Ltd, Shenzhen

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20201127

Termination date: 20210327

CF01 Termination of patent right due to non-payment of annual fee