Transaction processing method, device, equipment and storage medium
Through the unified management of data changes in transaction objects and the use of transaction identifiers to achieve data fallback, the complex problem of data consistency management in business systems is solved, the system efficiency is improved and the defect of data inconsistency is avoided.
Patent Information
- Application Number
- CN202111567500.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2041-12-20
AI Technical Summary
In the business system, some data is not stored in the database, resulting in complex data consistency management, and multiple logical judgments are required when handling exceptions, which easily lead to system defects in data inconsistent and reduce system efficiency.
Through transaction objects, all data changes in a transaction are managed uniformly, and data change records are used to achieve data backing of the entire transaction, ensuring data consistency and improving system efficiency.
Effectively manage data consistency, simplify the data fallback process, improve system efficiency, and avoid system defects of data inconsistent.
Smart Images

Figure CN114255004B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of transaction processing, and in particular to a transaction processing method, apparatus, device and storage medium. Background Art
[0002] When processing user operations or business events, business systems will be divided into multiple steps to affect multiple types of data. Since the data in business systems are usually strongly logically related to each other, how to maintain data consistency is an issue that needs to be considered in business systems.
[0003] Currently, some data in the business process is not saved in the database. In this case, the business system needs to manage the consistency of some data by itself. When an exception occurs during the processing, it requires a lot of logic to determine which data needs to be rolled back and which does not. At the same time, it is also necessary to determine the rollback amount of each data separately. This not only easily leads to system defects such as inconsistent data, but also leads to low system efficiency. Summary of the invention
[0004] Based on this, it is necessary to provide a transaction processing method, device, equipment and storage medium to address the above technical problems. All data changes in a transaction are uniformly managed through transaction objects. When the business process requires data rollback, the data change record stored in the transaction object corresponding to the transaction identifier is used to implement data rollback of the entire transaction, thereby ensuring data consistency and improving system efficiency.
[0005] In a first aspect, the present application provides a transaction processing method, the method comprising:
[0006] Receive a first operation request, the first operation request including a transaction identifier of a target transaction, the target transaction including at least one execution step, and the execution step is used to instruct to perform a corresponding data modification operation on a data source object;
[0007] When the first operation request is a data rollback operation request, a transaction object associated with the transaction identifier is obtained, wherein the transaction object includes a data change record corresponding to at least one data source object, and the data change record corresponding to the at least one data source object is a data change record generated by an execution step that has been completed when executing the target transaction;
[0008] According to the data change record respectively corresponding to the at least one data source object, the value of the at least one data source object is changed to an initial value.
[0009] In combination with the first aspect, in some embodiments, after changing the value of the at least one data source object to an initial value, the method further includes:
[0010] In the case where the value of each data source object in the at least one data source object is successfully changed to the initial value, deleting the transaction object associated with the transaction identifier;
[0011] In the case where the value of any one of the at least one data source object fails to be changed to the initial value, the failure record of any one of the at least one data source object is obtained and the transaction object associated with the transaction identifier is deleted. In combination with the first aspect, in some embodiments, before receiving the first operation request, the method further includes:
[0012] receiving a second operation request, where, when the second operation request is a data modification operation request, the second operation request includes a transaction identifier of the target transaction, an object identifier of the modified data source object, and a change record of the data source object;
[0013] Acquire a transaction object associated with the transaction identifier, and store data change records corresponding to the at least one data source object in the transaction object. The data change records corresponding to the at least one data source object include the object identifier of the data source object and the change record of the data source object.
[0014] In combination with the first aspect, in some embodiments, storing in the transaction object the object identifier of the data change record data source object respectively corresponding to the at least one data source object and the change record of the data source object includes:
[0015] Use the object identifier of the above data source object as a key in a key-value pair;
[0016] Record the changes of the above data source object as the value of the above key-value pair;
[0017] The key-value pair is stored in the transaction object.
[0018] In combination with the first aspect, in some embodiments, after receiving the first operation request, the method further includes:
[0019] When the first operation request is a transaction submission operation request, a transaction object associated with the transaction identifier is obtained, and the transaction object is deleted.
[0020] In combination with the first aspect, in some embodiments, before receiving the first operation request, the method further includes:
[0021] When an execution instruction for a target transaction is received, a transaction object corresponding to the target transaction is created.
[0022] In combination with the first aspect, in some embodiments, after receiving the first operation request, the method further includes:
[0023] Obtaining the operation type identifier in the first operation request;
[0024] If the operation type identifier is the first operation type identifier, determining that the first operation request is a data rollback operation request;
[0025] If the operation type identifier is the second operation type identifier, it is determined that the first operation request is a transaction commit operation request.
[0026] In a second aspect, the present application provides a transaction processing device, the device comprising:
[0027] A receiving unit, configured to receive a first operation request, wherein the first operation request includes a transaction identifier of a target transaction, and the target transaction includes at least one execution step, wherein the execution step is used to instruct execution of a corresponding data modification operation on a data source object;
[0028] an acquisition unit, configured to acquire a transaction object associated with the transaction identifier when the first operation request is a data rollback operation request, wherein the transaction object includes a data change record corresponding to at least one data source object, and the data change record corresponding to the at least one data source object is a data change record generated by an execution step that has been completed when executing the target transaction;
[0029] The changing unit is used to change the value of the at least one data source object to an initial value according to the data change record respectively corresponding to the at least one data source object.
[0030] In conjunction with the second aspect, in some embodiments, the apparatus further includes a deleting unit:
[0031] The deleting unit is configured to delete the transaction object associated with the transaction identifier when the value of each data source object in the at least one data source object is successfully changed to the initial value;
[0032] The above-mentioned deleting unit is also used to obtain the failure record of any one of the above-mentioned at least one data source object and delete the above-mentioned transaction object associated with the above-mentioned transaction identifier when the value of any one of the above-mentioned at least one data source object fails to be changed to the initial value.
[0033] In conjunction with the second aspect, in some embodiments, the device further includes a storage unit:
[0034] The receiving unit is further used to receive a second operation request. When the second operation request is a data modification operation request, the second operation request includes a transaction identifier of the target transaction, an object identifier of the modified data source object, and a change record of the data source object.
[0035] The storage unit is used to obtain the transaction object associated with the transaction identifier, and store the data change record corresponding to the at least one data source object in the transaction object, wherein the data change record corresponding to the at least one data source object includes the object identifier of the data source object and the change record of the data source object. In conjunction with the second aspect, in some embodiments, the storage unit is specifically used to:
[0036] Use the object identifier of the above data source object as a key in a key-value pair;
[0037] Record the changes of the above data source object as the value of the above key-value pair;
[0038] The key-value pair is stored in the transaction object. In conjunction with the second aspect, in some embodiments, the apparatus further includes:
[0039] The deleting unit is further configured to, when the first operation request is a transaction submission operation request, obtain a transaction object associated with the transaction identifier and delete the transaction object.
[0040] In conjunction with the second aspect, in some embodiments, the apparatus further includes a creating unit:
[0041] The creation unit is used to create a transaction object corresponding to the target transaction when receiving an execution instruction for the target transaction.
[0042] In conjunction with the second aspect, in some embodiments, the apparatus further includes a determining unit:
[0043] The acquisition unit is further used to acquire the operation type identifier in the first operation request;
[0044] The determination unit is configured to determine, if the operation type identifier is the first operation type identifier, that the first operation request is a data rollback operation request;
[0045] The determination unit is further configured to determine, if the operation type identifier is a second operation type identifier, that the first operation request is a transaction commit operation request.
[0046] In a third aspect, the present application provides a computer device comprising a processor, a memory, and a communication interface, wherein the processor, the memory, and the communication interface are interconnected, wherein the communication interface is used to receive and send data, the memory is used to store program code, and the processor is used to call the program code to execute the method described in the first aspect and any possible implementation method of the first aspect.
[0047] In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program; when the computer program runs on one or more processors, the terminal device executes the method described in the first aspect and any possible implementation of the first aspect.
[0048] In an embodiment of the present application, an operation request sent by a business process is received. When the operation request is a data rollback operation request, a transaction object corresponding to the transaction identifier in the operation request is obtained, and the value of the at least one data source object is changed to an initial value according to the data change records corresponding to the at least one data source object that successfully performs the data change operation in the target transaction stored in the transaction object. In an embodiment of the present application, all data changes in a transaction are uniformly managed through a transaction object. When the business process needs to perform data rollback, data rollback of the entire transaction is implemented through the data change records stored in the transaction object corresponding to the transaction identifier, thereby ensuring data consistency and improving system efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments are briefly introduced below.
[0050] Figure 1 A flowchart of a transaction processing method provided in an embodiment of the present application;
[0051] Figure 2 A flowchart of another transaction processing method provided in an embodiment of the present application;
[0052] Figure 3 A schematic diagram of the system architecture of the transaction processing method provided in the embodiment of the present application;
[0053] Figure 4 A schematic diagram of a transaction processing device provided in an embodiment of the present application;
[0054] Figure 5 A schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] The present invention is further described in detail below in conjunction with the accompanying drawings.
[0056] The embodiments of the present application are used to uniformly manage transactions through a transaction manager. In order to more clearly describe the solution of the present invention, the following first introduces some of the knowledge involved in the transaction processing method, device, equipment and storage medium provided by the embodiments of the present application. Among them, a transaction generally refers to something to be done or done, and is composed of all operations performed between the start of the transaction and the end of the transaction. In computer terms, it refers to a program execution unit that accesses and may update various data items in a database. Transactions are usually caused by the execution of user programs written in high-level database manipulation languages or programming languages. In a distributed transaction, each participating resource has a local transaction manager to track incoming and outgoing transactions on this computer.
[0057] XA: refers to the specification of distributed transaction processing. The XA specification mainly defines the interface between the transaction manager and the local resource manager. A two-phase commit method is used to manage distributed transactions. In the embodiment of the present application, the data source object inherits from the XA resource object to support virtual transactions.
[0058] Thread local variables: Mainly used as a means to solve Java concurrency problems, by storing thread local variables, resources between threads can be isolated to avoid concurrency problems caused by multiple threads accessing shared variables.
[0059] An embodiment of the present application provides a transaction processing method. In order to more clearly describe the solution of the present application, some drawings involved in the present application are further introduced below.
[0060] See also Figure 1 , Figure 1 A flowchart of a transaction processing method provided in an embodiment of the present application. Figure 1 As shown, the method comprises the following steps:
[0061] S101, receiving a first operation request, wherein the first operation request includes a transaction identifier of a target transaction, and the target transaction includes at least one execution step, and the execution step is used to instruct execution of a corresponding data modification operation on a data source object.
[0062] In an embodiment of the present application, the first operation request is a request sent when a business process needs to perform a certain operation on a target transaction, and the operation may include a data rollback operation and a transaction commit operation. The target transaction is a transaction that the business process needs to complete, and may include at least one execution step. The transaction identifier is a thread-local variable used to represent the identity identifier of the target transaction, and the thread-local variable is used to isolate operations between the current thread and other threads.
[0063] Optionally, at least one of the above-mentioned execution steps is interrelated and has a sequential logic, and the above-mentioned data source object is an object that needs to perform a data change operation in an execution step. For example, when user A buys fund B with 500 yuan, a transaction is opened, and the transaction includes execution step 1 "user A's account decreases by 500 yuan", execution step 2 "the platform to which fund B belongs increases by 500 yuan", and execution step 3 "user A's share of fund B increases by 500 yuan". In the above three execution steps, the data source object of the above-mentioned execution step 1 is "user A's account", and the data change operation is "decrease by 500 yuan", the data source object of the above-mentioned execution step 2 is "the platform to which fund B belongs", and the data change operation is "increase by 500 yuan", and the data source object of the above-mentioned execution step 3 is "user A's share of fund B", and the data change operation is "increase by 500 yuan". The above three execution steps need to be executed in sequence to complete the above transaction.
[0064] S102, when the above-mentioned first operation request is a data rollback operation request, obtain the transaction object associated with the above-mentioned transaction identifier, the above-mentioned transaction object includes data change records corresponding to at least one data source object, and the data change records corresponding to the above-mentioned at least one data source object are data change records generated by the execution steps that have been executed when executing the above-mentioned target transaction.
[0065] S103: Change the value of the at least one data source object to an initial value according to the data change record respectively corresponding to the at least one data source object.
[0066] In an embodiment of the present application, if any execution step in the above-mentioned target transaction fails to execute, the business process performs a data rollback operation and sends a data rollback operation request to the transaction manager. The transaction manager obtains the corresponding transaction object according to the transaction identifier in the above-mentioned operation request. The transaction object is used to uniformly manage the changes of the data source object in the above-mentioned target transaction and store data change records. The above-mentioned data change record is generated when an execution step is successfully executed, that is, the data source object in the execution step successfully executes the corresponding data change operation. The above-mentioned data change record includes the object identifier of the above-mentioned data source object and the change record of the above-mentioned data source object, and the change record includes the initial value and the changed value of the above-mentioned data source object. The above-mentioned initial value is the value when the above-mentioned data source object does not execute the data change operation, and the above-mentioned changed value is the value after the above-mentioned data source object successfully executes the above-mentioned data change operation.
[0067] Optionally, the transaction manager finds the corresponding at least one data source object according to the data change record corresponding to the at least one data source object, calls the data rollback interface of the at least one data source object, and passes the data change record corresponding to the at least one data source object. The at least one data source object changes its value to the initial value according to its corresponding data change record. Exemplarily, in the transaction, for example, after the execution of the above step 3, the share of fund B owned by user A has not increased by 500 yuan, indicating that the execution of the above step 3 has failed, and the transaction needs to be rolled back. The business process sends a data rollback operation request, and the transaction manager receives the data rollback operation request and obtains the corresponding transaction object, which includes the data change record of the data source object in the execution step 1 and the data change record of the data source object in the execution step 2. For example, the account of user A has an initial value of 1,000 yuan. After the execution of step 1 is successful, the account of user A has a changed value of 500 yuan. The data change record of the data source object in the execution step 1 includes the account identifier of user A and the above initial value and the above changed value. For example, the platform of Fund B has an initial value of 1,000 yuan. After executing step 2 successfully, the platform of Fund B has a changed value of 1,500 yuan. The data change record of the data source object in the above step 2 includes the platform identifier of Fund B and the above initial value and the above changed value. When performing a data rollback operation, the account of user A needs to change the value to the initial value of 1,000 yuan according to the data change record of the data source object in the above step 1, and the platform of Fund B needs to change the value to the initial value of 1,000 yuan according to the data change record of the data source object in the above step 2.
[0068] Furthermore, after all the above data source objects are successfully rolled back, it means that the transaction execution has failed, and the operation is stopped. The corresponding transaction object is no longer needed to manage the changes in the data in the transaction, and the transaction object corresponding to the above transaction is deleted through the transaction manager.
[0069] Please refer to Figure 2 , is a flow chart of another transaction processing method provided in an embodiment of the present application. Figure 2 As shown, the method comprises the following steps:
[0070] S201, when receiving an execution instruction for a target transaction, creating a transaction object corresponding to the target transaction.
[0071] Optionally, the target transaction is called by the business process in an explicit transaction mode, which is used to explicitly specify the start of a transaction. The target transaction can be started by calling con.BeginTransaction(). The execution instruction is an instruction sent by the business process to the transaction manager when the execution step in the target transaction is executed for the first time, indicating that the transaction has been started. The transaction manager creates a transaction object associated with the target transaction according to the execution instruction.
[0072] S202, receiving a second operation request. When the second operation request is a data change operation request, the second operation request includes a transaction identifier of the target transaction, obtains a transaction object associated with the transaction identifier, and stores data change records corresponding to the at least one data source object in the transaction object.
[0073] Optionally, after the business process successfully performs a data change operation on the data source object, the data source object calls its corresponding change interface to generate a data change record. The second operation request includes a data change record, which includes the object identifier of the data source object and the change record of the data source object. The data change record is stored in the transaction object associated with the transaction identifier in the form of a key-value pair. Specifically, the object identifier is used as the key in the key-value pair, and the change record is used as the pair in the key-value pair.
[0074] For example, after step 1 is successfully executed in the transaction of step S101, the data change record generated for the account of user A includes the account ID and change record of user A. Optionally, the format of the change record is set in advance by the developer, which may be "1000 (initial value) → 500 (changed value)" or "1000 (initial value), 500 (changed value)".
[0075] S203, receiving a first operation request, wherein the first operation request includes a transaction identifier of a target transaction, and the target transaction includes at least one execution step, and the execution step is used to instruct execution of a corresponding data modification operation on a data source object.
[0076] For step S203 of this embodiment of the present application, please refer to Figure 1 The description of step S101 of the embodiment will not be repeated here.
[0077] S204, obtaining the operation type identifier in the first operation request; if the operation type identifier is the first operation type identifier, determining that the first operation request is a data rollback operation request; if the operation type identifier is the second operation type identifier, determining that the first operation request is a transaction commit operation request.
[0078] Optionally, the above operation type identifier is pre-set by the developer and may include various information such as text, numbers, symbols, etc. For example, by setting keywords, "rollback" is set as the first operation type identifier, and "submit" is set as the second operation type identifier. For example, by setting numbers, "01" is set as the first operation type identifier, and "02" is set as the second operation type identifier. By setting the operation type identifier, the type of the above first operation request can be determined, and further subsequent operations can be performed.
[0079] S205. When the first operation request is a data rollback operation request, obtain a transaction object associated with the transaction identifier. The transaction object includes data change records corresponding to at least one data source object. The data change records corresponding to the at least one data source object are data change records generated by the execution steps that have been completed when executing the target transaction.
[0080] S206: Change the value of the at least one data source object to an initial value according to the data change record corresponding to the at least one data source object.
[0081] For steps S204-S205 of this embodiment of the present application, please refer to Figure 1 The description of steps S102-S103 of the embodiment will not be repeated here.
[0082] S207, when the value of each of the at least one data source object is successfully changed to the initial value, delete the transaction object associated with the transaction identifier; when the value of any one of the at least one data source object fails to be changed to the initial value, obtain the failure record of any one of the data source objects and delete the transaction object associated with the transaction identifier.
[0083] In an embodiment of the present application, any one of the at least one data source objects changes its value to obtain a final value, and compares the final value with the initial value. If the final value is equal to the initial value, it means that the at least one data source object has been successfully changed. If the final value is not equal to the initial value, it means that the change of any one of the at least one data source object has failed. For example, in step S103, assuming that the value of the account of user A is changed to 1,200 yuan, it means that the account of user A has failed to be changed; assuming that the value of the account of user A is changed to 1,000 yuan, and the platform of fund B is changed to 1,000 yuan, it means that both the account of user A and the platform of fund B have been changed successfully.
[0084] Exemplarily, when the at least one data source object is changed successfully, it indicates that the execution of the target transaction fails, and the transaction object associated with the transaction identifier is deleted.
[0085] Exemplarily, when the change of any one of the at least one data source objects fails, the any one data source object sends the above-mentioned failure record to the above-mentioned transaction manager, and the failure record may include the object identifier and failure identifier of the above-mentioned any one data source object. The above-mentioned failure identifier is set in advance by the developer, and the number "04" may be used to indicate that the rollback of any one of the above-mentioned data source objects fails, or keywords such as "error", "error", "failure" may be used as prompts. The above-mentioned transaction manager sends the failure record to the above-mentioned business process, and then deletes the above-mentioned transaction object associated with the above-mentioned transaction identifier.
[0086] By sending the failure record to the business process through the transaction manager, the business process or management personnel can be informed of the abnormal situation of the data source object in the entire transaction and make further processing.
[0087] S208: When the first operation request is a transaction commit operation request, obtain a transaction object associated with the transaction identifier, and delete the transaction object.
[0088] In the embodiment of the present application, if all execution steps in the target transaction are successfully executed, it indicates that the target transaction is successfully executed, and the transaction object associated with the transaction identifier is deleted.
[0089] In an embodiment of the present application, an operation request sent by a business process is received. When the operation request is a data rollback operation request, a transaction object corresponding to the transaction identifier in the operation request is obtained, and the value of the at least one data source object is changed to an initial value according to the data change records corresponding to the at least one data source object that successfully performs the data change operation in the target transaction stored in the transaction object. In an embodiment of the present application, all data changes in a transaction are uniformly managed through a transaction object. When the business process needs to perform data rollback, data rollback of the entire transaction is implemented through the data change records stored in the transaction object corresponding to the transaction identifier, thereby ensuring data consistency and improving system efficiency.
[0090] Please refer to Figure 3 , is a schematic diagram of the system architecture of the transaction processing method provided in the embodiment of the present application. Figure 3 As shown, the system architecture may include:
[0091] Business process: a series of activities completed by different people to achieve a specific value goal. Not only is there a strict sequence of activities, but the content, method, responsibility, etc. of the activities must also be clearly arranged and defined to make it possible for different activities to be transferred between different job roles. The transfer between activities in time and space can have a large span. In the embodiment of the present application, it is responsible for executing each execution step in the target transaction to complete the target transaction, and sends corresponding operation requests to the transaction manager when performing data change operations, data rollback operations, and transaction commit operations.
[0092] Data source object: inherited from the XA resource object, used to support virtual transactions, and is the target object for data change operations in each execution step. In the embodiment of the present application, data changes are made according to the data change operation request of the business process. If the data change is successful, the change interface is called to generate a data change record, which is then sent to the transaction manager. If the data change fails, the data is rolled back according to the data change record corresponding to the target object passed in by the transaction manager.
[0093] Transaction manager: used to manage the entire life cycle of transaction objects. It is responsible for creating transaction objects according to business requests and deleting transaction objects after transaction submission or data rollback. If the data change operation is successful, the data change record sent by the data source object is received and stored in the corresponding transaction object. If the data change operation fails, the rollback interface of the data source object is called and the corresponding data change record in the transaction object is passed in.
[0094] Transaction object: used to record the changes of data source objects in a virtual transaction. It is created by the transaction manager when a transaction is started. It is responsible for storing the object identifier of the data source object and the corresponding data change record after the data change operation is successful. The data change record is called after the data change operation fails. It is deleted by the transaction manager after the transaction is successfully submitted or failed.
[0095] Please refer to Figure 4 , is a schematic diagram of a transaction processing device provided in an embodiment of the present application. Figure 4 As shown, the transaction processing device may include:
[0096] The receiving unit 401 is configured to receive a first operation request, wherein the first operation request includes a transaction identifier of a target transaction, and the target transaction includes at least one execution step, and the execution step is used to instruct to perform a corresponding data modification operation on a data source object;
[0097] The acquisition unit 402 is used to acquire the transaction object associated with the transaction identifier when the first operation request is a data rollback operation request, wherein the transaction object includes a data change record corresponding to at least one data source object, and the data change record corresponding to the at least one data source object is a data change record generated by an execution step that has been completed when executing the target transaction;
[0098] The changing unit 403 is used to change the value of the at least one data source object to an initial value according to the data change record respectively corresponding to the at least one data source object.
[0099] In a possible design, the apparatus further includes a deleting unit 404:
[0100] The deleting unit 404 is configured to delete the transaction object associated with the transaction identifier when the value of each data source object in the at least one data source object is successfully changed to the initial value;
[0101] The deleting unit 404 is further configured to obtain a failure record of any one of the at least one data source objects and delete the transaction object associated with the transaction identifier when the value of any one of the at least one data source objects fails to be changed to the initial value.
[0102] In a possible design, when the operation request is a data change operation request, the operation request also includes an object identifier of the changed data source object and a change record of the data source object, and the change record includes an initial value of the data source object before the change and a changed value of the data source object after the change;
[0103] The device also includes a storage unit 405:
[0104] The receiving unit 401 is further configured to receive a second operation request. When the second operation request is a data modification operation request, the second operation request includes a transaction identifier of the target transaction, an object identifier of the modified data source object, and a change record of the data source object.
[0105] The storage unit 405 is used to obtain the transaction object associated with the transaction identifier, and store the data change records corresponding to the at least one data source object in the transaction object. The data change records corresponding to the at least one data source object include the object identifier of the data source object and the change record of the data source object.
[0106] In one possible design,
[0107] The storage unit 405 is specifically used for:
[0108] Use the object identifier of the above data source object as a key in a key-value pair;
[0109] Record the changes of the above data source object as the value of the above key-value pair;
[0110] The key-value pair is stored in the transaction object. In one possible design, the device further includes:
[0111] The deleting unit 404 is further configured to, when the first operation request is a transaction submission operation request, obtain a transaction object associated with the transaction identifier and delete the transaction object.
[0112] In a possible design, the apparatus further includes a creating unit 406:
[0113] The creation unit 406 is configured to create a transaction object corresponding to the target transaction when receiving an execution instruction for the target transaction.
[0114] In a possible design, the apparatus further includes a determining unit 407:
[0115] The acquisition unit 402 is further configured to acquire an operation type identifier in the first operation request;
[0116] The determining unit 407 is configured to determine, if the operation type identifier is the first operation type identifier, that the first operation request is a data rollback operation request;
[0117] The determining unit 407 is further configured to determine, if the operation type identifier is the second operation type identifier, that the first operation request is a transaction commit operation request.
[0118] in, Figure 4 The detailed description of the embodiment of the device shown can refer to the aforementioned Figure 1 or Figure 2 The specific description of the illustrated method embodiment will not be repeated here.
[0119] Please refer to Figure 5 , is a schematic diagram of the structure of a computer device provided in an embodiment of the present application, such as Figure 5As shown, the computer device 500 may include: at least one processor 501, such as a CPU, at least one communication interface 503, a memory 504, and at least one communication bus 502. The communication bus 502 is used to realize the connection and communication between these components. The communication interface 503 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface). The memory 504 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 504 may optionally also be at least one storage device located away from the aforementioned processor 501. As shown in FIG. Figure 5 As shown, the memory 504 as a computer storage medium may include an operating system, a network communication unit, and program instructions.
[0120] exist Figure 5 In the computer device 500 shown, the processor 501 may be used to load program instructions stored in the memory 504 and specifically perform the following operations:
[0121] Receive a first operation request, the first operation request including a transaction identifier of a target transaction, the target transaction including at least one execution step, and the execution step is used to instruct to perform a corresponding data modification operation on a data source object;
[0122] When the first operation request is a data rollback operation request, a transaction object associated with the transaction identifier is obtained, wherein the transaction object includes a data change record corresponding to at least one data source object, and the data change record corresponding to the at least one data source object is a data change record generated by an execution step that has been completed when executing the target transaction;
[0123] According to the data change record respectively corresponding to the at least one data source object, the value of the at least one data source object is changed to an initial value.
[0124] It should be noted that the specific implementation process can be found in Figure 1 The specific description of the illustrated method embodiment will not be repeated here.
[0125] The present application also provides a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded and executed by a processor as described above. Figure 1 or Figure 2 The method steps of the embodiment shown in the figure can be found in the specific implementation process. Figure 1 or Figure 2 The specific description of the illustrated embodiment will not be repeated here.
[0126] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server, a data center, etc. that contains one or more available media integration. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk), etc.
[0127] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.
Claims
1. A transaction processing method, It is characterized in that include: The transaction manager receives an execution instruction for a target transaction, and creates a transaction object corresponding to the target transaction according to the execution instruction; The execution instruction is sent to the transaction manager when the business process executes the execution step in the target transaction for the first time; the target transaction includes at least one execution step, and the execution step is used to instruct to perform a corresponding data modification operation on the data source object; After the business process successfully performs a data change operation on the data source object, the data source object calls a corresponding change interface, generates a data change record, and sends a second operation request to the transaction manager; The transaction manager receives the second operation request, where the second operation request includes the transaction identifier of the target transaction, the object identifier of the changed data source object, and a data change record, where the data change record includes the object identifier of the data source object and a change record of the data source object, where the change record includes an initial value and a changed value of the data source object; The transaction manager obtains the transaction object associated with the transaction identifier, and stores the data change record corresponding to the data source object in the transaction object; The transaction manager receives a first operation request, wherein the first operation request includes a transaction identifier of a target transaction; When the first operation request is a data rollback operation request, the transaction manager obtains a transaction object associated with the transaction identifier, wherein the transaction object includes a data change record corresponding to at least one data source object, and the data change record corresponding to the at least one data source object is a data change record generated by an execution step that has been completed when executing the target transaction; The transaction manager calls the data rollback interface of the at least one data source object and passes in the data change record corresponding to the at least one data source object; The at least one data source object changes the value of the data source object to an initial value according to the data change record.
2. The method according to claim 1, further comprising: include: In a case where the value of each data source object in the at least one data source object is successfully changed to the initial value, deleting the transaction object associated with the transaction identifier; In the case that the value of any one of the at least one data source object fails to be changed to the initial value, a failure record of the any one data source object is obtained and the transaction object associated with the transaction identifier is deleted.
3. The method according to claim 1, wherein the data change record corresponding to the data source object is stored in the transaction object. include: Using the object identifier of the data source object as a key in a key-value pair; Using the change record of the data source object as the value in the key-value pair; The key-value pair is stored in the transaction object.
4. The method according to claim 1, further comprising: include: When the first operation request is a transaction submission operation request, a transaction object associated with the transaction identifier is obtained, and the transaction object is deleted.
5. The method according to claim 4, further comprising: include: Obtaining an operation type identifier in the first operation request; If the operation type identifier is the first operation type identifier, determining that the first operation request is a data rollback operation request; If the operation type identifier is the second operation type identifier, it is determined that the first operation request is a transaction commit operation request.
6. A transaction processing device, It is characterized in that The device comprises a unit for executing the method according to any one of claims 1 to 5, the device comprising: A receiving unit, configured to receive a first operation request, wherein the first operation request includes a transaction identifier of a target transaction, wherein the target transaction includes at least one execution step, and the execution step is used to instruct to perform a corresponding data modification operation on a data source object; an acquisition unit, configured to acquire, when the first operation request is a data rollback operation request, a transaction object associated with the transaction identifier, wherein the transaction object includes a data change record corresponding to at least one data source object, and the data change record corresponding to the at least one data source object is a data change record generated by an execution step that has been completed when executing the target transaction; The changing unit is used to change the value of the at least one data source object to an initial value according to the data change record respectively corresponding to the at least one data source object.
7. A computer device, It is characterized in that It includes a processor, a memory and a communication interface, wherein the processor, the memory and the communication interface are interconnected, wherein the communication interface is used to receive and send data, the memory is used to store a computer program, and the processor is used to call the computer program to execute the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program; when the computer program runs on one or more processors, the method according to any one of claims 1 to 5 is executed.
Citation Information
Patent Citations
Data processing system and data processing method
CN108874947A
Data processing method and device and electronic equipment
CN112231144A