CN111813791B - Distributed transaction compensation method and equipment - Google Patents
Distributed transaction compensation method and equipment Download PDFInfo
- Publication number
- CN111813791B CN111813791B CN202010554152.1A CN202010554152A CN111813791B CN 111813791 B CN111813791 B CN 111813791B CN 202010554152 A CN202010554152 A CN 202010554152A CN 111813791 B CN111813791 B CN 111813791B
- Authority
- CN
- China
- Prior art keywords
- transaction
- compensation
- business
- service
- business system
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
- G06F16/2379—Updates performed during online database operations; commit processing
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06Q—INFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
- G06Q30/00—Commerce
- G06Q30/02—Marketing; Price estimation or determination; Fundraising
- G06Q30/0207—Discounts or incentives, e.g. coupons or rebates
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Business, Economics & Management (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Accounting & Taxation (AREA)
- Development Economics (AREA)
- Finance (AREA)
- Strategic Management (AREA)
- Computing Systems (AREA)
- Entrepreneurship & Innovation (AREA)
- Game Theory and Decision Science (AREA)
- Economics (AREA)
- Marketing (AREA)
- General Business, Economics & Management (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
技术领域Technical Field
本申请涉及计算机领域,尤其涉及一种分布式补偿事务的方法及设备。The present application relates to the field of computers, and in particular to a method and device for distributed compensation transactions.
背景技术Background technique
在分布式环境下,为了保证不同数据源之间的数据一致性,一般会采用分布式事务,目前分布式事务的实现方式主要包括以下几种:两阶段提交事务;可靠消息事务;补偿事务。但这些方式分别具有以下缺点:两阶段提交事务的方式实现复杂,牺牲了可用性,对性能影响较大,不适合高并发高性能场景;可靠消息事务方式虽然避免了分布式事务,实现了最终一致性但对中间件的可靠性有要求;补偿事务方式实现简单,但事务记录表会耦合到业务系统中,若没有封装好的解决方案,需要处理的步骤较多。In a distributed environment, in order to ensure data consistency between different data sources, distributed transactions are generally used. Currently, the implementation methods of distributed transactions mainly include the following: two-phase commit transactions; reliable message transactions; compensation transactions. However, these methods have the following disadvantages: the two-phase commit transaction method is complex to implement, sacrifices availability, has a greater impact on performance, and is not suitable for high-concurrency and high-performance scenarios; although the reliable message transaction method avoids distributed transactions and achieves eventual consistency, it has requirements for the reliability of the middleware; the compensation transaction method is simple to implement, but the transaction record table will be coupled to the business system. If there is no encapsulated solution, there are many steps to be processed.
发明内容Summary of the invention
本申请的一个目的是提供一种的方法及设备,解决现有技术中数据一致性、事务处理过程复杂以及解耦过程中需要其他处理操作的问题。One purpose of the present application is to provide a method and device to solve the problems of data consistency, complex transaction processing process and the need for other processing operations in the decoupling process in the prior art.
根据本申请的一个方面,提供了一种分布式补偿事务的方法,该方法包括:According to one aspect of the present application, a distributed compensation transaction method is provided, the method comprising:
在业务系统中设定业务方法对应的补偿事务服务;Set up compensation transaction services corresponding to business methods in the business system;
当执行所述业务方法时记录补偿事务信息,并存储至数据库中;When executing the business method, the compensation transaction information is recorded and stored in the database;
执行本地事务,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务。Execute the local transaction, and process the compensation transaction information and the compensation transaction service according to the execution result of the local transaction.
进一步地,在业务系统中设定业务方法对应的补偿事务服务,包括:Furthermore, a compensation transaction service corresponding to the business method is set in the business system, including:
在业务系统中的业务方法上标明补偿事务服务中的补偿事务注解,并设定所述补偿事务的最大超时时间以及补偿逻辑的重试次数。The compensating transaction annotation in the compensating transaction service is marked on the business method in the business system, and the maximum timeout of the compensating transaction and the number of retries of the compensation logic are set.
进一步地,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务,包括:Further, processing the compensation transaction information and the compensation transaction service according to the execution result of the local transaction includes:
当所述本地事务的执行结果为事务成功,则通过所述补偿事务服务自动删除所述补偿事务信息。When the execution result of the local transaction is that the transaction is successful, the compensation transaction information is automatically deleted through the compensation transaction service.
进一步地,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务,包括:Further, processing the compensation transaction information and the compensation transaction service according to the execution result of the local transaction includes:
当所述本地事务的执行结果为事务失败,则将所述补偿事务信息以消息通知方式通知所述业务系统,由所述业务系统执行所述补偿事务服务中的补偿逻辑。When the execution result of the local transaction is a transaction failure, the compensation transaction information is notified to the business system in a message notification manner, and the business system executes the compensation logic in the compensation transaction service.
进一步地,当所述本地事务的执行结果为事务失败,则将所述补偿事务信息以消息通知方式通知所述业务系统,包括:Further, when the execution result of the local transaction is a transaction failure, the compensating transaction information is notified to the business system in a message notification manner, including:
开启所述补偿事务服务对应的事务扫描任务,通过所述事务扫描任务获取所述数据库中的异常事务的事务补偿记录;Starting a transaction scanning task corresponding to the compensation transaction service, and obtaining transaction compensation records of abnormal transactions in the database through the transaction scanning task;
将所述异常事务的事务补偿记录以消息通知方式通知所述业务系统。The transaction compensation record of the abnormal transaction is notified to the business system in a message notification manner.
进一步地,所述方法包括:Further, the method comprises:
通过所述业务系统监听所述消息通知,根据自身业务信息执行或重试补偿逻辑。The business system monitors the message notification and executes or retries the compensation logic according to its own business information.
进一步地,由所述业务系统执行所述补偿事务服务中的补偿逻辑,包括:Furthermore, the business system executes the compensation logic in the compensation transaction service, including:
由所述业务系统中设定的补偿事务服务根据补偿事务注解确定所述补偿事务注解上配置的业务系统中对应的补偿逻辑方法;The compensation transaction service set in the business system determines the corresponding compensation logic method in the business system configured on the compensation transaction annotation according to the compensation transaction annotation;
通过反射方式调用所述补偿逻辑方法以执行。The compensation logic method is called by reflection to be executed.
根据本申请又一个方面,还提供了一种分布式补偿事务的设备,该设备包括:According to another aspect of the present application, a device for distributed compensation transactions is also provided, the device comprising:
设定装置,用于在业务系统中设定业务方法对应的补偿事务服务;A setting device, used for setting a compensation transaction service corresponding to a business method in a business system;
记录装置,用于当执行所述业务方法时记录补偿事务信息,并存储至数据库中;A recording device, used to record compensation transaction information when executing the business method, and store it in a database;
执行装置,用于执行本地事务,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务。The execution device is used to execute the local transaction and process the compensation transaction information and the compensation transaction service according to the execution result of the local transaction.
根据本申请又一个方面,还提供了一种分布式补偿事务的设备,所述设备包括:According to another aspect of the present application, a device for distributed compensation transactions is also provided, the device comprising:
一个或多个处理器;以及one or more processors; and
存储有计算机可读指令的存储器,所述计算机可读指令在被执行时使所述处理器执行如前述所述方法的操作。A memory storing computer readable instructions, which, when executed, cause the processor to perform the operations of the method as described above.
根据本申请再一个方面,还提供了一种计算机可读介质,其上存储有计算机可读指令,所述计算机可读指令可被处理器执行以实现如前述所述的方法。According to another aspect of the present application, a computer-readable medium is provided, on which computer-readable instructions are stored. The computer-readable instructions can be executed by a processor to implement the method described above.
与现有技术相比,本申请通过在业务系统中设定业务方法对应的补偿事务服务;当执行所述业务方法时记录补偿事务信息,并存储至数据库中;执行本地事务,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务。可保证分布式环境下数据的一致性,降低事务处理过程的复杂度,解耦业务系统中除业务补偿处理部分的其他补偿事务操作。Compared with the prior art, this application sets the compensation transaction service corresponding to the business method in the business system; records the compensation transaction information when executing the business method and stores it in the database; executes the local transaction, and processes the compensation transaction information and the compensation transaction service according to the execution result of the local transaction. It can ensure the consistency of data in a distributed environment, reduce the complexity of the transaction processing process, and decouple other compensation transaction operations in the business system except the business compensation processing part.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
通过阅读参照以下附图所作的对非限制性实施例所作的详细描述,本申请的其它特征、目的和优点将会变得更明显:Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
图1示出根据本申请的一个方面提供的一种分布式补偿事务的方法流程示意图;FIG1 is a schematic diagram showing a method flow of a distributed compensation transaction provided according to one aspect of the present application;
图2示出本申请一具体实施例中通过业务系统及补偿事务服务实现分布式补偿事务的方法流程示意图;FIG2 is a flow chart showing a method for implementing distributed compensation transactions through a business system and a compensation transaction service in a specific embodiment of the present application;
图3示出本申请又一个方面提供一种分布式补偿事务的设备的结构示意图。FIG3 shows a schematic structural diagram of a device for distributed compensation transactions according to another aspect of the present application.
附图中相同或相似的附图标记代表相同或相似的部件。The same or similar reference numerals in the drawings represent the same or similar components.
具体实施方式Detailed ways
下面结合附图对本申请作进一步详细描述。The present application is described in further detail below in conjunction with the accompanying drawings.
在本申请一个典型的配置中,终端、服务网络的设备和可信方均包括一个或多个处理器(例如中央处理器(Central Processing Unit,CPU))、输入/输出接口、网络接口和内存。In a typical configuration of the present application, the terminal, the device of the service network and the trusted party all include one or more processors (eg, a central processing unit (CPU)), an input/output interface, a network interface and a memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RandomAccess Memory,RAM)和/或非易失性内存等形式,如只读存储器(Read Only Memory,ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(Phase-Change RAM,PRAM)、静态随机存取存储器(Static Random Access Memory,SRAM)、动态随机存取存储器(Dynamic RandomAccess Memory,DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(Electrically Erasable Programmable Read-Only Memory,EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(Compact Disc Read-Only Memory,CD-ROM)、数字多功能光盘(Digital Versatile Disk,DVD)或其他光学存储、磁盒式磁带,磁带磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非暂存电脑可读媒体(transitorymedia),如调制的数据信号和载波。Computer readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, Phase-Change RAM (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of random access memory (RAM), Read-Only Memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory media such as modulated data signals and carrier waves.
图1示出根据本申请的一个方面提供的一种分布式补偿事务的方法流程示意图,该方法包括:步骤S11~步骤S13,FIG1 shows a schematic flow chart of a method for distributed compensation transactions according to one aspect of the present application. The method comprises: steps S11 to S13.
在步骤S11中,在业务系统中设定业务方法对应的补偿事务服务;在此,在业务系统中引入通用补偿事务RPC服务,对需要支持补偿事务的业务类中的具体方法进行有关补偿事务服务的设定;例如,抽奖发放优惠券需求的业务,抽奖操作和发放优惠券属于两个业务系统的两个操作,该两个操作必须是原子的、数据最终一致的,都成功或都失败,在分布式环境中,可能存在抽中奖品但发放奖品失败的情况,为保证数据最终一致,需要添加事务,即在抽奖发放优惠券需求的业务系统中针对抽奖操作的方法和发放优惠券的方法设定对应的补偿事务服务。In step S11, a compensation transaction service corresponding to the business method is set in the business system; here, a general compensation transaction RPC service is introduced in the business system, and the compensation transaction service is set for the specific methods in the business class that need to support compensation transactions; for example, in the business of lottery and coupon issuance, the lottery operation and coupon issuance belong to two operations of two business systems. The two operations must be atomic and the data must be eventually consistent, and both must succeed or fail. In a distributed environment, there may be a situation where the prize is won but the prize issuance fails. In order to ensure the eventual consistency of the data, it is necessary to add a transaction, that is, in the business system of lottery and coupon issuance, corresponding compensation transaction services are set for the lottery operation method and the coupon issuance method.
在步骤S12中,当执行所述业务方法时记录补偿事务信息,并存储至数据库中;在此,业务系统执行补偿事务对应的业务方法时,通过补偿事务RPC服务记录补偿事务信息,将记录到的补偿事务信息存储至数据库中,从而事务执行完毕后不再保存补偿事务信息。In step S12, when the business method is executed, the compensation transaction information is recorded and stored in the database; here, when the business system executes the business method corresponding to the compensation transaction, the compensation transaction information is recorded through the compensation transaction RPC service, and the recorded compensation transaction information is stored in the database, so that the compensation transaction information is no longer saved after the transaction is executed.
在步骤S13中,执行本地事务,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务。在此,执行本地事务得到执行结果,该执行结果为事务成功或事务失败,当超时或异常时都可认为为事务失败。根据执行结果对应处理补偿事务信息以及执行补偿事务服务。In step S13, the local transaction is executed, and the compensation transaction information and the compensation transaction service are processed according to the execution result of the local transaction. Here, the local transaction is executed to obtain an execution result, which is a transaction success or a transaction failure. When a timeout or an exception occurs, it can be considered as a transaction failure. The compensation transaction information is processed and the compensation transaction service is executed according to the execution result.
在本申请一实施例中,在步骤S11中,在业务系统中的业务方法上标明补偿事务服务中的补偿事务注解,并设定所述补偿事务的最大超时时间以及补偿逻辑的重试次数。在此,在需要支持补偿事务的业务类中的具体方法上标明补偿事务注解,设定补偿实现的具体方法,事务的最大超时时间以及补偿逻辑的重试次数。其中,事务采用的机制可先尝试正向逻辑,成功则直接提交,但失败则需要执行回滚逻辑保证数据最终一致。补偿方法为网络超时或其他未知原因导致的尝试失败时的回滚逻辑,由补偿式事务组件自动调用执行。使用注解可以更方便使用,封装注解的逻辑为针对该注解添加Spring AOP切面,处理添加了该注解的方法;处理的内容为:业务方法执行前首先在数据库中插入事务记录,随后执行业务方法,若成功则删除事务记录,若失败则更新事务状态为失败。业务系统执行补偿事务的业务方法时,会通过补偿事务服务记录补偿事务信息,补偿逻辑执行采用最大努力通知型方案,业务方可自设定最大超时时间、补偿逻辑的重试次数,从而避免无限重试造成的资源浪费。In one embodiment of the present application, in step S11, the compensation transaction annotation in the compensation transaction service is marked on the business method in the business system, and the maximum timeout of the compensation transaction and the number of retries of the compensation logic are set. Here, the compensation transaction annotation is marked on the specific method in the business class that needs to support compensation transactions, and the specific method of compensation implementation, the maximum timeout of the transaction and the number of retries of the compensation logic are set. Among them, the mechanism adopted by the transaction can first try the forward logic, and directly submit if successful, but if it fails, the rollback logic needs to be executed to ensure the final consistency of the data. The compensation method is the rollback logic when the attempt fails due to network timeout or other unknown reasons, and is automatically called and executed by the compensating transaction component. Using annotations can be more convenient to use. The logic of encapsulating annotations is to add Spring AOP aspects to the annotations and process the methods with the annotations added; the processing content is: before the business method is executed, the transaction record is first inserted into the database, and then the business method is executed. If successful, the transaction record is deleted, and if it fails, the transaction status is updated to failure. When the business system executes the business method of the compensation transaction, the compensation transaction information will be recorded through the compensation transaction service. The compensation logic execution adopts the best effort notification solution. The business party can set the maximum timeout time and the number of retries of the compensation logic to avoid resource waste caused by infinite retries.
在本申请一实施例中,在步骤S13中,当所述本地事务的执行结果为事务成功,则通过所述补偿事务服务自动删除所述补偿事务信息。在此,业务系统执行业务方法成功后,会通过补偿事务RPC服务自动删除补偿事务信息,事务记录时存储在数据库中,事务执行完毕后不再有保存的必要,在事务处理完毕后补偿服务自动删除记录可以避免事务记录表数据量过大影响性能。In one embodiment of the present application, in step S13, when the execution result of the local transaction is a successful transaction, the compensation transaction information is automatically deleted through the compensation transaction service. Here, after the business system successfully executes the business method, the compensation transaction information is automatically deleted through the compensation transaction RPC service. The transaction record is stored in the database, and there is no need to save it after the transaction is executed. After the transaction is processed, the compensation service automatically deletes the record to avoid the performance being affected by the excessive amount of data in the transaction record table.
在本申请一实施例中,在步骤S13中,当所述本地事务的执行结果为事务失败,则将所述补偿事务信息以消息通知方式通知所述业务系统,由所述业务系统执行所述补偿事务服务中的补偿逻辑。在此,执行本地事务若事务超时或异常等,事务失败,则补偿事务服务调度扫描异常事务通知业务系统进行补偿,具体地由补偿事务服务发送事务补偿信息MQ通知业务系统执行补偿逻辑,由业务系统执行补偿事务。In one embodiment of the present application, in step S13, when the execution result of the local transaction is a transaction failure, the compensation transaction information is notified to the business system in a message notification manner, and the business system executes the compensation logic in the compensation transaction service. Here, when executing a local transaction, if the transaction times out or is abnormal, the transaction fails, then the compensation transaction service schedules scanning abnormal transactions to notify the business system for compensation. Specifically, the compensation transaction service sends transaction compensation information MQ to notify the business system to execute the compensation logic, and the business system executes the compensation transaction.
在本申请一具体实施例中,如图2所示,补偿事务服务通过RPC服务的形式向业务系统提供补偿事务机制保证,记录补偿事务信息、删除补偿事务记录操作,事务执行成功则直接删除补偿事务记录,事务执行失败则通过补偿事务的定时扫描调度发送MQ消息通知业务系统执行事务补偿逻辑,具体过程如下:业务系统记录补偿事务服务的补偿事务信息,其中,补偿事务信息包括补偿依赖数据、事务超时信息以及补偿重试信息;补偿事务服务返回操作结果至业务系统,由业务系统执行本地事务,若事务成功则删除补偿事务信息,若事务失败,则补偿事务服务发送事务补偿信息MQ通知业务系统执行补偿逻辑,由业务系统执行补偿事务。In a specific embodiment of the present application, as shown in Figure 2, the compensation transaction service provides a compensation transaction mechanism guarantee to the business system in the form of an RPC service, records compensation transaction information, deletes compensation transaction record operations, and directly deletes the compensation transaction record if the transaction is successfully executed. If the transaction fails, an MQ message is sent through the scheduled scanning schedule of the compensation transaction to notify the business system to execute the transaction compensation logic. The specific process is as follows: the business system records the compensation transaction information of the compensation transaction service, wherein the compensation transaction information includes compensation dependency data, transaction timeout information, and compensation retry information; the compensation transaction service returns the operation result to the business system, and the business system executes the local transaction. If the transaction is successful, the compensation transaction information is deleted. If the transaction fails, the compensation transaction service sends transaction compensation information MQ to notify the business system to execute the compensation logic, and the business system executes the compensation transaction.
在本申请一实施例中,可以开启所述补偿事务服务对应的事务扫描任务,通过所述事务扫描任务获取所述数据库中的异常事务的事务补偿记录;将所述异常事务的事务补偿记录以消息通知方式通知所述业务系统。在此,补偿事务服务中开启对应的事务扫描任务,定时扫描失败的需要重试的事务,发送MQ通知业务系统执行其对应的事务补偿逻辑。In one embodiment of the present application, the transaction scanning task corresponding to the compensation transaction service can be started, and the transaction compensation record of the abnormal transaction in the database can be obtained through the transaction scanning task; the transaction compensation record of the abnormal transaction is notified to the business system in the form of a message notification. Here, the corresponding transaction scanning task is started in the compensation transaction service, and the failed transactions that need to be retried are scanned regularly, and MQ is sent to notify the business system to execute its corresponding transaction compensation logic.
在本申请一实施例中,所述方法包括:通过所述业务系统监听所述消息通知,根据自身业务信息执行或重试补偿逻辑。具体地,可以由所述业务系统中设定的补偿事务服务根据补偿事务注解确定所述补偿事务注解上配置的业务系统中对应的补偿逻辑方法;通过反射方式调用所述补偿逻辑方法以执行。在此,业务系统监听补偿事务通知MQ,根据自身业务情况或重试补偿逻辑,补偿逻辑需要支持幂等,补偿逻辑的执行最终是通过消费MQ消息的方式实现的,在网络异常等极端条件下,为保证消息的可靠触达,MQ消息可能会存在重复发送的情况,为避免重复消费造成的数据不一致,需要业务方自行做补偿逻辑的幂等处理。事务重试时会发送MQ消息通知业务系统,补偿事务服务会根据事务注解上配置的系统中对应的补偿逻辑方法,并通过反射方式调用该方法,补偿实现由业务使用方提供补偿实现;补偿实现,例如,抽奖成功,但优惠券发放异常中断,则检查优惠券是否发放成功,如果成功则更新抽奖记录状态为有效,否则不做处理,抽奖记录状态默认为无效。In one embodiment of the present application, the method includes: monitoring the message notification through the business system, and executing or retrying the compensation logic according to its own business information. Specifically, the compensation transaction service set in the business system can determine the corresponding compensation logic method in the business system configured on the compensation transaction annotation according to the compensation transaction annotation; and call the compensation logic method by reflection to execute. Here, the business system monitors the compensation transaction notification MQ, and according to its own business situation or retrying the compensation logic, the compensation logic needs to support idempotence. The execution of the compensation logic is ultimately realized by consuming MQ messages. Under extreme conditions such as network anomalies, in order to ensure the reliable reach of the message, the MQ message may be repeatedly sent. In order to avoid data inconsistency caused by repeated consumption, the business party needs to perform idempotence processing of the compensation logic by itself. When the transaction is retried, an MQ message will be sent to notify the business system. The compensation transaction service will call the corresponding compensation logic method in the system configured on the transaction annotation by reflection, and the compensation implementation is provided by the business user; compensation implementation, for example, if the lottery is successful, but the coupon issuance is abnormally interrupted, then check whether the coupon issuance is successful. If successful, the lottery record status is updated to valid, otherwise no processing is performed, and the lottery record status defaults to invalid.
通过本申请上述所述的方法,可保证分布式环境下数据的一致性,降低事务处理过程的复杂度,解耦业务系统中除业务补偿处理部分的其他补偿事务操作。Through the method described above in this application, the consistency of data in a distributed environment can be guaranteed, the complexity of the transaction processing process can be reduced, and other compensation transaction operations in the business system except the business compensation processing part can be decoupled.
此外,本申请实施例还提供了一种计算机可读介质,其上存储有计算机可读指令,所述计算机可读指令可被处理器执行以实现前述一种分布式补偿事务的方法。In addition, an embodiment of the present application further provides a computer-readable medium on which computer-readable instructions are stored. The computer-readable instructions can be executed by a processor to implement the aforementioned distributed compensation transaction method.
与上文所述的方法相对应的,本申请还提供一种终端,其包括能够执行上述图1或图2或各个实施例所述的方法步骤的模块或单元,这些模块或单元可以通过硬件、软件或软硬结合的方式来实现,本申请并不限定。例如,在本申请一实施例中,还提供了一种分布式补偿事务的设备,所述设备包括:Corresponding to the method described above, the present application also provides a terminal, which includes a module or unit capable of executing the method steps described in Figure 1 or Figure 2 or each embodiment. These modules or units can be implemented by hardware, software, or a combination of hardware and software, which is not limited by the present application. For example, in one embodiment of the present application, a device for distributed compensation transactions is also provided, and the device includes:
一个或多个处理器;以及one or more processors; and
存储有计算机可读指令的存储器,所述计算机可读指令在被执行时使所述处理器执行如前述所述方法的操作。A memory storing computer readable instructions, which, when executed, cause the processor to perform the operations of the method as described above.
例如,计算机可读指令在被执行时使所述一个或多个处理器:For example, the computer readable instructions, when executed, cause the one or more processors to:
在业务系统中设定业务方法对应的补偿事务服务;Set up compensation transaction services corresponding to business methods in the business system;
当执行所述业务方法时记录补偿事务信息,并存储至数据库中;When executing the business method, the compensation transaction information is recorded and stored in the database;
执行本地事务,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务。Execute the local transaction, and process the compensation transaction information and the compensation transaction service according to the execution result of the local transaction.
图3示出本申请又一个方面提供一种分布式补偿事务的设备的结构示意图,该设备包括:设定装置11、记录装置12和执行装置13,其中,设定装置11用于在业务系统中设定业务方法对应的补偿事务服务;记录装置12用于当执行所述业务方法时记录补偿事务信息,并存储至数据库中;执行装置13用于执行本地事务,根据本地事务的执行结果处理所述补偿事务信息及所述补偿事务服务。Figure 3 shows a structural schematic diagram of a device for distributed compensation transactions provided in accordance with another aspect of the present application, the device comprising: a setting device 11, a recording device 12 and an execution device 13, wherein the setting device 11 is used to set a compensation transaction service corresponding to a business method in a business system; the recording device 12 is used to record compensation transaction information when executing the business method and store it in a database; the execution device 13 is used to execute local transactions and process the compensation transaction information and the compensation transaction service according to the execution result of the local transaction.
需要说明的是,设定装置11、记录装置12及执行装置13执行的内容分别与上述步骤S11、S12和S13中的内容相同或相应相同,为简明起见,在此不再赘述。It should be noted that the contents executed by the setting device 11, the recording device 12 and the execution device 13 are respectively the same or correspondingly the same as the contents in the above steps S11, S12 and S13, and for the sake of simplicity, they are not repeated here.
显然,本领域的技术人员可以对本申请进行各种改动和变型而不脱离本申请的精神和范围。这样,倘若本申请的这些修改和变型属于本申请权利要求及其等同技术的范围之内,则本申请也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
需要注意的是,本申请可在软件和/或软件与硬件的组合体中被实施,例如,可采用专用集成电路(ASIC)、通用目的计算机或任何其他类似硬件设备来实现。在一个实施例中,本申请的软件程序可以通过处理器执行以实现上文所述步骤或功能。同样地,本申请的软件程序(包括相关的数据结构)可以被存储到计算机可读记录介质中,例如,RAM存储器,磁或光驱动器或软磁盘及类似设备。另外,本申请的一些步骤或功能可采用硬件来实现,例如,作为与处理器配合从而执行各个步骤或功能的电路。It should be noted that the present application can be implemented in software and/or a combination of software and hardware, for example, can be implemented using an application specific integrated circuit (ASIC), a general purpose computer or any other similar hardware device. In one embodiment, the software program of the present application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of the present application (including relevant data structures) can be stored in a computer-readable recording medium, for example, a RAM memory, a magnetic or optical drive or a floppy disk and similar devices. In addition, some steps or functions of the present application can be implemented using hardware, for example, as a circuit that cooperates with a processor to perform each step or function.
另外,本申请的一部分可被应用为计算机程序产品,例如计算机程序指令,当其被计算机执行时,通过该计算机的操作,可以调用或提供根据本申请的方法和/或技术方案。而调用本申请的方法的程序指令,可能被存储在固定的或可移动的记录介质中,和/或通过广播或其他信号承载媒体中的数据流而被传输,和/或被存储在根据所述程序指令运行的计算机设备的工作存储器中。在此,根据本申请的一个实施例包括一个装置,该装置包括用于存储计算机程序指令的存储器和用于执行程序指令的处理器,其中,当该计算机程序指令被该处理器执行时,触发该装置运行基于前述根据本申请的多个实施例的方法和/或技术方案。In addition, a part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and/or technical solution according to the present application through the operation of the computer. The program instruction for calling the method of the present application may be stored in a fixed or removable recording medium, and/or transmitted through a data stream in a broadcast or other signal-bearing medium, and/or stored in a working memory of a computer device that runs according to the program instruction. Here, according to an embodiment of the present application, a device is included, the device including a memory for storing computer program instructions and a processor for executing program instructions, wherein, when the computer program instruction is executed by the processor, the device is triggered to run the method and/or technical solution based on the aforementioned multiple embodiments according to the present application.
对于本领域技术人员而言,显然本申请不限于上述示范性实施例的细节,而且在不背离本申请的精神或基本特征的情况下,能够以其他的具体形式实现本申请。因此,无论从哪一点来看,均应将实施例看作是示范性的,而且是非限制性的,本申请的范围由所附权利要求而不是上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化涵括在本申请内。不应将权利要求中的任何附图标记视为限制所涉及的权利要求。此外,显然“包括”一词不排除其他单元或步骤,单数不排除复数。装置权利要求中陈述的多个单元或装置也可以由一个单元或装置通过软件或者硬件来实现。第一,第二等词语用来表示名称,而并不表示任何特定的顺序。It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or basic features of the present application. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present application is limited by the attached claims rather than the above description, so it is intended to include all changes that fall within the meaning and scope of the equivalent elements of the claims in the present application. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
Claims (8)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010554152.1A CN111813791B (en) | 2020-06-17 | 2020-06-17 | Distributed transaction compensation method and equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010554152.1A CN111813791B (en) | 2020-06-17 | 2020-06-17 | Distributed transaction compensation method and equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111813791A CN111813791A (en) | 2020-10-23 |
CN111813791B true CN111813791B (en) | 2024-05-21 |
Family
ID=72846276
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010554152.1A Active CN111813791B (en) | 2020-06-17 | 2020-06-17 | Distributed transaction compensation method and equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111813791B (en) |
Families Citing this family (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112463810A (en) * | 2020-12-08 | 2021-03-09 | 佳讯飞鸿(北京)智能科技研究院有限公司 | Data processing method, device, equipment and storage medium based on distributed transaction |
CN112769712B (en) * | 2020-12-23 | 2022-10-18 | 中移(杭州)信息技术有限公司 | A compensation method, device, electronic device and storage medium |
CN112597246B (en) * | 2020-12-25 | 2024-04-12 | 中国农业银行股份有限公司 | Method, device and system for maintaining data consistency |
CN113760467A (en) * | 2021-01-15 | 2021-12-07 | 北京京东拓先科技有限公司 | Transaction processing method, device, computer system and storage medium |
CN113778631A (en) * | 2021-01-29 | 2021-12-10 | 北京沃东天骏信息技术有限公司 | Distributed transaction compensation method and device, electronic equipment and readable storage medium |
CN113032176B (en) * | 2021-03-23 | 2024-11-22 | 中国邮政储蓄银行股份有限公司 | Distributed transaction double compensation method and device based on end-of-day reconciliation |
CN113204575B (en) * | 2021-05-28 | 2023-08-01 | 西藏宁算科技集团有限公司 | Distributed flow processing solution method and system based on cloud platform |
CN113342852B (en) * | 2021-06-09 | 2023-06-30 | 上海万物新生环保科技集团有限公司 | Method and equipment for realizing distributed configuration |
CN115545629A (en) * | 2021-06-30 | 2022-12-30 | 网联清算有限公司 | Business data checking method and equipment |
CN114327792A (en) * | 2021-11-29 | 2022-04-12 | 北京金山云网络技术有限公司 | Transaction processing method, system and device |
CN114024999B (en) * | 2022-01-10 | 2022-04-08 | 中航信移动科技有限公司 | Task compensation method, system, device, electronic equipment and storage medium |
CN115187337A (en) * | 2022-07-08 | 2022-10-14 | 中信百信银行股份有限公司 | Order compensation method, apparatus and equipment, and storage medium |
CN116578272A (en) * | 2023-02-17 | 2023-08-11 | 李清 | Centralized transfer distributed transaction solution |
CN116560896B (en) * | 2023-07-11 | 2023-10-10 | 智慧眼科技股份有限公司 | Anomaly compensation method, device, equipment and storage medium |
CN116909760B (en) * | 2023-09-13 | 2023-11-28 | 中移(苏州)软件技术有限公司 | Data processing method, device, readable storage medium and electronic equipment |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP2482210A2 (en) * | 2005-08-23 | 2012-08-01 | Ricoh Company, Ltd. | System and methods for creation and use of a mixed media environment |
CN106503257A (en) * | 2016-11-15 | 2017-03-15 | 北京京东金融科技控股有限公司 | Distributed transaction server method and system based on binlog compensation mechanism |
CN107368498A (en) * | 2016-05-13 | 2017-11-21 | 阿里巴巴集团控股有限公司 | The lock for optimizing MySQL Pessimistic Lockings waits the method and device of time-out time |
CN108459919A (en) * | 2018-03-29 | 2018-08-28 | 中信百信银行股份有限公司 | A kind of distributed transaction processing method and device |
CN110399236A (en) * | 2019-07-25 | 2019-11-01 | 泰康保险集团股份有限公司 | Adaptation method, device, medium and the electronic equipment of message queue |
CN111046106A (en) * | 2019-12-19 | 2020-04-21 | 杭州中恒电气股份有限公司 | Cache data synchronization method, device, device and medium |
CN111143041A (en) * | 2019-12-31 | 2020-05-12 | 中国银行股份有限公司 | Data consistency method, distributed coordinator and central coordinator |
CN111198751A (en) * | 2018-11-20 | 2020-05-26 | 北京京东尚科信息技术有限公司 | Service processing method and device |
CN111209092A (en) * | 2020-01-09 | 2020-05-29 | 江苏艾佳家居用品有限公司 | Distributed transaction processing method based on Saga mode |
CN111258790A (en) * | 2018-12-03 | 2020-06-09 | 北京京东振世信息技术有限公司 | Anomaly compensation method and device |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7979519B2 (en) * | 2003-10-09 | 2011-07-12 | Oki Electric Industry Co., Ltd. | System for providing information between different protocol environments cooperative with each other and a method therefor |
CA2622404A1 (en) * | 2004-09-15 | 2006-03-23 | Adesso Systems, Inc. | System and method for managing data in a distributed computer system |
US8024313B2 (en) * | 2008-05-09 | 2011-09-20 | Protecode Incorporated | System and method for enhanced direction of automated content identification in a distributed environment |
CN104598840A (en) * | 2015-02-04 | 2015-05-06 | 新余兴邦信息产业有限公司 | Multi-data-source data processing method and system based on HTTP (hyper text transport protocol) |
US20170041392A1 (en) * | 2015-08-04 | 2017-02-09 | Smart Technologies Ulc | Method of distributing a file and a computing system employing same |
-
2020
- 2020-06-17 CN CN202010554152.1A patent/CN111813791B/en active Active
Patent Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP2482210A2 (en) * | 2005-08-23 | 2012-08-01 | Ricoh Company, Ltd. | System and methods for creation and use of a mixed media environment |
CN107368498A (en) * | 2016-05-13 | 2017-11-21 | 阿里巴巴集团控股有限公司 | The lock for optimizing MySQL Pessimistic Lockings waits the method and device of time-out time |
CN106503257A (en) * | 2016-11-15 | 2017-03-15 | 北京京东金融科技控股有限公司 | Distributed transaction server method and system based on binlog compensation mechanism |
CN108459919A (en) * | 2018-03-29 | 2018-08-28 | 中信百信银行股份有限公司 | A kind of distributed transaction processing method and device |
CN111198751A (en) * | 2018-11-20 | 2020-05-26 | 北京京东尚科信息技术有限公司 | Service processing method and device |
CN111258790A (en) * | 2018-12-03 | 2020-06-09 | 北京京东振世信息技术有限公司 | Anomaly compensation method and device |
CN110399236A (en) * | 2019-07-25 | 2019-11-01 | 泰康保险集团股份有限公司 | Adaptation method, device, medium and the electronic equipment of message queue |
CN111046106A (en) * | 2019-12-19 | 2020-04-21 | 杭州中恒电气股份有限公司 | Cache data synchronization method, device, device and medium |
CN111143041A (en) * | 2019-12-31 | 2020-05-12 | 中国银行股份有限公司 | Data consistency method, distributed coordinator and central coordinator |
CN111209092A (en) * | 2020-01-09 | 2020-05-29 | 江苏艾佳家居用品有限公司 | Distributed transaction processing method based on Saga mode |
Also Published As
Publication number | Publication date |
---|---|
CN111813791A (en) | 2020-10-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111813791B (en) | Distributed transaction compensation method and equipment | |
CN111585867B (en) | Message processing method and device, electronic equipment and readable storage medium | |
WO2020108325A1 (en) | Transaction processing method, apparatus and device | |
CN111198751B (en) | Service processing method and device | |
CN112486719B (en) | Method and equipment for RPC interface call failure processing | |
CN111245900A (en) | Distributed message sending processing system and processing method thereof | |
CN112667439A (en) | Data processing method and device and electronic equipment | |
US12001450B2 (en) | Distributed table storage processing method, device and system | |
CN111274047A (en) | Information processing method, terminal, system, computer device and storage medium | |
CN111865687A (en) | Method and device for updating business data | |
CN111899087A (en) | Data providing method and device, electronic equipment and computer readable storage medium | |
CN114860473A (en) | A message processing method, processor and storage medium | |
CN114024999A (en) | A task compensation method, system, device, electronic device, and storage medium | |
CN116662035A (en) | Method and device for processing transaction message of message queue | |
CN110941622A (en) | Data processing method and device | |
CN111858487A (en) | Data update method and device | |
CN114895975B (en) | A preheating method and device for a server system | |
CN116795548A (en) | Interface processing method, device, system and storage medium based on multi-cloud management | |
CN113347028B (en) | Internet of things platform management system developed based on MQTT and RocktMQ | |
CN114896082A (en) | Message processing method, apparatus, electronic device and storage medium | |
CN114968982A (en) | Business processing method and device for sub-database sub-table scenario | |
CN114513483A (en) | Message notification method and device based on service system | |
CN114764324A (en) | Enterprise resource planning system and integration method thereof | |
CN116643733B (en) | Service processing system and method | |
CN109753389A (en) | Method, device, storage medium and server for ensuring data consistency |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
CB02 | Change of applicant information |
Address after: Room 1101-1103, No. 433, Songhu Road, Yangpu District, Shanghai Applicant after: Shanghai wanwansheng Environmental Protection Technology Group Co.,Ltd. Address before: Room 1101-1103, No. 433, Songhu Road, Yangpu District, Shanghai Applicant before: SHANGHAI YUEYI NETWORK INFORMATION TECHNOLOGY Co.,Ltd. |
|
CB02 | Change of applicant information | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CP03 | Change of name, title or address |
Address after: Room 1101-1103, No. 433, Songhu Road, Yangpu District, Shanghai Patentee after: Shanghai Wanwu Xinsheng Information Technology Group Co.,Ltd. Country or region after: China Address before: Room 1101-1103, No. 433, Songhu Road, Yangpu District, Shanghai Patentee before: Shanghai wanwansheng Environmental Protection Technology Group Co.,Ltd. Country or region before: China |
|
CP03 | Change of name, title or address |