A method, device and medium for ensuring final data consistency of distributed transactions

By generating and performing idempotent tasks in distributed transactions, the problem of difficult to achieve the final data consistency of distributed transactions in distributed systems is solved, and data consistency with low time lag and high success rate is achieved, which improves the user experience.

CN110737514BActive Publication Date: 2025-01-14TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN201910915138.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-09-26
Publication Date
2025-01-14
Estimated Expiration
2039-12-30

AI Technical Summary

Technical Problem

The existing technology is difficult to achieve the final data consistency of distributed transactions with low time lag and high success rate in distributed systems. The second-stage submission protocol has low success rate and poor fault tolerance rate. However, the reconciliation-based solution has a long time lag, which is difficult to Meet user needs.

Method used

By obtaining the parameters required by distributed transactions, generating and executing idempotent tasks, the data participating in the transactions have the final data consistency after the idempotent task is completed, avoiding reconciliation processing, and significantly reducing the consistency status. time required and reduce lag at high success rates.

Benefits of technology

It realizes that the viscosity of the user experience is significantly improved in distributed transactions, ensures high success rate distributed transaction execution, and reduces time lag and avoids the time lag problems caused by reconciliation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110737514B_ABST
    Figure CN110737514B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and medium for ensuring the final data consistency of distributed transactions, the method comprising obtaining a business request, obtaining a service set consisting of various services associated with the business request, wherein the server set includes at least two services; obtaining parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and obtaining a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set; generating an idempotent task according to the parameter set, wherein the idempotent task is used to perform idempotent operations on various parameters in the parameter set; executing the idempotent task and returning the execution result of the idempotent task. The present invention significantly reduces the time required to reach the final data consistency state, and reduces the time lag while ensuring the high success rate of executing distributed transactions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of distributed transactions, and in particular to a method, device and medium for ensuring final data consistency of distributed transactions. Background Art

[0002] As business complexity increases, more and more businesses need to rely on the interaction of different nodes in a distributed system, and different nodes can provide different services. In a distributed system, each node is physically independent of each other and communicates and coordinates through the network. However, independent nodes cannot accurately know the transaction execution status of other nodes, so it is difficult to ensure the final data consistency between nodes. The final data consistency means that as time passes, the corresponding data on different nodes always changes in a convergent direction, thereby reaching a final consistent state. The existing solutions to ensure the final data consistency between nodes are mainly:

[0003] (1) Ensure final data consistency based on the two-phase commit protocol. The two-phase commit protocol can be summarized as follows: the participants notify the coordinator of the success or failure of the operation, and the coordinator decides whether each participant should commit the operation or terminate the operation based on the feedback information of all participants. The two phases refer to: the first phase is the request phase (voting phase), and the second phase is the submission phase (execution phase). This protocol has very strict requirements on each node involved in the business, with low fault tolerance and success rate.

[0004] (2) Ensure final data consistency based on reconciliation. Due to the influence of reconciliation frequency, the cycle for achieving final data consistency is long, which reduces user experience. Summary of the invention

[0005] In order to solve the technical problem that the prior art cannot provide a solution with low latency and high success rate to ensure the final data consistency of distributed transactions, the embodiments of the present invention provide a method, device and medium for ensuring the final data consistency of distributed transactions.

[0006] In one aspect, the present invention provides a method for ensuring final data consistency of a distributed transaction, the method comprising:

[0007] Obtaining a service request, and obtaining a service set consisting of various services associated with the service request, wherein the service set includes at least two services;

[0008] Acquire parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and obtain a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set;

[0009] Generate an idempotent task according to the parameter set, where the idempotent task is used to perform an idempotent operation on each parameter in the parameter set;

[0010] A distributed transaction is generated for processing the business request, the idempotent task is executed in the distributed transaction, and the execution result of the idempotent task is returned.

[0011] In another aspect, the present invention provides a device for ensuring final data consistency of a distributed transaction, the device comprising:

[0012] A service set acquisition module, used to acquire a service request, and acquire a service set consisting of various services associated with the service request, wherein the service set includes at least two services;

[0013] A parameter set acquisition module, used to acquire parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and obtain a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set;

[0014] An idempotent task generation module, used for generating an idempotent task according to the parameter set, wherein the idempotent task is used for performing an idempotent operation on each parameter in the parameter set;

[0015] The idempotent task execution module is used to generate a distributed transaction for processing the business request, execute the idempotent task in the distributed transaction, and return the execution result of the idempotent task.

[0016] On the other hand, the present invention provides a device for ensuring the final data consistency of distributed transactions, characterized in that the device includes a processor and a memory, the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement a method for ensuring the final data consistency of distributed transactions.

[0017] On the other hand, the present invention provides a computer storage medium, characterized in that the storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to ensure the final data consistency of distributed transactions.

[0018] The present invention provides a method, device and medium for ensuring the final data consistency of distributed transactions. The present invention obtains various parameters required for implementing distributed transactions, and generates and executes idempotent tasks based on the parameters, so that after the idempotent tasks are executed, all relevant data participating in the distributed transactions have final data consistency, and no reconciliation processing is required, thereby significantly reducing the time required to reach the final data consistency state, reducing the time lag while ensuring a high success rate for executing distributed transactions, thereby significantly improving user stickiness. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 It is a schematic diagram of an implementation environment of a method for ensuring final data consistency of distributed transactions provided by the present invention;

[0021] Figure 2 It is an optional structural diagram of the blockchain system provided by the present invention;

[0022] Figure 3 It is an optional schematic diagram of the block structure (Block Structure) provided by the present invention;

[0023] Figure 4 It is a flow chart of a method for ensuring final data consistency of distributed transactions provided by the present invention;

[0024] Figure 5 The present invention provides a method for generating a distributed transaction for processing the business request, and executing the idempotent task flow chart in the distributed transaction;

[0025] Figure 6 The flowchart of executing the idempotent task in the distributed transaction according to the first execution strategy provided by the present invention;

[0026] Figure 7 The present invention provides a flowchart for continuing to execute the idempotent task according to the state of the distributed transaction;

[0027] Figure 8 The flowchart of executing the idempotent task in the distributed transaction according to the second execution strategy provided by the present invention;

[0028] Fig. 9The present invention provides a flowchart for continuing to execute the idempotent task according to the state of the distributed transaction;

[0029] Fig.10 The flowchart of executing the idempotent task in the distributed transaction according to the second execution strategy provided by the present invention;

[0030] Fig.11 It is a logical schematic diagram of a method for ensuring final data consistency of distributed transactions provided by the present invention;

[0031] Fig.12 It is a block diagram of a device for ensuring final data consistency of distributed transactions provided by the present invention;

[0032] Fig.13 It is a schematic diagram of the hardware structure of a device provided by the present invention for implementing the method provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0034] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.

[0035] In order to make the purpose, technical solution and advantages disclosed in the embodiments of the present invention more clearly understood, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the embodiments of the present invention and are not used to limit the embodiments of the present invention.

[0036] In the following, the terms "first" and "second" are used for descriptive purposes only and shall not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this embodiment, unless otherwise specified, "multiple" means two or more. In order to facilitate the understanding of the technical solutions described in the embodiments of the present invention and the technical effects produced therefrom, the embodiments of the present invention first explain the relevant professional terms:

[0037] Eventual data consistency: As time goes by, the corresponding data on different nodes always change in a similar direction, so after a period of time, the corresponding data between nodes will eventually reach a consistent state.

[0038] Taking the distributed transaction of successfully purchasing movie tickets as an example, this distributed transaction needs to be implemented by the payment system and the movie ticket issuing system in collaboration. If the user successfully purchases movie tickets, the data in the payment system should be the data generated by the user's successful payment of the movie ticket money, and the corresponding data in the movie ticket issuing system should be the data generated for the user's successful ticket issuance. The data in the payment system and the corresponding data in the movie ticket issuing system both point to the same distributed transaction: successful purchase of movie tickets, then the distributed transaction complies with the principle of data consistency. If the data in the payment system and the corresponding data in the movie ticket issuing system need to point to the same distributed transaction: successful purchase of movie tickets after a preset time, then the distributed transaction complies with the principle of final data consistency.

[0039] In order to ensure that distributed transactions comply with the principle of final data consistency, the prior art has proposed a technical solution of a two-phase commit protocol. However, this solution can only implement the distributed transaction after the voting results of each node related to the distributed transaction are clear. If any node vetoes the distributed transaction, the implementation of the distributed transaction will fail. Therefore, its success rate is low and its fault tolerance is poor.

[0040] Other existing technologies have also proposed using reconciliation to ensure that distributed transactions comply with the principle of final data consistency. Reconciliation is to check accounts, and the reconciliation operation is time-consuming, so the reconciliation frequency is low. Many business systems only reconcile once a day. It can be seen that the time lag caused by ensuring final data consistency based on reconciliation is long, which is difficult to meet user needs.

[0041] In order to solve the technical problem that the prior art cannot provide a solution with low latency and high success rate to ensure the final data consistency of distributed transactions, an embodiment of the present invention provides a method for ensuring the final data consistency of distributed transactions.

[0042] Firstly, an embodiment of the present invention discloses an implementation environment of a method for ensuring final data consistency of distributed transactions in a feasible embodiment.

[0043] See also Figure 1 , the implementation environment includes: at least one client 01 and a server 03.

[0044] The client 01 may include physical devices such as smart phones, tablet computers, laptop computers, digital assistants, smart wearable devices, and vehicle-mounted terminals, and may also include software running in physical devices, such as applications with payment functions, etc. The client 01 may be connected to the server 03 in a communication manner based on a browser / server mode (B / S) or a client / server mode (C / S).

[0045] The server 03 may receive a payment function-related service request sent by the client 01, implement a distributed transaction based on the service request, and ensure the final consistency of the distributed transaction. The server 03 may also feedback the service processing result generated by the service request to the client 01. The server 03 may include an independently operated server, a distributed server, or a server cluster consisting of multiple servers.

[0046] The relevant data generated by the distributed transaction implemented in the server 03 can be stored in one or more nodes of the distributed system. The distributed system can be a blockchain structure, and any node in the blockchain structure can store the relevant data generated by the distributed transaction.

[0047] In a preferred embodiment, the relevant data generated by the distributed transaction is stored in the blockchain system. Figure 2 , Figure 2 This is an optional structural diagram of the blockchain system provided by the embodiment of the present invention. A peer-to-peer (P2P) network is formed between multiple nodes. The P2P protocol is an application layer protocol running on the Transmission Control Protocol (TCP). In the blockchain system, any machine such as a server or a terminal can join and become a node. The node includes a hardware layer, an intermediate layer, an operating system layer, and an application layer.

[0048] See also Figure 2 The functions of each node in the blockchain system shown include:

[0049] 1) Routing: a basic function of a node, used to support communication between nodes.

[0050] In addition to the routing function, the node can also have the following functions:

[0051] 2) Applications are deployed in the blockchain to implement specific businesses based on actual business needs, record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system for other nodes to add the record data to a temporary block when they successfully verify the source and integrity of the record data.

[0052] 3) Blockchain, including a series of blocks that are connected to each other in the order of their generation. Once a new block is added to the blockchain, it will not be removed. The block records the record data submitted by the nodes in the blockchain system.

[0053] See also Figure 3 , Figure 3 This is an optional schematic diagram of the block structure provided by an embodiment of the present invention. Each block includes the hash value of the transaction record stored in this block (the hash value of this block) and the hash value of the previous block. Each block is connected by the hash value to form a blockchain. In addition, the block can also include information such as the timestamp when the block was generated. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains relevant information for verifying the validity of its information (anti-counterfeiting) and generating the next block.

[0054] Please refer to Figure 4 , which shows a flow chart of a method for ensuring the final data consistency of distributed transactions, the method can be Figure 1 The server in the implementation environment is implemented as an execution subject, and the method may include:

[0055] S101. Obtain a service request, and obtain a service set consisting of various services associated with the service request, wherein the service set includes at least two services.

[0056] Since the service set includes at least two services, each service in the service set needs to rely on collaboration to successfully respond to the business request, and this collaboration process corresponds to the execution process of a distributed transaction, and the related services are the services associated with the business request.

[0057] Taking the business request of purchasing movie tickets as an example, in order to successfully purchase movie tickets, the payment service provided by the payment system and the ticket issuance service provided by the movie ticket issuance system need to collaborate. The payment service and the ticket issuance service are the services associated with the business request, and the service set is {payment service, ticket issuance service}.

[0058] S103. Obtain parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and obtain a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set.

[0059] Taking the business request of buying movie tickets as an example, the payment service related parameters are {A1, A2, ..., AN}, then {A1, A2, ..., AN} is the parameter subset corresponding to the payment service, and the ticket service related parameters are {B1, B2, ..., BM}, then {B1, B2, ..., BM} is the parameter subset corresponding to the ticket service. Correspondingly, {payment service {A1, A2, ..., AN}, ticket service {B1, B2, ..., BM}} is the parameter set corresponding to the service set.

[0060] S105. Generate an idempotent task according to the parameter set, where the idempotent task is used to perform an idempotent operation on each parameter in the parameter set.

[0061] For a step, if the impact of executing it any multiple times is the same as the impact of executing it once, then this step is an idempotent step. Similarly, the meaning of idempotent operation in the embodiment of the present invention is that the impact of executing any multiple operations on the parameter is the same as the impact of executing it once. In the embodiment of the present invention, idempotent operations can include idempotent withholding, idempotent consumption, idempotent release and idempotent rollback.

[0062] Taking consumption parameter A1 as an example, any multiple consumption of parameter A1 will only produce two results, one result is consumption failure, and the other result is that consumption parameter A1 is successfully consumed once. In the payment scenario, if the idempotent operation is to deduct 500 yuan from the user, the result it produces is deduction failure or only deducting 500 yuan from the user, and the user will not be charged repeatedly.

[0063] The process of consuming each parameter by the idempotent task requires calling the service associated with the parameter. Therefore, the execution process of the idempotent task reflects the collaboration process of each service.

[0064] S107. Generate a distributed transaction for processing the business request, execute the idempotent task in the distributed transaction, and return the execution result of the idempotent task.

[0065] In order to reduce the complexity of idempotent task execution and improve the efficiency of idempotent task execution, the various parameters in the parameter set are classified in an embodiment of the present invention. In a feasible embodiment, various parameters are classified into limited use parameters and unlimited use parameters. The resources corresponding to the limited use parameters are limited. For example, the number of accounts in a user account is a limited resource parameter, which can only be deducted a limited number of times. The resources corresponding to the unlimited use parameters can be considered to be unlimited. In the embodiment of the present invention, the meaning of unlimited is that the resources are sufficient so that the implementation results of distributed transactions will not be affected by resource exhaustion. For example, the message sent to the user is an unlimited resource parameter, that is, it can be considered that any number of messages can be sent without the problem of exhaustion of the resources corresponding to the message.

[0066] Accordingly, the idempotent task is executed in the distributed transaction, such as Figure 5 As shown, including:

[0067] S1071. Determine whether there are infinite usage parameters in the idempotent task.

[0068] S1073. If there is no infinite usage parameter, execute the idempotent task in the distributed transaction according to the first execution strategy.

[0069] Since each parameter in the idempotent task is a limited-use parameter, consumption failure may occur, so it is necessary to pre-withhold the resources pointed to by the limited-use parameters (the embodiment of the present invention refers to the pre-withholding parameters). After the idempotent task starts, it first pre-withholds each limited-use resource. If successful, the limited-use resources corresponding to the limited-use parameters are actually used (the embodiment of the present invention refers to the consumption parameters). If it fails, the pre-withheld limited-use resources are released (the embodiment of the present invention refers to the release parameters). If an accident occurs during the process of pre-withholding, consumption, and release, the idempotent task can ensure that the data corresponding to each service has final data consistency.

[0070] In the embodiment of the present invention, the withholding, consumption and release of each parameter can be achieved by calling the service pointed to by the parameter.

[0071] During the execution of idempotent tasks, the consumption and release of limited-use parameters will cause changes in the data corresponding to the corresponding services. For example, if idempotent consumption is to deduct 500 yuan from the user, the data of the user account corresponding to the payment service will be reduced by 500. If idempotent release is used, the data of the user account corresponding to the payment service will remain unchanged, while withholding will only cause the payment service to freeze 500 yuan in the user account and will not cause changes in the account data. For the payment service, the corresponding actions of withholding, consumption and release are freezing account funds, deducting account funds and restoring frozen account funds.

[0072] Specifically, the idempotent task is executed in the distributed transaction according to the first execution strategy, such as Figure 6 As shown, including:

[0073] S10731. The transaction management process marks the state of the distributed transaction as an execution state, and the distributed transaction is created by the transaction management process.

[0074] S10733. Push the idempotent task into the idempotent task execution manager.

[0075] In a preferred embodiment, the result of the idempotent task being pushed into the task execution manager can also be fed back to the transaction management process.

[0076] Specifically, the idempotent task execution manager is used to execute one or more idempotent tasks according to a preset management policy. If business requests are centrally acquired, the embodiment of the present invention will also centrally generate idempotent tasks for each business request, and each idempotent task is pushed into the idempotent task execution manager to be executed according to the preset management policy.

[0077] In a feasible embodiment, the idempotent task execution manager can be a queue, which pushes the newly generated idempotent task into the tail of the queue, and extracts the idempotent task at the head of the queue in sequence according to the first-in-first-out principle of the queue for execution, so as to achieve the purpose of executing idempotent tasks according to a preset management strategy.

[0078] S10735. The transaction management process starts executing the distributed transaction to trigger the execution of the idempotent task, withholds various parameters in the idempotent task, and modifies the state of the distributed transaction according to the withholding result.

[0079] Specifically, if all parameters are successfully pre-withheld, the state of the distributed transaction is modified to a normal execution state; if at least one of the parameters fails to be pre-withheld, the state of the distributed transaction is modified to an abnormal execution state.

[0080] S10737. Continue to execute the idempotent task according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, return the execution result of the idempotent task.

[0081] After the idempotent task is executed, it is cleared from the idempotent task execution manager.

[0082] Specifically, the idempotent task is continued to be executed according to the state of the distributed transaction, such as Figure 7 As shown, including:

[0083] S107371. If the state of the distributed transaction is a normal execution state, the idempotent consumption of each parameter in the idempotent task is performed cyclically until each parameter is consumed successfully, and the state of the distributed task is modified to an end state.

[0084] S107373. If the state of the distributed transaction is an abnormal execution state, the idempotent release of each parameter in the idempotent task is performed cyclically until all parameters are released, and the state of the distributed task is modified to the end state.

[0085] S1075. If there is an infinite usage parameter, execute the idempotent task in the distributed transaction according to the second execution strategy.

[0086] Since there are unlimited usage parameters and unlimited usage parameters will not cause consumption failure, it is only necessary to withhold the limited usage parameters in the idempotent task.

[0087] Specifically, the idempotent task is executed in the distributed transaction according to the second execution strategy, such as Figure 8 As shown, including:

[0088] S10751. The transaction management process marks the state of the distributed transaction as an execution state, and the distributed transaction is created by the transaction management process.

[0089] S10753. Push the idempotent task into the idempotent task execution manager.

[0090] In a preferred embodiment, the result of the idempotent task being pushed into the task execution manager can also be fed back to the transaction management process.

[0091] S10755. The transaction management process starts executing the distributed transaction to trigger the execution of the idempotent task, withholds each limited-use parameter in the idempotent task, and modifies the state of the distributed transaction according to the withholding result.

[0092] Specifically, if all limited-use parameters are successfully pre-withheld, the state of the distributed transaction is modified to a normal execution state; if at least one of the limited-use parameters fails to be pre-withheld, the state of the distributed transaction is modified to an abnormal execution state.

[0093] S10757. Continue to execute the idempotent task according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, return the execution result of the idempotent task.

[0094] After the idempotent task is executed, it is cleared from the idempotent task execution manager.

[0095] Specifically, the idempotent task is continued to be executed according to the state of the distributed transaction, such as Fig. 9 As shown, including:

[0096] S107571. If the state of the distributed transaction is a normal execution state, the idempotent consumption of each parameter in the idempotent task is performed cyclically until each parameter is consumed successfully, and the state of the distributed task is modified to an end state.

[0097] S107573. If the state of the distributed transaction is an abnormal execution state, the idempotent release of each limited-use parameter in the idempotent task is performed cyclically until all limited-use parameters are released, and the state of the distributed task is modified to the end state.

[0098] In another feasible embodiment, limited use resources may not be withheld. Specifically, the idempotent task is executed in the distributed transaction according to the second execution strategy, such as Fig.10 As shown, including:

[0099] S10752. The transaction management process marks the state of the distributed transaction as an execution state, and the distributed transaction is created by the transaction management process.

[0100] S10754. Push the idempotent task into the idempotent task execution manager.

[0101] S10756. Consume each limited-use parameter in the idempotent task. If each limited-use parameter is consumed successfully, the distributed transaction state is modified to a normal state. If at least one of the limited-use parameters fails to be consumed, the distributed transaction state is modified to an abnormal state.

[0102] S10758. Continue to execute the idempotent task according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, return the execution result of the idempotent task.

[0103] After the idempotent task is executed, it is cleared from the idempotent task execution manager.

[0104] Specifically, executing the idempotent task according to the state of the distributed transaction includes:

[0105] S107581. If the state of the distributed transaction is a normal execution state, then the idempotent consumption of each infinitely used parameter in the idempotent task is performed cyclically until each parameter is consumed successfully, and the state of the distributed task is modified to an end state.

[0106] S107583. If the state of the distributed transaction is an abnormal execution state, the idempotent rollback is performed cyclically on each limited-use parameter in the idempotent task until all limited-use parameters are rolled back, and the state of the distributed task is modified to the end state.

[0107] Rollback can be regarded as the reverse operation of consumption. For example, in the payment system, if 500 yuan is consumed, the user account funds will be reduced by 500 yuan. If 500 yuan is rolled back, the user account funds will be increased by 500 yuan. If rollback and consumption are performed for the same limited use parameter, the limited use resource pointed to by the limited use parameter can be regarded as not changed in the end.

[0108] The embodiment of the present invention discloses a method for ensuring the final data consistency of distributed transactions, which obtains various parameters required for implementing distributed transactions, and generates and executes idempotent tasks based on the parameters, so that after the idempotent tasks are executed, all relevant data participating in the distributed transactions have final data consistency, and no reconciliation processing is required, thereby significantly reducing the time required to reach the final data consistency state, while ensuring a high success rate for executing distributed transactions, reducing time lag, and significantly improving user stickiness. The embodiment of the present invention can be widely used in various scenarios that require the use of distributed transactions, such as various scenarios that require payment.

[0109] like Fig.11 As shown, it shows a logical schematic diagram of a method for ensuring the final data consistency of a distributed transaction in an embodiment of the present invention. Since each action in the process of executing an idempotent task is idempotent, it can be ensured that the parameters involved in the idempotent task ultimately point to the same result, that is, if A fails to be used, B also fails to be used, and if A is used successfully, B is also used successfully. It can be seen that when the idempotent task is completed, the data involved in the distributed transaction are eventually consistent.

[0110] The embodiment of the present invention also provides a device for ensuring the final data consistency of a distributed transaction, such as Fig.12 As shown, the device comprises:

[0111] The service set acquisition module 201 is used to acquire a service request and acquire a service set consisting of various services associated with the service request, wherein the service set includes at least two services;

[0112] A parameter set acquisition module 203, configured to acquire parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and to obtain a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set;

[0113] An idempotent task generating module 205, used for generating an idempotent task according to the parameter set, wherein the idempotent task is used for performing an idempotent operation on each parameter in the parameter set;

[0114] The idempotent task execution module 207 is used to generate a distributed transaction for processing the business request, execute the idempotent task in the distributed transaction, and return the execution result of the idempotent task.

[0115] Specifically, the device and method embodiments for ensuring final data consistency of distributed transactions described in the embodiments of the present invention are based on the same inventive concept. For details, please refer to the method embodiment, which will not be repeated here.

[0116] The embodiment of the present invention further provides a computer storage medium, which can store multiple instructions. The instructions can be suitable for being loaded by a processor and executing a method for ensuring the final data consistency of a distributed transaction according to an embodiment of the present invention, the method comprising at least the following steps:

[0117] A method for ensuring final data consistency of a distributed transaction, the method comprising:

[0118] Obtaining a service request, and obtaining a service set consisting of various services associated with the service request, wherein the service set includes at least two services;

[0119] Acquire parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and obtain a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set;

[0120] Generate an idempotent task according to the parameter set, where the idempotent task is used to perform an idempotent operation on each parameter in the parameter set;

[0121] A distributed transaction is generated for processing the business request, the idempotent task is executed in the distributed transaction, and the execution result of the idempotent task is returned.

[0122] In a preferred embodiment, executing the idempotent task in the distributed transaction includes:

[0123] Determine whether there is an infinite usage parameter in the idempotent task;

[0124] If there is no infinite usage parameter, executing the idempotent task in the distributed transaction according to the first execution strategy;

[0125] If there is an infinite usage parameter, the idempotent task is executed in the distributed transaction according to the second execution strategy.

[0126] In a preferred embodiment, executing the idempotent task in the distributed transaction according to the first execution strategy includes:

[0127] The transaction management process marks the state of the distributed transaction as an execution state, and the distributed transaction is created by the transaction management process;

[0128] The transaction management process starts executing the distributed transaction to trigger the execution of the idempotent task, withholds various parameters in the idempotent task, and modifies the state of the distributed transaction according to the withholding result;

[0129] The idempotent task continues to be executed according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, the execution result of the idempotent task is returned.

[0130] In a preferred embodiment, the step of continuing to execute the idempotent task according to the state of the distributed transaction includes:

[0131] If the state of the distributed transaction is a normal execution state, the idempotent consumption of each parameter in the idempotent task is performed cyclically until each parameter is consumed successfully, and the state of the distributed task is changed to an end state;

[0132] If the state of the distributed transaction is an abnormal execution state, the idempotent release of each parameter in the idempotent task is performed cyclically until each parameter is released, and the state of the distributed task is modified to an end state.

[0133] In a preferred embodiment, executing the idempotent task in the distributed transaction according to the second execution strategy includes:

[0134] The transaction management process marks the state of the distributed transaction as an execution state, and the distributed transaction is created by the transaction management process;

[0135] The transaction management process starts executing the distributed transaction to trigger the execution of the idempotent task, withholds each limited-use parameter in the idempotent task, and modifies the state of the distributed transaction according to the withholding result;

[0136] The idempotent task continues to be executed according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, the execution result of the idempotent task is returned.

[0137] In a preferred embodiment, the step of continuing to execute the idempotent task according to the state of the distributed transaction includes:

[0138] If the state of the distributed transaction is a normal execution state, the idempotent consumption of each parameter in the idempotent task is performed cyclically until each parameter is consumed successfully, and the state of the distributed task is changed to an end state;

[0139] If the state of the distributed transaction is an abnormal execution state, the idempotent release of each limited-use parameter in the idempotent task is performed cyclically until each limited-use parameter is released, and the state of the distributed task is modified to an end state.

[0140] In a preferred embodiment, executing the idempotent task in the distributed transaction according to the second execution strategy includes:

[0141] The transaction management process marks the state of the distributed transaction as an execution state, and the distributed transaction is created by the transaction management process;

[0142] Consume each limited-use parameter in the idempotent task. If each limited-use parameter is consumed successfully, modify the distributed transaction state to a normal state. If at least one of the limited-use parameters fails to be consumed, modify the distributed transaction state to an abnormal state.

[0143] The idempotent task continues to be executed according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, the execution result of the idempotent task is returned.

[0144] In a preferred embodiment, the step of continuing to execute the idempotent task according to the state of the distributed transaction includes:

[0145] If the state of the distributed transaction is a normal execution state, the idempotent consumption is performed on each infinitely used parameter in the idempotent task in a loop until each parameter is consumed successfully, and the state of the distributed task is changed to an end state;

[0146] If the state of the distributed transaction is an abnormal execution state, the idempotent rollback is performed cyclically on each limited-use parameter in the idempotent task until all limited-use parameters are rolled back, and the state of the distributed task is modified to the end state.

[0147] Further, Fig.13 A schematic diagram of the hardware structure of a device for implementing the method provided by an embodiment of the present invention is shown, and the device may participate in constituting or include the apparatus or system provided by an embodiment of the present invention. Fig.13As shown, the device 10 may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Fig.13 The structure shown is for illustration only and does not limit the structure of the electronic device. Fig.13 More or fewer components as shown, or with Fig.13 Different configurations are shown.

[0148] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the device 10 (or mobile device). As involved in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0149] The memory 104 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, to implement the above-mentioned method of ensuring the final data consistency of distributed transactions. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the device 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0150] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the device 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.

[0151] The display may be, for example, a touch screen liquid crystal display (LCD) that may enable a user to interact with a user interface of device 10 (or mobile device).

[0152] It should be noted that the sequence of the embodiments of the present invention described above is for description only and does not represent the advantages and disadvantages of the embodiments. The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0153] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and server embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.

[0154] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0155] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for ensuring final data consistency of distributed transactions, characterized in that: The method comprises: Obtaining a service request, and obtaining a service set consisting of various services associated with the service request, wherein the service set includes at least two services; Acquire parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and obtain a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set; Generate an idempotent task according to the parameter set, where the idempotent task is used to perform an idempotent operation on each parameter in the parameter set; Generate a distributed transaction for processing the business request, execute the idempotent task in the distributed transaction, and return the execution result of the idempotent task; Wherein, executing the idempotent task in the distributed transaction includes: Determine whether there is an infinite usage parameter in the idempotent task; If there is no infinite use parameter, the idempotent task is executed in the distributed transaction according to the first execution strategy; wherein, the idempotent task is executed in the distributed transaction according to the first execution strategy, including: marking the state of the distributed transaction as an execution state by the transaction management process, and the distributed transaction is created by the transaction management process; the transaction management process starts to execute the distributed transaction to trigger the execution of the idempotent task, withholds various parameters in the idempotent task, and modifies the state of the distributed transaction according to the withholding result; continues to execute the idempotent task according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, returns the execution result of the idempotent task; If there are unlimited usage parameters, the idempotent task is executed in the distributed transaction according to the second execution strategy; wherein, the execution of the idempotent task in the distributed transaction according to the second execution strategy includes: marking the state of the distributed transaction as an execution state by a transaction management process, and the distributed transaction is created by the transaction management process; starting the execution of the distributed transaction by the transaction management process to trigger the execution of the idempotent task, withholding each limited usage parameter in the idempotent task, and modifying the state of the distributed transaction according to the withholding result; continuing to execute the idempotent task according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, returning the execution result of the idempotent task.

2. The method according to claim 1, characterized in that The continuing to execute the idempotent task according to the state of the distributed transaction includes: If the state of the distributed transaction is a normal execution state, the idempotent consumption is performed on each parameter in the idempotent task in a loop until each parameter is successfully consumed, and the state of the distributed transaction is changed to an end state; If the state of the distributed transaction is an abnormal execution state, the idempotent release is performed cyclically on each parameter in the idempotent task until each parameter is released, and the state of the distributed transaction is modified to an end state.

3. The method according to claim 1, characterized in that The continuing to execute the idempotent task according to the state of the distributed transaction includes: If the state of the distributed transaction is a normal execution state, the idempotent consumption is performed on each parameter in the idempotent task in a loop until each parameter is successfully consumed, and the state of the distributed transaction is changed to an end state; If the state of the distributed transaction is an abnormal execution state, the idempotent release of each limited-use parameter in the idempotent task is performed cyclically until each limited-use parameter is released, and the state of the distributed transaction is modified to an end state.

4. The method according to claim 1, characterized in that: Executing the idempotent task in the distributed transaction according to the second execution strategy includes: The transaction management process marks the state of the distributed transaction as an execution state, and the distributed transaction is created by the transaction management process; Consume each limited-use parameter in the idempotent task. If each limited-use parameter is consumed successfully, modify the distributed transaction state to a normal state. If at least one of the limited-use parameters fails to be consumed, modify the distributed transaction state to an abnormal state. The idempotent task continues to be executed according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, the execution result of the idempotent task is returned.

5. The method according to claim 4, characterized in that The continuing to execute the idempotent task according to the state of the distributed transaction includes: If the state of the distributed transaction is a normal execution state, the idempotent consumption is performed on each infinitely used parameter in the idempotent task in a loop until each parameter is consumed successfully, and the state of the distributed transaction is changed to an end state; If the state of the distributed transaction is an abnormal execution state, the idempotency rollback is performed cyclically on each limited-use parameter in the idempotent task until all limited-use parameters are rolled back, and the state of the distributed transaction is modified to an end state.

6. A device for ensuring final data consistency of distributed transactions, characterized in that: The device comprises: A service set acquisition module, used to acquire a service request and acquire a service set consisting of various services associated with the service request, wherein the service set includes at least two services; A parameter set acquisition module, used to acquire parameters of each service related to the business request to obtain a parameter subset corresponding to the service, and obtain a parameter set corresponding to the service set based on the parameter subsets corresponding to each service in the service set; An idempotent task generation module, used for generating an idempotent task according to the parameter set, wherein the idempotent task is used for performing an idempotent operation on each parameter in the parameter set; An idempotent task execution module, used to generate a distributed transaction for processing the business request, execute the idempotent task in the distributed transaction, and return the execution result of the idempotent task; Wherein, executing the idempotent task in the distributed transaction includes: Determine whether there is an infinite usage parameter in the idempotent task; If there is no infinite use parameter, the idempotent task is executed in the distributed transaction according to the first execution strategy; wherein, the idempotent task is executed in the distributed transaction according to the first execution strategy, including: marking the state of the distributed transaction as an execution state by the transaction management process, and the distributed transaction is created by the transaction management process; the transaction management process starts to execute the distributed transaction to trigger the execution of the idempotent task, withholds various parameters in the idempotent task, and modifies the state of the distributed transaction according to the withholding result; continues to execute the idempotent task according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, returns the execution result of the idempotent task; If there are unlimited usage parameters, the idempotent task is executed in the distributed transaction according to the second execution strategy; wherein, the execution of the idempotent task in the distributed transaction according to the second execution strategy includes: marking the state of the distributed transaction as an execution state by a transaction management process, and the distributed transaction is created by the transaction management process; starting the execution of the distributed transaction by the transaction management process to trigger the execution of the idempotent task, withholding each limited usage parameter in the idempotent task, and modifying the state of the distributed transaction according to the withholding result; continuing to execute the idempotent task according to the state of the distributed transaction, and when the state of the distributed transaction is modified to the end state, returning the execution result of the idempotent task.

7. A computer storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement a method for ensuring the final data consistency of distributed transactions as described in any one of claims 1-5.

Citation Information

Patent Citations

  • Service processing method and apparatus

    CN109063027A