[go: up one dir, main page]

CN109783204A - Distributed transaction processing method, device and storage medium - Google Patents

Distributed transaction processing method, device and storage medium Download PDF

Info

Publication number
CN109783204A
CN109783204A CN201811652896.6A CN201811652896A CN109783204A CN 109783204 A CN109783204 A CN 109783204A CN 201811652896 A CN201811652896 A CN 201811652896A CN 109783204 A CN109783204 A CN 109783204A
Authority
CN
China
Prior art keywords
equipment
transaction
execution
affairs
request
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.)
Pending
Application number
CN201811652896.6A
Other languages
Chinese (zh)
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.)
China Mobile Communications Group Co Ltd
MIGU Culture Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
MIGU Culture 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 China Mobile Communications Group Co Ltd, MIGU Culture Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN201811652896.6A priority Critical patent/CN109783204A/en
Publication of CN109783204A publication Critical patent/CN109783204A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明实施例提供一种分布式事务处理方法以及装置,其中所述方法应用于协调设备,所述协调设备用于管理至少一个执行设备,所述方法包括:接收所述至少一个执行设备中的第一执行设备的事务参与请求;所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;接收所述第一执行设备发来的事务提交请求;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;基于所述第一执行设备的事务提交请求,向所述第一执行设备发送事务提交指令。

Embodiments of the present invention provide a distributed transaction processing method and apparatus, wherein the method is applied to a coordination device, and the coordination device is used to manage at least one execution device, and the method includes: receiving a data from the at least one execution device. A transaction participation request from the first execution device; the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions; receive a transaction submission request sent by the first execution device; The transaction commit request is used to represent that the first execution device has completed the local transaction; based on the transaction commit request of the first execution device, a transaction commit instruction is sent to the first execution device.

Description

一种分布式事务处理方法、装置及存储介质Distributed transaction processing method, device and storage medium

技术领域technical field

本发明涉及后台分布式系统,具体涉及一种分布式事务处理方法、装置及存储介质。The invention relates to a background distributed system, in particular to a distributed transaction processing method, device and storage medium.

背景技术Background technique

在分布式系统中,为了保证数据的高可用,通常会将数据保留多个副本,这些副本会放置在不同的物理的机器上。在数据有多份副本的情况下,如果网络、服务器或者软件出现故障,会导致部分副本写入成功,部分副本写入失败。这就造成各个副本之间的数据不一致,数据内容冲突,造成事实上的数据不一致。In a distributed system, in order to ensure high availability of data, multiple copies of data are usually kept, and these copies are placed on different physical machines. In the case of multiple copies of data, if the network, server or software fails, some copies will be successfully written and some copies will fail. This results in data inconsistency among the replicas, conflicts in data content, and actual data inconsistency.

为了解决这种分布式一致性问题,已经提出了如图1所示的二阶段提交协议(Two-Phase Commit Protocol,2PC)和如图2所示的三阶段提交协议(Three-Phase CommitProtocol,3PC),但是这两种提交协议都存在各自的缺陷。二阶段提交协议存在同步阻塞、单点故障等问题;而三阶段提交协议会存在数据不一致问题。In order to solve this distributed consistency problem, the Two-Phase Commit Protocol (2PC) shown in Figure 1 and the Three-Phase Commit Protocol (3PC) shown in Figure 2 have been proposed ), but both commit protocols have their own flaws. The two-phase commit protocol has problems such as synchronization blocking and single point of failure; while the three-phase commit protocol has the problem of data inconsistency.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明的主要目的在于提供一种分布式事务处理方法、装置及存储介质,能够解决分布式系统中的事务阻塞问题,保证数据的一致性。In view of this, the main purpose of the present invention is to provide a distributed transaction processing method, device and storage medium, which can solve the problem of transaction blocking in a distributed system and ensure data consistency.

为达到上述目的,本发明的技术方案是这样实现的:In order to achieve the above object, the technical scheme of the present invention is achieved in this way:

本发明实施例的一种分布式事务处理方法,应用于协调设备,所述协调设备用于管理至少一个执行设备,其特征在于,所述方法包括:A distributed transaction processing method according to an embodiment of the present invention is applied to a coordination device, and the coordination device is used to manage at least one execution device, wherein the method includes:

接收所述至少一个执行设备中的第一执行设备的事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;receiving a transaction participation request from a first execution device in the at least one execution device; wherein the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions;

接收所述第一执行设备发来的事务提交请求;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;receiving a transaction submission request sent by the first execution device; wherein the transaction submission request is used to indicate that the first execution device has completed the local transaction;

基于所述第一执行设备的事务提交请求,向所述第一执行设备发送事务提交指令。Based on the transaction commit request of the first execution device, a transaction commit instruction is sent to the first execution device.

在上述方案中,所述向所述第一执行设备发送事务提交指令之前,所述方法还包括:In the above solution, before the transaction commit instruction is sent to the first execution device, the method further includes:

在确定收到所述第一执行设备发送的事务提交请求后,将所述第一执行设备所执行的与本地事务相关的日志和锁信息储存在数据库表中。After it is determined that the transaction commit request sent by the first execution device is received, log and lock information related to the local transaction executed by the first execution device is stored in a database table.

在上述方案中,所述方法还包括:In the above scheme, the method further includes:

检测是否接收到所述至少一个执行设备中的全部执行设备发来的事务提交确认消息;Detecting whether a transaction commit confirmation message sent by all execution devices in the at least one execution device is received;

若是,则确认全局事务完成;基于所述全局事务的标识符,对所述至少一个执行设备所对应的数据库进行清理;其中,所述全局事务由协调设备管理的执行设备所执行的本地事务组成。If so, confirm that the global transaction is completed; based on the identifier of the global transaction, clean up the database corresponding to the at least one execution device; wherein, the global transaction is composed of local transactions executed by the execution devices managed by the coordination device .

本发明实施例还提供一种分布式事务处理方法,应用于第一执行设备,其特征在于,所述方法包括:An embodiment of the present invention further provides a distributed transaction processing method, which is applied to the first execution device, wherein the method includes:

向协调设备发送事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;所述协调设备用于管理至少一个执行设备,所述至少一个执行设备中包含第一执行设备;Send a transaction participation request to the coordination device; wherein the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions; the coordination device is used to manage at least one execution device, and the The at least one execution device includes a first execution device;

执行本地事务,在完成所述本地事务的处理时向所述协调设备发送事务提交请求;其中,所述本地事务为所述协调设备在接收到事务参与请求之前为所述第一执行设备分配的事务;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;Execute a local transaction, and send a transaction submission request to the coordination device when the processing of the local transaction is completed; wherein, the local transaction is the first execution device allocated by the coordination device before receiving the transaction participation request. transaction; wherein, the transaction commit request is used to represent that the first execution device has completed the local transaction;

当接收到所述协调设备发来的事务提交指令时,提交所述本地事务。When receiving the transaction commit instruction sent by the coordinating device, commit the local transaction.

在上述方案中,所述提交所述本地事务之后,所述方法还包括:In the above solution, after the local transaction is submitted, the method further includes:

向协调设备发送确认消息,所述确认消息用于通知所述本地事务已提交。An acknowledgment message is sent to the coordinating device, the acknowledgment message being used to notify that the local transaction has been committed.

在上述方案中,所述提交所述本地事务之后,所述方法还包括:In the above solution, after the local transaction is submitted, the method further includes:

释放参与所述本地事务的数据库的连接资源。Release the connection resources of the database participating in the local transaction.

本发明还提供一种分布式事务处理装置,所述装置包括:第一接收模块、第二接收模块和第一发送模块,其中,The present invention further provides a distributed transaction processing device, the device includes: a first receiving module, a second receiving module and a first sending module, wherein,

所述第一接收模块,用于接收所述至少一个执行设备中的第一执行设备的事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;The first receiving module is configured to receive a transaction participation request from a first execution device in the at least one execution device; wherein the transaction participation request is used to indicate to the coordination device that the first execution device is in a capable state. the status of executing local transactions;

所述第二接收模块,用于接收所述第一执行设备发来的事务提交请求;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;The second receiving module is configured to receive a transaction submission request sent by the first execution device; wherein the transaction submission request is used to indicate that the first execution device has completed the local transaction;

所述第一发送模块,用于基于所述第一执行设备的事务提交请求,向所述第一执行设备发送事务提交指令。The first sending module is configured to send a transaction submission instruction to the first execution device based on the transaction submission request of the first execution device.

本发明还提供一种分布式事务处理装置,所述装置包括:请求模块、执行模块和提交模块,其中,The present invention also provides a distributed transaction processing device, the device includes: a request module, an execution module and a submission module, wherein,

所述请求模块,用于向协调设备发送事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;所述协调设备用于管理至少一个执行设备,所述至少一个执行设备中包含第一执行设备;The request module is configured to send a transaction participation request to the coordination device; wherein, the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions; the coordination device is used for Manage at least one execution device, the at least one execution device includes a first execution device;

所述执行模块,用于执行本地事务,在完成所述本地事务的处理时向所述协调设备发送事务提交请求;其中,所述本地事务为所述协调设备在接收到事务参与请求之前为所述第一执行设备分配的事务;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;The execution module is configured to execute a local transaction, and send a transaction submission request to the coordination device when the processing of the local transaction is completed; wherein, the local transaction is a transaction submitted by the coordination device before receiving the transaction participation request. The transaction allocated by the first execution device; wherein, the transaction submission request is used to represent that the first execution device has completed the local transaction;

所述提交模块,用于当接收到所述协调设备发来的事务提交指令时,提交所述本地事务。The committing module is configured to commit the local transaction when receiving the transaction commit instruction sent by the coordinating device.

本发明还提供一种计算机可读存储介质,其上存储有计算机程序,其中,所述计算机程序被处理器执行时上述所述方法的任一步骤。The present invention also provides a computer-readable storage medium on which a computer program is stored, wherein when the computer program is executed by a processor, any step of the above-mentioned method is executed.

本发明还提供一种分布式事务处理装置,包括:处理器和用于存储能够在处理器上运行的计算机程序的存储器,其中,所述处理器用于运行所述计算机程序时,执行上述所述方法的任一步骤。The present invention also provides a distributed transaction processing device, comprising: a processor and a memory for storing a computer program that can be executed on the processor, wherein the processor is configured to execute the above-mentioned computer program when running the computer program. any step of the method.

本发明实施例提供的分布式事务处理方法以及装置,通过各执行设备各自并行向协调设备提交参与请求,并各自自主执行本地任务的方式,无需同步等待其他的执行设备确认是否可以参加事务的回执,提高了分布式事务执行的效率;在各执行设备执行完本地事务后,由协调设备统一管控,执行提交或者回滚,很好的解决了分布式事务中的阻塞问题。并且,由于本发明实施例提供的分布式事务处理方法在全局事务提交中采用本地事务提交和全局事务标识符清理的方式,可以提高分布式事务的数据一致性,达到分布式事务的最大性能。In the distributed transaction processing method and device provided by the embodiments of the present invention, each executing device submits a participation request to the coordinating device in parallel and executes local tasks independently, without synchronously waiting for other executing devices to confirm whether they can participate in the transaction. , which improves the efficiency of distributed transaction execution; after each execution device completes the local transaction, the coordinating device performs unified management and control to perform commit or rollback, which solves the blocking problem in distributed transactions. Moreover, since the distributed transaction processing method provided by the embodiment of the present invention adopts the methods of local transaction submission and global transaction identifier cleaning in global transaction submission, the data consistency of distributed transactions can be improved, and the maximum performance of distributed transactions can be achieved.

附图说明Description of drawings

图1为两阶段提交协议的分布式事务处理方法的信息交互图;Fig. 1 is the information interaction diagram of the distributed transaction processing method of the two-phase commit protocol;

图2为三阶段提交协议的分布式事务处理方法的信息交互图;Fig. 2 is the information interaction diagram of the distributed transaction processing method of the three-phase commit protocol;

图3为本发明实施例的一种应用场景;3 is an application scenario of an embodiment of the present invention;

图4为本发明实施例提供的一种分布式事务处理方法的流程图;4 is a flowchart of a distributed transaction processing method provided by an embodiment of the present invention;

图5为本发明实施例提供的另一种分布式事务处理方法的流程图;5 is a flowchart of another distributed transaction processing method provided by an embodiment of the present invention;

图6为本发明实施例提供的协调设备与执行设备之间的交互示意图;6 is a schematic diagram of interaction between a coordination device and an execution device provided by an embodiment of the present invention;

图7为本发明实施例提供的分布式事务处理装置的结构示意图一;FIG. 7 is a schematic structural diagram 1 of a distributed transaction processing apparatus provided by an embodiment of the present invention;

图8为本发明实施例提供的分布式事务处理装置的结构示意图二;FIG. 8 is a second schematic structural diagram of a distributed transaction processing apparatus provided by an embodiment of the present invention;

图9是本发明实施例分布式事务处理装置的一种硬件结构示意图。FIG. 9 is a schematic diagram of a hardware structure of a distributed transaction processing apparatus according to an embodiment of the present invention.

具体实施方式Detailed ways

为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对发明的具体技术方案做进一步详细描述。以下实施例用于说明本发明,但不用来限制本发明的范围。To make the objectives, technical solutions and advantages of the embodiments of the present invention clearer, the specific technical solutions of the invention will be described in further detail below with reference to the accompanying drawings in the embodiments of the present invention. The following examples are intended to illustrate the present invention, but not to limit the scope of the present invention.

在描述本发明的实施例之前,先详细了解一下分布式事务的相关背景。Before describing the embodiments of the present invention, let's take a detailed look at the relevant background of distributed transactions.

分布式事务是指一次大的操作由不同的小操作组成,这些小的操作分布在不同的服务器上,且属于不同的应用,分布式事务需要保证这些小操作要么全部成功,要么全部失败。本质上来说,分布式事务就是为了保证不同数据库的数据一致性。但是,不同的小操作由不同的节点执行,而相互独立的节点之间无法准确的知道其他节点的事务执行情况。为了保证分布式系统中的数据一致性,分布式事务处理的关键是必须有一种方法可以知道事务在任何地方所做的所有动作,提交或回滚事务的决定必须产生统一的结果(全部提交或全部回滚)。所以,常规的解决办法就是引入一个“协调者”的组件来统一调度所有分布式节点的执行。Distributed transaction means that a large operation consists of different small operations. These small operations are distributed on different servers and belong to different applications. Distributed transactions need to ensure that these small operations either all succeed or all fail. Essentially, distributed transactions are to ensure data consistency across different databases. However, different small operations are performed by different nodes, and the independent nodes cannot accurately know the transaction execution status of other nodes. In order to guarantee data consistency in a distributed system, the key to distributed transaction processing is that there must be a way to know all the actions a transaction has made anywhere, and the decision to commit or roll back a transaction must yield a uniform result (all commit or roll back all). Therefore, the conventional solution is to introduce a "coordinator" component to uniformly schedule the execution of all distributed nodes.

在图3所示的应用场景中,当任务来临时,应用系统(AP,Application),即业务系统可以根据业务的具体情况将业务划分为多个分支事务,并将划分的多个分支事务发送给事务管理器(TM,Transaction Manager),即协调设备。这里,所述业务系统AP将划分的多个分支事务发送给协调设备TM,具体是通过调用分布式事务的操作接口TX来实现的。In the application scenario shown in Figure 3, when the task comes, the application system (AP, Application), that is, the business system, can divide the business into multiple branch transactions according to the specific situation of the business, and send the divided multiple branch transactions. To the transaction manager (TM, Transaction Manager), that is, the coordination device. Here, the business system AP sends the divided multiple branch transactions to the coordination device TM, which is specifically implemented by invoking the operation interface TX of the distributed transaction.

协调设备TM在接收到上述多个分支事务后,对多个分支进行解析,确定各分支的处理对象以及对应的资源,并给事务分配标识符;在确定各分支业务后,通过资源管理器(RM,Resource Manager)提供的操作接口XA来统一调度各资源管理器RM,即执行设备,以实现分布式事务。这里,资源管理器RM一般是数据库,也可以是其他的资源管理器,如消息队列(如JMS数据源)等。After receiving the above-mentioned multiple branch transactions, the coordination device TM parses the multiple branches, determines the processing objects and corresponding resources of each branch, and assigns an identifier to the transaction; after determining each branch service, the resource manager ( RM, Resource Manager) provides an operation interface XA to uniformly schedule each resource manager RM, that is, an execution device, to realize distributed transactions. Here, the resource manager RM is generally a database, and may also be other resource managers, such as a message queue (eg, a JMS data source).

需要注意的是,在图3中,业务系统AP和执行设备RM之间则通过RM提供的本地接口(Native API)进行资源控制;这里,本地接口没有进行接口规范的约定,目前是各个厂商自己实现自己的资源控制。It should be noted that in Figure 3, resource control is performed between the business system AP and the execution device RM through the native API (Native API) provided by the RM; here, the local interface does not have an interface specification agreement, and currently each manufacturer owns Implement your own resource control.

通过XA接口规范实现分布式事务的目前有两阶段提交协议、三阶段提交协议。在实践中发现二阶段提交存在同步阻塞、单点故障以及数据不一致等问题,而三阶段提交解决了单点故障问题,并可以减少阻塞,但是由于其交互机制使得一旦参与者无法及时收到来自协调者的信息之后,它会默认执行提交(commit),而不会一直持有事务资源并处于阻塞状态;这种机制一方面可以很大程度的减少阻塞问题,但也会导致数据一致性问题:由于网络原因,协调设备TM发送的终止(abort)响应没有及时被执行设备RM接收到,那么执行设备RM在等待超时之后执行了提交(commit)操作。这样就和其他接到终止(abort)命令并执行回滚的执行设备RM之间存在数据不一致的情况。There are currently two-phase commit protocols and three-phase commit protocols for implementing distributed transactions through the XA interface specification. In practice, it is found that there are problems such as synchronous blocking, single point of failure and data inconsistency in the two-phase submission, while the three-phase submission solves the single point of failure problem and can reduce blocking, but due to its interaction mechanism, once the participant cannot receive the incoming data in time After the information of the coordinator, it will perform commit by default instead of holding transaction resources and blocking; on the one hand, this mechanism can greatly reduce blocking problems, but it will also cause data consistency problems : Due to network reasons, the abort response sent by the coordinating device TM is not received by the executing device RM in time, then the executing device RM performs a commit operation after waiting for a timeout. In this way, there is data inconsistency between other execution devices RM that receive an abort command and perform rollback.

基于此,本发明实施例的提供一种分布式事务处理方法,应用于协调设备,所述协调设备用于管理至少一个执行设备,如图4所示,该方法包括:Based on this, an embodiment of the present invention provides a distributed transaction processing method, which is applied to a coordination device, where the coordination device is used to manage at least one execution device. As shown in FIG. 4 , the method includes:

S101,接收所述至少一个执行设备中的第一执行设备的事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;S101, receiving a transaction participation request of a first execution device in the at least one execution device; wherein, the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions;

S102,接收所述第一执行设备发来的事务提交请求;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;S102, receiving a transaction submission request sent by the first execution device; wherein the transaction submission request is used to indicate that the first execution device has completed the local transaction;

S103,基于所述第一执行设备的事务提交请求,向所述第一执行设备发送事务提交指令。S103, based on the transaction commit request of the first execution device, send a transaction commit instruction to the first execution device.

这里,所述协调设备TM是分布式系统中用于统一调度所有分布式节点,即执行设备RM执行任务的设备,所述协调设备TM的确定,可以是按业务的执行的顺序决定,即第一个业务的执行者为协调设备TM,也可以是根据业务中各个子业务之间的相互关联关系,选取关联关系最多的执行设备为协调设备TM,当然,此处协调设备TM的确定也可以是其他确定方式。Here, the coordination device TM is a device used to uniformly schedule all distributed nodes in a distributed system, that is, a device that performs tasks performed by the device RM. The executor of a business is the coordinating device TM, and it can also be based on the interrelated relationship between the various sub-services in the business, and the executing device with the most association relationship is selected as the coordinating device TM. Of course, the determination of the coordinating device TM here can also be is another way of determining.

所述执行设备RM是分布式系统中执行本地事务的设备。在一个分布式系统中,一般只有一个协调设备TM,但有多个执行设备RM。所述“第一”、“第二”等仅用于区分描述,而不能理解为指示或暗示相对重要性。The execution device RM is a device that executes local transactions in a distributed system. In a distributed system, there is generally only one coordinating device TM, but there are multiple executing devices RM. The "first", "second", etc. are only used for distinguishing descriptions, and should not be construed as indicating or implying relative importance.

在步骤S101中,协调设备TM接收所述至少一个执行设备中的第一执行设备的事务参与请求,具体包括:当业务来临时,业务系统AP根据业务的具体情况将业务划分为多个分支事务,并将划分的多个分支事务发送给协调设备TM,协调设备TM根据各分支事务情况,通过XA接口注册执行设备RM,即注册此次业务需要的执行设备RM。这里,当被注册的执行设备RM中有的处于能够执行本地事务的状态时,所述处于能够执行本地事务状态的执行设备RM主动向协调设备TM发送事务参与请求,而协调设备TM接收所述第一执行设备的事务参与请求。In step S101, the coordination device TM receives the transaction participation request of the first execution device in the at least one execution device, which specifically includes: when the service comes, the service system AP divides the service into multiple branch transactions according to the specific situation of the service , and send the divided multiple branch transactions to the coordination device TM, and the coordination device TM registers the execution device RM through the XA interface according to the situation of each branch transaction, that is, registers the execution device RM required by this service. Here, when some of the registered execution devices RM are in a state capable of executing local transactions, the execution devices RM in the state capable of executing local transactions take the initiative to send a transaction participation request to the coordinating device TM, and the coordinating device TM receives the Transaction participation request of the first execution device.

在步骤S102中,所述协调设备TM接收所述第一执行设备发来的事务提交请求;这里,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;In step S102, the coordination device TM receives a transaction commit request sent by the first execution device; here, the transaction commit request is used to indicate that the first execution device has completed the local transaction;

在步骤S103中,在协调设备TM接收事务提交请求之后,所述协调设备TM基于所述第一执行设备的事务提交请求,向所述第一执行设备发送事务提交指令,开始正式的提交过程。In step S103, after the coordination device TM receives the transaction submission request, the coordination device TM sends a transaction submission instruction to the first execution device based on the transaction submission request of the first execution device to start a formal submission process.

这里,协调设备TM向所述第一执行设备发送事务提交指令之前,所述分布式事务处理方法还包括:Here, before the coordination device TM sends a transaction commit instruction to the first execution device, the distributed transaction processing method further includes:

在确定收到所述第一执行设备发送的事务提交请求后,将所述第一执行设备所执行的与本地事务相关的日志和锁信息储存在数据库表中。After it is determined that the transaction commit request sent by the first execution device is received, log and lock information related to the local transaction executed by the first execution device is stored in a database table.

这里,协调设备TM收到第一执行设备发送的事务提交请求,就将所述第一执行设备执行本地任务的相关日志信息和锁信息进行储存。Here, the coordination device TM receives the transaction submission request sent by the first execution device, and stores the log information and lock information about the local task performed by the first execution device.

需要说明的是,所述日志信息包括本地事务的undo日志和redo日志;所述锁信息是指在事务的提交之前,锁定资源。所述undo日志用于存放数据修改前的值;所述redo日志,用于记录修改后的数据,顺序记录。It should be noted that the log information includes the undo log and the redo log of the local transaction; the lock information refers to locking resources before committing the transaction. The undo log is used to store the value before data modification; the redo log is used to record the modified data, which is recorded sequentially.

还需要说明的是,一般地,关系型数据库管理系统是由两个文件组成的,一个数据库文件和一个日志文件。数据库进行任何写入操作的时候都是要先写日志的;在执行事务的时候,数据库首先会记录下这个事务的本地redo日志,即记录修改后的数据,然后才开始真正操作数据库;在操作之前首先会把日志文件写入磁盘。那么当突然断电的时候,即使操作没有完成,在重新启动数据库时候,数据库会根据当前数据的情况进行undo回滚或者是redo前滚,这样就保证了数据的强一致性。It should also be noted that, generally, a relational database management system is composed of two files, a database file and a log file. When the database performs any write operation, it must first write the log; when executing a transaction, the database first records the local redo log of the transaction, that is, records the modified data, and then starts to actually operate the database; The log file is written to disk first. Then, when there is a sudden power failure, even if the operation is not completed, when the database is restarted, the database will perform undo rollback or redo rollforward according to the current data situation, which ensures strong data consistency.

当数据库对数据做修改的时候,需要把数据页从磁盘读到缓存区域(BufferPool)中,所述缓存区域用来缓存数据和索引至内存,可以用来加速数据的读写。在数据页从磁盘读到缓存区域后,如果在缓存区域中进行数据的修改,那么缓存区域中的数据页就与磁盘上的数据页内容不一致,此时缓存区域的数据页称为脏页(dirty page)。如果这个时候发生非正常的数据库服务重启,那么这些数据并没有同步到磁盘文件中,也就是会发生数据丢失。如果这个时候,能够在有一个文件,当缓存区域中的dirty page变更结束后,把相应修改记录记录到redo日志文件中,那么当数据库服务发生崩溃后,恢复数据库的时候,可以根据redo日志文件的记录内容,重新应用到磁盘文件,数据保持一致。When the database modifies the data, it needs to read the data pages from the disk into the cache area (BufferPool). After the data page is read from the disk to the cache area, if the data is modified in the cache area, the content of the data page in the cache area is inconsistent with the data page on the disk. At this time, the data page in the cache area is called a dirty page ( dirty page). If an abnormal database service restart occurs at this time, the data will not be synchronized to the disk file, that is, data loss will occur. If there is a file at this time, when the dirty page in the cache area is changed, the corresponding modification records can be recorded in the redo log file, then when the database service crashes and the database is restored, it can be based on the redo log file. The recorded content is reapplied to the disk file, and the data remains consistent.

进一步地,在本实施例的分布式事务处理方法,还包括:Further, the distributed transaction processing method in this embodiment further includes:

检测是否接收到所述至少一个执行设备中的全部执行设备发来的事务提交确认消息;Detecting whether a transaction commit confirmation message sent by all execution devices in the at least one execution device is received;

若是,则确认全局事务完成;基于所述全局事务的标识符,对所述至少一个执行设备所对应的数据库进行清理;其中,所述全局事务由协调设备管理的执行设备所执行的本地事务组成;If so, confirm that the global transaction is completed; based on the identifier of the global transaction, clean up the database corresponding to the at least one execution device; wherein, the global transaction is composed of local transactions executed by the execution devices managed by the coordination device ;

这里,需要说明的是,当执行设备根据协调设备发送的事务提交指令,执行本地任务的提交,如果所述协调设备成功的执行了提交操作,则向协调设备返回确认(ACK)响应,所述确认响应用于表征所述执行设备已经正确的提交事务。Here, it should be noted that when the executing device performs the submission of the local task according to the transaction submission instruction sent by the coordinating device, if the coordinating device successfully executes the submission operation, it returns an acknowledgment (ACK) response to the coordinating device. A confirmation response is used to characterize that the executing device has correctly committed the transaction.

那么,当协调设备接收到全部执行设备发来的事务提交确认消息时,表示全局事务完成。这时,基于所述全局事务的标识符,对所述至少一个执行设备所对应的数据库进行清理,释放全部数据库资源。Then, when the coordinating device receives the transaction commit confirmation message sent by all the executing devices, it means that the global transaction is completed. At this time, based on the identifier of the global transaction, the database corresponding to the at least one execution device is cleaned up, and all database resources are released.

这里,由于在事务分配时,协调设备对整个事务涉及的各子事务都分配了统一的标识符,在事务提交之后,需要对此次全局事务处理过程所占用的数据库资源进行释放,以便其他事务可以访问此数据库。Here, since the coordinating device assigns a uniform identifier to each sub-transaction involved in the entire transaction during transaction allocation, after the transaction is committed, the database resources occupied by the global transaction process need to be released so that other transactions can This database can be accessed.

作为一种示例,当用户A购买一个商品时,用户A的支付数据库、商品信息数据库均会发生更新,在进行提交操作时,需要对操作的数据库进行锁定,以防止“用户A购买一个商品”这个事务之外的其他事务对上述商品信息数据库进行操作,在“用户A购买一个商品”整个任务提交完成后,对所述事务涉及的相关数据库如支付数据库、商品信息数据库的资源进行释放,以便其他的事务(例如:“用户B购买一个商品”这一事务)可以访问此支付数据库、商品信息数据库。As an example, when user A buys a commodity, both the payment database and commodity information database of user A will be updated. When the submission operation is performed, the database of the operation needs to be locked to prevent "user A from purchasing a commodity" Transactions other than this transaction operate on the above commodity information database. After the entire task of “User A buys a commodity” is submitted, the related databases involved in the transaction, such as the payment database and the commodity information database, are released. Other transactions (for example: "User B purchases a commodity") can access the payment database and commodity information database.

在本发明的一种可选实施例中,在上述步骤S103之后,所述方法可以包括:In an optional embodiment of the present invention, after the above step S103, the method may include:

判断是否存在本地事务执行失败的执行设备,若存在,向全局事务相关的全部执行设备发送回滚指令;其中,所述全局事务由协调设备管理的执行设备所执行的本地事务组成;Determine whether there is an execution device that fails to execute the local transaction, and if so, send a rollback instruction to all execution devices related to the global transaction; wherein, the global transaction is composed of the local transaction executed by the execution device managed by the coordination device;

这里,当协调设备在预设时间内没有收到某一执行设备发送的提交请求,则认为所述某一执行设备本地事务执行失败。当存在本地事务执行失败的执行设备时,所述协调设备可以向全局事务相关的全部执行设备发送回滚指令;即一个执行设备本地任务执行失败,则全部的执行设备都进行数据的回滚操作。Here, when the coordinating device does not receive a commit request sent by a certain execution device within a preset time, it is considered that the execution of the local transaction of the certain execution device fails. When there is an execution device that fails to execute a local transaction, the coordinating device can send a rollback instruction to all execution devices related to the global transaction; that is, if one execution device fails to execute a local task, all the execution devices perform data rollback operations .

在本发明的另一种可选实施例中,在上述步骤S103之后,所述方法还可以包括:In another optional embodiment of the present invention, after the above step S103, the method may further include:

判断是否存在本地事务执行失败的第二执行设备,若存在,则向所述第二执行设备发送回滚指令。Determine whether there is a second execution device that fails to execute the local transaction, and if so, send a rollback instruction to the second execution device.

这里,当只有第二执行设备执行本地事务执行失败时,协调设备只向所述第二执行设备发送回滚指令;Here, when only the second execution device fails to execute the local transaction, the coordination device only sends a rollback instruction to the second execution device;

需要说明的是,此处协调设备向所述第二执行设备发送回滚指令的次数不能过多,当多次执行回滚操作还未成功时,所述协调设备向全局事务相关的全部执行设备发送回滚指令。这里,由于很多事务在操作时有时间的限制,当回滚次数过多时,会影响全局事务提交的效率,可以设置发送回滚指令的次数不超过3次,或者是其他方式进行次数的限定。It should be noted that the number of times that the coordinating device sends the rollback instruction to the second execution device cannot be too many. When the rollback operation is executed multiple times and has not been successful, the coordinating device sends all execution devices related to the global transaction. Send a rollback command. Here, since many transactions have time limitations during operation, when the number of rollbacks is too large, the efficiency of global transaction submission will be affected.

为了更清晰的表达本实施例的内容,这里结合具体应用情况进行说明,以如下业务需求为例:In order to express the content of this embodiment more clearly, the description is given here in conjunction with the specific application situation, taking the following business requirements as an example:

转账业务,账户A向账户B转账1000元,在转账的过程中,账户A、B都向账户C提交10元的手续费。那么此次分布式事务可以划分为6个分支事务,即:“A-1000”、“B+1000”、“A-10”、“B-10”、“C+10”、“C+10”;在进行本实施例分布式事务处理之前,业务系统会将划分的所述6个分支事务发送给协调设备TM,协调设备TM根据所述6个分支事务处理的对象和资源,确定对资源的处理方式和依赖关系,通过XA接口注册此次分布式事务需要的6个执行设备RM,通知所述RM开启各数据库的操作。In the transfer business, account A transfers 1,000 yuan to account B. During the transfer process, both accounts A and B submit a handling fee of 10 yuan to account C. Then this distributed transaction can be divided into 6 branch transactions, namely: "A-1000", "B+1000", "A-10", "B-10", "C+10", "C+10" "; before carrying out the distributed transaction processing in this embodiment, the business system will send the divided six branch transactions to the coordination device TM, and the coordination device TM determines the resource allocation according to the objects and resources of the six branch transactions. The six execution devices RM required for this distributed transaction are registered through the XA interface, and the RM is notified to open the operation of each database.

当这6个执行设备RM中有的处于能够执行本地事务的状态时,例如,执行“A-10”操作的执行设备RM处于能够执行事务的状态,此时,本实施例分布式事务处理的第一步是:所述协调设备TM会接收到“A-10”操作的执行设备RM的事务参与请求,在其“A-10”操作完成后,协调设备TM会接收到“A-10”操作的执行设备发来的事务提交请求;这时,协调设备TM会基于所述提交请求,向“A-10”操作的执行设备发送事务提交指令。When some of the six execution devices RM are in a state capable of executing local transactions, for example, the execution device RM that executes the "A-10" operation is in a state capable of executing transactions, at this time, the distributed transaction processing in this embodiment The first step is: the coordinating device TM will receive the transaction participation request of the executing device RM of the "A-10" operation, and after the "A-10" operation is completed, the coordinating device TM will receive "A-10" A transaction commit request sent by the execution device of the operation; at this time, the coordinating device TM will send a transaction commit instruction to the execution device of the "A-10" operation based on the commit request.

这里,所述确定对资源的处理方式和依赖关系,可以是找出事务之间的存在的先后顺序,或者是事务之间可以并行处理的情况。例如当“A-1000”和“A-10”可以并行处理。Here, the determining of the processing mode and the dependency relationship of the resources may be the order of finding out the existence of the transactions, or the case where the transactions can be processed in parallel. For example when "A-1000" and "A-10" can be processed in parallel.

本发明实施例提供的分布式事务处理方法,通过协调设备接收执行设备的事务参与请求、事务提交请求,判断所述执行设备本地任务的成功执行,进而向执行设备发送事务提交指令。由于在任务分配后,无需等待协调设备的命令,极大的提高了执行的效率,同时由于协调设备可以修改回滚权限,对执行错误的执行设备采取主动回滚的方式,保证了事务的原子性。The distributed transaction processing method provided by the embodiment of the present invention receives the transaction participation request and the transaction submission request of the execution device by the coordination device, judges the successful execution of the local task of the execution device, and then sends the transaction submission instruction to the execution device. After the task is assigned, there is no need to wait for the command of the coordinating device, which greatly improves the efficiency of execution. At the same time, because the coordinating device can modify the rollback authority, the wrong execution device can be actively rolled back to ensure the atomicity of the transaction. sex.

本发明实施例提供另一种分布式事务处理方法,应用于第一执行设备,如图5所示,所述方法包括:An embodiment of the present invention provides another distributed transaction processing method, which is applied to the first execution device. As shown in FIG. 5 , the method includes:

S201,向协调设备发送事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;所述协调设备用于管理至少一个执行设备,所述至少一个执行设备中包含第一执行设备;S201: Send a transaction participation request to a coordination device; wherein the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions; the coordination device is used to manage at least one execution device , the at least one execution device includes a first execution device;

S202,执行本地事务,在完成所述本地事务的处理时向所述协调设备发送事务提交请求;其中,所述本地事务为所述协调设备在接收到事务参与请求之前为所述第一执行设备分配的事务;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;S202: Execute a local transaction, and send a transaction submission request to the coordinating device when processing the local transaction is completed; wherein, the local transaction is that the coordinating device is the first executing device before receiving the transaction participation request an assigned transaction; wherein the transaction commit request is used to indicate that the first execution device has completed the local transaction;

S203,当接收到所述协调设备发来的事务提交指令时,提交所述本地事务。S203, when receiving the transaction commit instruction sent by the coordinating device, commit the local transaction.

在步骤S201中,当业务来临时,业务系统AP根据业务的具体情况将业务划分为多个分支事务,并将划分的多个分支事务发送给协调设备TM,协调设备TM根据各分支事务情况,通过XA接口注册执行设备RM,即注册此次业务需要的执行设备RM。这里,当被注册的执行设备RM中有的处于能够执行本地事务的状态时,所述处于能够执行本地事务状态的执行设备RM主动向协调设备TM发送事务参与请求。In step S201, when the service comes, the service system AP divides the service into multiple branch transactions according to the specific conditions of the service, and sends the divided multiple branch transactions to the coordination device TM, and the coordination device TM, according to the situation of each branch transaction, Register the execution device RM through the XA interface, that is, register the execution device RM required for this service. Here, when some of the registered execution devices RM are in a state capable of executing local transactions, the execution devices RM in the state capable of executing local transactions take the initiative to send a transaction participation request to the coordination device TM.

这里,所述协调设备TM是分布式系统中用于统一调度所有参与事务的RM执行任务的设备,所述执行设备RM是分布式系统中执行本地事务的设备,有多个执行设备RM,上述至少一个执行设备中包含第一执行设备;Here, the coordination device TM is a device in a distributed system that is used to uniformly schedule all RMs participating in transactions to execute tasks, and the execution device RM is a device that executes local transactions in a distributed system. There are multiple execution devices RM. At least one execution device includes a first execution device;

在步骤S202中,在第一执行设备向协调设备TM发送事务参与请求后,开始执行自己被分配的分支事务,即本地事务,在本地事务完成后,向协调设备TM发起事务提交请求;这里,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;In step S202, after the first execution device sends a transaction participation request to the coordination device TM, it starts to execute its assigned branch transaction, that is, a local transaction, and after the local transaction is completed, a transaction submission request is initiated to the coordination device TM; here, The transaction commit request is used to represent that the first execution device has completed the local transaction;

这里,所述第一执行设备执行本地事务时,所述方法还包括:Here, when the first execution device executes the local transaction, the method further includes:

存储本地日志信息。Store local log information.

所述本地日志信息包括本地事务的undo日志和redo日志;所述undo日志用于存放数据修改前的值;所述redo日志,用于记录修改后的数据,顺序记录。The local log information includes the undo log and the redo log of the local transaction; the undo log is used to store the value before data modification; the redo log is used to record the modified data, which is recorded sequentially.

需要说明的是,在第一执行设备执行本地事务的时候,即操作数据库的时候,首先会记录下这个事务的本地redo日志,即记录修改后的数据,然后才开始真正操作数据库;在操作之前首先会把日志文件写入磁盘。那么当突然断电的时候,即使操作没有完成,在重新启动数据库时候,数据库会根据当前数据的情况进行undo回滚或者是redo前滚,这样就保证了数据的强一致性。It should be noted that when the first execution device executes a local transaction, that is, when operating the database, it will first record the local redo log of the transaction, that is, record the modified data, and then start to actually operate the database; before the operation The log file is first written to disk. Then, when there is a sudden power failure, even if the operation is not completed, when the database is restarted, the database will perform undo rollback or redo rollforward according to the current data situation, which ensures strong data consistency.

在步骤S203中,当接收到所述协调设备发来的事务提交指令时,提交所述本地事务。In step S203, when receiving the transaction commit instruction sent by the coordinating device, commit the local transaction.

在提交所述本地事务之后,所述方法还包括:After committing the local transaction, the method further includes:

向协调设备发送确认消息,所述确认消息用于通知所述本地事务已提交。An acknowledgment message is sent to the coordinating device, the acknowledgment message being used to notify that the local transaction has been committed.

这里,当第一执行设备根据协调设备发送的事务提交指令,成功的执行了本地事务的提交后,会向协调设备返回确认(ACK)响应,所述确认响应用于表征所述第一执行设备已经正确的提交事务。Here, when the first execution device successfully executes the submission of the local transaction according to the transaction submission instruction sent by the coordinator device, it will return an acknowledgement (ACK) response to the coordinator device, and the acknowledgment response is used to represent the first execution device. The transaction has been correctly committed.

所述提交所述本地事务之后,所述方法还包括:After the committing the local transaction, the method further includes:

释放参与所述本地事务的数据库的连接资源。Release the connection resources of the database participating in the local transaction.

这里,由于在对数据库进行操作时,对数据库资源进行了锁定,其他事务不能访问数据库资源,那么在本地任务提交之后,需要对此次本地事务所占用的数据库资源进行释放,以便其他事务可以访问此数据库。Here, since the database resources are locked when the database is operated, other transactions cannot access the database resources. After the local task is submitted, the database resources occupied by the local transaction need to be released so that other transactions can access the database resources. this database.

作为一种可选的实施例,所述分布式事务处理方法在提交本地事务之后,所述方法还包括:As an optional embodiment, after the distributed transaction processing method submits the local transaction, the method further includes:

接收协调设备发来的数据回滚指令,执行数据回滚。Receive the data rollback command sent by the coordinating device, and execute the data rollback.

这里,具体是针对存在本地事务未执行成功的情况,所述协调设备会发送数据回滚指令,根据接收的数据回滚指令,执行数据回滚。Here, specifically, in the case that the local transaction is not successfully executed, the coordination device will send a data rollback instruction, and execute the data rollback according to the received data rollback instruction.

为了更清晰的表达本实施例的内容,这里结合具体应用情况进行说明,以如下业务需求为例:In order to express the content of this embodiment more clearly, the description is given here in conjunction with the specific application situation, taking the following business requirements as an example:

转账业务,账户A向账户B转账1000元,在转账的过程中,账户A、B都向账户C提交10元的手续费。那么此次分布式事务可以划分为6个分支事务,即:“A-1000”、“B+1000”、“A-10”、“B-10”、“C+10”、“C+10”;在进行本实施例分布式事务处理之前,业务系统会将划分的所述6个分支事务发送给协调设备TM,协调设备TM根据所述6个分支事务处理的对象和资源,确定对资源的处理方式和依赖关系,通过XA接口注册此次分布式事务需要的6个执行设备RM,通知所述RM开启各数据库的操作。In the transfer business, account A transfers 1,000 yuan to account B. During the transfer process, both accounts A and B submit a handling fee of 10 yuan to account C. Then this distributed transaction can be divided into 6 branch transactions, namely: "A-1000", "B+1000", "A-10", "B-10", "C+10", "C+10" "; before carrying out the distributed transaction processing in this embodiment, the business system will send the divided six branch transactions to the coordination device TM, and the coordination device TM determines the resource allocation according to the objects and resources of the six branch transactions. The six execution devices RM required for this distributed transaction are registered through the XA interface, and the RM is notified to open the operation of each database.

当这6个执行设备RM中有的处于能够执行本地事务的状态时,例如,执行“A-10”操作的执行设备RM处于能够执行事务的状态,此时,本实施例分布式事务处理的第一步是:执行“A-10”操作的执行设备RM自行向协调设备TM发送事务参与请求,并自行执行本地任务,即执行“A-10”操作;在完成“A-10”操作后,向所述协调设备TM发送“A-10”操作的提交请求;最后根据接收到协调设备发来的事务提交指令时,提交所述本地事务“A-10”操作。When some of the six execution devices RM are in a state capable of executing local transactions, for example, the execution device RM that executes the "A-10" operation is in a state capable of executing transactions, at this time, the distributed transaction processing in this embodiment The first step is: the execution device RM that executes the "A-10" operation sends a transaction participation request to the coordinating device TM by itself, and executes the local task by itself, that is, executes the "A-10" operation; after completing the "A-10" operation , send a commit request of the "A-10" operation to the coordination device TM; finally, submit the local transaction "A-10" operation according to the transaction commit instruction received from the coordination device.

本发明实施例提供的分布式事务处理方法,通过各执行设备各自并行向协调设备提交参与请求,并各自自主执行本地任务的方式,无需同步等待所有的事务参与者确认是否可以参加事务的回执,很好的解决了分布式事务中的阻塞问题。在各自本地任务完成后,发起任务提交请求,并根据提交指令提交所述本地事务,能实现数据库资源的迅速释放。In the distributed transaction processing method provided by the embodiment of the present invention, each executing device submits a participation request to the coordinating device in parallel, and each executes local tasks independently, without synchronously waiting for all transaction participants to confirm whether they can participate in the transaction. It solves the blocking problem in distributed transactions very well. After the respective local tasks are completed, a task submission request is initiated, and the local transaction is submitted according to the submission instruction, which can realize the rapid release of database resources.

图6为本发明实施例提供的协调设备与执行设备之间实现分布式事务处理方法的交互示意图,在图6中,所述事务协调者TM是指协调设备TM,它是分布式系统中用于统一调度所有执行设备的设备,所述事务参与者是指执行设备RM,在一个分布式事务中,只有一个协调设备TM,但有多个事务参与者,即多个执行设备RM。所述分布式事务处理方法包括:FIG. 6 is a schematic diagram of interaction between a coordination device and an execution device for implementing a distributed transaction processing method according to an embodiment of the present invention. In FIG. 6, the transaction coordinator TM refers to the coordination device TM, which is used in the distributed system. In order to uniformly schedule devices of all execution devices, the transaction participants refer to execution devices RM. In a distributed transaction, there is only one coordination device TM, but there are multiple transaction participants, ie, multiple execution devices RM. The distributed transaction processing method includes:

S301,第一执行设备向协调设备发送事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;所述协调设备用于管理至少一个执行设备,所述至少一个执行设备中包含第一执行设备;S301, a first execution device sends a transaction participation request to a coordination device; wherein the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions; the coordination device is used to manage at least one execution device, the at least one execution device includes a first execution device;

S302,所述协调设备接收所述至少一个执行设备中的第一执行设备的事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;S302, the coordination device receives a transaction participation request from a first execution device in the at least one execution device; wherein the transaction participation request is used to indicate to the coordination device that the first execution device is capable of executing local transactions status;

S303,所述第一执行设备执行本地事务,在完成所述本地事务的处理时向所述协调设备发送事务提交请求;其中,所述本地事务为所述协调设备在接收到事务参与请求之前为所述第一执行设备分配的事务;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;S303, the first execution device executes a local transaction, and sends a transaction submission request to the coordinating device when processing the local transaction is completed; wherein, the local transaction is that the coordinating device is before receiving the transaction participation request The transaction allocated by the first execution device; wherein, the transaction submission request is used to represent that the first execution device has completed the local transaction;

S304,所述协调设备接收所述第一执行设备发来的事务提交请求;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;S304, the coordination device receives a transaction commit request sent by the first execution device; wherein, the transaction commit request is used to indicate that the first execution device has completed the local transaction;

S305,基于所述第一执行设备的事务提交请求,所述协调设备向所述第一执行设备发送事务提交指令。S305. Based on the transaction commit request of the first execution device, the coordination device sends a transaction commit instruction to the first execution device.

S306,当所述第一执行设备接收到所述协调设备发来的事务提交指令时,提交所述本地事务。S306, when the first execution device receives the transaction submission instruction sent by the coordination device, submit the local transaction.

这里,在步骤S303中,所述第一执行设备执行本地事务时,会存储本地日志信息。Here, in step S303, when the first execution device executes the local transaction, the local log information will be stored.

在步骤S305之前,所述协调设备在确定收到所述第一执行设备发送的事务提交请求后,将所述第一执行设备所执行的与本地事务相关的日志和锁信息储存在数据库表中。所述本地日志信息包括本地事务的undo日志和redo日志;所述undo日志用于存放数据修改前的值;所述redo日志,用于记录修改后的数据,顺序记录。这里,存储本地事务相关的日志和锁信息是为了在突发状况时,数据库会根据当前数据的情况进行undo回滚或者是redo前滚,可以保证数据的强一致性。Before step S305, after determining that the coordinating device has received the transaction commit request sent by the first executing device, it stores the log and lock information related to the local transaction executed by the first executing device in a database table . The local log information includes the undo log and the redo log of the local transaction; the undo log is used to store the value before data modification; the redo log is used to record the modified data, which is recorded sequentially. Here, the log and lock information related to local transactions are stored so that in the event of an emergency, the database will perform undo rollback or redo rollforward according to the current data situation, which can ensure strong data consistency.

在步骤S306之后,所述方法还包括:所述协调设备判断是否存在本地事务执行失败的执行设备,若存在,向全局事务相关的全部执行设备发送回滚指令;After step S306, the method further includes: the coordinating device determines whether there is an execution device that fails to execute the local transaction, and if so, sends a rollback instruction to all execution devices related to the global transaction;

这里,还包括另一种实现方法,即所述协调设备判断是否存在本地事务执行失败的第二执行设备,若存在,则向所述第二执行设备发送回滚指令。Here, another implementation method is also included, that is, the coordination device determines whether there is a second execution device that fails to execute the local transaction, and if there is, sends a rollback instruction to the second execution device.

在所述第一执行设备提交所述本地事务后,所述第一执行设备会向协调设备发送确认消息,所述确认消息用于通知所述本地事务已提交;所述协调设备检测是否接收到所述至少一个执行设备中的全部执行设备发来的事务提交确认消息;若是,则确认全局事务完成;基于所述全局事务的标识符,所述协调设备对所述至少一个执行设备所对应的数据库进行清理;所述第一执行设备会释放参与所述本地事务的数据库的连接资源。其中,所述全局事务由协调设备管理的执行设备所执行的本地事务组成;After the first execution device submits the local transaction, the first execution device will send a confirmation message to the coordination device, where the confirmation message is used to notify that the local transaction has been submitted; the coordination device detects whether it receives A transaction commit confirmation message sent by all execution devices in the at least one execution device; if yes, confirm that the global transaction is completed; The database is cleaned up; the first execution device releases the connection resources of the database participating in the local transaction. Wherein, the global transaction is composed of local transactions executed by the execution device managed by the coordination device;

为了更清晰的表达本实施例的内容,这里结合具体应用情况进行说明,以如下业务需求为例:In order to express the content of this embodiment more clearly, the description is given here in conjunction with the specific application situation, taking the following business requirements as an example:

转账业务,账户A向账户B转账1000元,在转账的过程中,账户A、B都向账户C提交10元的手续费。那么此次分布式事务可以划分为6个分支事务,即:“A-1000”、“B+1000”、“A-10”、“B-10”、“C+10”、“C+10”;在进行本实施例分布式事务处理之前,业务系统会将划分的所述6个分支事务发送给协调设备TM,协调设备TM根据所述6个分支事务处理的对象和资源,确定对资源的处理方式和依赖关系,通过XA接口注册此次分布式事务需要的6个执行设备RM,通知所述RM开启各数据库的操作。In the transfer business, account A transfers 1,000 yuan to account B. During the transfer process, both accounts A and B submit a handling fee of 10 yuan to account C. Then this distributed transaction can be divided into 6 branch transactions, namely: "A-1000", "B+1000", "A-10", "B-10", "C+10", "C+10" "; before carrying out the distributed transaction processing in this embodiment, the business system will send the divided six branch transactions to the coordination device TM, and the coordination device TM determines the resource allocation according to the objects and resources of the six branch transactions. The six execution devices RM required for this distributed transaction are registered through the XA interface, and the RM is notified to open the operation of each database.

当这6个执行设备RM中有的处于能够执行本地事务的状态时,例如,执行“A-10”操作的执行设备RM处于能够执行事务的状态,此时,本实施例分布式事务处理的第一步是:执行“A-10”操作的执行设备RM自行向协调设备TM发送事务参与请求,并自行执行本地任务;所述协调设备TM会接收到“A-10”操作的执行设备RM的事务参与请求,在执行设备RM完成“A-10”操作后,所述协调设备TM会接收到“A-10”操作的执行设备发来的事务提交请求,进而基于所述提交请求,协调设备TM向“A-10”操作的执行设备RM发送事务提交指令,执行设备RM根据接收到协调设备TM发来的事务提交指令时,提交所述本地事务“A-10”操作。When some of the six execution devices RM are in a state capable of executing local transactions, for example, the execution device RM that executes the "A-10" operation is in a state capable of executing transactions, at this time, the distributed transaction processing in this embodiment The first step is: the execution device RM that executes the "A-10" operation sends a transaction participation request to the coordination device TM by itself, and executes local tasks by itself; the coordination device TM will receive the execution device RM of the "A-10" operation. After the execution device RM completes the "A-10" operation, the coordinating device TM will receive the transaction submission request sent by the execution device of the "A-10" operation, and based on the submission request, coordinate the The equipment TM sends a transaction commit instruction to the execution equipment RM of the "A-10" operation, and the execution equipment RM commits the local transaction "A-10" operation according to the receipt of the transaction commit instruction sent by the coordination equipment TM.

本发明实施例提供的分布式事务处理方法,通过各执行设备各自并行向协调设备提交参与请求,并各自自主执行本地任务的方式,无需同步等待所有的事务参与者确认是否可以参加事务的回执,很好的解决了分布式事务中的阻塞问题。在各执行设备执行完本地事务后,最后由协调设备TM统一管控,执行提交或者回滚;由于协调设备可以修改回滚权限,对执行错误的执行设备采取主动回滚的方式,保证了事务的原子性。并且,由于本发明实施例提供的分布式事务处理方法基于XA模型,能放便的支持数据库、消息队列等多种资源管理器RM。在数据一致性上,由于本发明实施例提供的分布式事务处理方法在全局事务提交中分两步,采用本地事务提交和全局事务标识符清理的方式,可以达到分布式事务的最大性能。In the distributed transaction processing method provided by the embodiment of the present invention, each executing device submits a participation request to the coordinating device in parallel, and each executes local tasks independently, without synchronously waiting for all transaction participants to confirm whether they can participate in the transaction. It solves the blocking problem in distributed transactions very well. After each execution device completes the execution of the local transaction, the coordinating device TM performs unified management and control to execute commit or rollback; since the coordinating device can modify the rollback authority, it takes the initiative to roll back the wrong execution device to ensure the transaction atomicity. Moreover, since the distributed transaction processing method provided by the embodiment of the present invention is based on the XA model, it can easily support various resource managers such as databases and message queues. In terms of data consistency, since the distributed transaction processing method provided by the embodiment of the present invention divides the global transaction submission into two steps, and adopts the method of local transaction submission and global transaction identifier cleaning, the maximum performance of the distributed transaction can be achieved.

基于前述实施例相同的技术构思,本发明实施例提供一种分布式事务处理装置400,如图7所示,所述装置包括:第一接收模块401、第二接收模块402和第一发送模块403,其中,Based on the same technical concept as the foregoing embodiments, an embodiment of the present invention provides a distributed transaction processing apparatus 400. As shown in FIG. 7, the apparatus includes: a first receiving module 401, a second receiving module 402, and a first sending module 403, of which,

所述第一接收模块401,用于接收所述至少一个执行设备中的第一执行设备的事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;The first receiving module 401 is configured to receive a transaction participation request from a first execution device in the at least one execution device; wherein the transaction participation request is used to indicate to the coordination device that the first execution device is in a The state of being able to perform local transactions;

所述第二接收模块402,用于接收所述第一执行设备发来的事务提交请求;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;The second receiving module 402 is configured to receive a transaction submission request sent by the first execution device; wherein, the transaction submission request is used to indicate that the first execution device has completed the local transaction;

所述第一发送模块403,用于基于所述第一执行设备的事务提交请求,向所述第一执行设备发送事务提交指令。The first sending module 403 is configured to send a transaction commit instruction to the first execution device based on the transaction commit request of the first execution device.

其中,所述第一发送模块403,还用于在确定收到所述第一执行设备发送的事务提交请求后,将所述第一执行设备所执行的与本地事务相关的日志和锁信息储存在数据库表中。The first sending module 403 is further configured to store the log and lock information related to the local transaction executed by the first execution device after receiving the transaction submission request sent by the first execution device. in the database table.

进一步地,所述装置400还包括:检测模块,所述检测模块,用于检测是否接收到所述至少一个执行设备中的全部执行设备发来的事务提交确认消息;若是,则确认全局事务完成;基于所述全局事务的标识符,对所述至少一个执行设备所对应的数据库进行清理;其中,所述全局事务由协调设备管理的执行设备所执行的本地事务组成。Further, the apparatus 400 further includes: a detection module, the detection module is configured to detect whether a transaction commit confirmation message sent by all execution devices in the at least one execution device is received; if so, confirm that the global transaction is completed ; clean up the database corresponding to the at least one execution device based on the identifier of the global transaction; wherein, the global transaction is composed of local transactions executed by the execution device managed by the coordination device.

所述装置400还包括:第一判断模块:所述第一判断模块,用于判断是否存在本地事务执行失败的执行设备,若存在,向全局事务相关的全部执行设备发送回滚指令;The apparatus 400 further includes: a first judging module: the first judging module is used to judge whether there is an execution device that fails to execute the local transaction, and if so, send a rollback instruction to all execution devices related to the global transaction;

所述装置400还包括:第二判断模块:所述第二判断模块,用于判断是否存在本地事务执行失败的第二执行设备,若存在,则向所述第二执行设备发送回滚指令。The apparatus 400 further includes: a second judging module: the second judging module is configured to judge whether there is a second execution device that fails to execute the local transaction, and if so, send a rollback instruction to the second execution device.

需要说明的是,由于所述分布式事务处理装置400解决问题的原理与前述应用于协调设备的分布式事务处理方法相似,因此,所述分布式事务处理设备400的具体实施过程及实施原理均可以参见前述方法和实施过程,以及实施原理的描述,重复之处不再赘述。It should be noted that, since the principle of solving the problem of the distributed transaction processing apparatus 400 is similar to the aforementioned distributed transaction processing method applied to the coordination device, the specific implementation process and implementation principle of the distributed transaction processing apparatus 400 are both Reference may be made to the foregoing method and implementation process, as well as the description of the implementation principle, and repeated descriptions will not be repeated.

本发明实施例提供的分布式事务处理装置,通过接收执行设备的事务参与请求、事务提交请求,判断所述执行设备本地任务的成功执行,进而向执行设备发送事务提交指令。由于在任务分配后,无需等待协调设备的命令,极大的提高了执行的效率,同时由于协调设备可以修改回滚权限,对执行错误的执行设备采取主动回滚的方式,保证了事务的原子性。The distributed transaction processing apparatus provided by the embodiment of the present invention judges the successful execution of the local task of the execution device by receiving the transaction participation request and the transaction submission request of the execution device, and then sends a transaction submission instruction to the execution device. After the task is assigned, there is no need to wait for the command of the coordinating device, which greatly improves the efficiency of execution. At the same time, because the coordinating device can modify the rollback authority, the wrong execution device can be actively rolled back to ensure the atomicity of the transaction. sex.

基于前述实施例相同的技术构思,本发明实施例提供另一种分布式事务处理装置500,如图8所示,所述装置包括:请求模块501、执行模块502和提交模块503,其中,Based on the same technical concept as the foregoing embodiments, an embodiment of the present invention provides another distributed transaction processing apparatus 500. As shown in FIG. 8, the apparatus includes: a request module 501, an execution module 502, and a submission module 503, wherein,

所述请求模块501,用于向协调设备发送事务参与请求;其中,所述事务参与请求用于向所述协调设备指示所述第一执行设备处于能够执行本地事务的状态;所述协调设备用于管理至少一个执行设备,所述至少一个执行设备中包含第一执行设备;The request module 501 is configured to send a transaction participation request to the coordination device; wherein, the transaction participation request is used to indicate to the coordination device that the first execution device is in a state capable of executing local transactions; For managing at least one execution device, the at least one execution device includes a first execution device;

所述执行模块502,用于执行本地事务,在完成所述本地事务的处理时向所述协调设备发送事务提交请求;其中,所述本地事务为所述协调设备在接收到事务参与请求之前为所述第一执行设备分配的事务;其中,所述事务提交请求用于表征所述第一执行设备已完成所述本地事务;The execution module 502 is configured to execute a local transaction, and send a transaction submission request to the coordinating device when processing the local transaction is completed; wherein, the local transaction is that the coordinating device is before receiving the transaction participation request. The transaction allocated by the first execution device; wherein, the transaction submission request is used to represent that the first execution device has completed the local transaction;

所述提交模块503,用于当接收到所述协调设备发来的事务提交指令时,提交所述本地事务。The committing module 503 is configured to commit the local transaction when receiving the transaction commit instruction sent by the coordinating device.

其中,所述执行模块502,还用于存储本地日志信息。The execution module 502 is further configured to store local log information.

所述装置500还包括:第二发送模块,所述第二发送模块,用于向协调设备发送确认消息,所述确认消息用于通知所述本地事务已提交。The apparatus 500 further includes: a second sending module, configured to send a confirmation message to the coordination device, where the confirmation message is used to notify that the local transaction has been committed.

所述装置500还包括:释放模块,所述释放模块,用于释放参与所述本地事务的数据库的连接资源。The apparatus 500 further includes: a release module configured to release connection resources of the database participating in the local transaction.

所述装置500还包括:第三接收模块,所述第三接收模块,用于接收协调设备发来的数据回滚指令,执行数据回滚。The apparatus 500 further includes: a third receiving module, where the third receiving module is configured to receive a data rollback instruction sent by the coordination device, and perform data rollback.

需要说明的是,由于所述分布式事务处理装置500解决问题的原理与前述应用于第一执行设备的分布式事务处理方法相似,因此,所述分布式事务处理设备500的具体实施过程及实施原理均可以参见前述方法和实施过程,以及实施原理的描述,重复之处不再赘述。It should be noted that since the principle of solving the problem of the distributed transaction processing apparatus 500 is similar to the aforementioned distributed transaction processing method applied to the first execution device, the specific implementation process and implementation of the distributed transaction processing apparatus 500 For the principles, reference may be made to the foregoing method and implementation process, as well as the description of the implementation principle, and repeated descriptions will not be repeated.

本发明实施例提供的分布式事务处理装置,通过各执行设备各自并行向协调设备提交参与请求,并各自自主执行本地任务的方式,无需同步等待所有的事务参与者确认是否可以参加事务的回执,很好的解决了分布式事务中的阻塞问题。在各自本地任务完成后,发起任务提交请求,并根据提交指令提交所述本地事务,能实现数据库资源的迅速释放。In the distributed transaction processing apparatus provided by the embodiment of the present invention, each executing device submits a participation request to the coordinating device in parallel, and each executes local tasks independently, without synchronously waiting for all transaction participants to confirm whether they can participate in the transaction. It solves the blocking problem in distributed transactions very well. After the respective local tasks are completed, a task submission request is initiated, and the local transaction is submitted according to the submission instruction, which can realize the rapid release of database resources.

本发明实施例还提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序处理器被处理器执行时实现上述方法实施例的步骤,而前述的存储介质包括:移动存储设备、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random AccessMemory)、磁碟或者光盘等各种可以存储程序代码的介质。Embodiments of the present invention further provide a computer-readable storage medium on which a computer program is stored, and when the computer program processor is executed by the processor, the steps of the foregoing method embodiments are implemented, and the foregoing storage medium includes: a removable storage device , Read-Only Memory (ROM, Read-Only Memory), Random Access Memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes.

本发明实施例还提供一种分布式事务处理装置,包括:处理器和用于存储能够在处理器上运行的计算机程序的存储器,其中,所述处理器用于运行所述计算机程序时,执行存储在存储器中的上述方法实施例的步骤。An embodiment of the present invention further provides a distributed transaction processing apparatus, comprising: a processor and a memory for storing a computer program that can be executed on the processor, wherein the processor is configured to execute the memory when running the computer program The steps of the above-described method embodiments are in memory.

图9是本发明实施例分布式事务处理装置的一种硬件结构示意图,该分布式事务处理装置600包括:至少一个处理器601、存储器602,分布式事务处理装置600中的各个组件通过总线系统603耦合在一起,可理解,总线系统603用于实现这些组件之间的连接通信。总线系统603除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明起见,在图9中将各种总线都标为总线系统603。FIG. 9 is a schematic diagram of a hardware structure of a distributed transaction processing apparatus according to an embodiment of the present invention. The distributed transaction processing apparatus 600 includes: at least one processor 601 and a memory 602. Each component in the distributed transaction processing apparatus 600 passes through a bus system 603 is coupled together, and it can be understood that the bus system 603 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 603 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the various buses are labeled as bus system 603 in FIG. 9 .

可以理解,存储器602可以是易失性存储器或非易失性存储器,也可包括易失性和非易失性存储器两者。其中,非易失性存储器可以是只读存储器(ROM,Read Only Memory)、可编程只读存储器(PROM,Programmable Read-Only Memory)、可擦除可编程只读存储器(EPROM,Erasable Programmable Read-Only Memory)、电可擦除可编程只读存储器(EEPROM,Electrically Erasable Programmable Read-Only Memory)、磁性随机存取存储器(FRAM,ferromagnetic random access memory)、快闪存储器(Flash Memory)、磁表面存储器、光盘、或只读光盘(CD-ROM,Compact Disc Read-Only Memory);磁表面存储器可以是磁盘存储器或磁带存储器。易失性存储器可以是随机存取存储器(RAM,Random AccessMemory),其用作外部高速缓存。通过示例性但不是限制性说明,许多形式的RAM可用,例如静态随机存取存储器(SRAM,Static Random Access Memory)、同步静态随机存取存储器(SSRAM,Synchronous Static Random Access Memory)、动态随机存取存储器(DRAM,Dynamic Random Access Memory)、同步动态随机存取存储器(SDRAM,SynchronousDynamic Random Access Memory)、双倍数据速率同步动态随机存取存储器(DDRSDRAM,Double Data Rate Synchronous Dynamic Random Access Memory)、增强型同步动态随机存取存储器(ESDRAM,Enhanced Synchronous Dynamic Random Access Memory)、同步连接动态随机存取存储器(SLDRAM,SyncLink Dynamic Random Access Memory)、直接内存总线随机存取存储器(DRRAM,Direct Rambus Random Access Memory)。本发明实施例描述的存储器602旨在包括但不限于这些和任意其它适合类型的存储器。It will be appreciated that the memory 602 may be either volatile memory or non-volatile memory, and may include both volatile and non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read-Only Memory), an erasable programmable read-only memory (EPROM, Erasable Programmable Read-only memory) Only Memory), Electrically Erasable Programmable Read-Only Memory (EEPROM, Electrically Erasable Programmable Read-Only Memory), Magnetic Random Access Memory (FRAM, ferromagnetic random access memory), Flash Memory (Flash Memory), Magnetic Surface Memory , CD-ROM, or Compact Disc Read-Only Memory (CD-ROM, Compact Disc Read-Only Memory); the magnetic surface memory can be a magnetic disk memory or a tape memory. The volatile memory may be Random Access Memory (RAM), which is used as an external cache memory. By way of example and not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Synchronous Static Random Access Memory (SSRAM), Dynamic Random Access Memory Memory (DRAM, Dynamic Random Access Memory), Synchronous Dynamic Random Access Memory (SDRAM, SynchronousDynamic Random Access Memory), Double Data Rate Synchronous Dynamic Random Access Memory (DDRSDRAM, Double Data Rate Synchronous Dynamic Random Access Memory), Enhanced Synchronous Dynamic Random Access Memory (ESDRAM, Enhanced Synchronous Dynamic Random Access Memory), Synchronous Link Dynamic Random Access Memory (SLDRAM, SyncLink Dynamic Random Access Memory), Direct Memory Bus Random Access Memory (DRRAM, Direct Rambus Random Access Memory) . The memory 602 described in the embodiments of the present invention is intended to include, but not be limited to, these and any other suitable types of memory.

本发明实施例中的存储器602用于存储各种类型的数据以支持分布式事务处理装置600的操作。这些数据的示例包括:用于在分布式事务处理装置600上操作的任何计算机程序,如存储的本地日志信息、数据回滚指令等,实现本发明实施例方法的程序可以包含在存储器602中。The memory 602 in the embodiment of the present invention is used for storing various types of data to support the operation of the distributed transaction processing apparatus 600 . Examples of these data include: any computer program used to operate on the distributed transaction processing apparatus 600 , such as stored local log information, data rollback instructions, etc. The programs implementing the methods of the embodiments of the present invention may be contained in the memory 602 .

上述本发明实施例揭示的方法可以应用于处理器601中,或者由处理器601实现。处理器可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器可以是通用处理器、数字信号处理器(DSP,Digital Signal Processor),或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。处理器可以实现或者执行本发明实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者任何常规的处理器等。结合本发明实施例所公开的方法的步骤,可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于存储介质中,该存储介质位于存储器,处理器读取存储器中的信息,结合其硬件完成前述方法的步骤。The methods disclosed in the above embodiments of the present invention may be applied to the processor 601 or implemented by the processor 601 . A processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above-mentioned method can be completed by a hardware integrated logic circuit in a processor or an instruction in the form of software. The above-mentioned processor may be a general-purpose processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. The processor may implement or execute the methods, steps, and logical block diagrams disclosed in the embodiments of the present invention. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the method disclosed in combination with the embodiments of the present invention can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module may be located in a storage medium, the storage medium is located in a memory, and the processor reads the information in the memory, and completes the steps of the foregoing method in combination with its hardware.

在示例性实施例中,分布式事务处理装置600可以被一个或多个应用专用集成电路(ASIC,Application Specific Integrated Circuit)、DSP、可编程逻辑器件(PLD,Programmable Logic Device)、复杂可编程逻辑器件(CPLD,Complex Programmable LogicDevice)、现场可编程门阵列(FPGA,Field-Programmable Gate Array)、通用处理器、控制器、微控制器(MCU,Micro Controller Unit)、微处理器(Microprocessor)、或其他电子元件实现,用于执行上述方法。In an exemplary embodiment, the distributed transaction processing apparatus 600 may be implemented by one or more Application Specific Integrated Circuit (ASIC, Application Specific Integrated Circuit), DSP, Programmable Logic Device (PLD, Programmable Logic Device), complex programmable logic Device (CPLD, Complex Programmable LogicDevice), Field Programmable Gate Array (FPGA, Field-Programmable Gate Array), General Purpose Processor, Controller, Microcontroller (MCU, Micro Controller Unit), Microprocessor (Microprocessor), or Other electronic components are implemented for performing the above method.

在本申请所提供的几个实施例中,应该理解到,所揭露的设备和方法,可以通过其它的方式实现。以上所描述的设备实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,如:多个单元或组件可以结合,或可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的各组成部分相互之间的耦合、或直接耦合、或通信连接可以是通过一些接口,设备或单元的间接耦合或通信连接,可以是电性的、机械的或其它形式的。In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined, or Can be integrated into another system, or some features can be ignored, or not implemented. In addition, the coupling, or direct coupling, or communication connection between the components shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical or other forms. of.

上述作为分离部件说明的单元可以是、或也可以不是物理上分开的,作为单元显示的部件可以是、或也可以不是物理单元,即可以位于一个地方,也可以分布到多个网络单元上;可以根据实际的需要选择其中的部分或全部单元来实现本实施例方案的目的。The unit described above as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or distributed to multiple network units; Some or all of the units may be selected according to actual needs to achieve the purpose of the solution in this embodiment.

另外,在本发明各实施例中的各功能单元可以全部集成在一个处理单元中,也可以是各单元分别单独作为一个单元,也可以两个或两个以上单元集成在一个单元中;上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present invention may all be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integration The unit can be implemented either in the form of hardware or in the form of hardware plus software functional units.

本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储于一计算机可读取存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:移动存储设备、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by program instructions related to hardware, the aforementioned program can be stored in a computer-readable storage medium, and when the program is executed, execute Including the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: a mobile storage device, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk and other various A medium on which program code can be stored.

或者,本发明上述集成的单元如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明实施例的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机、服务器、或者网络设备等)执行本发明各个实施例所述方法的全部或部分。而前述的存储介质包括:移动存储设备、ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present invention may be embodied in the form of software products in essence or the parts that make contributions to the prior art. The computer software products are stored in a storage medium and include several instructions for A computer device (which may be a personal computer, a server, or a network device, etc.) is caused to execute all or part of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: a removable storage device, a ROM, a RAM, a magnetic disk or an optical disk and other mediums that can store program codes.

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention. should be included within the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims (10)

1. a kind of distributed transaction processing method is applied to coordinate equipment, the coordination equipment is for managing at least one execution Equipment, which is characterized in that the described method includes:
It receives at least one described first affairs for executing equipment executed in equipment and participates in request;Wherein, the affairs participate in It requests for indicating the first execution equipment in the state for being able to carry out local matter to the coordination equipment;
It receives the affairs that the first execution equipment is sent and submits request;Wherein, the affairs submit request described for characterizing The local matter is completed in first execution equipment;
The affairs for executing equipment based on described first submit request, and Xiang Suoshu first executes equipment transmission affairs and submits instruction.
2. the method according to claim 1, wherein described refer to the first execution equipment transmission affairs submission Before order, the method also includes:
After determining that receiving the affairs that described first executes equipment transmission submits request, described first is executed performed by equipment Log relevant to local matter and lock information are stored in database table.
3. the method according to claim 1, wherein the method also includes:
Detect whether that receiving the affairs that at least one described whole execution equipment executed in equipment are sent submits confirmation messages;
If so, confirmation global transaction is completed;Based on the identifier of the global transaction, at least one described execution equipment institute Corresponding database is cleared up;Wherein, the global transaction local thing as performed by the execution equipment of coordination equipment management Business composition.
4. a kind of distributed transaction processing method is applied to first and executes equipment, which is characterized in that the described method includes:
Affairs participation request is sent to equipment is coordinated;Wherein, the affairs participate in request for indicating institute to the coordination equipment It states the first execution equipment and is in the state for being able to carry out local matter;The coordination equipment is set for managing at least one execution It is standby, equipment is executed comprising first at least one described execution equipment;
Local matter is executed, affairs is sent to the coordination equipment when completing the processing of the local matter and submits request;Its In, the local matter is that the coordination equipment is that the first execution equipment is distributed before receiving affairs and participating in request Affairs;Wherein, the affairs submit request that the local matter is completed for characterizing the first execution equipment;
When receiving the affairs submission instruction that the coordination equipment is sent, the local matter is submitted.
5. according to the method described in claim 4, it is characterized in that, the method is also after the submission local matter Include:
Confirmation message is sent to equipment is coordinated, the confirmation message is for notifying the local matter to have been filed on.
6. according to the method described in claim 4, it is characterized in that, the method is also after the submission local matter Include:
Release participates in the connection resource of the database of the local matter.
7. a kind of distributing real time system device, described device includes: the first receiving module, the second receiving module and the first transmission Module, wherein
First receiving module is asked for receiving at least one described affairs participation for executing the first execution equipment in equipment It asks;Wherein, the affairs participate in request and are able to carry out this for being in coordination equipment instruction the first execution equipment The state of ground affairs;
Second receiving module submits request for receiving the affairs that the first execution equipment is sent;Wherein, the affairs Submit request that the local matter is completed for characterizing the first execution equipment;
First sending module, the affairs for executing equipment based on described first submit request, and the execution of Xiang Suoshu first is set Preparation send affairs to submit instruction.
8. a kind of distributing real time system device, described device includes: request module, execution module and submission module, wherein
The request module participates in request for sending affairs to coordination equipment;Wherein, the affairs participate in request for institute It states coordination equipment and indicates that the first execution equipment is in the state for being able to carry out local matter;The coordination equipment is for managing At least one executes equipment, includes the first execution equipment at least one described execution equipment;
The execution module is sent out when completing the processing of the local matter to the coordination equipment for executing local matter Affairs are sent to submit request;Wherein, it is described before receiving affairs and participating in request that the local matter, which is the coordination equipment, First executes the affairs of equipment distribution;Wherein, the affairs submit request that institute is completed for characterizing the first execution equipment State local matter;
The submission module, for submitting the local thing when receiving the affairs submission instruction that the coordination equipment is sent Business.
9. a kind of computer readable storage medium, is stored thereon with computer program, which is characterized in that the computer program quilt The step of any one of claim 1 to 6 the method is realized when processor executes.
10. a kind of distributing real time system device characterized by comprising processor and for store can be on a processor The memory of the computer program of operation, wherein the processor is for when running the computer program, perform claim to be required The step of any one of 1 to 6 the method.
CN201811652896.6A 2018-12-28 2018-12-28 Distributed transaction processing method, device and storage medium Pending CN109783204A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811652896.6A CN109783204A (en) 2018-12-28 2018-12-28 Distributed transaction processing method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811652896.6A CN109783204A (en) 2018-12-28 2018-12-28 Distributed transaction processing method, device and storage medium

Publications (1)

Publication Number Publication Date
CN109783204A true CN109783204A (en) 2019-05-21

Family

ID=66499745

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811652896.6A Pending CN109783204A (en) 2018-12-28 2018-12-28 Distributed transaction processing method, device and storage medium

Country Status (1)

Country Link
CN (1) CN109783204A (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111522631A (en) * 2020-03-23 2020-08-11 支付宝(杭州)信息技术有限公司 Distributed transaction processing method, device, server and medium
CN111611058A (en) * 2020-05-21 2020-09-01 北京明略软件系统有限公司 Task execution method and device and electronic equipment
CN111639089A (en) * 2020-05-29 2020-09-08 北京奇艺世纪科技有限公司 Transaction processing method and device, electronic equipment and computer readable storage medium
CN112148394A (en) * 2020-09-08 2020-12-29 上加下信息技术成都有限公司 Distributed transaction coordination method and device and electronic equipment
CN112181377A (en) * 2020-10-12 2021-01-05 汇智点亮科技(北京)有限公司 Transaction manager collaboration framework for service invocation, design method and cloud platform
CN112445860A (en) * 2019-09-02 2021-03-05 北京京东振世信息技术有限公司 Method and device for processing distributed transaction
CN112650561A (en) * 2019-10-11 2021-04-13 中兴通讯股份有限公司 Transaction management method, system, network device and readable storage medium
CN112866316A (en) * 2019-11-27 2021-05-28 北京沃东天骏信息技术有限公司 Distributed transaction processing method and device
CN112995262A (en) * 2019-12-18 2021-06-18 中国移动通信集团浙江有限公司 Distributed transaction submission method, system and computing equipment

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1798031A (en) * 2004-12-27 2006-07-05 北京航空航天大学 Transaction processing system and transaction method for Web service
US20070143299A1 (en) * 2005-12-19 2007-06-21 Huras Matthew A Commitment of transactions in a distributed system
CN103399894A (en) * 2013-07-23 2013-11-20 中国科学院信息工程研究所 Distributed transaction processing method on basis of shared storage pool
CN103677968A (en) * 2012-09-07 2014-03-26 腾讯科技(深圳)有限公司 Transaction processing method, transaction coordinator device and transaction participant device and system
CN104580428A (en) * 2014-12-27 2015-04-29 北京奇虎科技有限公司 Data routing method, data management device and distributed storage system
US20150309834A1 (en) * 2014-04-28 2015-10-29 Oracle International Corporation System and method for supporting common transaction identifier (xid) optimization based on resource manager (rm) instance awareness in a transactional environment
WO2016024986A1 (en) * 2014-08-15 2016-02-18 Hewlett-Packard Development Company, L.P. Three phase commit for a distributed file system
CN106547610A (en) * 2016-10-11 2017-03-29 北京国电通网络技术有限公司 The method and system that a kind of distributed transaction is submitted to
CN107045453A (en) * 2016-02-05 2017-08-15 慧与发展有限责任合伙企业 Two-phase commitment protocol for distributed transaction is mixed

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1798031A (en) * 2004-12-27 2006-07-05 北京航空航天大学 Transaction processing system and transaction method for Web service
US20070143299A1 (en) * 2005-12-19 2007-06-21 Huras Matthew A Commitment of transactions in a distributed system
CN103677968A (en) * 2012-09-07 2014-03-26 腾讯科技(深圳)有限公司 Transaction processing method, transaction coordinator device and transaction participant device and system
CN103399894A (en) * 2013-07-23 2013-11-20 中国科学院信息工程研究所 Distributed transaction processing method on basis of shared storage pool
US20150309834A1 (en) * 2014-04-28 2015-10-29 Oracle International Corporation System and method for supporting common transaction identifier (xid) optimization based on resource manager (rm) instance awareness in a transactional environment
WO2016024986A1 (en) * 2014-08-15 2016-02-18 Hewlett-Packard Development Company, L.P. Three phase commit for a distributed file system
CN104580428A (en) * 2014-12-27 2015-04-29 北京奇虎科技有限公司 Data routing method, data management device and distributed storage system
CN107045453A (en) * 2016-02-05 2017-08-15 慧与发展有限责任合伙企业 Two-phase commitment protocol for distributed transaction is mixed
CN106547610A (en) * 2016-10-11 2017-03-29 北京国电通网络技术有限公司 The method and system that a kind of distributed transaction is submitted to

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112445860A (en) * 2019-09-02 2021-03-05 北京京东振世信息技术有限公司 Method and device for processing distributed transaction
CN112445860B (en) * 2019-09-02 2023-11-03 北京京东振世信息技术有限公司 Method and device for processing distributed transaction
CN112650561A (en) * 2019-10-11 2021-04-13 中兴通讯股份有限公司 Transaction management method, system, network device and readable storage medium
CN112866316A (en) * 2019-11-27 2021-05-28 北京沃东天骏信息技术有限公司 Distributed transaction processing method and device
CN112995262B (en) * 2019-12-18 2022-06-10 中国移动通信集团浙江有限公司 Distributed transaction commit method, system and computing device
CN112995262A (en) * 2019-12-18 2021-06-18 中国移动通信集团浙江有限公司 Distributed transaction submission method, system and computing equipment
CN111522631A (en) * 2020-03-23 2020-08-11 支付宝(杭州)信息技术有限公司 Distributed transaction processing method, device, server and medium
CN111522631B (en) * 2020-03-23 2024-02-06 支付宝(杭州)信息技术有限公司 Distributed transaction processing method, device, server and medium
CN111611058A (en) * 2020-05-21 2020-09-01 北京明略软件系统有限公司 Task execution method and device and electronic equipment
CN111639089A (en) * 2020-05-29 2020-09-08 北京奇艺世纪科技有限公司 Transaction processing method and device, electronic equipment and computer readable storage medium
CN111639089B (en) * 2020-05-29 2024-03-08 北京奇艺世纪科技有限公司 Transaction processing method, transaction processing device, electronic equipment and computer readable storage medium
CN112148394A (en) * 2020-09-08 2020-12-29 上加下信息技术成都有限公司 Distributed transaction coordination method and device and electronic equipment
CN112181377A (en) * 2020-10-12 2021-01-05 汇智点亮科技(北京)有限公司 Transaction manager collaboration framework for service invocation, design method and cloud platform
CN112181377B (en) * 2020-10-12 2023-10-17 汇智点亮科技(北京)有限公司 Business manager collaborative framework for service call, design method and cloud platform

Similar Documents

Publication Publication Date Title
CN109783204A (en) Distributed transaction processing method, device and storage medium
WO2018103318A1 (en) Distributed transaction handling method and system
CN107771321B (en) Recovery in the data center
US10296606B2 (en) Stateless datastore—independent transactions
JP6677759B2 (en) Scalable log-based transaction management
CN111314479B (en) Data processing method and equipment
US20180047002A1 (en) Cross-data-store operations in log-coordinated storage systems
US9323569B2 (en) Scalable log-based transaction management
US10303795B2 (en) Read descriptors at heterogeneous storage systems
US7900085B2 (en) Backup coordinator for distributed transactions
US10373247B2 (en) Lifecycle transitions in log-coordinated data stores
US7293192B2 (en) System and method for failover
JP3790589B2 (en) Commitment method for distributed database transactions
WO2016180164A1 (en) Method and apparatus for rolling back distributed transaction
US10698767B1 (en) Decentralized management of multi-service workflows
US9798639B2 (en) Failover system and method replicating client message to backup server from primary server
US20110246822A1 (en) Transaction participant registration with caveats
US20050193039A1 (en) Fault tolerant mechanism to handle initial load of replicated object in live system
CN110888718A (en) Method and device for realizing distributed transaction
CN113064744A (en) Task processing method and device, computer readable medium and electronic equipment
US20170235600A1 (en) System and method for running application processes
CN115220876A (en) Virtual resource creating method, device, program product, medium and electronic equipment
CN113961315A (en) Transaction processing method, device, equipment and storage medium
WO2023103340A1 (en) Block data committing method and apparatus
WO2024046130A1 (en) Task processing method, electronic device, and 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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20190521