Method and related device for detecting rationality of Saga distributed transaction design

By parsing the log of Saga distributed transactions and converting them into SQL statements, and inserting error events to determine the rationality of the design, the problem of relying on technical documents and test data in the existing technology is solved, achieving a more accurate and reliable detection effect.

CN119520337AActive Publication Date: 2025-02-25AGRICULTURAL BANK OF CHINA

Patent Information

Application Number
CN202411726073.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-02-25
Estimated Expiration
2044-11-28

AI Technical Summary

Technical Problem

When detecting the rationality of Saga's distributed transaction design, the prior art needs to rely on technical documents and test data, resulting in the accuracy and completeness of the test results being affected by the quality of technical documents and changes in the test data.

Method used

By obtaining the business identity and log number of the test case, the data operations in the log are parsed, converted into a structured query language SQL statement, and error events are inserted to determine the design rationality of Saga distributed transactions.

Benefits of technology

A detection method that does not rely on technical documents and test data is implemented, and the impact of technical documents quality and test data changes on test results is excluded, which improves the accuracy and reliability of the detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119520337A_ABST
    Figure CN119520337A_ABST
Patent Text Reader

Abstract

The invention discloses a method and a related device for detecting rationality of Saga distributed transaction design, and relates to the field of distributed transactions, and the method comprises the following steps: obtaining a service identifier of a test case and a log number of a log, and based on the service identifier and the log number, obtaining the log generated when the test case is used for a reverse test; according to the sequence of the operation time, converting the data operation in the log into a plurality of SQL statements which are sequentially arranged according to the sequence of the operation time; determining the occurrence time of an error event in the log, and inserting the error event into a plurality of SQL statements arranged in sequence based on the occurrence time; on the basis of the multiple SQL statements which are inserted with the error events and are arranged in sequence, determining a test result after the reverse test is carried out by utilizing the test case; and determining whether the target design is reasonable based on a test result after the reverse test. According to the method, the influence of the quality of the technical document and the change of the test data on the accuracy and completeness of the test result can be eliminated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of distributed transaction technology, and in particular to a method and related device for detecting the rationality of Saga distributed transaction design. Background Art

[0002] The core idea of ​​​​Saga transactions is to split a long transaction (Long Live Transaction, LLT) into multiple local short transactions, which are coordinated by the Saga transaction coordinator. If they end normally, they are completed normally. If a step fails, the compensation operation is called according to the specified order.

[0003] The Saga model regards distributed transactions as a chain of subtransactions. Each Saga subtransaction has a corresponding forward operation (execute) Tn and a corresponding compensation operation (compensate) Cn. Cn is used to undo the results caused by Tn. If all subtransactions are executed successfully, the entire transaction is successful; if any subtransaction fails, the entire transaction model will be canceled. The compensation operation (compensate) cancels the behavior of Tn from a semantic perspective, but it may not return the database to the state before Tn was executed.

[0004] Currently, the design rationality test of Saga distributed transactions needs to rely on technical documents and compare the data snapshots before and after the test case execution. The quality of technical documents and changes in test data have a great impact on the accuracy and completeness of the test results. Summary of the invention

[0005] In view of the above problems, the present application provides a method and related device for detecting the rationality of Saga distributed transaction design, so as to achieve the purpose of detecting the rationality of Saga distributed transaction design without relying on technical documents and test data. The specific scheme is as follows:

[0006] The first aspect of the present application provides a method for detecting the rationality of Saga distributed transaction design, including:

[0007] Obtaining a business identifier of a test case and a log number of a log associated with the business identifier, wherein the test case is a case for reverse testing a business system of a target design using a Saga distributed transaction;

[0008] Based on the service identifier and the log number, obtaining a log generated when performing a reverse test using the test case;

[0009] Converting the data operations in the log into a plurality of structured query language SQL statements arranged in sequence according to the sequence of operation times;

[0010] Determine the occurrence time of the error event in the log, and insert the error event into the plurality of structured query language SQL statements arranged in sequence based on the occurrence time;

[0011] Determine a test result after reverse testing using the test case based on the plurality of structured query language SQL statements arranged in sequence inserted into the error event;

[0012] Based on the test results after the reverse test, determine whether the target design of the Saga distributed transaction used by the business system is reasonable.

[0013] In a possible implementation, determining the test result after reverse testing using the test case based on the plurality of structured query language SQL statements arranged in sequence and inserted into the error event includes:

[0014] Determine the SQL statement arranged before the error event as a forward operation, and determine the SQL statement arranged after the error event as a compensation operation;

[0015] Determine the forward operation and the compensation operation performed on the same data table as an operation group;

[0016] Determine a test result after each of the operation groups operates the same data table.

[0017] In a possible implementation, determining a test result after each operation group operates the same data table includes:

[0018] Each of the operation groups is processed as follows:

[0019] The forward operation and the compensation operation included in the operation group are analyzed to determine whether the compensation operation can restore the operation result of the forward operation in the operation group. If so, the test result after the operation group operates the same data table is determined to be reasonable. If not, the test result after the operation group operates the same data table is determined to be unreasonable.

[0020] In a possible implementation, parsing the forward operation and the compensation operation included in the operation group to determine whether the compensation operation can restore the operation result of the forward operation in the operation group includes:

[0021] The operation types of the forward operation and the compensation operation included in the operation group are analyzed. If the operation type of the compensation operation is opposite to the operation type of the forward operation, it is determined that the compensation operation can restore the operation result of the forward operation in the operation group; otherwise, it is determined that the compensation operation cannot restore the operation result of the forward operation in the operation group.

[0022] In a possible implementation, determining whether the target design of the Saga distributed transaction used by the business system is reasonable based on the test result after the reverse test includes:

[0023] If the test results after each of the operation groups operates the same data table are all reasonable, it is determined that the target design of the Saga distributed transaction used by the business system is reasonable;

[0024] If the test result after at least one of the operation groups operates the same data table is unreasonable, it is determined that the target design of the Saga distributed transaction used by the business system is unreasonable.

[0025] A second aspect of the present application provides a device for detecting the rationality of Saga distributed transaction design, including:

[0026] An identification obtaining unit, used to obtain a business identification of a test case and a log number of a log associated with the business identification, wherein the test case is a case for reverse testing a business system of a target design using a Saga distributed transaction;

[0027] A log obtaining unit, configured to obtain, based on the service identifier and the log number, a log generated when performing a reverse test using the test case;

[0028] A conversion unit, configured to convert the data operations in the log into a plurality of structured query language SQL statements arranged in sequence according to the sequence of operation times;

[0029] An inserting unit, used for determining the occurrence time of the error event in the log, and inserting the error event into the plurality of structured query language SQL statements arranged in sequence based on the occurrence time;

[0030] A result determination unit, configured to determine a test result after reverse testing using the test case based on the plurality of sequentially arranged structured query language SQL statements inserted into the error event;

[0031] The reasonable determination unit is used to determine whether the target design of the Saga distributed transaction used by the business system is reasonable based on the test results after the reverse test.

[0032] In a possible implementation, the result determination unit includes:

[0033] An operation determination subunit, used to determine the SQL statement arranged before the error event as a forward operation, and determine the SQL statement arranged after the error event as a compensation operation;

[0034] An operation group subunit, used for determining the forward operation and the compensation operation operated on the same data table as an operation group;

[0035] The result determination subunit is used to determine the test result after each operation group operates the same data table.

[0036] The third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the method for detecting the rationality of the Saga distributed transaction design according to the first aspect or any implementation of the first aspect.

[0037] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0038] The memory is used to store computer programs;

[0039] The processor is used to execute the computer program so that the electronic device can implement the method for detecting the rationality of the Saga distributed transaction design according to the above-mentioned first aspect or any implementation method of the first aspect.

[0040] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement a method for detecting the rationality of the Saga distributed transaction design according to the above-mentioned first aspect or any implementation of the first aspect.

[0041] By means of the above technical scheme, the present application provides a method and related device for detecting the rationality of the design of Saga distributed transactions, which can obtain the business identification of the test case and the log number of the log associated with the business identification, and obtain the log generated when the test case is used for reverse testing based on the business identification and the log number; according to the chronological order of the operation time, the data operation in the log is converted into a plurality of structured query language SQL statements arranged in sequence according to the chronological order of the operation time; the occurrence time of the error event in the log is determined, and the error event is inserted into the plurality of structured query language SQL statements arranged in sequence based on the occurrence time; based on the plurality of structured query language SQL statements arranged in sequence into which the error event is inserted, the test result after reverse testing using the test case is determined; based on the test result after reverse testing, whether the target design of the Saga distributed transaction used by the business system is reasonable is determined. The present application does not use technical documents and test data, but determines the test results based on the log, and then determines whether the target design of the Saga distributed transaction used by the business system is reasonable, which can exclude the influence of the quality of the technical documents and the change of the test data on the accuracy and completeness of the test results. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0043] Figure 1 A schematic diagram of a system architecture provided for this application;

[0044] Figure 2 A schematic diagram of an optional hardware structure of a terminal provided in this application;

[0045] Figure 3 A schematic diagram of the structure of the server provided for this application;

[0046] Figure 4 A flowchart of a method for detecting the rationality of Saga distributed transaction design provided in this application;

[0047] Figure 5 A flowchart of determining the test result after reverse testing using a test case based on multiple structured query language SQL statements arranged in sequence according to the insertion error event provided by the present application;

[0048] Figure 6 A schematic diagram of the structure of a device for detecting the rationality of Saga distributed transaction design provided by the present application;

[0049] Figure 7 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION

[0050] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0051] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0052] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0053] See also Figure 1 , Figure 1 A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers ( Figure 1 In the example, a server is included, and the server 200 can provide the method provided in the embodiment of the present application for one or more terminals.

[0054] Among them, an application for detecting the rationality of the Saga distributed transaction design can be installed on the terminal 100. The above application and web page can provide an interface. The terminal 100 can receive relevant parameters entered by the user on the interface (such as the business identifier of the test case and the log number of the log associated with the business identifier), and send the above parameters to the server 200. The server 200 can obtain the processing result based on the received parameters and return the processing result to the terminal 100.

[0055] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters by itself without the cooperation of the server, and the embodiments of the present application are not limited to this.

[0056] Next describe Figure 1The product form of the mid-terminal 100;

[0057] The terminal 100 in the embodiment of the present application can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiment of the present application does not impose any limitation on this.

[0058] Figure 2 An optional hardware structure diagram of the terminal 100 is shown.

[0059] refer to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), an earphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190 and other components. Those skilled in the art will appreciate that Figure 2 These are merely examples of terminals or multi-function devices and do not constitute limitations on the terminals or multi-function devices, which may include more or fewer components than those shown in the figures, or combinations of certain components, or different components.

[0060] The input unit 130 can be used to receive input digital or character information, and generate key signal input related to the user settings and function control of the portable multifunctional device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect the user's touch operations on or near it (such as the user's operation on or near the touch screen using any suitable object such as fingers, joints, stylus, etc.), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the user's touch action on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute the command sent by the processor 170; the touch signal at least includes the touch point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, the touch screen can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic wave. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.

[0061] Among them, the input device 132 can receive input data and the like.

[0062] The display unit 140 may be used to display information input by the user or information provided to the user, various menus of the terminal 100, interactive interfaces, file display, and / or playback of any multimedia file. In an embodiment of the present application, the display unit 140 may be used to display an interface for inputting parameters, processing results, and the like.

[0063] The memory 120 can be used to store instructions and data. The memory 120 can mainly include an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files, texts, etc.; the instruction storage area can store software units such as operating systems, applications, instructions required for at least one function, or their subsets and extensions. It can also include a non-volatile random access memory; provide the processor 170 with hardware, software and data resources including management of computing and processing equipment, and support control software and applications. It is also used for the storage of multimedia files, and the storage of running programs and applications.

[0064] The processor 170 is the control center of the terminal 100. It uses various interfaces and lines to connect various parts of the entire terminal 100. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal 100 and processes data, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips. The processor 170 may also be used to generate corresponding operation control signals, send them to corresponding components of the computing and processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein performs corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.

[0065] Among them, the memory 120 can be used to store software codes related to the method for detecting the rationality of the Saga distributed transaction design, the processor 170 can execute the steps of the method for detecting the rationality of the Saga distributed transaction design, and can also schedule other units (such as the above-mentioned input unit 130 and the display unit 140) to implement corresponding functions.

[0066] The radio frequency unit 110 (optional) can be used for receiving and sending information or receiving and sending signals during a call, for example, after receiving the downlink information of the base station, it is sent to the processor 170 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (Global System of Mobile communication, GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE), email, Short Messaging Service (SMS), etc.

[0067] In this embodiment of the present application, the RF unit 110 can send data to the server 200 and receive processing results sent by the server 200.

[0068] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network port.

[0069] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption.

[0070] The terminal 100 further includes an external interface 180 , which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal 100 to communicate with other devices, or to connect a charger to charge the terminal 100 .

[0071] Although not shown, the terminal 100 may also include a flashlight, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which are not described in detail here. Some or all of the methods described below may be applied in the following embodiments. Figure 2 In the terminal 100 shown.

[0072] Next describe Figure 1 The product form of the server 200;

[0073] Figure 3 A structural diagram of a server 200 is provided, such as Figure 3 As shown, the server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other via the bus 201.

[0074] The bus 201 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0075] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0076] The memory 204 may include a volatile memory, such as a random access memory (RAM). The memory 204 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0077] Among them, the memory 204 can be used to store software codes related to the method for detecting the rationality of the Saga distributed transaction design, the processor 202 can execute the steps of the method for detecting the rationality of the Saga distributed transaction design of the chip, and can also schedule other units to implement corresponding functions.

[0078] It should be understood that the above-mentioned terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above-mentioned terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as application specific integrated circuit (ASIC), field-programmable gate array (FPGA), general-purpose processor, digital signal processor (DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.

[0079] The embodiment of the present application provides a method for detecting the rationality of the design of a Saga distributed transaction. The method for detecting the rationality of the design of a Saga distributed transaction in the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0080] Reference Figure 4 , Figure 4 A flow chart of a method for detecting the rationality of Saga distributed transaction design provided in an embodiment of the present application is as follows: Figure 4 As shown, a data processing method provided in an embodiment of the present application may include steps 401 to 406, and these steps are described in detail below.

[0081] 401. Obtain a business identifier of a test case and a log number of a log associated with the business identifier. The test case is a case for reverse testing a business system designed to use a Saga distributed transaction.

[0082] There are many types of business systems, such as financial business systems, office business systems, etc. The following will take the financial business system as an example for illustration.

[0083] In financial business systems, transactions are often performed, for example, transferring funds from account A to account B. In this fund transfer process, at least two operations are involved, namely, reducing funds from account A and increasing corresponding funds in account B. If both operations are completed successfully, the transaction is successful. If the operation of reducing funds from account A is completed successfully, but the operation of increasing corresponding funds in account B fails, the operation of reducing funds from account A needs to be canceled through compensation operation, that is, the funds in account A are restored to the amount before the operation of reducing funds from account A is performed. If the financial business system uses the target design of Saga distributed transactions, if the target design is reasonable, the financial business system using the target design can restore the funds in account A to the amount before the operation of reducing funds from account A is performed when the operation of increasing corresponding funds in account B fails (that is, the compensation operation of the target design works normally). In order to verify whether the target design is reasonable, it can be tested through test cases. Since it is to verify the compensation operation, the test case is a case for reverse testing, that is, a case that will inevitably trigger the compensation operation. For example: A transaction case in which funds in account A are transferred to account B when account B is frozen.

[0084] It should be noted that there are many types of services that can be performed in a business system. For example, for a financial business system, the services that can be performed include: cash transaction services, time deposit services, account opening services, SMS notification services, online banking services, etc. Different services have different identifiers, and a business identifier can uniquely identify a business. For example, in the case where account B is frozen, the identifier of a transaction business that transfers funds from account A to account B can be 000001.

[0085] A log is a file that records various important information during the operation of a business system. Different logs have different log numbers. When executing a certain business, this application can record the new log generated during the execution of the business, and associate the log number of the new log generated with the business ID of the business. In this way, this application obtains the log number of the log associated with the business ID.

[0086] 402. Based on the business identifier and the log number, obtain the log generated when the reverse test is performed using the test case.

[0087] In some cases, a log may record information of multiple services, so the present application can obtain the log generated when the reverse test is performed using the test case based on the service identifier and the log number. Specifically, the present application can first find the log with the log number according to the log number, and then find the service identifier obtained in step 401 in the log. If it is found, it is determined that the log contains information generated when the test case is executed, and the log can be determined as a log generated when the reverse test is performed using the test case. If it is not found, it is considered that the log is not a log generated when the reverse test is performed using the test case.

[0088] In practical applications, as time goes by, there are more and more logs, so this application can also determine the logs generated when the reverse test is performed according to the date of the reverse test. For example, if a reverse test is performed on January 3, 2021, the logs generated when the reverse test is performed using the test case can be queried based on the business identifier, log number, and January 3, 2021. When querying, you can only query in the logs generated on January 3, 2021, which greatly speeds up the query.

[0089] 403. Convert the data operations in the log into a plurality of structured query language SQL statements arranged in sequence according to the sequence of operation times.

[0090] The log may record multiple data operations. For example, when account B is frozen, the log generated after the execution of a transaction case of transferring funds from account A to account B will record: the operation of reducing funds from account A and the operation of adding corresponding funds to account B. Of course, since account B is frozen, the operation of adding corresponding funds to account B will fail, so the log will also record: the operation of restoring the funds in account A to the amount before the operation of reducing funds from account A is executed. The operation time of these operations is sequential, for example: first execute the operation of reducing funds from account A, then execute the operation of adding corresponding funds to account B, and then execute the operation of restoring the funds in account A to the amount before the operation of reducing funds from account A is executed.

[0091] The operation time of each operation will be recorded in the log. This application can obtain the operation time from the log, and then use the order of the operation time to convert the data operations in the log into multiple structured query language SQL statements arranged in order according to the order of the operation time.

[0092] The types of data operations include: add, delete, and modify. Based on the operation object, operation condition, operation type, operation data, etc. of the data operation, the data operation can be converted into an SQL statement. For example, the content of a data operation is: insert a group of data into table 2, the value of the group of data in field ID_1 is 01, the value of the group of data in field ID_2 is 01000022, and the value of the group of data in field ID_3 is 614. Then the data operation can be converted into the following SQL statement:

[0093] INSERT into table2 (ID_1,ID_2,ID_3) values('01', '01000022', '614').

[0094] 404. Determine the occurrence time of the error event in the log, and insert the error event into a plurality of structured query language SQL statements arranged in sequence based on the occurrence time.

[0095] Since the test case is used to reversely test the business system designed with the target of using Saga distributed transactions, it will inevitably cause the business system to report an error, thereby triggering the compensation operation of the Saga distributed transaction. When an error occurs in the business system, the relevant information of the error event will be recorded in the log. Since Saga distributed transactions will perform compensation operations after an error occurs, this application can insert the error event into multiple structured query language SQL statements arranged in sequence based on the time when the error event occurs, so that the forward operation and the compensation operation can be distinguished.

[0096] Table 1 is an example of data operations performed by the business system for reverse testing and the converted SQL statements.

[0097] Table 1

[0098]

[0099] The serial numbers in Table 1 are the serial numbers of data operations and error events arranged in chronological order. The operation type is the operation type of each data operation, including: update, insert, delete, and error event. The involved tables in Table 1 are the tables targeted by the data operations.

[0100] 405. Based on the plurality of structured query language SQL statements arranged in sequence of the insertion error event, determine the test result after reverse testing using the test case.

[0101] Since SQL statements can be parsed very conveniently, it is possible to determine whether the table can be restored to the state before the reverse test after the SQL statements for the same table are processed in sequence based on multiple structured query language SQL statements arranged in sequence for the insertion error event, thereby obtaining the test results after the SQL statement performs the reverse test on each table.

[0102] 406. Based on the test results after the reverse test, determine whether the target design of the Saga distributed transaction used by the business system is reasonable.

[0103] If the operations of each SQL statement on each table can restore the table to the state before the reverse test, it can be determined that the target design of the Saga distributed transaction used by the business system is reasonable. On the contrary, if at least one table cannot be restored to the state before the reverse test, it can be determined that the target design of the Saga distributed transaction used by the business system is unreasonable.

[0104] The embodiment of the present application provides a method for detecting the rationality of the design of Saga distributed transactions, which can obtain the business identification of the test case and the log number of the log associated with the business identification, and obtain the log generated when the test case is used for reverse testing based on the business identification and the log number; according to the chronological order of the operation time, the data operation in the log is converted into a plurality of structured query language SQL statements arranged in sequence according to the chronological order of the operation time; the occurrence time of the error event in the log is determined, and the error event is inserted into the plurality of structured query language SQL statements arranged in sequence based on the occurrence time; based on the plurality of structured query language SQL statements arranged in sequence into which the error event is inserted, the test result after reverse testing using the test case is determined; based on the test result after reverse testing, whether the target design of the Saga distributed transaction used by the business system is reasonable. The present application does not use technical documents and test data, but determines the test results based on the log, and then determines whether the target design of the Saga distributed transaction used by the business system is reasonable, which can eliminate the influence of the quality of the technical documents and the change of the test data on the accuracy and completeness of the test results.

[0105] In a possible implementation, in a method for detecting the rationality of Saga distributed transaction design provided by the present application, based on multiple structured query language SQL statements arranged in sequence for inserting error events, determining the test result after reverse testing using the test case may include: Figure 5 Steps 501-503 are shown.

[0106] 501. Determine the SQL statement arranged before the error event as a forward operation, and determine the SQL statement arranged after the error event as a compensation operation;

[0107] Since the test case is used to reversely test the business system designed using the Saga distributed transaction, it will inevitably cause the business system to report an error, thereby triggering the compensation operation of the Saga distributed transaction. Therefore, step 501 can identify the forward operation and the compensation operation according to the sorting position of the error event.

[0108] 502. Determine a forward operation and a compensation operation performed on the same data table as an operation group;

[0109] As shown in Table 1, the two operations with serial numbers 1 and 10 are for the same data table, that is, table 1. Therefore, the two operations with serial numbers 1 and 10 can be determined as an operation group.

[0110] 503. Determine the test result after each operation group operates the same data table.

[0111] Optionally, step 503 may specifically include:

[0112] Each operation group is processed as follows:

[0113] The forward operation and compensation operation included in the operation group are analyzed to determine whether the compensation operation can restore the operation result of the forward operation in the operation group. If it can be restored, the test result after the operation group operates the same data table is determined to be reasonable. If it cannot be restored, the test result after the operation group operates the same data table is determined to be unreasonable.

[0114] Still taking Table 1 as an example, for an operation group consisting of two operations with sequence numbers 5 and 7, the operation with sequence number 5 is a forward operation, and the operation with sequence number 7 is a compensation operation. The forward operation with sequence number 5 inserts a row of data in table 4, and the compensation operation with sequence number 7 also inserts a row of data in table 4. Therefore, the compensation operation with sequence number 7 cannot restore the operation result of the forward operation with sequence number 5. It can be determined that the test result after the operation group consisting of the operations with sequence numbers 5 and 7 operates table 4 is unreasonable. Assuming that the compensation operation with sequence number 7 deletes the row of data inserted in table 4 by the forward operation with sequence number 5, the compensation operation with sequence number 7 can restore the operation result of the forward operation with sequence number 5. It can be determined that the test result after the operation group consisting of the operations with sequence numbers 5 and 7 operates table 4 is reasonable.

[0115] In an optional implementation, parsing the forward operation and the compensation operation included in the operation group to determine whether the compensation operation can restore the operation result of the forward operation in the operation group may include:

[0116] The operation types of the forward operation and the compensation operation included in the operation group are analyzed. If the operation type of the compensation operation is opposite to the operation type of the forward operation, it is determined that the compensation operation can restore the operation result of the forward operation in the operation group. Otherwise, it is determined that the compensation operation cannot restore the operation result of the forward operation in the operation group.

[0117] Since SQL statements are relatively complex, in an optional implementation, the present application can determine whether the compensation operation can restore the operation result of the forward operation in the operation group only based on the operation type. When the operation type of the compensation operation is opposite to the operation type of the forward operation, it can be considered that the compensation operation can restore the operation result of the forward operation in the operation group. If not, it is considered that the compensation operation cannot restore the operation result of the forward operation in the operation group. For example: if the operation type of the forward operation is insert, and the operation type of the compensation operation is delete "delete", then there is no need to parse the other contents of the SQL statement to determine that the compensation operation can restore the operation result of the forward operation in the operation group. For example: if the operation type of the forward operation is insert, and the operation type of the compensation operation is insert, then there is no need to parse the other contents of the SQL statement to determine that the compensation operation cannot restore the operation result of the forward operation in the operation group.

[0118] The above method of determining whether the compensation operation can restore the operation result of the forward operation in the operation group only by the operation type has low accuracy, but higher processing efficiency.

[0119] Of course, in another possible implementation of the present application, all SQL statements can also be parsed, and based on the parsing results, it is determined whether the compensation operation can restore the operation results of the forward operation in the operation group. The present application can use SQL parsing tools to parse SQL statements, wherein the SQL parsing tools may include: Druid, JSqlParser, Apache Calcite, large prediction models, etc.

[0120] In one possible implementation, Figure 5 Based on the embodiment shown, Figure 4 Step 406 may specifically include:

[0121] If the test results of each operation group operating the same data table are all reasonable, it is determined that the target design of the Saga distributed transaction used by the business system is reasonable;

[0122] If the test result after at least one operation group operates on the same data table is unreasonable, it is determined that the target design of the Saga distributed transaction used by the business system is unreasonable.

[0123] For a test case, only when each compensation operation during reverse testing using the test case can restore the results of all forward operations, can it be determined that the target design of the Saga distributed transaction used by the business system is reasonable.

[0124] A method for detecting the rationality of a Saga distributed transaction design provided in an embodiment of the present application is introduced above. A device for executing the method for detecting the rationality of a Saga distributed transaction design will be introduced below.

[0125] See also Figure 6 , Figure 6 A schematic diagram of the structure of a device for detecting the rationality of Saga distributed transaction design provided in an embodiment of the present application. Figure 6 As shown, the device for detecting the rationality of the Saga distributed transaction design includes:

[0126] The identification obtaining unit 601 is used to obtain the business identification of the test case and the log number of the log associated with the business identification, and the test case is a case for reverse testing the business system of the target design using the Saga distributed transaction;

[0127] The log obtaining unit 602 is used to obtain the log generated when the reverse test is performed using the test case based on the service identifier and the log number;

[0128] The conversion unit 603 is used to convert the data operations in the log into a plurality of structured query language SQL statements arranged in sequence according to the sequence of operation time;

[0129] An inserting unit 604 is used to determine the occurrence time of the error event in the log, and insert the error event into a plurality of structured query language SQL statements arranged in sequence based on the occurrence time;

[0130] A result determination unit 605, configured to determine a test result after reverse testing using the test case based on the plurality of structured query language SQL statements arranged in sequence of the insertion error event;

[0131] The reasonable determination unit 606 is used to determine whether the target design of the Saga distributed transaction used by the business system is reasonable based on the test result after the reverse test.

[0132] Optionally, the result determination unit 605 includes:

[0133] An operation determination subunit, used to determine the SQL statement arranged before the error event as a forward operation, and determine the SQL statement arranged after the error event as a compensation operation;

[0134] The operation group subunit is used to determine the forward operation and the compensation operation operated on the same data table as an operation group;

[0135] The result determination subunit is used to determine the test result after each operation group operates the same data table.

[0136] Optionally, a result determination subunit is used to:

[0137] Each operation group is processed as follows:

[0138] The forward operation and compensation operation included in the operation group are analyzed to determine whether the compensation operation can restore the operation result of the forward operation in the operation group. If it can be restored, the test result after the operation group operates the same data table is determined to be reasonable. If it cannot be restored, the test result after the operation group operates the same data table is determined to be unreasonable.

[0139] Optionally, the result determination subunit analyzes the forward operation and the compensation operation included in the operation group to determine whether the compensation operation can restore the operation result of the forward operation in the operation group, and is specifically set as:

[0140] The operation types of the forward operation and the compensation operation included in the operation group are analyzed. If the operation type of the compensation operation is opposite to the operation type of the forward operation, it is determined that the compensation operation can restore the operation result of the forward operation in the operation group. Otherwise, it is determined that the compensation operation cannot restore the operation result of the forward operation in the operation group.

[0141] Optionally, the reasonable determination unit 606 is specifically configured to:

[0142] If the test results of each operation group operating the same data table are all reasonable, it is determined that the target design of the Saga distributed transaction used by the business system is reasonable;

[0143] If the test result after at least one operation group operates on the same data table is unreasonable, it is determined that the target design of the Saga distributed transaction used by the business system is unreasonable.

[0144] The present application provides a device for detecting the rationality of the design of Saga distributed transactions, which can obtain the business identification of the test case and the log number of the log associated with the business identification, and obtain the log generated when the test case is used for reverse testing based on the business identification and the log number; according to the chronological order of the operation time, the data operation in the log is converted into a plurality of structured query language SQL statements arranged in sequence according to the chronological order of the operation time; the occurrence time of the error event in the log is determined, and the error event is inserted into the plurality of structured query language SQL statements arranged in sequence based on the occurrence time; based on the plurality of structured query language SQL statements arranged in sequence into which the error event is inserted, the test result after reverse testing using the test case is determined; based on the test result after reverse testing, whether the target design of the Saga distributed transaction used by the business system is reasonable is determined. The present application does not use technical documents and test data, but determines the test results based on the log, and then determines whether the target design of the Saga distributed transaction used by the business system is reasonable, which can eliminate the influence of the quality of the technical documents and the change of the test data on the accuracy and completeness of the test results.

[0145] The present application also provides an electronic device in an embodiment. Figure 7 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 7 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0146] like Figure 7 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 to a random access memory (RAM) 703. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 703. The processing device 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0147] Typically, the following devices may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a memory card, a hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 7 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0148] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any method for detecting the rationality of the Saga distributed transaction design provided in the embodiment of the present application.

[0149] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any method for detecting the rationality of the Saga distributed transaction design provided in an embodiment of the present application.

[0150] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0151] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0152] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0153] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A method for detecting the rationality of Saga distributed transaction design, characterized in that: include: Obtaining a business identifier of a test case and a log number of a log associated with the business identifier, wherein the test case is a case for reverse testing a business system of a target design using a Saga distributed transaction; Based on the service identifier and the log number, obtaining a log generated when performing a reverse test using the test case; Converting the data operations in the log into a plurality of structured query language SQL statements arranged in sequence according to the sequence of operation times; Determine the occurrence time of the error event in the log, and insert the error event into the plurality of structured query language SQL statements arranged in sequence based on the occurrence time; Determine a test result after reverse testing using the test case based on the plurality of structured query language SQL statements arranged in sequence inserted into the error event; Based on the test results after the reverse test, determine whether the target design of the Saga distributed transaction used by the business system is reasonable.

2. The method for detecting the rationality of Saga distributed transaction design according to claim 1 is characterized in that: The step of determining the test result after reverse testing using the test case based on the plurality of structured query language SQL statements arranged in sequence and inserted into the error event comprises: Determine the SQL statement arranged before the error event as a forward operation, and determine the SQL statement arranged after the error event as a compensation operation; Determine the forward operation and the compensation operation performed on the same data table as an operation group; Determine a test result after each of the operation groups operates the same data table.

3. The method for detecting the rationality of Saga distributed transaction design according to claim 2 is characterized in that: Determining the test result after each operation group operates the same data table includes: Each of the operation groups is processed as follows: The forward operation and the compensation operation included in the operation group are analyzed to determine whether the compensation operation can restore the operation result of the forward operation in the operation group. If so, the test result after the operation group operates the same data table is determined to be reasonable. If not, the test result after the operation group operates the same data table is determined to be unreasonable.

4. The method for detecting the rationality of Saga distributed transaction design according to claim 3 is characterized in that: The parsing the forward operation and the compensation operation included in the operation group to determine whether the compensation operation can restore the operation result of the forward operation in the operation group includes: The operation types of the forward operation and the compensation operation included in the operation group are analyzed. If the operation type of the compensation operation is opposite to the operation type of the forward operation, it is determined that the compensation operation can restore the operation result of the forward operation in the operation group; otherwise, it is determined that the compensation operation cannot restore the operation result of the forward operation in the operation group.

5. The method for detecting the rationality of Saga distributed transaction design according to any one of claims 2 to 4, characterized in that: The test result after the reverse test is performed, determining whether the target design of the Saga distributed transaction used by the business system is reasonable, including: If the test results after each of the operation groups operates the same data table are all reasonable, it is determined that the target design of the Saga distributed transaction used by the business system is reasonable; If the test result after at least one of the operation groups operates the same data table is unreasonable, it is determined that the target design of the Saga distributed transaction used by the business system is unreasonable.

6. A device for detecting the rationality of Saga distributed transaction design, characterized in that: include: An identification obtaining unit, used to obtain a business identification of a test case and a log number of a log associated with the business identification, wherein the test case is a case for reverse testing a business system of a target design using a Saga distributed transaction; A log obtaining unit, configured to obtain, based on the service identifier and the log number, a log generated when performing a reverse test using the test case; A conversion unit, configured to convert the data operations in the log into a plurality of structured query language SQL statements arranged in sequence according to the sequence of operation times; An inserting unit, used for determining the occurrence time of the error event in the log, and inserting the error event into the plurality of structured query language SQL statements arranged in sequence based on the occurrence time; A result determination unit, configured to determine a test result after reverse testing using the test case based on the plurality of sequentially arranged structured query language SQL statements inserted into the error event; The reasonable determination unit is used to determine whether the target design of the Saga distributed transaction used by the business system is reasonable based on the test results after the reverse test.

7. The device for detecting rationality of Saga distributed transaction design according to claim 6, characterized in that: The result determination unit comprises: An operation determination subunit, used to determine the SQL statement arranged before the error event as a forward operation, and determine the SQL statement arranged after the error event as a compensation operation; An operation group subunit, used for determining the forward operation and the compensation operation operated on the same data table as an operation group; The result determination subunit is used to determine the test result after each operation group operates the same data table.

8. A computer program product, characterized in that It includes computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the method for detecting the rationality of the Saga distributed transaction design as described in any one of claims 1 to 5.

9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the method for detecting the rationality of the Saga distributed transaction design as described in any one of claims 1 to 5.

10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the method for detecting the rationality of the Saga distributed transaction design as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Compensation trace evaluation method and device, electronic equipment and storage medium

    CN117632983A

  • Distributed transaction test method and device, electronic equipment and storage medium

    CN117687913A

  • System and method for increased transaction throughput and improved response time under high contention

    US20240126741A1

  • Transaction processing method and apparatus for distributed database system

    WO2016078423A1

Cited By

  • Distributed transaction exception processing method and device, storage medium and electronic equipment

    CN121187837A