Transaction processing method and device, computer equipment, readable storage medium and program product
By introducing state machines and write log states in transaction processing, the problem of poor stability of traditional transaction processing technology is solved, and higher stability and success rate are achieved.
Patent Information
- Application Number
- CN202411751801.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-02
- Publication Date
- 2025-03-18
AI Technical Summary
When traditional transaction processing technology fails on the coordination and/or execution side, the transaction state logic becomes chaotic and the processing stability is poor.
The state transformation of the state machine leads the transaction processing process, adds the log writing status to ensure the success of the transaction preparation phase, and changes the state machine status to the processing state after feedback of the successful preparation message on the execution side.
Improve the stability of transaction processing, reduce the processing complexity caused by failures, and ensure the success of the transaction preparation phase.
Smart Images

Figure CN119645943A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a transaction processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] With the development of database technology, transaction processing technology has emerged, which divides the submission of distributed transactions into preparation phase and submission phase. In the preparation phase, the coordinating end notifies all executing ends to reserve resources. After all executing ends return success, the coordinating end notifies the executing ends to execute the submission, otherwise the current transaction is rolled back.
[0003] However, when using traditional transaction processing technology, if the coordination end and / or the execution end fails, since the execution end is distributed with multiple nodes, the execution of transactions on different nodes and network communications may return multiple problems, which will cause the logic for determining the overall status of the transaction to become confusing. Therefore, traditional transaction processing technology has the problem of poor processing stability. Summary of the invention
[0004] Based on this, it is necessary to provide a transaction processing method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve stability in response to the above technical problems.
[0005] In a first aspect, the present application provides a transaction processing method, comprising:
[0006] In response to a transaction processing request initiated by a user, framework information of the transaction to be processed is obtained, and the state of the state machine is adjusted to a first log writing state; the state machine is used to reflect the state of the transaction processing;
[0007] When the framework information is written into the transaction processing log, the state of the state machine is changed from the first log writing state to the ready state;
[0008] Sending a transaction preparation instruction to the execution end of the transaction to be processed through the state machine;
[0009] When a preparation success message fed back by the execution end is obtained, the state of the state machine is changed from the preparation state to the second log writing state;
[0010] When the transaction preparation information of the execution end is written into the transaction processing log, the state of the state machine is changed from the second log writing state to the processing state; the processing state is used to instruct the execution end to perform transaction processing on the pending transaction.
[0011] In one embodiment, in response to a transaction processing request initiated by a user, obtaining framework information of a transaction to be processed includes:
[0012] In response to a transaction processing request initiated by a user, extracting a transaction processing intent from the transaction processing request;
[0013] Determine a pending transaction that matches the transaction processing intention, and obtain framework information of the pending transaction.
[0014] In one embodiment, there are multiple execution ends; the method further includes:
[0015] If there is a target execution end that does not feedback a successful preparation message within the set time, the state of the state machine is changed from the preparation state to the third log writing state;
[0016] When the transaction preparation information of each execution end is written into the transaction processing log, the state of the state machine is changed from the third log writing state to a rollback state; the rollback state is used to instruct each execution end to roll back the transaction.
[0017] In one embodiment, the framework information includes a plurality of framework sub-information; the transaction preparation information includes a plurality of transaction sub-information; and the method further includes:
[0018] Performing feature extraction on each of the transaction sub-information and each of the framework sub-information respectively to obtain a transaction feature of each of the transaction sub-information and a framework feature of each of the framework sub-information;
[0019] For each of the transaction sub-information, determining a target feature that matches the transaction feature of the transaction sub-information from the framework features;
[0020] The transaction sub-information is filled into the location of the framework sub-information represented by the target feature in the transaction processing log.
[0021] In one embodiment, the method further comprises:
[0022] If the transaction preparation information is not successfully written into the transaction processing log within the preset time period, a comprehensive analysis is performed on the writing status in the transaction processing log and the connection status with the execution end to determine the cause of the failure;
[0023] The transaction processing log and the connection status are adjusted based on the failure reason, and the process returns to the step of writing the framework information into the transaction processing log until the transaction preparation information is successfully written into the transaction processing log within the preset time period.
[0024] In one embodiment, the method further comprises:
[0025] After the execution end completes processing the pending transaction, receiving a transaction processing completion message fed back by the execution end;
[0026] Based on the transaction processing completion message, the transaction processing log is cleared.
[0027] In a second aspect, the present application further provides a transaction processing device, including:
[0028] A framework information acquisition module, used to respond to a transaction processing request initiated by a user, acquire the framework information of the transaction to be processed, and adjust the state of the state machine to a first log writing state; the state machine is used to reflect the state of the transaction processing;
[0029] A first state adjustment module, configured to change the state of the state machine from the first log writing state to a ready state when the framework information is written into a transaction processing log;
[0030] An instruction sending module, used for sending a transaction preparation instruction to the execution end of the transaction to be processed through the state machine;
[0031] A second state adjustment module is used to change the state of the state machine from the preparation state to the second log writing state when a preparation success message fed back by the execution end is obtained;
[0032] The third state adjustment module is used to change the state of the state machine from the second log writing state to the processing state when the transaction preparation information of the execution end is written into the transaction processing log; the processing state is used to instruct the execution end to perform transaction processing on the pending transaction.
[0033] In a third aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the above method are implemented.
[0034] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0035] In a fifth aspect, the present application further provides a computer program product, wherein the computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0036] The transaction processing method, apparatus, computer device, computer-readable storage medium and computer program product described above, in response to a transaction processing request initiated by a user, obtains framework information of the transaction to be processed, and adjusts the state of the state machine to the first log write state, so as to determine the specific situation of the transaction to be processed, wherein the state machine is used to reflect the status of transaction processing, and when the framework information is written into the transaction processing log, the state of the state machine is changed from the first log write state to the ready state, that is, only when the framework information is successfully written into the transaction processing log, the state of the state machine can be changed from the first log write state to the ready state, thereby ensuring the success of the transaction preparation stage, and sending a transaction preparation instruction to the execution end of the transaction to be processed through the state machine, and when a preparation success message fed back by the execution end is obtained, the state of the state machine is changed from the ready state to the second log write state, and when the transaction preparation information of the execution end is written into the transaction processing log, the state of the state machine is changed from the second log write state to the processing state; the processing state is used to instruct the execution end to perform transaction processing on the transaction to be processed. By adopting the above transaction processing method, on the one hand, a corresponding log writing state is added before each actual processing state. Only after the log writing operation is completed can the log writing state be converted into the actual operation state, which can ensure the success of the transaction preparation phase; on the other hand, by leading the transaction processing process through the state change of the state machine, the processing complexity caused by faults can be reduced and the stability of transaction processing can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0038] Figure 1 An application environment diagram of a transaction processing method in an embodiment;
[0039] Figure 2 A flowchart of a transaction processing method in one embodiment;
[0040] Figure 3 A flowchart of transaction processing steps in one embodiment;
[0041] Figure 4 A flowchart of a transaction processing method in another embodiment;
[0042] Figure 5 An interface diagram of a transaction processing step in an embodiment;
[0043] Figure 6 A flowchart of a transaction processing method in another embodiment;
[0044] Figure 7 is a structural block diagram of a transaction processing device in one embodiment;
[0045] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is 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 present application and are not used to limit the present application.
[0047] The transaction processing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown in FIG. 1 , the coordination end 102 communicates with the execution end 104 through the network. The coordination end 102 is the core component in the distributed transaction processing process, responsible for coordinating and managing the entire transaction process. The execution end 104 is each node or service participating in the distributed transaction, which performs specific transaction operations and communicates with the coordinator to determine the final result of the transaction. Specifically, during the transaction processing process, the coordination end 102 responds to the transaction processing request initiated by the user, obtains the framework information of the transaction to be processed, and adjusts the state of the state machine to the first log write state; the state machine is used to reflect the status of transaction processing; when the framework information is written into the transaction processing log, the state of the state machine is changed from the first log write state to the preparation state; through the state machine, a transaction preparation instruction is sent to the execution end 104 of the transaction to be processed; when a preparation success message is obtained from the execution end 104, the state of the state machine is changed from the preparation state to the second log write state; when the transaction preparation information of the execution end 104 is written into the transaction processing log, the state of the state machine is changed from the second log write state to the processing state; the processing state is used to instruct the execution end 104 to perform transaction processing on the transaction to be processed.
[0048] In an exemplary embodiment, Figure 2 As shown, a transaction processing method is provided, which is applied to Figure 1 Taking the coordination end 102 in the example as an example, the method includes the following steps S202 to S210. Among them:
[0049] Step S202: in response to a transaction processing request initiated by a user, framework information of the transaction to be processed is obtained, and the state of the state machine is adjusted to a first log writing state.
[0050] Among them, transaction processing requests usually involve the management of atomicity, consistency, isolation and persistence of a series of operations in the database. The state machine is used to reflect the state of transaction processing. Framework information, which can also be understood as template information, includes actual data structures for storing operation information, such as lists, maps, trees, etc., and metadata about the transaction itself, such as transaction ID, start time, execution end list, etc. The first write log state refers to the write log state before the prepare state, which is used to characterize that the transaction state at this time is the write log state, that is, the framework information needs to be written into the transaction processing log. In a distributed transaction system, the state machine is used to describe the transition and flow rules of transactions between different states. Through the state machine, the initial state, intermediate state, final state of the transaction, and the events and conditions that trigger the state transition can be clearly defined. The state machine can ensure that the transaction is correctly executed according to the predetermined process in a distributed environment, and roll back or compensate when necessary. After an event occurs, the state machine can determine the action to be executed based on the current state and set the next state.
[0051] Specifically, after the user initiates a transaction processing request, the coordination end needs to first obtain the framework information of the pending transaction that the user wants to process, determine the specific matters of the pending transaction, and then adjust the state of the state machine to the first log writing state to facilitate the subsequent process of writing information to the log. In some specific embodiments, the coordination end can determine the target pending transaction that the user wants to process from multiple candidate pending transactions based on the transaction processing request initiated by the user.
[0052] Step S204: When the framework information is written into the transaction processing log, the state of the state machine is changed from the first log writing state to the ready state.
[0053] Among them, the transaction log is a file that stores all transactions and data modification records of the corresponding database. In database systems such as SQLServer, each database has a corresponding log file. These log files record the start and end of the transaction and every insertion, deletion and modification operation on the database. The preparation state refers to the state of the transaction preparation on the execution end.
[0054] Specifically, if the framework information is successfully written into the transaction processing log, it indicates that the transaction preparation process can be successfully carried out, so the state of the state machine can be changed from the first log writing state to the preparation state. It can be understood that if the framework information is not successfully written into the transaction processing log, the above-mentioned operation of writing the transaction processing log needs to be repeated until the framework information is successfully written into the transaction processing log, that is, after the log is written, the coordination end enters the execution phase of the actual transaction again, ensuring that the submitted transaction can be restored to the correct state by replaying the log after the node hangs up.
[0055] Step S206: Send a transaction preparation instruction to the execution end of the transaction to be processed through the state machine.
[0056] The transaction preparation instruction is used to indicate to the execution end that a transaction preparation operation can be performed.
[0057] Specifically, the coordinating end may send a transaction preparation instruction to the executing end of the transaction to be processed through the state machine, so that the executing end starts the transaction preparation operation.
[0058] Step S208: When a preparation success message fed back by the execution end is obtained, the state of the state machine is changed from the preparation state to the second log writing state.
[0059] The preparation success message refers to the message that the execution end has been successfully prepared and sent to the coordination end. The second log writing state refers to the log writing state before the transaction processing state.
[0060] Specifically, when a successful preparation message is obtained from the execution end, it indicates that the execution end has successfully prepared the resources required for the transaction. Therefore, the state of the state machine can be changed from the preparation state to the second log writing state to execute the action represented by the next state.
[0061] Step S210, when the transaction preparation information of the execution end is written into the transaction processing log, the state of the state machine is changed from the second log writing state to the processing state.
[0062] The processing status is used to instruct the execution end to perform transaction processing on the pending transaction.
[0063] Specifically, when the transaction preparation information of the execution end is written into the transaction processing log, it indicates that the transaction preparation information can be used for transaction processing, that is, there will be no problem in the subsequent transaction processing process. Therefore, the state of the state machine can be changed from the second log writing state to the processing state.
[0064] The transaction processing method described above obtains framework information of the pending transaction in response to a transaction processing request initiated by a user, and adjusts the state of the state machine to a first log write state, so as to determine the specific situation of the pending transaction, wherein the state machine is used to reflect the status of transaction processing, and when the framework information is written into the transaction processing log, the state of the state machine is changed from the first log write state to the ready state, that is, only when the framework information is successfully written into the transaction processing log, the state of the state machine can be changed from the first log write state to the ready state, thereby ensuring the success of the transaction preparation stage, and sending a transaction preparation instruction to the execution end of the pending transaction through the state machine, and when a preparation success message fed back by the execution end is obtained, the state of the state machine is changed from the ready state to the second log write state, and when the transaction preparation information of the execution end is written into the transaction processing log, the state of the state machine is changed from the second log write state to the processing state; the processing state is used to instruct the execution end to perform transaction processing on the pending transaction. By adopting the above transaction processing method, on the one hand, a corresponding log writing state is added before each actual processing state. Only after the log writing operation is completed can the log writing state be converted into the actual operation state, which can ensure the success of the transaction preparation phase; on the other hand, by leading the transaction processing process through the state change of the state machine, the processing complexity caused by faults can be reduced and the stability of transaction processing can be improved.
[0065] In an exemplary embodiment, in response to a transaction processing request initiated by a user, framework information of a pending transaction is obtained, including: in response to the transaction processing request initiated by the user, extracting a transaction processing intent from the transaction processing request; determining a pending transaction that matches the transaction processing intent, and obtaining framework information of the pending transaction.
[0066] The transaction processing intent describes the operations to be performed and the purpose to be achieved when processing a transaction.
[0067] Specifically, when a user needs to perform transaction processing, he can initiate a transaction processing request to the coordination end. After receiving the transaction processing request, the coordination end can extract the transaction processing intent from the transaction processing request, determine the operations to be performed and the purpose to be achieved when the user processes the transaction, and then determine the pending transactions that match the transaction processing intent and obtain the framework information of the pending transactions to facilitate subsequent transaction processing.
[0068] In this embodiment, the intent extraction of the transaction request initiated by the user can ensure the accuracy of the determination of the transaction to be processed.
[0069] In an exemplary embodiment, there are multiple execution ends; the method also includes: if there is a target execution end that has not fed back a successful preparation message within a set time period, the state of the state machine is changed from the preparation state to the third log writing state; when the transaction preparation information of each execution end is written into the transaction processing log, the state of the state machine is changed from the third log writing state to the rollback state.
[0070] The third log writing state refers to the log writing state before the rollback state. The rollback state is used to instruct each execution end to roll back the transaction.
[0071] Specifically, if there is a target execution end that has not fed back a successful preparation message within the set time, it indicates that there is a target execution end that cannot complete the transaction processing item. Therefore, it is necessary to change the state of the state machine from the preparation state to the third write log state. When the transaction preparation information of each execution end is written into the transaction processing log, it means that the rollback item can be successfully completed. Therefore, the state of the state machine can be changed from the third write log state to the rollback state, and the coordination end can instruct each execution end to perform the transaction rollback operation, thereby ensuring that the rollback operation represented by the rollback state can be successfully performed.
[0072] In an exemplary embodiment, the framework information includes multiple framework sub-information; the transaction preparation information includes multiple transaction sub-information; the method also includes: performing feature extraction on each transaction sub-information and each framework sub-information respectively to obtain the transaction feature of each transaction sub-information and the framework feature of each framework sub-information; for each transaction sub-information, determining the target feature that matches the transaction feature of the transaction sub-information from each framework feature; and filling the transaction sub-information to the position of the framework sub-information represented by the target feature in the transaction processing log.
[0073] Among them, transaction sub-information refers to multiple sub-category information included in transaction preparation information. Framework sub-information refers to multiple sub-category information included in framework information. For example, framework sub-information can be transaction ID, transaction type, etc. Transaction feature refers to feature information corresponding to transaction sub-information. Framework information refers to feature information corresponding to framework sub-information.
[0074] Specifically, in order to write the transaction preparation information of the execution end into the transaction processing log, feature extraction can be performed on each transaction sub-information and each framework sub-information respectively to obtain the transaction features of each transaction sub-information and the framework features of each framework sub-information. For each transaction sub-information, the target features that match the transaction features of the transaction sub-information are determined from the framework features. Finally, the transaction sub-information is filled in to the position of the framework sub-information represented by the target feature in the transaction processing log. In this way, the transaction preparation information of the execution end can be written into the transaction processing log while ensuring the accuracy of the filling.
[0075] In an exemplary embodiment, the method also includes: if the transaction preparation information is not successfully written into the transaction processing log within a preset time period, a comprehensive analysis is performed on the writing status in the transaction processing log and the connection status with the execution end to determine the cause of the failure; based on the cause of the failure, the transaction processing log and the connection status are adjusted, and the step of writing the framework information into the transaction processing log is returned until the transaction preparation information is successfully written into the transaction processing log within the preset time period.
[0076] Specifically, if the transaction preparation information is not successfully written into the transaction processing log within the preset time, it indicates that a fault may have occurred. Therefore, a comprehensive analysis can be conducted on the writing status in the transaction processing log and the connection status with the execution end to determine the cause of the failure. That is, it can be determined whether the cause of the failure is a writing failure or a connection failure with the execution end. After that, the transaction processing log and the connection status can be adjusted based on the cause of the failure, and the step of writing the framework information into the transaction processing log can be returned until the transaction preparation information is successfully written into the transaction processing log within the preset time. This ensures that the transaction preparation information is successfully written into the transaction processing log before the actual operation of the transaction preparation, thereby ensuring the success rate of the actual operation of food preparation.
[0077] In an exemplary embodiment, the method further includes: after the execution end completes processing of the pending transaction, receiving a transaction processing completion message fed back by the execution end; and clearing the transaction processing log based on the transaction processing completion message.
[0078] The transaction completion message refers to a message indicating that the transaction has been submitted and completed.
[0079] Specifically, after the transaction is processed, the transaction processing log needs to be cleared to indicate that all transaction processing matters have been completed. Therefore, the coordinating end can receive the transaction processing completion message fed back by the executing end after the executing end has completed the processing of the pending transaction. Based on the transaction processing completion message, the transaction processing log is cleared to ensure the continuity of subsequent transaction processing.
[0080] In a specific embodiment, a transaction processing method for an actual application scenario is also provided, and the distributed transaction status saved on the coordinator is divided into 7 states, namely WriteJournalForPrepare, Prepare, WriteJournalForCommit, Commit, WriteJournalforRollback, Rollback, and Finish. That is, the state of pre-writing the log is added before the preparation phase, the commit phase, and the rollback phase of the transaction. Among them, the WriteJournalForPrepare, WriteJournalForCommit, and WriteJournalforRollback states are log writing states, which can only handle log writing success events. When the log writing fails, the log writing is directly retried. After the log is written, the coordinator enters the execution phase of the actual transaction to ensure that the submitted transaction can be restored to the correct state by replaying the log after the node hangs up. The introduction of the log record state as a separate state is the inventive point of this embodiment. The specific state transfer is related to the following. Figure 3 shown.
[0081] This embodiment provides support for transaction state management for the coordinator (coordinator end) module in distributed transactions. After the transaction begins, an instance of the transaction management class transaction_manager is created to save all read and write operation information in the transaction. At this time, there is no need to interact with the participants (executors). Figure 4 As shown, after the coordinator receives the commit request, it starts the transaction state machine tc_state_machine, and the state machine enters the write log state. The transaction_manager encodes all the recorded write operation information and writes it to the log. It generates a persist_success_event event in the callback of successful log writing. After receiving the event, the state machine enters the prepare state.
[0082] The entry action of the Prepare state is to broadcast the prepare message to all participants. The participants start to prepare the resources required for the transaction. If the resources are successfully prepared, prepare_success_event is generated, otherwise prepare_fail_event is generated. According to the result, the state machine enters the commit state or rollback state. The entry action of the commit state is to return success to the caller and broadcast the commit information to the participants. After receiving the return of successful commit, commit_success_event is generated, and the end stage is entered to clean up all information related to transaction_manager and log information.
[0083] Based on the state machine design, transaction_manager only needs to implement the following Figure 5 The interface shown. When the caller does not initiate a commit operation, the data does not generate a real write operation, and the transaction can be rolled back directly by cleaning up the local transaction_manager data, without interacting with the participants, simplifying the transaction process. The operations of transaction state management are called as the entry and exit actions of the state machine to avoid redundant or erroneous processing logic in the event of a failure.
[0084] For 2PC operations without explicit begin, such as batchPut, the processing logic does not have the caller explicitly calling the commit operation. Therefore, the state machine is started when the coordinator receives the request. After receiving the request, two timestamps are applied at the same time, which are used as the transaction ID and the commit time respectively, and the state machine is started directly. The process is unified.
[0085] In a specific embodiment, Figure 6 As shown, a transaction processing method is also provided, including:
[0086] Step S601, in response to a transaction processing request initiated by a user, extracting a transaction processing intent from the transaction processing request, determining a pending transaction matching the transaction processing intent, obtaining framework information of the pending transaction, and adjusting the state of the state machine to the first log writing state;
[0087] Among them, the state machine is used to reflect the status of transaction processing;
[0088] Step S602, when the framework information is written into the transaction processing log, the state of the state machine is changed from the first log writing state to the preparation state, and a transaction preparation instruction is sent to the execution end of the transaction to be processed through the state machine;
[0089] Step S603, when a preparation success message fed back by the execution end is obtained, the state of the state machine is changed from the preparation state to the second log writing state;
[0090] The framework information includes multiple framework sub-information; the transaction preparation information includes multiple transaction sub-information;
[0091] Step S604, if the transaction preparation information is not successfully written into the transaction processing log within the preset time, a comprehensive analysis is performed on the writing status in the transaction processing log and the connection status with the execution end to determine the reason for the failure;
[0092] Step S605, adjusting the transaction processing log and the connection status based on the failure reason, and returning to the step of writing the framework information into the transaction processing log until the transaction preparation information is successfully written into the transaction processing log within a preset time period;
[0093] Step S606, extracting features from each transaction sub-information and each framework sub-information to obtain transaction features of each transaction sub-information and framework features of each framework sub-information;
[0094] Step S607, for each transaction sub-information, determine a target feature that matches the transaction feature of the transaction sub-information from each framework feature, and fill the transaction sub-information into the position of the framework sub-information represented by the target feature in the transaction processing log;
[0095] Step S608, when the transaction preparation information of the execution end is written into the transaction processing log, the state of the state machine is changed from the second log writing state to the processing state;
[0096] Among them, the processing status is used to instruct the execution end to perform transaction processing on the pending transaction;
[0097] Step S609, after the execution end completes processing the pending transaction, a transaction processing completion message fed back by the execution end is received, and based on the transaction processing completion message, the transaction processing log is cleared;
[0098] Among them, there are multiple execution ends;
[0099] Step S610, if there is a target execution end that has not fed back a preparation success message within the set time period, the state of the state machine is changed from the preparation state to the third log writing state;
[0100] Step S611, when the transaction preparation information of each execution end is written into the transaction processing log, the state of the state machine is changed from the third log writing state to the rollback state;
[0101] The rollback status is used to instruct each execution end to roll back the transaction.
[0102] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0103] Based on the same inventive concept, the embodiment of the present application also provides a transaction processing device for implementing the transaction processing method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more transaction processing device embodiments provided below can refer to the limitations on the transaction processing method above, and will not be repeated here.
[0104] In an exemplary embodiment, Figure 7 As shown, a transaction processing device 700 is provided, including: a framework information acquisition module 702, a first state adjustment module 704, an instruction sending module 706, a second state adjustment module 708 and a third state adjustment module 710, wherein:
[0105] The framework information acquisition module 702 is used to respond to the transaction processing request initiated by the user, obtain the framework information of the transaction to be processed, and adjust the state of the state machine to the first log writing state; the state machine is used to reflect the state of the transaction processing;
[0106] A first state adjustment module 704, configured to change the state of the state machine from the first write log state to the ready state when the framework information is written into the transaction processing log;
[0107] The instruction sending module 706 is used to send a transaction preparation instruction to the execution end of the transaction to be processed through the state machine;
[0108] The second state adjustment module 708 is used to change the state of the state machine from the preparation state to the second log writing state when a preparation success message fed back by the execution end is obtained;
[0109] The third state adjustment module 710 is used to change the state of the state machine from the second log writing state to the processing state when the transaction preparation information of the execution end is written into the transaction processing log; the processing state is used to instruct the execution end to perform transaction processing on the pending transaction.
[0110] In an exemplary embodiment, the framework information acquisition module 702 is specifically used to:
[0111] In response to a transaction processing request initiated by a user, extracting a transaction processing intent from the transaction processing request;
[0112] Determine a pending transaction that matches the transaction intent and obtain framework information of the pending transaction.
[0113] In an exemplary embodiment, there are multiple execution ends. In this embodiment, the transaction processing device 700 further includes a transaction rollback module, which is specifically used to:
[0114] If there is a target execution end that does not send back a successful preparation message within the set time, the state of the state machine is changed from the preparation state to the third log writing state;
[0115] When the transaction preparation information of each execution end is written into the transaction processing log, the state of the state machine is changed from the third log writing state to the rollback state; the rollback state is used to instruct each execution end to roll back the transaction.
[0116] In an exemplary embodiment, the framework information includes multiple framework sub-information; the transaction preparation information includes multiple transaction sub-information. In the case of this embodiment, the transaction processing device 700 also includes an information filling module, which is specifically used to:
[0117] Extract features from each transaction sub-information and each framework sub-information respectively, to obtain transaction features of each transaction sub-information and framework features of each framework sub-information;
[0118] For each transaction sub-information, determine a target feature that matches the transaction feature of the transaction sub-information from among the framework features;
[0119] The transaction sub-information is filled into the position of the framework sub-information represented by the target feature in the transaction processing log.
[0120] In an exemplary embodiment, the transaction processing device 700 further includes a repeated writing module, which is specifically configured to:
[0121] If the transaction preparation information is not successfully written into the transaction processing log within the preset time, a comprehensive analysis is performed on the writing status in the transaction processing log and the connection status with the execution end to determine the cause of the failure;
[0122] The transaction log and connection status are adjusted based on the reason for the failure, and the step of writing the framework information into the transaction log is returned until the transaction preparation information is successfully written into the transaction log within a preset time.
[0123] In an exemplary embodiment, the transaction processing apparatus 700 further includes a transaction clearing module, which is specifically configured to:
[0124] After the execution end completes the processing of the pending transaction, a transaction completion message fed back by the execution end is received;
[0125] Based on the transaction completion message, the transaction log is cleared.
[0126] Each module in the transaction processing device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0127] In an exemplary embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as shown in FIG. Figure 8 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a transaction processing method is implemented. The display unit of the computer device is used to form a visually visible picture, which can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0128] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0129] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above method when executing the computer program.
[0130] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0131] In one embodiment, a computer program product is provided, comprising a computer program, which implements the steps of the above method when executed by a processor.
[0132] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0133] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0134] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0135] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A transaction processing method, characterized in that: The method comprises: In response to a transaction processing request initiated by a user, framework information of the transaction to be processed is obtained, and the state of the state machine is adjusted to a first log writing state; the state machine is used to reflect the state of the transaction processing; When the framework information is written into the transaction processing log, the state of the state machine is changed from the first log writing state to the ready state; Sending a transaction preparation instruction to the execution end of the transaction to be processed through the state machine; When a preparation success message fed back by the execution end is obtained, the state of the state machine is changed from the preparation state to the second log writing state; When the transaction preparation information of the execution end is written into the transaction processing log, the state of the state machine is changed from the second log writing state to the processing state; the processing state is used to instruct the execution end to perform transaction processing on the pending transaction.
2. The method according to claim 1, characterized in that The step of obtaining framework information of a transaction to be processed in response to a transaction processing request initiated by a user includes: In response to a transaction processing request initiated by a user, extracting a transaction processing intent from the transaction processing request; Determine a pending transaction that matches the transaction processing intention, and obtain framework information of the pending transaction.
3. The method according to claim 1, characterized in that There are multiple execution ends; the method also includes: If there is a target execution end that does not feedback a successful preparation message within the set time, the state of the state machine is changed from the preparation state to the third log writing state; When the transaction preparation information of each execution end is written into the transaction processing log, the state of the state machine is changed from the third log writing state to a rollback state; the rollback state is used to instruct each execution end to roll back the transaction.
4. The method according to claim 1, characterized in that The framework information includes a plurality of framework sub-information; the transaction preparation information includes a plurality of transaction sub-information; and the method further includes: Performing feature extraction on each of the transaction sub-information and each of the framework sub-information respectively to obtain a transaction feature of each of the transaction sub-information and a framework feature of each of the framework sub-information; For each of the transaction sub-information, determining a target feature that matches the transaction feature of the transaction sub-information from the framework features; The transaction sub-information is filled into the location of the framework sub-information represented by the target feature in the transaction processing log.
5. The method according to claim 1, characterized in that The method further comprises: If the transaction preparation information is not successfully written into the transaction processing log within the preset time period, a comprehensive analysis is performed on the writing status in the transaction processing log and the connection status with the execution end to determine the cause of the failure; The transaction processing log and the connection status are adjusted based on the failure reason, and the process returns to the step of writing the framework information into the transaction processing log until the transaction preparation information is successfully written into the transaction processing log within the preset time period.
6. The method according to claim 1, characterized in that The method further comprises: After the execution end completes processing the pending transaction, receiving a transaction processing completion message fed back by the execution end; Based on the transaction processing completion message, the transaction processing log is cleared.
7. A transaction processing device, characterized in that: The device comprises: A framework information acquisition module, used to respond to a transaction processing request initiated by a user, acquire the framework information of the transaction to be processed, and adjust the state of the state machine to a first log writing state; the state machine is used to reflect the state of the transaction processing; A first state adjustment module, configured to change the state of the state machine from the first log writing state to a ready state when the framework information is written into a transaction processing log; An instruction sending module, used for sending a transaction preparation instruction to the execution end of the transaction to be processed through the state machine; A second state adjustment module is used to change the state of the state machine from the preparation state to the second log writing state when a preparation success message fed back by the execution end is obtained; The third state adjustment module is used to change the state of the state machine from the second log writing state to the processing state when the transaction preparation information of the execution end is written into the transaction processing log; the processing state is used to instruct the execution end to perform transaction processing on the pending transaction.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.