Abnormality processing method, device and equipment of business and storage medium
Patent Information
- Application Number
- CN201910578353.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-06-28
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2039-06-28
AI Technical Summary
[0003]本发明的主要目的在于提出一种业务的异常处理方法、装置、设备及计算机可读存储介质,旨在解决现有业务处理代码不仅可读性以及可维护性差而且可拓展性低下的技术问题
Smart Images

Figure CN110309017B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of financial technology (Fintech), and more particularly to methods, apparatus, devices, and computer-readable storage media for handling business anomalies. Background Technology
[0002] With the development of computer technology, more and more technologies (big data, distributed systems, blockchain, artificial intelligence, etc.) are being applied in the financial field. The traditional financial industry is gradually transforming into Fintech. However, due to the security and real-time requirements of the financial industry, higher demands are being placed on technology. For banks, the business transaction processes are generally relatively simple, but if any step in the transaction process fails, data rollback of the already executed steps is required. This not only reduces code readability and maintainability but also results in poor scalability. Summary of the Invention
[0003] The main objective of this invention is to propose a method, apparatus, device, and computer-readable storage medium for handling business exceptions, aiming to solve the technical problems of poor readability, maintainability, and scalability of existing business processing code.
[0004] To achieve the above objectives, the present invention provides a method for handling business exceptions, the method comprising the following steps:
[0005] When the failure of the target service execution action is detected by the state machine framework, the executed actions of the target service and the data rollback order of the executed actions are determined according to the action record list in the state machine framework.
[0006] Based on the class name of the executed action, determine the action data rollback logic corresponding to the executed action in the state machine framework;
[0007] According to the data rollback order and the action data rollback logic, the corresponding data rollback operations are performed on the executed actions in sequence.
[0008] Optionally, before the step of determining the action data rollback logic corresponding to the executed action in the state machine framework based on the class name of the executed action, the method further includes:
[0009] Upon receiving a rollback logic registration instruction, the action logic to be registered in the rollback logic registration instruction is obtained, and the action logic to be registered and the class name of the corresponding action are associated and stored in the state machine framework.
[0010] Optionally, the step of determining the executed actions of the target service and the data rollback order of the executed actions according to the action record list in the state machine framework when the execution of the target service action is detected to have failed through the state machine framework specifically includes:
[0011] When the failure of the target service execution action is detected through the state machine framework, the executed action of the target service is determined according to the action class name in the action record list in the state machine framework.
[0012] The data rollback order of the executed actions is generated according to the reverse order of the action execution sequence in the state machine framework.
[0013] Optionally, the step of sequentially performing corresponding data rollback operations on the executed actions according to the data rollback order and the action data rollback logic specifically includes:
[0014] Based on the data rollback order of the executed actions, one of the executed actions is sequentially obtained as the action to be rolled back;
[0015] According to the action data rollback logic corresponding to the data to be rolled back, perform the corresponding data rollback operation on the data to be rolled back.
[0016] When the successful execution instruction of the pending data rollback operation is detected, the next execution action in the executed actions is obtained in sequence according to the data rollback order, and is used as the pending data rollback operation. Then, the following steps are performed: according to the action data rollback logic corresponding to the pending data rollback operation, the corresponding data rollback operation is performed on the pending data rollback operation.
[0017] Optionally, after the step of performing a corresponding data rollback operation on the data to be rolled back according to the action data rollback logic corresponding to the data to be rolled back operation, the method further includes:
[0018] When a failure instruction for the pending data rollback operation is detected, the current data rollback task in the failure instruction is obtained, and other pending data rollback tasks after the current data rollback task are determined according to the data rollback order.
[0019] The state machine framework is used to forward and store the current data rollback task and other data rollback tasks to the database.
[0020] Optionally, after the step of forwarding and storing the current data rollback task and other data rollback tasks to the database through the state machine framework, the method further includes:
[0021] According to a preset time interval, the data rollback task in the pending state of the database is re-executed through the state machine framework, and when the successful execution of the data rollback task in the pending state is detected, the task status of the successfully executed data rollback task is changed to executed.
[0022] Optionally, before the step of determining the executed actions of the target service and the data rollback order of the executed actions based on the action record list in the state machine framework when the execution of the target service action is detected to have failed through the state machine framework, the method further includes:
[0023] The state machine framework creates a new action record list corresponding to the target service, and when the state machine framework detects the action execution instruction of the target service, the execution action corresponding to the target service is recorded in the action record list.
[0024] Optionally, before the step of determining the executed actions of the target service and the data rollback order of the executed actions based on the action record list in the state machine framework when the execution of the target service action is detected to have failed through the state machine framework, the method further includes:
[0025] When the action completion instruction of the target service is detected through the state machine framework, the action execution state corresponding to the currently executed action in the action completion instruction is obtained, and the current execution action is judged to be successful based on the action execution state;
[0026] If the current action is executed successfully, the state machine framework controls the target service to execute the next action to be executed.
[0027] Furthermore, to achieve the above objectives, the present invention also provides a service exception handling apparatus, the service exception handling apparatus comprising:
[0028] The rollback action acquisition module is used to determine the executed actions of the target service and the data rollback order of the executed actions based on the action record list in the state machine framework when the failure of the target service execution action is detected through the state machine framework.
[0029] The rollback logic determination module is used to determine the action data rollback logic corresponding to the executed action in the state machine framework based on the class name of the executed action.
[0030] The rollback operation execution module is used to perform corresponding data rollback operations on the executed actions sequentially according to the data rollback order and the action data rollback logic.
[0031] Optionally, the anomaly handling device for the service further includes:
[0032] The rollback logic registration module is used to obtain the action logic to be registered in the rollback logic registration instruction when a rollback logic registration instruction is received, and to associate and store the action logic to be registered and the class name of the corresponding action in the state machine framework.
[0033] Optionally, the rollback operation acquisition module is further configured to:
[0034] When the failure of the target service execution action is detected through the state machine framework, the executed action of the target service is determined according to the action class name in the action record list in the state machine framework.
[0035] The data rollback order of the executed actions is generated according to the reverse order of the action execution sequence in the state machine framework.
[0036] Optionally, the rollback operation execution module specifically includes:
[0037] The rollback action acquisition unit is used to sequentially acquire one of the executed actions according to the data rollback order of the executed actions, as the data rollback action to be rolled back;
[0038] The rollback operation execution unit is used to perform a corresponding data rollback operation on the data to be rolled back operation according to the action data rollback logic corresponding to the data to be rolled back operation.
[0039] The rollback loop execution unit is used to, when a successful execution instruction for the data rollback operation is detected, sequentially obtain the next execution action from the already executed actions according to the data rollback order, use it as the data rollback operation, and transfer it to the rollback operation execution unit.
[0040] Optionally, the exception handling device for the service further includes a rollback task storage module, which is used for:
[0041] When a failure instruction for the pending data rollback operation is detected, the current data rollback task in the failure instruction is obtained, and other pending data rollback tasks after the current data rollback task are determined according to the data rollback order.
[0042] The state machine framework is used to forward and store the current data rollback task and other data rollback tasks to the database.
[0043] In addition, to achieve the above objectives, the present invention also provides a service exception handling device, the service exception handling device comprising: a memory, a processor, and a service exception handling program stored in the memory and executable on the processor, wherein when the service exception handling program is executed by the processor, it implements the steps of the service exception handling method as described above.
[0044] In addition, to achieve the above objectives, the present invention also provides a computer-readable storage medium storing a service exception handling program, wherein when the service exception handling program is executed by a processor, it implements the steps of the service exception handling method as described above.
[0045] When the failure of a target service execution action is detected through a state machine framework, this invention determines the executed actions of the target service and the data rollback order of the executed actions based on the action record list in the state machine framework; based on the class name of the executed actions, it determines the corresponding action data rollback logic in the state machine framework; and based on the data rollback order and the action data rollback logic, it sequentially performs corresponding data rollback operations on the executed actions. Through this method, this invention isolates the business code and data rollback logic using a state machine framework, storing the action data rollback logic separately. That is, the data rollback logic is invisible to the business processing flow. When the business processing flow is modified, it is not necessary to modify the entire business processing code; only the corresponding processing module and the corresponding data rollback logic need to be added or modified. This not only improves the readability and maintainability of the business processing code but also enhances its extensibility, solving the technical problem that existing business processing code suffers from poor readability, maintainability, and extensibility. Attached Figure Description
[0046] Figure 1 This is a schematic diagram of the device structure of the hardware operating environment involved in the embodiments of the present invention;
[0047] Figure 2 This is a flowchart illustrating the first embodiment of the exception handling method for the business operations of the present invention;
[0048] Figure 3 A diagram illustrating the addition of a data rollback process to an existing business workflow;
[0049] Figure 4 A schematic diagram illustrating the process of adding functionality to an existing business workflow;
[0050] Figure 5 This is a schematic diagram of the first process of the exception handling method of the present invention.
[0051] Figure 6 This is a schematic diagram of the second process of the exception handling method of the present invention;
[0052] Figure 7 This is a schematic diagram illustrating the addition of a new action in the exception handling method of the present invention.
[0053] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0054] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0055] like Figure 1 As shown, Figure 1 This is a schematic diagram of the device structure of the hardware operating environment involved in the embodiments of the present invention.
[0056] The exception handling device in this embodiment of the invention can be a PC or a server device running a Java Virtual Machine.
[0057] like Figure 1 As shown, the exception handling device for this service may include: a processor 1001, such as a CPU; a network interface 1004; a user interface 1003; a memory 1005; and a communication bus 1002. The communication bus 1002 is used to establish communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be high-speed RAM or non-volatile memory, such as a disk drive. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0058] Those skilled in the art will understand that Figure 1 The device structure shown does not constitute a limitation on the device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0059] like Figure 1 As shown, the memory 1005, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a service exception handling program.
[0060] exist Figure 1 In the device shown, the network interface 1004 is mainly used to connect to the backend server and communicate data with the backend server; the user interface 1003 is mainly used to connect to the client (user terminal) and communicate data with the client; and the processor 1001 can be used to call the exception handling program of the service stored in the memory 1005 and execute the operations in the exception handling method of the following service.
[0061] Based on the above hardware structure, an embodiment of the anomaly handling method for the business of this invention is proposed.
[0062] Reference Figure 2 , Figure 2 This is a flowchart illustrating a first embodiment of the exception handling method for the business operations of the present invention. The exception handling method for the business operations includes:
[0063] Step S10: When the failure of the target service execution action is detected by the state machine framework, the executed actions of the target service and the data rollback order of the executed actions are determined according to the action record list in the state machine framework.
[0064] The business transaction processes of a target bank's business system are generally relatively simple. However, if any step in the business transaction process fails, it is necessary to roll back the data for the steps already executed. Taking a loan disbursement transaction as an example, the disbursement transaction includes the following steps: Action 1: Deduct the deposit from the customer's account; Action 2: Record the loan in the system (for calculating interest and penalty interest); Action 3: Transfer 10,000 to the customer's account. If the transfer to the customer's account (Action 3) fails due to insufficient funds, then data rollback Action 2 (delete the loan in the system) and then data rollback Action 1 (refund the deposit) are required. Figure 3 As shown, exception handling code has been added to the existing business logic code, such as data rollback code. This includes two parts: 1. Code to determine whether data rollback is needed; 2. Code to execute the data rollback logic in sequence. Therefore, the original simple business process (Action 1 -> Action 2 -> Action 3) has become Action 1 -> Action 2 -> Action 1 data rollback -> Action 3 -> Action 2 data rollback -> Action 1 data rollback due to the added exception handling steps. Thus, the simple business process suffers from reduced readability and maintainability due to the addition of exception handling code. Furthermore, if a handling fee (Action 4) needs to be charged before recording the loan (Action 2), Action 4 needs to be added before Action 2. Figure 4As shown, the code for actions 2 and 3 needs to be modified first, and data rollback logic for action 4 needs to be added simultaneously. Therefore, if modifications to the existing business processing flow are required, the operation is very complex, and the scalability of the existing business processing code is very low. To solve the above technical problems, this embodiment provides an exception handling method for business operators. The business code and data rollback logic are isolated through a state machine framework, and the action data rollback logic is stored separately. That is, the data rollback logic is not visible to the business processing flow. When the business processing flow is modified, it is not necessary to modify the entire business processing code. Only the corresponding processing module and the corresponding data rollback logic need to be added or modified separately. Specifically, this embodiment drives the transaction process of the target business through the state machine framework. The state machine framework is implemented by borrowing the idea of the state machine model. It is a driver that realizes the transition from one state to the next state by executing actions. The state machine, also known as a finite state automaton, is a mathematical model that represents a finite number of states and the transitions and actions between these states. When the state machine framework detects a failure in the execution of a target service action, the executed actions corresponding to the target service are determined based on the action record list used to record the executed actions of the target service within the state machine framework. Since the executed actions recorded in the action record list are arranged sequentially according to their execution order, the execution order of the executed actions can also be determined based on the action record list, thereby determining the data rollback order corresponding to the executed actions. Figure 5 As shown, the data rollback logic corresponding to Action 1, Action 2 and Action 3 are stored separately. When rolling back data later, the data rollback operation is performed in reverse order of execution.
[0065] Furthermore, prior to step S10, the procedure also includes:
[0066] The state machine framework creates a new action record list corresponding to the target service, and when the state machine framework detects the action execution instruction of the target service, the execution action corresponding to the target service is recorded in the action record list.
[0067] To facilitate subsequent data rollback operations, in this embodiment, a corresponding list is pre-created for each service within the state machine framework to record the executed actions of the corresponding service, and these actions are recorded sequentially according to their execution time. The executed actions corresponding to the target service are then recorded in the action record list corresponding to the target service.
[0068] Furthermore, prior to step S10, the procedure also includes:
[0069] When the action completion instruction of the target service is detected through the state machine framework, the action execution state corresponding to the currently executed action in the action completion instruction is obtained, and the current execution action is judged to be successful based on the action execution state;
[0070] If the current action is executed successfully, the state machine framework controls the target service to execute the next action to be executed.
[0071] In this embodiment, the transaction process of the target service is driven by the state machine framework to achieve automatic data rollback of the target service. When the action completion instruction of the target service is detected by the state machine framework, the currently executing action and the corresponding action execution status in the action completion instruction are obtained. The "whether completed" field in the action execution status is used to determine whether the currently executing action has been successfully completed. If the currently executing action has been successfully completed, the next action to be executed in the target service is executed through the state machine framework, and the action execution status of the next action to be executed is monitored. If the currently executing action fails, that is, the execution action of the target service fails, the process proceeds to step S10, that is, the data rollback operation of the executed action is performed through the state machine framework.
[0072] Further, step S10 specifically includes:
[0073] When the failure of the target service execution action is detected through the state machine framework, the executed action of the target service is determined according to the action class name in the action record list in the state machine framework.
[0074] The data rollback order of the executed actions is generated according to the reverse order of the action execution sequence in the state machine framework.
[0075] In this embodiment, when the state machine framework detects the action execution instruction of the target service, the name of the completed action class is stored in the action record list. If an action fails to execute, the executed actions requiring data rollback for the target service are determined based on the action class names stored in the action record list. Since the action data rollback needs to be performed in reverse order of the executed actions, the reverse order of the execution sequence of the executed actions is used as the data rollback order of the executed actions.
[0076] Step S20: Based on the class name of the executed action, determine the action data rollback logic corresponding to the executed action in the state machine framework;
[0077] In this embodiment, data rollback tasks are generated based on the executed actions. Each data rollback task calls the corresponding data rollback logic in the state machine framework through the interface of the state machine framework. The state machine framework pre-registers and stores the data rollback logic corresponding to each data rollback task in a Spring bean. Upon receiving a call instruction, the action data rollback logic corresponding to each executed action is obtained by using the class name of each executed action. The action data rollback logic is used to perform undo and restore operations on the relevant data generated by the executed actions, that is, to restore the relevant data corresponding to the target business to the data state before the executed action was performed.
[0078] Step S30: According to the data rollback order and the action data rollback logic, perform corresponding data rollback operations on the executed actions in sequence.
[0079] In this embodiment, based on the data rollback order corresponding to the executed actions, i.e., the execution order of the data rollback operations for each executed action, and the action data rollback logic corresponding to each executed action, the executed actions are rolled back according to their respective execution order to undo the operations performed by the executed actions on the target service. For example... Figure 7 As shown, if the transaction fails after successful execution of action 3, it needs to be executed in the order that is, the reverse order of actions 1, 2, and 3, which is the data rollback operation corresponding to action 3, the data rollback operation corresponding to action 2, and the data rollback operation corresponding to action 1.
[0080] In this embodiment, when a target service execution action fails to be detected through the state machine framework, the executed actions of the target service and the data rollback order of the executed actions are determined according to the action record list in the state machine framework. Based on the class name of the executed action, the corresponding action data rollback logic is determined in the state machine framework. According to the data rollback order and the action data rollback logic, the corresponding data rollback operations are performed on the executed actions sequentially. Through this method, the present invention isolates the business code and data rollback logic through the state machine framework, storing the action data rollback logic separately. That is, the data rollback logic is invisible to the business processing flow. When the business processing flow is modified, it is not necessary to modify the entire business processing code; only the corresponding processing module and the corresponding data rollback logic need to be added or modified. This not only improves the readability and maintainability of the business processing code but also enhances its extensibility, solving the technical problem that existing business processing code suffers from poor readability, maintainability, and extensibility.
[0081] Furthermore, based on the first embodiment of the exception handling method for the business of the present invention, a second embodiment of the exception handling method for the business of the present invention is proposed.
[0082] In this embodiment, before step S20, the method further includes:
[0083] Upon receiving a rollback logic registration instruction, the action logic to be registered in the rollback logic registration instruction is obtained, and the action logic to be registered and the class name of the corresponding action are associated and stored in the state machine framework.
[0084] To facilitate the addition of new business function modules, this embodiment provides a data rollback logic registration function for business modules. Upon receiving a rollback logic registration instruction, the action logic in the instruction, i.e., the action logic to be registered, is obtained. The logic to be registered and the class name of the corresponding action that calls this logic are stored in a Spring bean within the state machine framework. Subsequently, the associated stored action data rollback logic method can be directly called based on the action's class name. In a specific embodiment, the code for the new module can be added to the business process code of the target business, such as... Figure 7 As shown, the code module for action 4 is added to the business process, and the data rollback logic for action 4 is registered in the state machine framework. This does not affect the original code for actions 2 and 3, or their corresponding data rollback logic. This improves the extensibility, readability, and maintainability of the business exception handling code.
[0085] Further, step S30 specifically includes:
[0086] Based on the data rollback order of the executed actions, one of the executed actions is sequentially obtained as the action to be rolled back;
[0087] According to the action data rollback logic corresponding to the data to be rolled back, perform the corresponding data rollback operation on the data to be rolled back.
[0088] When the successful execution instruction of the pending data rollback operation is detected, the next execution action in the executed actions is obtained in sequence according to the data rollback order, and is used as the pending data rollback operation. Then, the following steps are performed: according to the action data rollback logic corresponding to the pending data rollback operation, the corresponding data rollback operation is performed on the pending data rollback operation.
[0089] In this embodiment, as Figure 6As shown, if the state machine framework detects a transaction failure after action 3 is executed successfully, it checks the currently recorded actions (i.e., executed actions) through the state machine framework: namely, action 3, action 2, and action 1. It sequentially retrieves the data rollback operation for action 3, and when a successful execution instruction corresponding to the data rollback operation of action 3 is detected, it continues to retrieve the data rollback operation for action 2 until a successful execution instruction for the data rollback operation of action 1 is detected.
[0090] Furthermore, based on the second embodiment of the exception handling method for the business of the present invention, a third embodiment of the exception handling method for the business of the present invention is proposed.
[0091] In this embodiment, after the step of performing a corresponding data rollback operation on the data to be rolled back according to the action data rollback logic corresponding to the data to be rolled back operation, the method further includes:
[0092] When a failure instruction for the pending data rollback operation is detected, the current data rollback task in the failure instruction is obtained, and other pending data rollback tasks after the current data rollback task are determined according to the data rollback order.
[0093] The state machine framework is used to forward and store the current data rollback task and other data rollback tasks to the database.
[0094] To prevent the data rollback process from being aborted due to failed rollback operations, this embodiment stores failed rollback operations in the database. For example, after a transaction completes actions 1, 2, and 3, the transaction fails. Data rollback operations for actions 3, 2, and 1 are required. However, if the data rollback operation for action 2 fails (e.g., due to a network timeout), the state machine framework will invoke its internal store-and-forward tool to store the failed rollback tasks for actions 1 and 2 in the database.
[0095] Furthermore, after the step of forwarding and storing the current data rollback task and other data rollback tasks to the database through the state machine framework, the method further includes:
[0096] According to a preset time interval, the data rollback task in the pending state of the database is re-executed through the state machine framework, and when the successful execution of the data rollback task in the pending state is detected, the task status of the successfully executed data rollback task is changed to executed.
[0097] In this embodiment, the store-and-forward tool periodically restarts the data rollback tasks previously written to the database by the state machine framework according to a preset time interval. The data rollback task is in a pending state before successful re-execution, and its state is changed to "executed" after successful re-execution. Then, the store-and-forward tool periodically re-executes the data rollback operations of Action 2 and Action 1, which previously failed. If the data rollback still fails, the store-and-forward tool will restart the data rollback tasks again after a preset time interval. This continues until the data rollback operations of Action 2 and Action 1 are successfully executed, and the state of the successfully executed Action 2 and Action 1 data rollback tasks is changed to "executed". Generally, network timeout issues can be resolved by re-execution twice, after which the data rollback will be successful.
[0098] The present invention also provides a service exception handling apparatus, the service exception handling apparatus comprising:
[0099] The rollback action acquisition module is used to determine the executed actions of the target service and the data rollback order of the executed actions based on the action record list in the state machine framework when the failure of the target service execution action is detected through the state machine framework.
[0100] The rollback logic determination module is used to determine the action data rollback logic corresponding to the executed action in the state machine framework based on the class name of the executed action.
[0101] The rollback operation execution module is used to perform corresponding data rollback operations on the executed actions sequentially according to the data rollback order and the action data rollback logic.
[0102] Furthermore, the anomaly handling device for the service also includes:
[0103] The rollback logic registration module is used to obtain the action logic to be registered in the rollback logic registration instruction when a rollback logic registration instruction is received, and to associate and store the action logic to be registered and the class name of the corresponding action in the state machine framework.
[0104] Furthermore, the rollback operation acquisition module is also used for:
[0105] When the failure of the target service execution action is detected through the state machine framework, the executed action of the target service is determined according to the action class name in the action record list in the state machine framework.
[0106] The data rollback order of the executed actions is generated according to the reverse order of the action execution sequence in the state machine framework.
[0107] Furthermore, the rollback operation execution module specifically includes:
[0108] The rollback action acquisition unit is used to sequentially acquire one of the executed actions according to the data rollback order of the executed actions, as the data rollback action to be rolled back;
[0109] The rollback operation execution unit is used to perform a corresponding data rollback operation on the data to be rolled back operation according to the action data rollback logic corresponding to the data to be rolled back operation.
[0110] The rollback loop execution unit is used to, when a successful execution instruction for the data rollback operation is detected, sequentially obtain the next execution action from the already executed actions according to the data rollback order, use it as the data rollback operation, and transfer it to the rollback operation execution unit.
[0111] Furthermore, the exception handling device for the aforementioned business also includes a rollback task storage module, which is used for:
[0112] When a failure instruction for the pending data rollback operation is detected, the current data rollback task in the failure instruction is obtained, and other pending data rollback tasks after the current data rollback task are determined according to the data rollback order.
[0113] The state machine framework is used to forward and store the current data rollback task and other data rollback tasks to the database.
[0114] Furthermore, the anomaly handling device for the service also includes:
[0115] The action recording module is used to create a list of action records corresponding to the target service through the state machine framework, and when the action execution instruction of the target service is detected through the state machine framework, record the execution action corresponding to the target service to the action record list.
[0116] Furthermore, the anomaly handling device for the service also includes an action status determination module, which is used for:
[0117] When the action completion instruction of the target service is detected through the state machine framework, the action execution state corresponding to the currently executed action in the action completion instruction is obtained, and the current execution action is judged to be successful based on the action execution state;
[0118] If the current action is executed successfully, the state machine framework controls the target service to execute the next action to be executed.
[0119] The methods executed by the above-mentioned program modules can be referred to in the various embodiments of the exception handling method of the present invention, which will not be repeated here.
[0120] The present invention also provides a computer-readable storage medium.
[0121] The present invention provides a computer-readable storage medium storing a service exception handling program, which, when executed by a processor, implements the steps of the service exception handling method described above.
[0122] The method implemented when the exception handling program of the service running on the processor is executed can be referred to in various embodiments of the exception handling method of the service of the present invention, and will not be repeated here.
[0123] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0124] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0125] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0126] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A method for handling business exceptions, characterized in that, The exception handling method for the aforementioned service includes the following steps: Upon receiving a rollback logic registration instruction, the action logic to be registered in the rollback logic registration instruction is obtained, and the action logic to be registered and the class name of the corresponding action are associated and stored in the state machine framework. A new action record list corresponding to the target service is created through the state machine framework, and when the action execution instruction of the target service is detected through the state machine framework, the execution action corresponding to the target service is recorded in the action record list; When the failure of the target service execution action is detected through the state machine framework, the executed actions of the target service and the data rollback order of the executed actions are determined according to the action record list in the state machine framework. Based on the class name of the executed action, the action data rollback logic corresponding to the executed action is determined in the state machine framework; the state machine framework isolates the business code and the action data rollback logic, and stores the action data rollback logic separately; According to the data rollback order and the action data rollback logic, the corresponding data rollback operations are performed on the executed actions in sequence.
2. The method for handling business anomalies as described in claim 1, characterized in that, When the failure of the target service execution action is detected through the state machine framework, the step of determining the executed actions of the target service and the data rollback order of the executed actions according to the action record list in the state machine framework specifically includes: When the failure of the target service execution action is detected through the state machine framework, the executed action of the target service is determined according to the action class name in the action record list in the state machine framework; The data rollback order of the executed actions is generated according to the reverse order of the action execution sequence in the state machine framework.
3. The abnormal handling method for business operations as described in claim 2, characterized in that, The step of sequentially performing corresponding data rollback operations on the executed actions according to the data rollback order and the action data rollback logic specifically includes: According to the data rollback order of the executed actions, one of the executed actions is sequentially obtained as the action to be rolled back; According to the action data rollback logic corresponding to the data to be rolled back, perform the corresponding data rollback operation on the data to be rolled back. When the successful execution instruction of the pending data rollback operation is detected, the next execution action in the executed actions is obtained in sequence according to the data rollback order, and is used as the pending data rollback operation. Then, the following steps are performed: according to the action data rollback logic corresponding to the pending data rollback operation, the corresponding data rollback operation is performed on the pending data rollback operation.
4. The method for handling business anomalies as described in claim 3, characterized in that, After the step of performing a corresponding data rollback operation on the data to be rolled back according to the action data rollback logic corresponding to the data to be rolled back operation, the method further includes: When a failure instruction for the pending data rollback operation is detected, the current data rollback task in the failure instruction is obtained, and other pending data rollback tasks after the current data rollback task are determined according to the data rollback order. The state machine framework is used to forward and store the current data rollback task and other data rollback tasks to the database.
5. The abnormal handling method for business operations as described in claim 4, characterized in that, After the step of forwarding and storing the current data rollback task and other data rollback tasks to the database through the state machine framework, the method further includes: According to a preset time interval, the data rollback task in the pending state of the database is re-executed through the state machine framework, and when the successful execution of the data rollback task in the pending state is detected, the task status of the successfully executed data rollback task is changed to executed.
6. The method for handling service anomalies as described in any one of claims 1-5, characterized in that, Before the step of determining the executed actions of the target service and the data rollback order of the executed actions according to the action record list in the state machine framework when the execution action of the target service is detected to have failed through the state machine framework, the method further includes: When the action completion instruction of the target service is detected through the state machine framework, the action execution state corresponding to the currently executed action in the action completion instruction is obtained, and the current execution action is judged to be successful based on the action execution state; If the current action is executed successfully, the state machine framework controls the target service to execute the next action to be executed.
7. An anomaly handling device for a business, characterized in that, The anomaly handling device for the aforementioned service includes: The rollback logic registration module is used to obtain the action logic to be registered in the rollback logic registration instruction when a rollback logic registration instruction is received, and to associate and store the action logic to be registered and the class name of the corresponding action in the state machine framework. An action recording module is used to create a new action record list corresponding to the target service through the state machine framework, and when the action execution instruction of the target service is detected through the state machine framework, record the execution action corresponding to the target service to the action record list; The rollback action acquisition module is used to determine the executed actions of the target service and the data rollback order of the executed actions based on the action record list in the state machine framework when the failure of the target service execution action is detected through the state machine framework. The rollback logic determination module is used to determine the action data rollback logic corresponding to the executed action in the state machine framework based on the class name of the executed action; the state machine framework isolates the business code and the action data rollback logic, and stores the action data rollback logic separately; the rollback operation execution module is used to perform corresponding data rollback operations on the executed actions in sequence according to the data rollback order and the action data rollback logic.
8. The anomaly handling device for a business as described in claim 7, characterized in that, The rollback operation acquisition module is also used for: When the failure of the target service execution action is detected through the state machine framework, the executed action of the target service is determined according to the action class name in the action record list in the state machine framework; The data rollback order of the executed actions is generated according to the reverse order of the action execution sequence in the state machine framework.
9. The anomaly handling device for a business as described in claim 8, characterized in that, The rollback operation execution module specifically includes: The rollback action acquisition unit is used to sequentially acquire one of the executed actions according to the data rollback order of the executed actions, as the data rollback action to be rolled back; The rollback operation execution unit is used to perform a corresponding data rollback operation on the data to be rolled back operation according to the action data rollback logic corresponding to the data to be rolled back operation. The rollback loop execution unit is used to, when a successful execution instruction for the data rollback operation is detected, sequentially obtain the next execution action from the already executed actions according to the data rollback order, use it as the data rollback operation, and transfer it to the rollback operation execution unit.
10. The anomaly handling device for a business as described in claim 9, characterized in that, The exception handling device for the aforementioned business also includes a rollback task storage module, which is used for: When a failure instruction for the pending data rollback operation is detected, the current data rollback task in the failure instruction is obtained, and other pending data rollback tasks after the current data rollback task are determined according to the data rollback order. The state machine framework is used to forward and store the current data rollback task and other data rollback tasks to the database.
11. The anomaly handling apparatus for a service as described in claim 10, characterized in that, The anomaly handling device for the aforementioned service also includes: The rollback task forwarding module is used to re-execute the data rollback task in the pending state of the database through the state machine framework according to a preset time interval, and when it is detected that the data rollback task in the pending state has been successfully executed, the task status of the successfully executed data rollback task is changed to executed.
12. An anomaly handling device for a business, characterized in that, The service exception handling device includes: a memory, a processor, and a service exception handling program stored in the memory and executable on the processor. When the service exception handling program is executed by the processor, it implements the steps of the service exception handling method as described in any one of claims 1 to 6.
13. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a service exception handling program, which, when executed by a processor, implements the steps of the service exception handling method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Transaction processing method and device of distributed framework
CN109324925A