Method for detecting rationality of saga distributed transaction design and related device
By parsing the logs and operation time sequence of the business system and converting them into SQL statements to insert error events, the dependency problem of Saga distributed transaction design rationality testing was solved, and independent and accurate design rationality judgment was achieved.
Patent Information
- Application Number
- CN202411726073.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2044-11-28
AI Technical Summary
Existing tests on the rationality of Saga's distributed transaction design rely on technical documentation and test data. The quality and changes of these documents affect the accuracy and completeness of the test results.
By obtaining the business identifier and log number of the test case, parsing the data operations in the log, converting them into SQL statements according to the operation time sequence, inserting error events, determining the test results, and judging the rationality of Saga's distributed transaction design.
Without relying on technical documentation and test data, it accurately determines the rationality of Saga's distributed transaction design, eliminating the impact of document quality and data changes.
Smart Images

Figure CN119520337B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of distributed transactions, and in particular to a method for detecting rationality of Saga distributed transaction design and related devices. BACKGROUND
[0002] The core idea of Saga transaction is to split a long transaction (Long Live Transaction, LLT) into multiple local short transactions, which are coordinated by a Saga transaction coordinator. If it ends normally, it is completed normally. If a step fails, a compensation operation is called according to the order.
[0003] The Saga pattern regards a distributed transaction as a transaction chain of a series of sub-transactions. Each Saga sub-transaction 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 sub-transactions are successfully executed, the entire transaction is successful. If any sub-transaction fails, the entire transaction model will be canceled. The compensation operation (compensate) reverses the behavior of Tn from the semantic point of view, but it cannot necessarily return the database to the state before Tn is executed.
[0004] Currently, the rationality test of Saga distributed transaction design needs to rely on technical documents and compare the data snapshots before and after the test case execution. The quality of technical documents and the changes of test data have a great impact on the accuracy and completeness of the test results. SUMMARY
[0005] In view of the above problems, the present application provides a method for detecting rationality of Saga distributed transaction design and related devices to achieve the purpose of detecting 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 rationality of Saga distributed transaction design, comprising:
[0007] Obtaining a business identifier of a test case and a log number of a log associated with the business identifier, the test case being a case for reverse testing a target designed business system using Saga distributed transaction;
[0008] Based on the business identifier and the log number, obtaining a log generated when the test case is used for reverse testing;
[0009] According to the chronological order of operation, the data operations in the log are converted into a plurality of structured query language (SQL) statements arranged in chronological order of operation;
[0010] determining a time of occurrence of the error event in the log, inserting the error event into the sequentially arranged plurality of structured query language (SQL) statements based on the time of occurrence;
[0011] determining a test result after reverse testing with the test case based on the sequentially arranged plurality of structured query language (SQL) statements into which the error event is inserted;
[0012] determining whether a target design of a Saga distributed transaction used by the business system is reasonable based on the test result after reverse testing.
[0013] In a possible implementation, the determining the test result after reverse testing with the test case based on the sequentially arranged plurality of structured query language (SQL) statements into which the error event is inserted comprises:
[0014] determining a SQL statement arranged before the error event as a forward operation and a SQL statement arranged after the error event as a compensation operation;
[0015] determining the forward operation and the compensation operation that operate on a same data table as an operation group;
[0016] determining a test result after the operation group operates on the same data table.
[0017] In a possible implementation, the determining the test result after the operation group operates on the same data table comprises:
[0018] performing the following processing on each operation group:
[0019] performing analysis on the forward operation and the compensation operation included in the operation group, determining whether the compensation operation can restore an operation result of the forward operation in the operation group, and if yes, determining that the test result after the operation group operates on the same data table is reasonable, or if not, determining that the test result after the operation group operates on the same data table is unreasonable.
[0020] In a possible implementation, the performing analysis on the forward operation and the compensation operation included in the operation group, determining whether the compensation operation can restore an operation result of the forward operation in the operation group comprises:
[0021] The operation types of the forward operation and the compensation operation included in the operation group are parsed, 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, the 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 comprises:
[0023] If the test result after each operation group operates the same data table is reasonable, it is determined that the target design of the Saga distributed transaction used by the business system is reasonable.
[0024] If at least one test result after each operation group 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] The second aspect of the application provides a device for detecting the rationality of the design of a Saga distributed transaction, comprising:
[0026] An identification obtaining unit is configured to obtain a business identification of a test case and a log number of a log associated with the business identification, the test case being a case for reverse testing a business system using a target design of a Saga distributed transaction;
[0027] A log obtaining unit is configured to obtain a log generated when the test case is used for reverse testing based on the business identification and the log number;
[0028] A conversion unit is configured to convert data operations in the log into a plurality of structured query language (SQL) statements arranged in a time sequence of the operations according to the time sequence of the operations;
[0029] An insertion unit is configured to determine a time of occurrence of an error event in the log, and insert the error event into the plurality of SQL statements arranged in the time sequence based on the time of occurrence;
[0030] A result determining unit is configured to determine a test result after the reverse test based on the plurality of SQL statements arranged in the time sequence to which the error event is inserted;
[0031] A reasonable determination unit is configured 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.
[0032] In a possible implementation, the result determining unit comprises:
[0033] An operation determining subunit is configured to determine an SQL statement arranged before the error event as a forward operation, and determine an SQL statement arranged after the error event as a compensation operation;
[0034] An operation group subunit is configured to determine the forward operation and the compensation operation for operating on the same data table as an operation group;
[0035] A result determining subunit is configured to determine a test result after the operation group operates on the same data table.
[0036] The third aspect of the present application provides a computer program product, comprising computer readable instructions, when the computer readable instructions run on an electronic device, the electronic device implements the method for detecting the design rationality of the Saga distributed transaction of the first aspect or any implementation manner of the first aspect.
[0037] The fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected with the processor, wherein:
[0038] The memory is configured to store a computer program;
[0039] The processor is configured to execute the computer program, so that the electronic device can implement the method for detecting the design rationality of the Saga distributed transaction of the first aspect or any implementation manner of the first aspect.
[0040] The fifth aspect of the present application provides a computer storage medium, 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 the method for detecting the design rationality of the Saga distributed transaction of the first aspect or any implementation manner of the first aspect.
[0041] By the technical scheme, the method for detecting design rationality of Saga distributed transactions and the related device provided by the application can obtain the business identifier of the test case and the log number of the log associated with the business identifier, obtain the log generated when the test case is used for reverse testing based on the business identifier and the log number, convert the data operation in the log into a plurality of structured query language (SQL) statements arranged in sequence according to the operation time in the order of the operation time, determine the occurrence time of the error event in the log, insert the error event into the plurality of structured query language (SQL) statements arranged in sequence based on the occurrence time, determine the test result after the reverse testing based on the plurality of structured query language (SQL) statements arranged in sequence with the error event inserted, and determine whether the target design of the Saga distributed transactions used by the business system is reasonable based on the test result after the reverse testing. The application does not use technical documents and test data, but determines the test result according to the log, and then determines whether the target design of the Saga distributed transactions 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 result. BRIEF DESCRIPTION OF DRAWINGS
[0042] The above and other features, advantages, and aspects of the present disclosure will become more apparent by describing in detail exemplary embodiments thereof with reference to the attached drawings in which:
[0043] Figure 1 A system architecture schematic diagram is provided for the application;
[0044] Figure 2 An optional hardware structure schematic diagram of a terminal is provided for the application;
[0045] Figure 3 A structure schematic diagram of a server is provided for the application;
[0046] Figure 4 A flowchart of a method for detecting design rationality of Saga distributed transactions is provided for the application;
[0047] Figure 5 A flowchart of determining the test result after the reverse testing based on the plurality of structured query language (SQL) statements arranged in sequence with the error event inserted is provided for the application;
[0048] Figure 6 A structure schematic diagram of a device for detecting design rationality of Saga distributed transactions is provided for the application;
[0049] Figure 7 This is a schematic diagram of the structure of an electronic device provided in this application. Detailed Implementation
[0050] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is for explaining specific embodiments only and is not intended to limit the scope of this application.
[0051] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0052] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0053] See 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 (The example includes a server), and the server 200 can provide the method provided in the embodiments of this application to one or more terminals.
[0054] The terminal 100 may be equipped with an application for testing the rationality of the Saga distributed transaction design. The application and webpage can provide an interface. The terminal 100 can receive relevant parameters (such as the business identifier of the test case and the log number of the log associated with the business identifier) input by the user on the interface and send the 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 on its own, without the need for the server to cooperate. This application embodiment is not limited to this.
[0056] The following description Figure 1Product form of the terminal 100;
[0057] The terminal 100 in the embodiments 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 notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiments of the present application do not make any limitation thereto.
[0058] Figure 2 An optional hardware structure schematic diagram of the terminal 100 is shown.
[0059] Reference Figure 2 As shown, the terminal 100 can 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), a headset jack 163 (optional), a processor 170, an external interface 180, a power supply 190, etc. Those skilled in the art can understand that the terminal 100 can include more or less components, or combine certain components, or different components, without departing from the scope of the present application. Figure 2 The above-mentioned terminal or multi-functional device is merely an example and does not constitute a limitation on the terminal or multi-functional device, which can include more or less components, or combine certain components, or different components.
[0060] The input unit 130 can be used to receive inputted digital or character information, and to generate key signal inputs related to user settings of the portable multifunctional device and control of functions. Specifically, the input unit 130 can include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect touch operations (such as operations of a user using a finger, a knuckle, a stylus, or any suitable object on or near the touch screen) of the user thereon or therearound, and drive corresponding connected devices according to pre-set programs. The touch screen can detect touch actions of the user on the touch screen, convert the touch actions into touch signals and send the touch signals to the processor 170, and can receive commands from the processor 170 and execute the commands; the touch signals at least include 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 in various 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, the other input devices 132 can include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, on-off keys, etc.), trackballs, mice, joysticks, etc.
[0061] The input device 132 can receive inputted data, etc.
[0062] The display unit 140 can be used to display information inputted by the user or provided to the user, various menus of the terminal 100, interactive interfaces, file display, and / or playing of any kind of multimedia files. In the embodiments of the present application, the display unit 140 can be used to display interfaces for inputting parameters, processing results, etc.
[0063] The storage 120 can be used to store instructions and data. The storage 120 can mainly include a storage instruction area and a storage data area. The storage data area can store various data such as multimedia files, texts, etc.; the storage instruction area can store software units such as operating systems, applications, instructions required by at least one function, etc., or their subsets, expanded sets. It can also include a non-volatile random access memory; to provide the processor 170 with software and applications that include management of hardware, software, and data resources in the computing processing device, support control. It is also used for storage of multimedia files, and storage of running programs and applications.
[0064] The processor 170 is the control center of the terminal 100, connects each part of the whole terminal 100 by various interfaces and lines, executes various functions of the terminal 100 and processes data by running or executing the instructions stored in the memory 120 and calling the data stored in the memory 120, thereby overall controlling the terminal device. Optionally, the processor 170 can include one or more processing units; preferably, the processor 170 can integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processor 170. In some embodiments, the processor, the memory, can be realized on a single chip, and in some embodiments, they can also be realized on independent chips respectively. The processor 170 can also be used to generate corresponding operation control signals to the corresponding components of the computing processing device, read and process the data in the software, especially read and process the data and programs in the memory 120, so that each functional module therein executes corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.
[0065] The memory 120 can be used to store the software code related to the method for detecting the rationality of the Saga distributed transaction design, and the processor 170 can execute the steps of the method for detecting the rationality of the Saga distributed transaction design, or can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to realize the corresponding functions.
[0066] The RF unit 110 (optional) can be used to receive and send signals in the process of information or communication, for example, receiving the downlink information of the base station, and processing by the processor 170. In addition, the 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 (LNA), a duplexer, etc. In addition, the RF 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 for mobile communication (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), long term evolution (LTE), email, short messaging service (SMS), etc.
[0067] In the embodiments of the present application, the RF unit 110 can send data to the server 200 and receive the processing result sent by the server 200.
[0068] It should be understood that the RF unit 110 is optional, which can be replaced by other communication interfaces, for example, a network interface.
[0069] The terminal 100 further includes a power supply 190 (such as a battery) for supplying power to each component. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so as to realize the functions of power management, such as charge management, discharge management and power consumption management, through the power management system.
[0070] The terminal 100 further includes an external interface 180, which can be a standard Micro USB interface or a multi-pin connector. The external interface 180 can be used to connect the terminal 100 with other devices for communication, and can also be used to connect a charger for charging the terminal 100.
[0071] Although not shown, the terminal 100 can further include a flash, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which will not be described here. Some or all of the methods described below can be applied in the terminal 100 as shown. Figure 2
[0072] Next, the product form of the server 200 is described. Figure 1 The product form of the server 200 is described.
[0073] Figure 3 A structural diagram of the server 200 is provided, as shown in the figure. Figure 3 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 through the bus 201.
[0074] The bus 201 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 In the figure, only one thick line is used, but it does not mean that there is only one bus or one type of bus.
[0075] The processor 202 can 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), etc.
[0076] The memory 204 can include a volatile memory, such as a random access memory (RAM). The memory 204 can also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a mechanical hard disk drive (HDD), or a solid state drive (SSD).
[0077] The memory 204 can be used to store software code related to the method for detecting the rationality of the Saga distributed transaction design, and the processor 202 can execute the steps of the method for detecting the rationality of the Saga distributed transaction design of the chip, or can schedule other units to realize the corresponding functions.
[0078] It should be understood that the terminal 100 and the server 200 described above can be centralized or distributed devices, and the processors (for example, the processor 170 and the processor 202) in the terminal 100 and the server 200 can be hardware circuits (for example, an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, a digital signal processing (DSP), a microprocessor, a microcontroller, or the like) or a combination of the hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, a DSP, or the like, or a hardware system without an instruction execution function, such as an ASIC, an FPGA, or the like, or a combination of the hardware system without an instruction execution function and the hardware system with an instruction execution function.
[0079] The embodiment of the present application provides a method for detecting rationality of a Saga distributed transaction design.
[0080] Referring to Figure 4 , Figure 4 The flow of the method for detecting rationality of a Saga distributed transaction design provided by the embodiment of the present application is shown in FIG. 1, and the data processing method provided by the embodiment of the present application can include steps 401 to 406, which are described in detail as follows. Figure 4
[0081] 401, obtaining a business identifier of a test case and a log number of a log associated with the business identifier, the test case being a case for reverse testing a target design business system using a Saga distributed transaction.
[0082] The type of the business system can be various, such as a financial business system, an office business system, and the like. In the following, the financial business system is taken as an example for illustration.
[0083] In a financial service system, a transaction is often performed, for example, transferring funds in an A account to a B account. In this fund transfer process, at least two operations are involved, namely, reducing funds in the A account and increasing corresponding funds in the B account. If both operations are successfully completed, the transaction is successful, if the operation of reducing funds in the A account is successfully completed, but the operation of increasing corresponding funds in the B account fails, the operation of reducing funds in the A account needs to be reversed through a compensation operation, that is, the funds in the A account are restored to the amount before the operation of reducing funds in the A account is performed. If the financial service system uses a target design of Saga distributed transaction, if the target design is reasonable, the financial service system using the target design can restore the funds in the A account to the amount before the operation of reducing funds in the A account is performed when the operation of increasing corresponding funds in the B account fails (that is, the compensation operation of the target design is normally played). In order to verify whether the target design is reasonable, it can be tested by a test case. Since it is to verify the compensation operation, the test case is a reverse test case, that is, a case that will inevitably trigger the compensation operation. For example, a transaction case of transferring funds in the A account to the B account in the case that the B account is frozen.
[0084] It should be noted that there can be many businesses that can be performed in a business system, for example, for a financial service system, the businesses that can be performed include: cash transaction business, fixed deposit business, account opening business, short message notification opening business, online bank opening business, etc. The identities of different businesses are different, and the business identity can uniquely identify a business. For example, the identity of the above-mentioned transaction business of transferring funds in the A account to the B account in the case that the B account is frozen can be 000001.
[0085] The log is a file recording various important information in the running process of the business system, and different logs have different log numbers. When a certain business is performed, the present application can record the new log generated in the business execution process, and associate the log number of the new log with the business identity of the business. In this way, the present application obtains the log number of the log associated with the business identity.
[0086] 402、Based on the business identity and the log number, the log generated when the reverse test is performed using the test case is obtained.
[0087] In some cases, one log can record information of multiple businesses, and therefore the application can obtain the log generated by the reverse test using the test case based on the business identifier and the log number. Specifically, the application can first find the log with the log number according to the log number, and then find the business identifier obtained in step 401 in the log. If found, it is determined that the log contains information generated when the test case is executed, and the log can be determined as the log generated when the reverse test using the test case is performed. If not found, it is considered that the log is not generated when the reverse test using the test case is performed.
[0088] In actual applications, more and more logs are generated over time, and therefore the application can also determine the log generated when the reverse test is performed according to the date of the reverse test. For example, if the reverse test is performed on January 3, 2021, the log generated when the reverse test using the test case is performed can be queried based on the business identifier, the log number, and January 3, 2021. When querying, the query can be performed only in the logs generated on January 3, 2021, which greatly speeds up the query speed.
[0089] 403. Convert the data operations in the log into a plurality of structured query language (SQL) statements arranged in the order of operation time.
[0090] The log can record multiple data operations, for example, in the case of freezing the B account, the log generated after the execution of a transaction case of transferring funds in the A account to the B account can record the operation of reducing funds in the A account and the operation of increasing corresponding funds in the B account. Of course, since the B account is frozen, the operation of increasing corresponding funds in the B account will fail, and therefore the log will also record the operation of restoring the funds in the A account to the amount before the operation of reducing funds in the A account is executed. The operation time of these operations has a sequence, for example, the operation of reducing funds in the A account is executed first, then the operation of increasing corresponding funds in the B account is executed, and then the operation of restoring the funds in the A account to the amount before the operation of reducing funds in the A account is executed.
[0091] The operation time of each operation is recorded in the log, and the application can obtain the operation time from the log, and then convert the data operations in the log into a plurality of structured query language (SQL) statements arranged in the order of operation time.
[0092] The operation type of the data operation can include three types of add, delete, and modify. Based on the operation object, operation condition, operation type, and operation data of the data operation, the data operation can be converted into a SQL statement. For example, the content of a certain data operation is to insert a set of data into table 2, the value of the set of data in the field ID_1 is 01, the value of the set of data in the field ID_2 is 01000022, and the value of the set of data in the field ID_3 is 614. 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 the sequentially arranged plurality of structured query language (SQL) statements based on the occurrence time.
[0095] Since the test case is used to perform reverse testing on the business system designed for the target using Saga distributed transactions, it will inevitably cause the business system to report an error, and then trigger the compensation operation of the Saga distributed transaction. When the business system reports an error, the related information of the error event will be recorded in the log. Since the Saga distributed transaction will perform a compensation operation after an error occurs, the present application can insert the error event into the sequentially arranged plurality of structured query language (SQL) statements based on the occurrence time of the error event, so as to distinguish the forward operation and the compensation operation.
[0096] Table 1 is an example of data operations performed by the business system for reverse testing and converted SQL statements.
[0097] Table 1
[0098]
[0099] The serial number in Table 1 is the serial number of the data operation and the error event arranged in time sequence. The operation type is the operation type of each data operation, including: update (update), insert (insert), delete (delete), and error event (ERROR). The table involved in Table 1 is the table to which the data operation is directed.
[0100] 405、Determine the test result after reverse testing using the test case based on the sequentially arranged plurality of structured query language (SQL) statements inserted with the error event.
[0101] Since the SQL statements can be parsed very conveniently, the test results after the reverse test can be determined according to the sequentially arranged multiple structured query language (SQL) statements of the inserted error events, whether the SQL statements can sequentially process the same table to restore the table to the state before the reverse test, so as to obtain the test results of the reverse test of the SQL statements on each table.
[0102] 406. Based on the test results after the reverse test, it is determined 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 method for detecting the rationality of the Saga distributed transaction design provided by the embodiment of the application can obtain the business identifier of the test case and the log number of the log associated with the business identifier, obtain the log generated when the test case is used for reverse test based on the business identifier and the log number, convert the data operations in the log into multiple structured query language (SQL) statements arranged in the order of operation time according to the order of operation time, determine the occurrence time of the error event in the log, insert the error event into the sequentially arranged multiple structured query language (SQL) statements based on the occurrence time, determine the test results after the reverse test based on the sequentially arranged multiple structured query language (SQL) statements of the inserted error events, and 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. The application does not use technical documents and test data, but determines the test results according to 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.
[0105] In a possible implementation, the method for detecting the rationality of the Saga distributed transaction design provided by the application can include steps 501-503 as shown in FIG. 5. Figure 5
[0106] 501. The SQL statements arranged before the error event are determined as forward operations, and the SQL statements arranged after the error event are determined as compensation operations.
[0107] Since the test case is used to reverse test the business system designed with Saga distributed transactions, it will inevitably cause the business system to report errors, thereby triggering the compensation operation of Saga distributed transactions. Therefore, step 501 can identify the forward operation and the compensation operation based on the sorting position of the error events.
[0108] 502. Forward operations and compensation operations that operate on the same data table are identified as one operation group;
[0109] As shown in Table 1, the two operations with serial numbers 1 and 10 target the same data table, namely table 1. Therefore, the two operations with serial numbers 1 and 10 can be identified as an operation group.
[0110] 503. Determine the test results after each operation group operates on the same data table.
[0111] Optionally, step 503 may specifically include:
[0112] The following processing is performed on each operation group:
[0113] The operation group includes both forward and compensation operations. The compensation operation is analyzed to determine whether it can restore the result of the forward operation in the operation group. If it can restore the result, the test result of the operation group operating on the same data table is considered reasonable. If it cannot restore the result, the test result of the operation group operating on the same data table is considered unreasonable.
[0114] Using Table 1 as an example, consider the two operations numbered 5 and 7 forming an operation group. Operation 5 is the forward operation, and operation 7 is the compensation operation. The forward operation (number 5) inserts a row of data into Table 4, and the compensation operation (number 7) also inserts a row of data into Table 4. Therefore, the compensation operation (number 7) cannot restore the result of the forward operation (number 5). It can be determined that the test result of the operation group (numbers 5 and 7) operating on Table 4 is unreasonable. However, if the compensation operation (number 7) deletes the row of data inserted into Table 4 by the forward operation (number 5), then the compensation operation (number 7) can restore the result of the forward operation (number 5). Therefore, the test result of the operation group (numbers 5 and 7) operating on Table 4 is reasonable.
[0115] In one optional implementation, the forward operations and compensation operations included in the operation group are parsed to determine whether the compensation operation can restore the operation result of the forward operation in the operation group. This can include:
[0116] The operation type of the forward operation and the compensation operation included in the operation group is parsed. 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 the SQL statement is relatively complex, in an optional implementation, the present application can only determine whether the compensation operation can restore the operation result of the forward operation in the operation group according to 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, and if not, it is considered that the compensation operation cannot restore the operation result of the forward operation in the operation group. For example, the operation type of the forward operation is insert, and the operation type of the compensation operation is delete, so it can be determined that the compensation operation can restore the operation result of the forward operation in the operation group without further parsing other contents of the SQL statement. For example, the operation type of the forward operation is insert, and the operation type of the compensation operation is insert, so it can be determined that the compensation operation cannot restore the operation result of the forward operation in the operation group without further parsing other contents of the SQL statement.
[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 high processing efficiency.
[0119] Of course, in another possible implementation of the present application, all SQL statements can be parsed, and whether the compensation operation can restore the operation result of the forward operation in the operation group is determined according to the parsing result. The present application can parse the SQL statement by using a SQL parsing tool, wherein the SQL parsing tool can include Druid, JSqlParser, Apache Calcite, Big Prophet model, etc.
[0120] In a possible implementation, based on the embodiment shown in Figure 5 The step 406 shown in the embodiment can specifically include: Figure 4 The step 406 shown in the embodiment can specifically include:
[0121] If the test result of each operation group operating the same data table is 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 of at least one operation group operating 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] Only when each compensation operation in 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] The above introduces a method for detecting the rationality of a Saga distributed transaction design provided by an embodiment of the present application. The following describes an apparatus for executing the method for detecting the rationality of a Saga distributed transaction design.
[0125] Please refer to Figure 6 , Figure 6 The following is a structural schematic diagram of an apparatus for detecting the rationality of a Saga distributed transaction design provided by an embodiment of the present application. As shown in Figure 6 The apparatus for detecting the rationality of a Saga distributed transaction design includes:
[0126] An identification obtaining unit 601 is configured to obtain a business identification of a test case and a log number of a log associated with the business identification, the test case being a case for reverse testing a business system using a target design of a Saga distributed transaction;
[0127] A log obtaining unit 602 is configured to obtain a log generated when reverse testing using the test case based on the business identification and the log number;
[0128] A conversion unit 603 is configured to convert data operations in the log into a plurality of structured query language (SQL) statements arranged in a sequence of operation times;
[0129] An insertion unit 604 is configured to determine a time of occurrence of an error event in the log, and insert the error event into the plurality of SQL statements arranged in the sequence based on the time of occurrence;
[0130] A result determining unit 605 is configured to determine a test result after reverse testing using the test case based on the plurality of SQL statements arranged in the sequence with the error event inserted;
[0131] A rationality determining unit 606 is configured to determine whether the target design of the Saga distributed transaction used by the business system is reasonable based on the test result after reverse testing.
[0132] Optionally, the result determining unit 605 includes:
[0133] An operation determining sub-unit is configured to determine a SQL statement arranged before the error event as a forward operation, and determine a SQL statement arranged after the error event as a compensation operation;
[0134] The operation group subunit is configured to determine a forward operation and a compensation operation for operating on the same data table as one operation group;
[0135] The result determination subunit is configured to determine a test result after each operation group operates on the same data table.
[0136] Optionally, the result determination subunit is specifically configured to:
[0137] Each operation group is processed as follows:
[0138] The forward operation and the compensation operation included in the operation group are parsed to determine whether the compensation operation can restore the operation result of the forward operation in the operation group. If the operation result can be restored, it is determined that the test result after the operation group operates on the same data table is reasonable. If the operation result cannot be restored, it is determined that the test result after the operation group operates on the same data table is unreasonable.
[0139] Optionally, the result determination subunit parses 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 configured to:
[0140] The operation types of the forward operation and the compensation operation included in the operation group are parsed. 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 after each operation group operates on 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 device for detecting the design rationality of a Saga distributed transaction provided in the application can obtain a business identifier of a test case and a log number of a log associated with the business identifier, obtain a log generated when the test case is used for reverse testing based on the business identifier and the log number, convert data operations in the log into a plurality of structured query language (SQL) statements arranged in a sequence of operation times, determine a time of occurrence of an error event in the log, insert the error event into the plurality of SQL statements arranged in the sequence based on the time of occurrence, determine a test result after the reverse testing based on the plurality of SQL statements with the error event inserted, and determine whether a target design of a Saga distributed transaction used by a business system is reasonable based on the test result after the reverse testing. The application does not use technical documents and test data, but determines the test result 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 result.
[0145] The electronic device in the embodiments of the application is further provided. Figure 7 As shown in FIG. 1, a structural schematic diagram of an electronic device suitable for implementing the electronic device in the embodiments of the application is shown. The electronic device in the embodiments of the application can include, but is not limited to, a fixed terminal such as a mobile phone, a notebook computer, a PDA (personal digital assistant), a PAD (tablet computer), a desktop computer, and the like. Figure 7 The electronic device shown is only an example, and should not bring any limitation to the functions and use range of the embodiments of the application.
[0146] As shown in FIG. 1, a structural schematic diagram of an electronic device suitable for implementing the electronic device in the embodiments of the application is shown. The electronic device in the embodiments of the application can include, but is not limited to, a fixed terminal such as a mobile phone, a notebook computer, a PDA (personal digital assistant), a PAD (tablet computer), a desktop computer, and the like. Figure 7 The electronic device can include a processing device (for example, a central processor, a graphic processor, and the like) 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. In a state where 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 through a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0147] In general, the following devices can be connected to the I / O interface 705: input devices 706 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, and the like; output devices 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, and the like; storage devices 708 including, for example, a memory card, a hard disk, and the like; and communication devices 709. The communication devices 709 can allow the electronic device to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 7 An electronic device having various devices is shown, but it is understood that all of the shown devices are not required to be implemented or present. More or less devices can alternatively be implemented or present.
[0148] The embodiment of the present application further provides a computer program product comprising computer readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the methods for detecting rationality of design of Saga distributed transactions provided by the embodiments of the present application.
[0149] The embodiment of the present application further provides a computer readable storage medium carrying one or more computer programs, which, when executed by an electronic device, can cause the electronic device to implement any of the methods for detecting rationality of design of Saga distributed transactions provided by the embodiments of the present application.
[0150] In addition, it should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components can or can not be physically separated, and the components displayed as units can or can not be physical units, i.e. they can be located in one place, or distributed on multiple network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the embodiments. In addition, the connection relationship between the modules in the device embodiment provided by the present application indicates that there is a communication connection between them, which can be implemented as one or more communication buses or signal lines.
[0151] Those skilled in the art can clearly understand that the application can be implemented by means of software plus necessary universal hardware, and of course can also be implemented by means of dedicated hardware including special integrated circuit, special CPU, special memory, special component, etc. Generally, any function completed by computer program can be easily implemented by corresponding hardware, and the specific hardware structure for implementing the same function can also be various, such as analog circuit, digital circuit or special circuit, etc. However, for the application, software program implementation is a better embodiment. Based on such understanding, the technical solution of the application or the part of the application which makes contribution to the prior art can be embodied in the form of software product, which is stored in readable storage medium, such as computer floppy disk, U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a plurality of instructions for making a computer device (which can be personal computer, training device or network device, etc.) execute the method described in various embodiments of the application.
[0152] In the above embodiments, the implementation can be achieved by software, hardware, firmware or any combination thereof, entirely or partially. When implemented by software, the implementation can be achieved in the form of a computer program product, entirely or partially.
[0153] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the flow or function described in the embodiments of the application is generated entirely or partially. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another, for example, the computer instructions can be transmitted from one website, computer, training device or data center to another website, computer, training device or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that can be stored by a computer or a data storage device such as a training device, a data center, etc. integrated with one or more available media sets. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.
Claims
1. A method for detecting rationality of a Saga distributed transaction design, characterized in that, The method comprises the following steps: obtaining a business identifier of a test case and a log number of a log associated with the business identifier, the test case being a case for reverse testing a business system designed for a target using a Saga distributed transaction; obtaining a log generated when the test case is used for reverse testing based on the business identifier and the log number; converting data operations in the log into a plurality of structured query language (SQL) statements arranged in a time sequence of operation time; determining a time of occurrence of an error event in the log, and inserting the error event into the plurality of SQL statements arranged in the time sequence based on the time of occurrence; determining a test result after reverse testing based on the plurality of SQL statements arranged in the time sequence with the error event inserted; determining whether the target design of the Saga distributed transaction used by the business system is reasonable based on the test result after reverse testing.
2. The method for detecting the design rationality of Saga distributed transactions according to claim 1, characterized in that, The method of determining the test result after reverse testing based on the plurality of SQL statements arranged in the time sequence with the error event inserted comprises the following steps: determining a forward operation for a SQL statement arranged before the error event, and determining a compensation operation for a SQL statement arranged after the error event; determining the forward operation and the compensation operation for operations on the same data table as an operation group; determining a test result after the operation group operates on the same data table.
3. The method for detecting the design rationality of Saga distributed transactions according to claim 2, characterized in that, The method of determining the test result after the operation group operates on the same data table comprises the following steps: performing the following processing on each operation group: analyzing 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 if the operation result can be restored, determining that the test result after the operation group operates on the same data table is reasonable, and if the operation result cannot be restored, determining that the test result after the operation group operates on the same data table is unreasonable.
4. The method for detecting the design rationality of Saga distributed transactions according to claim 3, characterized in that, The method of analyzing 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 comprises the following steps: analyzing the operation types of the forward operation and the compensation operation included in the operation group, and if the operation type of the compensation operation is opposite to the operation type of the forward operation, determining that the compensation operation can restore the operation result of the forward operation in the operation group, otherwise, determining that the compensation operation cannot restore the operation result of the forward operation in the operation group.
5. The method for detecting the design rationality of Saga distributed transactions according to any one of claims 2-4, characterized in that, The method of determining whether the target design of the Saga distributed transaction used by the business system is reasonable based on the test result after reverse testing comprises the following steps: if the test result after each operation group operates on the same data table is reasonable, determining that the target design of the Saga distributed transaction used by the business system is reasonable. If a test result after at least one operation group operating on the same data table is unreasonable, it is determined that a target design of a Saga distributed transaction used by the business system is unreasonable.
6. An apparatus for detecting the rationality of Saga distributed transaction design, characterized in that, The method comprises: an identification obtaining unit configured to obtain a business identification of a test case and a log number of a log associated with the business identification, the test case being a case for reverse testing a business system using a target design of a Saga distributed transaction; a log obtaining unit configured to obtain, based on the business identification and the log number, a log generated when the test case is used for reverse testing; a conversion unit configured to convert data operations in the log into a plurality of structured query language (SQL) statements arranged in a time sequence of the operations; an insertion unit configured to determine a time of occurrence of an error event in the log, and insert the error event into the plurality of SQL statements arranged in the time sequence based on the time of occurrence; a result determining unit configured to determine a test result after the reverse testing using the test case based on the plurality of SQL statements arranged in the time sequence into which the error event is inserted; and a reasonableness determining unit configured 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 testing.
7. The apparatus for detecting the design rationality of Saga distributed transactions according to claim 6, characterized in that, The result determining unit comprises: an operation determining sub-unit configured to determine a SQL statement arranged before the error event as a forward operation, and determine a SQL statement arranged after the error event as a compensation operation; an operation group sub-unit configured to determine the forward operation and the compensation operation operating on the same data table as an operation group; and a result determining sub-unit configured to determine a test result after each operation group operating on the same data table.
8. A computer program product, characterised in that, The computer readable instructions, when executed on an electronic device, cause the electronic device to implement the method for detecting reasonableness of a Saga distributed transaction design according to any one of claims 1 to 5.
9. An electronic device, comprising: The electronic device comprises at least one processor and a memory connected to the processor, wherein: the memory is configured to store a computer program; the processor is configured to execute the computer program, so that the electronic device can implement the method for detecting reasonableness of a Saga distributed transaction design according to any one of claims 1 to 5.
10. A computer storage medium, characterized in that, The storage medium carries one or more computer programs, which, when executed by an electronic device, can cause the electronic device to implement the method for detecting reasonableness of a Saga distributed transaction design according to any one of claims 1 to 5.
Citation Information
Patent Citations
Distributed transaction test method and device, electronic equipment and storage medium
CN117687913A
Transaction processing method and apparatus for distributed database system
WO2016078423A1