Testing Method and System for Distributed System, Electronic Device and Storage Medium
By using a distributed exception simulator to simulate sub-transactions in a distributed system, the compensation operation of simulating sub-transactions is completed earlier than the forward operation, and the problem of difficulty in accurately simulating such scenarios in the prior art is solved, and the accuracy and efficiency of testing are improved.
Patent Information
- Application Number
- CN202111458897.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-01
- Publication Date
- 2025-06-27
- Estimated Expiration
- 2041-12-01
AI Technical Summary
The prior art is difficult to simulate a scenario where the compensation operation of sub-transactions is completed earlier than the forward operation in a distributed system, resulting in a reduced test accuracy.
By introducing a distributed exception simulator, the transaction service is diverted to its corresponding network service environment and injected preset faults. The compensation operation of simulating sub-transactions is completed earlier than the forward operation, thereby realizing the empty rollback test operation.
It effectively simulates the abnormal transaction sequence scenario caused by network blockage, jitter and other reasons in distributed transaction systems, and improves the accuracy and efficiency of testing.
Smart Images

Figure CN114237994B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of fintech, and in particular, to a test method and system for a distributed system, an electronic device, and a storage medium. Background Art
[0002] For a business system composed of multiple applications (for example, a financial business system), it has the characteristics of complex system, long transaction link, large transaction volume, and frequent interaction between applications. Based on business requirements, the system may need to support 7*24-hour customer service, with transactions running among multiple systems, operating independently in each application system, and interacting with each other in a certain order. However, due to reasons such as network congestion, network jitter, database connection exception, abnormal CPU usage, or disk failure, transaction failures or timeouts may occur, triggering compensation (reverse) operations. If the compensation (reverse) operation runs synchronously with the forward operation or completes earlier than the normal operation, it will cause abnormal transaction operation order.
[0003] With the development of computer technology, the coupling degree between systems is further reduced, and systems are becoming more and more independent. The participants in a transaction, the servers supporting the transaction, the resource servers, and the transaction manager are located on different nodes of a distributed system (different from a host system where all resources are concentrated on a single machine). For a long transaction chain, that is, a large operation is divided into a main transaction and N sub-transactions, and each small sub-transaction is distributed on different nodes and belongs to different applications. A distributed transaction system needs to ensure that these N sub-transactions either all succeed or all fail. However, due to reasons such as network congestion, network jitter, or database connection exception, some sub-transactions of a distributed transaction succeed, some sub-transactions fail or time out, triggering sub-transaction compensation for the entire transaction link. At this time, due to reasons such as network blockage and resource waiting, the forward operation of some timed-out forward sub-transactions may be in progress, while the compensated reverse operation has been invoked, resulting in the reverse operation being executed earlier than the forward operation and causing abnormal transaction operation order, thus leading to the failure of the entire transaction processing.
[0004] In the related art, it is difficult to simulate the above special production abnormal scenarios in a normal test environment, resulting in a reduction in test accuracy.
[0005] In view of the above problems, no effective solution has been proposed yet. Summary of the Invention
[0006] Embodiments of the present invention provide a test method and system for a distributed system, an electronic device, and a storage medium, so as to at least solve the technical problem in the related art that it is impossible to simulate a network service environment where the compensation operation of a sub-transaction is completed earlier than the forward operation, resulting in a reduction in test accuracy.
[0007] According to one aspect of the embodiments of the present invention, a test method for a distributed system is provided, including: initiating a transaction service; diverting the transaction service to a network service environment corresponding to a distributed exception simulator; injecting at least one preset fault into the network service environment, and completing the compensation operation of a sub-transaction earlier than the forward operation to implement an empty rollback test operation, where the sub-transaction refers to a sub-transaction in a distributed long transaction chain corresponding to a preset compensation mode used by the distributed system, and the compensation operation refers to an operation triggered by an exception of the transaction service due to a fault.
[0008] Optionally, obtain a service list carrying a specified tag, where the service list is used to match the transaction service, and the specified tag is used to match the service parameters of the transaction service and the empty rollback test operation; push the service list to a first type of server group, where the first type of server group locally caches the service list.
[0009] Optionally, configure the service parameters of the empty rollback test operation; push the service parameters to a first type of server group.
[0010] Optionally, diverting the transaction service to a network service environment corresponding to a distributed exception simulator includes: based on the transaction service, matching the service parameters for the empty rollback test operation; and in the case of successful matching, diverting the transaction service to the network service environment corresponding to the distributed exception simulator.
[0011] Optionally, in the case that the service parameters of the empty rollback test operation are not successfully matched based on the transaction service, call a preset network service environment in a second type of server group.
[0012] Optionally, completing the compensation operation of a sub-transaction earlier than the forward operation to implement an empty rollback test operation includes: injecting at least one preset fault into the network service environment to block the execution task of the sub-transaction in the compensation mode; and in the case that the execution task of the sub-transaction fails or times out, triggering the compensation operation of the sub-transaction, and calling the compensation operation of the sub-transaction to be executed earlier than the forward operation to implement the empty rollback test operation.
[0013] Optionally, the preset fault includes at least one of the following: network fault, CPU fault, cache fault, disk fault.
[0014] According to one aspect of the embodiments of the present invention, there is provided a test system for a distributed system, including: The test system at least includes: a transaction terminal device, a gateway device, a first type of server group, and a distributed exception simulator. Among them, the transaction terminal device is used to initiate a transaction service and send the transaction service to a first type of server through the gateway device. There are multiple first type of servers in the first type of server group; the first type of server diverts the transaction service to the network service environment corresponding to the distributed exception simulator; the distributed exception simulator injects at least one preset fault into the network service environment, and completes the compensation operation of the sub-transaction earlier than the forward operation, so as to implement an empty rollback test operation. Wherein, the sub-transaction refers to a certain sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode used by the distributed system, and the compensation operation refers to the operation triggered by the abnormal transaction service due to a fault.
[0015] Optionally, the distributed exception simulator includes: a service container that pushes a service list carrying a specified label to a registration unit, where the service list is used to match the transaction service, and the specified label is used to match the service parameters of the transaction service and the empty rollback test operation; a fault injection simulator for injecting at least one of the preset faults.
[0016] Optionally, the test system further includes: a registration unit that pushes the service list to the first type of server group, where the first type of server group locally caches the service list; a configuration unit that configures the service parameters for the empty rollback test operation and pushes the service parameters to the first type of server group.
[0017] Optionally, the test system further includes: a second type of server group, including multiple second type of servers, and each second type of server is used to provide a network service environment; wherein, in the case that the service parameters of the empty rollback test operation are not successfully matched based on the transaction service, the preset network service environment in the second type of server group is called.
[0018] According to another aspect of the embodiments of the present invention, there is also provided a computer-readable storage medium, which includes a stored computer program. When the computer program runs, it controls the device where the computer-readable storage medium is located to execute the above-mentioned test method for a distributed system.
[0019] According to another aspect of the embodiments of the present invention, there is also provided an electronic device, including one or more processors and a memory, where the memory is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the above-mentioned test method for a distributed system.
[0020] In the present disclosure, a transaction service can be initiated, and the transaction service can be diverted to the network service environment corresponding to the distributed exception simulator. At least one preset fault is injected into the network service environment, and the compensation operation of the sub-transaction is completed earlier than the forward operation, so as to implement an empty rollback test operation. Here, the sub-transaction refers to a certain sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode used by the distributed system, and the compensation operation refers to the operation triggered due to the exception of the transaction service caused by a fault. In the present application, a distributed exception simulator is introduced. By diverting the transaction service to the network service environment corresponding to the distributed exception simulator, it is possible to simulate the scenario where the compensation operation of the sub-transaction is completed earlier than the forward operation, resulting in an abnormal transaction operation order, which can solve the test problem, improve the test accuracy, and at the same time, improve the test efficiency of testers, thereby solving the technical problem in the related art that the network service environment where the compensation operation of the sub-transaction cannot be simulated to be completed earlier than the forward operation, resulting in a reduction in test accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The illustrative embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention. In the drawings:
[0022] Figure 1 is a flowchart of an optional test method for a distributed system according to an embodiment of the present invention;
[0023] Figure 2 is a schematic diagram of an optional test system for a distributed system according to an embodiment of the present invention;
[0024] Figure 3 is a schematic diagram of an optional structure of a distributed exception simulator according to an embodiment of the present invention;
[0025] Figure 4 is a schematic diagram of an optional SAGA compensation mode process according to an embodiment of the present invention;
[0026] Figure 5 is a schematic diagram of an optional main transaction state process according to an embodiment of the present invention;
[0027] Figure 6 is a schematic diagram of an optional transaction state process according to an embodiment of the present invention;
[0028] Figure 7 It is a schematic diagram of an optional empty rollback process of the SAGA compensation mode according to an embodiment of the present invention;
[0029] Figure 8 It is a schematic diagram of an optional test system for solving the empty rollback test scenario according to an embodiment of the present invention;
[0030] Figure 9 It is a flowchart of the operation of an optional test system for simulating an empty rollback test scenario according to an embodiment of the present invention;
[0031] Figure 10 It is a hardware structure block diagram of an electronic device (or mobile device) for a test method for a distributed system according to an embodiment of the present invention. Detailed implementation manners
[0032] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0033] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order different from those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0034] To facilitate the understanding of the present invention by those skilled in the art, some terms or nouns involved in the embodiments of the present invention are explained below:
[0035] SAGA: It splits a long transaction into multiple local short transactions, which are coordinated by a SAGA transaction coordinator. If it ends normally, it is completed normally. If a certain step fails, the compensation operation is called in the reverse order.
[0036] Remote Procedure Call (RPC): It is the basis of a distributed service framework and a way of inter - process communication. It requests services from a remote computer program through a network without the need to understand the protocol of the underlying network technology.
[0037] It should be noted that the test method and device for a distributed system in the present disclosure can be used in the financial technology field when testing a distributed system, and can also be used in any field other than the financial technology field when testing a distributed system. The application field of the test method and device for a distributed system in the present disclosure is not limited.
[0038] 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 for display, data for analysis, etc.) involved in the present disclosure are all information and data that have been authorized by the user or fully authorized by all parties.
[0039] The following embodiments of the present invention can be applied to various test scenarios of a distributed system. For example, in a financial business system, etc., the test scenario can be a scenario where due to network congestion, network jitter, or database connection anomalies in a simulated production environment, the compensation operation of a distributed transaction sub - transaction is completed earlier than the forward operation, resulting in an abnormal transaction operation sequence. The present invention can quickly simulate a technical scenario where due to network congestion, network jitter, or database connection anomalies, the compensation operation of a distributed transaction sub - transaction is completed earlier than the forward operation, resulting in an abnormal transaction operation sequence, thereby causing the entire transaction processing to fail, and timely and accurately implementing the empty rollback operation of a compensation mode (such as the SAGA compensation mode). The present invention introduces a distributed exception simulator. By parameter - guiding the service that needs to be tested for empty rollback into the distributed exception simulator, the test method is simple and fast, and is isolated from the normal test environment and test services, has no impact on normal testing. At the same time, the program content does not need to be modified at all, has no trauma to the program, and has no impact on the normal version. The present invention will be described below with reference to each embodiment.
[0040] Embodiment 1
[0041] According to an embodiment of the present invention, an embodiment of a security guarantee method for a financial account is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer - executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0042] Figure 1 It is a flowchart of an optional test method for a distributed system according to an embodiment of the present invention, as Figure 1As shown, the method includes the following steps:
[0043] Step S101, initiate a transaction service.
[0044] Step S102, divert the transaction service to the network service environment corresponding to the distributed exception simulator.
[0045] Step S103, inject at least one preset fault into the network service environment, complete the compensation operation of the sub-transaction earlier than the forward operation, and implement the null rollback test operation. Herein, the sub-transaction refers to a certain sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode used by the distributed system, and the compensation operation refers to the operation triggered due to the exception of the transaction service caused by a fault.
[0046] Through the above steps, a transaction service can be initiated, the transaction service can be diverted to the network service environment corresponding to the distributed exception simulator, at least one preset fault can be injected into the network service environment, the compensation operation of the sub-transaction can be completed earlier than the forward operation, and the null rollback test operation can be implemented. Herein, the sub-transaction refers to a certain sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode used by the distributed system, and the compensation operation refers to the operation triggered due to the exception of the transaction service caused by a fault. In the embodiment of the present invention, a distributed exception simulator is introduced. By diverting the transaction service to the network service environment corresponding to the distributed exception simulator, a scenario where the compensation operation of the sub-transaction is completed earlier than the forward operation, resulting in an abnormal transaction running order, can be simulated, which can solve the test problem, improve the test accuracy. At the same time, it also improves the test efficiency of testers, thereby solving the technical problem in the related art that a network service environment where the compensation operation of the sub-transaction cannot be simulated to be completed earlier than the forward operation, resulting in a reduction in test accuracy.
[0047] The embodiments of the present invention will be described in detail below in combination with the above steps.
[0048] Step S101, initiate a transaction service.
[0049] In the embodiment of the present invention, a transaction service can be initiated through a transaction terminal device. Herein, the transaction terminal device may include computer devices such as mobile phones, computers, tablets, and POS machines, which are used to input the initiation data of various transactions and display the output of various transaction results, and assume the role of initiating transactions (i.e., used to initiate a transaction service and send the transaction service to the first type of server (i.e., the consumer server) through a gateway device). The gateway device is a protocol converter that can promote the compatibility between different protocols and convert the transaction data generated by different transaction terminals into a unified identification format for convenient subsequent unified processing.
[0050] Step S102, divert the transaction service to the network service environment corresponding to the distributed exception simulator.
[0051] In an embodiment of the present invention, when a transaction service is initiated by a transaction terminal device, the transaction service can be sent to a first type of server through a gateway device. The first type of server group includes multiple first type of servers. Then, the transaction service can be diverted to a network service environment corresponding to a distributed exception simulator through the first type of server. Among them, the first type of server group (i.e., the consumer server group, which is schematically illustrated by the first type of server group in this embodiment and includes multiple first type of servers (i.e., consumer servers)) is a group of consumers (CONSUMER) of a distributed system. Its main function is to subscribe to a service list to facilitate service discovery, so as to remotely call a service through RPC and obtain parameters from a configuration center. For example, obtain service parameters that require null rollback testing. After receiving the service routed by a DSF (Distributed Service Framework) router, match the service parameters for null rollback testing. If the service parameters for null rollback testing cannot be matched, call the corresponding service in the producer server group according to the rules. If they are matched, call the corresponding service in the distributed exception simulator according to the rules (i.e., divert the transaction service to the network service environment corresponding to the distributed exception simulator). Among them, the network service environment is a production environment simulated by the distributed exception simulator, and this production environment is implemented by the producer server group.
[0052] Optionally, diverting the transaction service to the network service environment corresponding to the distributed exception simulator includes: matching service parameters for null rollback testing operations based on the transaction service; and in the case of successful matching, diverting the transaction service to the network service environment corresponding to the distributed exception simulator.
[0053] In an embodiment of the present invention, after the consumer server group receives the service routed by the DSF router (i.e., the transaction service), it matches the service parameters for null rollback testing operations. If the service parameters for null rollback testing cannot be matched, it calls the corresponding service in the producer server group according to the rules. If they are matched, it calls the corresponding service in the distributed exception simulator according to the rules (i.e., in the case of successful matching, divert the transaction service to the network service environment corresponding to the distributed exception simulator). Among them, the DSF router is used to receive the message service sent by a general gateway and route the message service to the consumer server group through route configuration.
[0054] Optionally, in the case where the service parameters for null rollback testing operations cannot be successfully matched based on the transaction service, call a preset network service environment in the second type of server group.
[0055] In an embodiment of the present invention, the second type of server group (i.e., the producer server group, including multiple second-type servers, each second-type server is used to provide a network service environment) is the producer group of the distributed system. Its main function is to push the service list to the registry, facilitating service discovery and providing the specific functions of the service. Moreover, in the case of service parameters based on the empty rollback test operation where the transaction service fails to match successfully, the preset network service environment in the second type of server group is called (i.e., the network service environment corresponding to the service parameters (i.e., the corresponding service)).
[0056] Step S103: Inject at least one preset fault into the network service environment, and complete the compensation operation of the sub-transaction earlier than the forward operation to implement the empty rollback test operation. Here, the sub-transaction refers to a certain sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode used by the distributed system, and the compensation operation refers to the operation triggered due to the abnormal transaction service caused by a fault.
[0057] In an embodiment of the present invention, at least one preset fault can be injected into the network service environment through a distributed exception simulator. The distributed exception simulator mainly includes two parts of functions: (1) It includes the PROVIDER function, which pushes the service list with special tags to the registry, facilitating service discovery and providing the specific functions of the service; (2) The fault injection function can inject network faults, CPU faults, cache faults, disk faults, etc. (i.e., a certain preset fault), simulate the corresponding fault scenario (i.e., inject at least one preset fault into the network service environment), and complete the compensation operation of the sub-transaction earlier than the forward operation to implement the empty rollback test operation. Here, the sub-transaction refers to a certain sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode (for example, the SAGA compensation mode) used by the distributed system, and the compensation operation refers to the operation triggered due to the abnormal transaction service caused by a fault.
[0058] Optionally, completing the compensation operation of the sub-transaction earlier than the forward operation to implement the empty rollback test operation includes: injecting at least one preset fault into the network service environment to block the execution task of the sub-transaction in the compensation mode; in the case where the execution task of the sub-transaction fails or times out, trigger the compensation operation of the sub-transaction, and call the compensation operation of the sub-transaction to be executed earlier than the forward operation to implement the empty rollback test operation.
[0059] Optionally, the preset fault includes at least one of the following: network fault, CPU fault, cache fault, disk fault.
[0060] In an embodiment of the present invention, by injecting faults through a fault injection module in a distributed anomaly simulator (i.e., injecting at least one preset fault into a network service environment, where the preset faults include but are not limited to: network faults, CPU faults, cache faults, disk faults, etc.), it is possible to reproduce faults such as network congestion, network jitter, database connection anomalies, CPU usage anomalies, or disk faults in the production environment (i.e., implement the execution task blocking of sub-transactions in the compensation mode), resulting in sub-transaction processing timeouts. When any sub-transaction fails or times out (i.e., in the case where the execution task of the sub-transaction fails or times out), a sub-transaction compensation operation is triggered, thereby causing the sub-transaction compensation (reverse) operation to complete earlier than the forward operation, and implementing an empty rollback test scenario (i.e., calling the compensation operation of the sub-transaction earlier than the forward operation is executed to implement the empty rollback test operation).
[0061] Optionally, obtain a service list carrying a specified tag, where the service list is used to match transaction services, and the specified tag is used to match the service parameters of the transaction service and the empty rollback test operation; push the service list to a first type of server group, where the first type of server group locally caches the service list.
[0062] Optionally, the test method further includes: configuring the service parameters of the empty rollback test operation; pushing the service parameters to the first type of server group.
[0063] In an embodiment of the present invention, a service list carrying a specified tag can be pushed to a registration unit through a service container in a distributed anomaly simulator, facilitating service discovery and providing specific service functions. The specified tag is used to match the service parameters of the transaction service and the empty rollback test operation, and the service list is used to match transaction services. Then, the registration unit pushes the service list to a first type of server group, where the first type of server group locally caches the service list.
[0064] In an embodiment of the present invention, according to the characteristic that a distributed transaction system needs to ensure that N sub-transactions either succeed together or fail together, quickly simulate scenarios such as network congestion, network jitter, or database connection anomalies, which cause the compensation operation of the distributed transaction sub-transaction to complete earlier than the forward operation, resulting in abnormal transaction running order, thereby causing the entire transaction processing to fail. In this embodiment, by diverting transaction services to the network service environment corresponding to the distributed anomaly simulator, it is possible to simulate a scenario where the compensation operation of the sub-transaction completes earlier than the forward operation, resulting in abnormal transaction running order, which can solve test problems, improve the accuracy of testing, and at the same time, improve the testing efficiency of testers.
[0065] Embodiment Two
[0066] Figure 2It is a schematic diagram of an optional test system for a distributed system according to an embodiment of the present invention. As Figure 2 shown, the test system at least includes: a transaction terminal device, a gateway device, a first type of server group, and a distributed exception simulator. Among them, the transaction terminal device is used to initiate a transaction service and send the transaction service to the first type of server through the gateway device. The first type of server group contains multiple first type of servers; the first type of server diverts the transaction service to the network service environment corresponding to the distributed exception simulator; the distributed exception simulator injects at least one preset fault into the network service environment, and completes the compensation operation of the sub-transaction earlier than the forward operation, so as to implement the null rollback test operation. Here, the sub-transaction refers to a certain sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode used by the distributed system, and the compensation operation refers to the operation triggered due to a fault causing the transaction service to be abnormal.
[0067] In the embodiment of the present invention, the transaction terminal device may include: computer devices such as mobile phones, computers, tablets, and POS machines, which are used to input the initiation data of various transactions and display the output of various transaction results, and undertake the role of initiating transactions (that is, used to initiate a transaction service and send the transaction service to the first type of server (i.e., the consumer server) through the gateway device);
[0068] General gateway (i.e., gateway device): It is a protocol converter that can promote compatibility between different protocols, convert the transaction data generated by different transaction terminals into a unified identification format, and facilitate subsequent unified processing;
[0069] Consumer server group (in this embodiment, it refers to the first type of server group, which contains multiple first type of servers (i.e., consumer servers)): It is the consumer (CONSUMER) group of the distributed system. Its main function is to subscribe to the service list to facilitate service discovery, so as to remotely call services through RPC, and obtain parameters from the configuration center. For example, obtain the service parameters required for the null rollback test. After receiving the service routed by the DSF (distributed service framework) router, match the service parameters for the null rollback test. If the service parameters for the null rollback test cannot be matched, call the corresponding service in the producer server group according to the rules. If they are matched, call the corresponding service in the distributed exception simulator according to the rules (that is, divert the transaction service to the network service environment corresponding to the distributed exception simulator). Here, the network service environment is a production environment simulated by the distributed exception simulator, and this production environment is implemented by the producer server group;
[0070] The distributed exception simulator mainly includes two parts of functions: (1) It includes the PROVIDER function, which pushes a service list with special tags to the registration center to facilitate the discovery of services and the provision of specific service functions; (2) The fault injection function can inject network faults, CPU faults, cache faults, disk faults, etc. (i.e., a certain preset fault), simulate the corresponding fault scenario (i.e., inject at least one preset fault into the network service environment), and complete the compensation operation of the sub-transaction earlier than the forward operation to achieve the null rollback test operation. Here, the sub-transaction refers to a sub-transaction in a distributed long transaction chain corresponding to a preset compensation mode (e.g., SAGA compensation mode) used by the distributed system, and the compensation operation refers to the operation triggered due to a fault resulting in abnormal transaction services.
[0071] Optionally, the distributed exception simulator includes: a service container that pushes a service list with a specified tag to the registration unit, where the service list is used to match transaction services, and the specified tag is used to match the service parameters of the transaction service and the null rollback test operation; a fault injection simulator for injecting at least one preset fault.
[0072] Optionally, the preset faults injected by the distributed exception simulator include at least one of the following: network faults, CPU faults, cache faults, disk faults.
[0073] In the embodiment of the present invention, Figure 3 is a schematic diagram of an optional structure of a distributed exception simulator according to an embodiment of the present invention, as Figure 3 shown, including a service container and a fault injection simulator, where
[0074] Service container: It has services 1 to N, can implement the producer function, and push a service list (used to match transaction services) with special tags (i.e., specified tags, used to match the service parameters of the transaction service and the null rollback test operation) to the registration center to facilitate the discovery of services and the provision of specific service functions;
[0075] The fault injection simulator can inject network faults, CPU faults, cache faults, disk faults, etc. (i.e., a certain preset fault) to simulate the corresponding fault scenario.
[0076] Optionally, the test system further includes: a registration unit that pushes the service list to the first type of server group, where the first type of server group locally caches the service list; a configuration unit that configures the service parameters for the null rollback test operation and pushes the service parameters to the first type of server group.
[0077] In an embodiment of the present invention, the test system further includes: a registration unit, configured to receive the registration functions of the consumer server group (i.e., the first type of server group), the producer server group, and the distributed anomaly simulator, and periodically push information such as service routing to the consumer server group, the producer server group, and the distributed anomaly simulator (i.e., push the service list to the first type of server group), so as to implement the service publishing and service subscription functions, wherein the first type of server group locally caches the service list.
[0078] The test system further includes: a configuration unit (i.e., a configuration center), configured to centrally manage the configurations of different environments and different clusters, and be able to push the configurations to the consumer server group in real time after the configurations are modified, and have characteristics such as standardized permissions and process governance. For example, configure the service parameters of the null rollback test operation and push the service parameters to the first type of server group.
[0079] Optionally, the test system further includes: a second type of server group, including multiple second type of servers, each second type of server being configured to provide a network service environment; wherein, in the case of the service parameters of the null rollback test operation not being successfully matched based on the transaction service, the preset network service environment in the second type of server group is called.
[0080] In an embodiment of the present invention, the test system further includes: a second type of server group (i.e., the producer server group, including multiple second type of servers, each second type of server being configured to provide a network service environment), which is the producer group of the distributed system, and its main function is to push the service list to the registration center to facilitate the discovery of services and provide the specific functions of the services. And, in the case of the service parameters of the null rollback test operation not being successfully matched based on the transaction service, the preset network service environment in the second type of server group is called (i.e., the network service environment corresponding to the service parameter (i.e., the corresponding service)).
[0081] In an embodiment of the present invention, the test system further includes: a DSF router, configured to receive the message service sent by the general gateway and route the message service to the consumer server group through routing configuration.
[0082] Optionally, diverting the transaction service to the network service environment corresponding to the distributed anomaly simulator includes: matching the service parameters of the null rollback test operation based on the transaction service; in the case of successful matching, diverting the transaction service to the network service environment corresponding to the distributed anomaly simulator.
[0083] In an embodiment of the present invention, after the consumer server group receives the service (i.e., transaction service) routed by the DSF router, it matches the service parameters of the null rollback test operation. If the null rollback test service parameters cannot be matched, it calls the corresponding service in the producer server group according to the rules. If they are matched, it calls the corresponding service in the distributed exception simulator according to the rules (i.e., in the case of successful matching, the transaction service is diverted to the corresponding network service environment of the distributed exception simulator).
[0084] Optionally, completing the null rollback test operation by making the compensation operation of the subtransaction earlier than the forward operation includes: injecting at least one preset fault into the network service environment to block the execution task of the subtransaction in the compensation mode; triggering the compensation operation of the subtransaction when the execution task of the subtransaction fails or times out, and calling the compensation operation of the subtransaction earlier than the forward operation to complete the null rollback test operation.
[0085] In an embodiment of the present invention, taking the SAGA compensation mode as an example for analysis, each transaction participant in the distributed transaction provides two types of processing: "forward - reverse". The transaction initiator calls the "forward" processing of each participant according to the business rules. If a participant's processing fails, the distributed transaction framework initiates "reverse" processing for other participants. Through the automatic exception recovery mechanism, the final consistency of the transaction can be ensured even after an exception occurs. The specific process is as follows:
[0086] (1) Before the main transaction first conducts a transaction (i.e., the main transaction is initiated), it first enters the compensation aspect, and then calls the transaction manager service to complete the record of the start state of the main transaction (i.e., record the start of the main transaction).
[0087] (2) The main transaction then calls the main transaction method to execute the business logic.
[0088] (3) If the main transaction method calls a subtransaction method, before executing the subtransaction method, it enters the compensation aspect. The compensation aspect first calls the transaction manager service to complete the record of the start state of the subtransaction (for example, record the start of transaction A), and then calls the subtransaction method to execute the subtransaction logic; after the subtransaction method is successfully executed, it calls the transaction manager service to complete the record of the successful state of the subtransaction, and the subtransaction execution ends.
[0089] (4) If the subtransaction method fails to execute, it enters the capture method in the compensation aspect, calls the transaction manager service to complete the record of the failed state of the subtransaction (for example, record the failure of a certain transaction), and the subtransaction execution ends.
[0090] (5) After the main transaction method is successfully executed (i.e., all subtransactions are successful), it calls the transaction manager service to complete the record of the successful state of the main transaction, and the main transaction execution ends.
[0091] (6) If the main transaction method fails (i.e., a sub - transaction fails or an exception is thrown by other methods of the main transaction), it enters the capture method in the compensation aspect, calls the transaction manager service to complete the recording of the compensation status of the main transaction, and the main transaction execution ends.
[0092] Figure 4 It is a schematic diagram of an optional SAGA compensation mode process according to an embodiment of the present invention. As Figure 4 shown, when the main transaction initiates a transaction request, the transaction manager records the start of the main transaction and returns to the transaction client of the main transaction. Then the main transaction can initiate a call request to sub - transaction A. After pre - processing (i.e., calling the transaction manager to record the start of A transaction), sub - transaction A executes the transaction logic of A transaction. After successful execution, it calls the transaction manager to record the end of A transaction (i.e., post - processing); meanwhile, the main transaction can initiate a call request to sub - transaction B. After pre - processing (i.e., calling the transaction manager to record the start of B transaction), sub - transaction B executes the transaction logic of B transaction. If an exception is thrown during the execution process, it calls the transaction manager to record the failure of B transaction and returns the exception to the transaction client of the main transaction to record the failure of the main transaction. After the main transaction method fails (i.e., a sub - transaction fails or an exception is thrown by other methods of the main transaction), it enters the capture method in the compensation aspect, calls the transaction manager to initiate compensation to sub - transaction A and sub - transaction B respectively, performs compensation transactions, completes the recording of the compensation status of the main transaction, and the main transaction execution ends.
[0093] Figure 5 It is a schematic diagram of an optional main transaction status process according to an embodiment of the present invention. As Figure 5 shown, (1) The main transaction creates a main transaction ID (CREATE), executes the business logic and sequentially invokes all sub - transactions. If all sub - transactions return successfully, the main transaction is executed successfully (COMMIT_SUCCESS); (2) If the business logic execution times out, the main transaction enters the timeout state (START_TIMEOUT); (3) If any one of the sub - transactions fails or times out, the main transaction execution is abnormal and enters the compensation stage (COMPENSATE), triggering the sub - transaction compensation operation. If all sub - transaction compensation operations are successful, the main transaction compensation is successful (COMPENSATE_SUCCESS); (4) If any one of the sub - transaction compensation operations fails, the main transaction compensation fails (COMPENSATE_FAILED).
[0094] Figure 6 It is a schematic diagram of an optional transaction status process according to an embodiment of the present invention. As Figure 6As shown in the figure, (1) The sub-transaction starts with a sub-transaction ID (START), executes the business logic. If the sub-transaction execution is successful (START_SUCCESS), it returns a notice to the main transaction that the transaction is successful (COMMIT_SUCCESS). After the sub-transaction execution is successful, compensation can also be initiated as appropriate; (2) If the sub-transaction execution fails (START_FAILED), it returns a notice to the main transaction that the transaction fails. If the sub-transaction execution times out (START_TIMEOUT), it returns a notice to the main transaction that the transaction fails. When the main transaction receives the transaction failure information, it triggers compensation. The sub-transaction initiates compensation (COMPENSATE_MANUAL), and the initial state is in the process of compensation (COMPENSATE). The compensation business logic is executed, and the compensation result is updated: the sub-transaction compensation fails (COMPENSATE_FAILED) (compensation can be re-initiated) or the sub-transaction compensation is successful (COMPENSATE_SUCCESS).
[0095] In an embodiment of the present invention, Figure 7 is a schematic diagram of an empty rollback process of an optional SAGA compensation mode according to an embodiment of the present invention, as Figure 7 shown in the figure: (1) After the main transaction starts, it completes the recording of the main transaction CREATE state; (2) The main transaction enters the main transaction method and executes business logic processing; (3) The sub-transaction is called to start a sub-transaction ID (i.e., sub-transaction ID generation). Then, by injecting at least one preset fault (such as network fault, CPU fault, cache fault, disk fault, etc.) into the network service environment, the execution task of the sub-transaction in the compensation mode is blocked, resulting in the sub-transaction processing timing out; (4) If any sub-transaction fails or times out (i.e., in the case where the sub-transaction execution task fails or times out), the main transaction times out and fails, enters the compensation stage (COMPENSATE), and triggers the sub-transaction compensation operation; (5) The reverse operation of the sub-transaction is called. Since the forward operation of the sub-transaction is blocked, the reverse operation of the sub-transaction is executed earlier than the forward operation (i.e., the reverse operation is successful), thereby realizing the empty rollback operation (i.e., the end of the empty rollback of the SAGA compensation mode). After the execution ends, it returns that the empty rollback is successful (i.e., the compensation operation of the sub-transaction is executed earlier than the forward operation, realizing the empty rollback test operation).
[0096] Figure 8 is a schematic diagram of an optional test system for solving the empty rollback test scenario according to an embodiment of the present invention, as Figure 8 shown in the figure, including: a transaction terminal device ( Figure 8Schematically shows three terminal devices: counter, mobile device, POS), general gateway, DSF router, consumer server group, registration center, configuration center, producer server group, and distributed anomaly simulator. Among them, the configuration center can configure information such as null rollback service tags and routing configurations, and the producer server group can provide performance monitoring services, log collection services, etc. In the embodiments of the present invention, the logic of each module is connected in series as follows:
[0097] When the distributed anomaly simulator starts, it pushes a service list with special tags to the registration center; when the containers in the producer server group restart, they push the service list to the registration center; the registration center pushes the service list to the consumer server group; when the containers in the consumer server group restart, they obtain the service list from the registration center to the local cache or receive the service list pushed by the registration center and store it in the local cache; the configuration center configures the service parameters that need null rollback testing and pushes them to the consumer server group in real time; the consumer server group caches the service parameters that need null rollback testing; the fault injection module in the distributed anomaly simulator injects faults; the transaction terminal device initiates a corresponding transaction, and the transaction passes through the general gateway and DSF router to reach the consumer server group, and uses the specific service to match the null rollback test service parameters. If a match is found, the transaction is diverted to the corresponding service on the distributed anomaly simulator. Through the fault simulation on the distributed anomaly simulator, faults such as network congestion, network jitter, database connection anomaly, CPU usage anomaly, or disk failure in the production environment are reproduced, thereby causing the sub-transaction compensation (reverse) operation to complete earlier than the forward operation, and realizing the null rollback test scenario.
[0098] In the embodiments of the present invention, according to the characteristic that the distributed transaction system needs to ensure that N sub-transactions are either all successful or all failed, network congestion, network jitter, or database connection anomalies are quickly simulated, etc., resulting in the compensation operation of the distributed transaction sub-transaction being completed earlier than the forward operation, causing the transaction operation sequence to be abnormal, thereby causing the entire transaction processing to fail in the technical scenario. The null rollback operation of the compensation mode is realized timely and accurately. In the embodiments of the present invention, a distributed anomaly simulator is introduced, and the services that need null rollback testing are diverted to the distributed anomaly simulator through parameters. The testing method is simple and fast, and is isolated from the normal testing environment and testing services, has no impact on normal testing, and the program content does not need any modification, causing no trauma to the program and having no impact on the normal version.
[0099] Embodiment III
[0100] Figure 9 Is a flowchart of the operation of a test system for simulating a null rollback test scenario according to an embodiment of the present invention, as Figure 9 shown. The method includes the following steps:
[0101] Step S100: When the distributed exception simulator starts, it pushes a service list with special tags to the registry center.
[0102] Step S200: The registry center pushes the service list to the consumer server group.
[0103] Step S300: The consumer server group locally caches the service list.
[0104] Step S400: The configuration center configures the service parameters that require null rollback testing, and the configuration center pushes the parameters to the consumer server group in real time.
[0105] Step S500: The fault injection module in the distributed exception simulator injects faults.
[0106] Step S600: The transaction terminal device initiates a transaction.
[0107] Step S700: The transaction reaches the consumer server through the general gateway and the DSF router.
[0108] Step S800: The consumer service matches the service parameters for null rollback testing. If a match is found, the transaction is diverted to the distributed exception simulator.
[0109] Step S900: On the distributed exception simulator, through fault simulation, the sub - transaction compensation (reverse) operation is completed earlier than the forward operation, realizing the null rollback operation.
[0110] In the embodiment of the present invention, it can quickly simulate technical scenarios where the compensation operation of the distributed transaction sub - transaction arrives earlier than the forward operation due to reasons such as network congestion, network jitter, or database connection exception, resulting in abnormal transaction operation order and causing the entire transaction processing to fail. It can timely and accurately implement the null rollback operation in the compensation mode, solve the testing problem, improve the testing accuracy, and at the same time improve the testing efficiency of testers. In the embodiment of the present invention, by parameter - diverting the service that requires null rollback testing into the distributed exception simulator, the testing method is simple and fast, and is isolated from the normal testing environment and testing services, has no impact on normal testing. At the same time, the program content does not need any modification, has no trauma to the program, and has no impact on the normal version.
[0111] According to another aspect of the embodiment of the present invention, an electronic device is further provided, including one or more processors and a memory. The memory is used to store one or more programs. When one or more programs are executed by one or more processors, one or more processors are enabled to implement the testing method for the distributed system described in any one of the above.
[0112] Figure 10The following is a hardware block diagram of an electronic device (or mobile device) for a test method of a distributed system according to an embodiment of the present invention. As Figure 10 shown, the electronic device may include one or more processors 102 (illustrated as 102a, 102b, ……, 102n in the figure) (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 104 for storing data. In addition, it may further include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply, and / or a camera. Those of ordinary skill in the art can understand that Figure 10 the structure shown is only schematic and does not limit the structure of the above-mentioned electronic device. For example, the electronic device may further include more or fewer components than Figure 10 shown, or have a different configuration from Figure 10 shown.
[0113] According to another aspect of the embodiments of the present invention, there is also provided a computer-readable storage medium, which includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the test method for a distributed system in any one of the above.
[0114] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0115] In the above embodiments of the present invention, the descriptions of the various embodiments have their own emphases. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0116] In several embodiments provided in the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units can be a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of the units or modules can be in an electrical or other form.
[0117] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0118] In addition, in each embodiment of the present invention, each functional unit may be integrated into one processing unit, may exist physically alone for each unit, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.
[0119] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention. The foregoing storage medium includes: various media such as USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical discs that can store program codes.
[0120] The above are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.
Claims
1. A test method for a distributed system, characterized in that, Including: Initiating a transaction service; Diverting the transaction service to a network service environment corresponding to a distributed anomaly simulator; Injecting at least one preset fault into the network service environment, completing the compensation operation of a sub-transaction earlier than the forward operation, and implementing an empty rollback test operation, where the sub-transaction refers to a certain sub-transaction in a distributed long transaction chain corresponding to a preset compensation mode used by a distributed system, and the compensation operation refers to an operation triggered by an anomaly of the transaction service due to a fault; Completing the compensation operation of a sub-transaction earlier than the forward operation and implementing an empty rollback test operation, including: injecting at least one preset fault into the network service environment to block the execution task of the sub-transaction in the compensation mode; in the case where the execution task of the sub-transaction fails or times out, triggering the compensation operation of the sub-transaction, and calling the compensation operation of the sub-transaction to be executed earlier than the forward operation to implement an empty rollback test operation.
2. The test method according to claim 1, wherein Further including: Obtaining a service list carrying a specified tag, where the service list is used to match the transaction service, and the specified tag is used to match the service parameters of the transaction service and the empty rollback test operation; Pushing the service list to a first type of server group, where the first type of server group locally caches the service list.
3. The test method according to claim 1, characterized in that Further including: Configuring service parameters for the empty rollback test operation; Pushing the service parameters to a first type of server group.
4. The test method according to claim 3, wherein Diverting the transaction service to a network service environment corresponding to a distributed anomaly simulator, including: Based on the transaction service, matching service parameters for the empty rollback test operation; In the case of successful matching, diverting the transaction service to the network service environment corresponding to the distributed anomaly simulator.
5. The test method according to claim 4, wherein In the case where the service parameters of the empty rollback test operation are not successfully matched based on the transaction service, calling a preset network service environment in a second type of server group.
6. The test method according to any one of claims 1 to 5, characterized in that, The preset fault includes at least one of the following: network fault, CPU fault, cache fault, disk fault.
7. A test system for a distributed system, characterized in that, The test system at least includes: a transaction terminal device, a gateway device, a first type of server group, and a distributed anomaly simulator, where The transaction terminal device is used to initiate a transaction service and send the transaction service to a first type of server through the gateway device, and the first type of server group includes multiple first type of servers; The first type of server diverts the transaction service to a network service environment corresponding to the distributed anomaly simulator; The distributed exception simulator injects at least one preset fault into the network service environment, and completes the compensation operation of the sub-transaction earlier than the forward operation, so as to implement the null rollback test operation. Wherein, the sub-transaction refers to a sub-transaction in the distributed long transaction chain corresponding to the preset compensation mode used by the distributed system, and the compensation operation refers to the operation triggered by the abnormal transaction service due to a fault. Completing the compensation operation of the sub-transaction earlier than the forward operation to implement the null rollback test operation includes: injecting at least one preset fault into the network service environment to block the execution task of the sub-transaction in the compensation mode; in the case where the execution task of the sub-transaction fails or times out, triggering the sub-transaction compensation operation, and calling the compensation operation of the sub-transaction to be executed earlier than the forward operation to implement the null rollback test operation.
8. The test system according to claim 7, characterized in that, The distributed exception simulator includes: A service container that pushes a service list with a specified label to a registration unit, where the service list is used to match the transaction service, and the specified label is used to match the service parameters of the transaction service and the null rollback test operation; A fault injection simulator for injecting at least one of the preset faults.
9. The test system according to claim 7, characterized in that It further includes: A second type of server group, including a plurality of second type of servers, and each of the second type of servers is used to provide a network service environment; Wherein, in the case that the service parameters of the null rollback test operation are not successfully matched based on the transaction service, a preset network service environment in the second type of server group is called.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the test method for a distributed system according to any one of claims 1 to 6.
11. An electronic device, characterized in that, It includes one or more processors and a memory, and the memory is used to store one or more programs. Wherein, when the one or more programs are executed by the one or more processors, the one or more processors implement the test method for a distributed system according to any one of claims 1 to 6.
Citation Information
Patent Citations
Method for fault-injection test based on virtual machine
CN101872323A
Business processing method, device and equipment
CN112766829A