Distributed transaction-based deadlock logic detection method and related product
By analyzing the link stack information and resource execution order of financial system transactions, judging and avoiding deadlock risks, the problem of deadlock phenomenon in financial system under high concurrency is solved, and the risk of customer loss is reduced.
Patent Information
- Application Number
- CN202411740117.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-18
AI Technical Summary
The financial system may experience deadlock under high concurrency, resulting in incomplete transactions, uncollected or over-received funds, which will lead to capital risks and customer losses.
By obtaining the link stack information of the target transaction, analyzing the resource groups used in the first transaction stage and the second transaction stage and their execution sequence, and determining whether there is a risk of deadlock. If present, adjust the order of resource execution or time difference to avoid deadlock risk.
Reduces the probability of deadlock, thereby reducing the probability of customers suffering losses due to deadlocks, and improving system stability and fund security.
Smart Images

Figure CN119645676A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of detection technology, and in particular to a deadlock logic detection method based on distributed transactions and related products. Background Art
[0002] With the rapid development of banking business and the upgrading of technology, systems often adopt distributed architecture, involving multiple parties, multiple microservices, and more complex programs. Some systems involving financial transactions will update account balances when moving accounts. It is possible that logical errors will occur when arranging and updating different balance types at different stages of the transaction, resulting in deadlocks under high concurrency after production.
[0003] The financial system serves tens of millions of non-bank users. If a transaction deadlock occurs, it will result in incomplete transactions, uncollected funds, over-collection or under-collection of funds, etc., which will bring financial risks and cause customer losses. Summary of the invention
[0004] Based on the above problems, the present application provides a deadlock logic detection method and related products based on distributed transactions to reduce the probability of deadlock, thereby reducing the probability of customers suffering losses due to deadlock.
[0005] The embodiments of the present application disclose the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides a deadlock logic detection method based on distributed transactions, the method comprising:
[0007] Get the link stack information of the target transaction;
[0008] According to the link stack information, a first resource group used in a first transaction phase of a target transaction, a second resource group used in a second transaction phase, and an execution order of each resource in the first resource group and the second resource group are obtained; wherein the first resource group and the second resource group both include at least a first resource and a second resource;
[0009] If the first resource and the second resource in the first resource group are executed sequentially, the second resource and the first resource in the second resource group are executed sequentially, and the time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is less than a preset threshold, there is a risk of deadlock in the target transaction.
[0010] Optionally, obtaining, according to the link stack information, a first resource group used in a first transaction phase of a target transaction, a second resource group used in a second transaction phase, and an execution order of each resource in the first resource group and the second resource group includes:
[0011] According to the start label statement and the end label statement of the target transaction in the first transaction phase and the second transaction phase, the SQL statement of the target transaction in the first transaction phase and the second transaction phase is extracted from the link stack information; the execution order of the first resource group and each resource in the first resource group used by the target transaction in the first transaction phase, and the execution order of each resource in the second resource group and the second resource group used in the second transaction phase are obtained in the SQL statement.
[0012] Optionally, obtain link stack information of the target transaction, including:
[0013] According to the transaction code of the target transaction, the link stack information of the target transaction is obtained from the application performance monitoring APM database.
[0014] Optionally, when the target transaction has a deadlock risk, the method further includes:
[0015] Adjust the execution order of resources in the first resource group so that the second resource and the first resource in the first resource group are executed in sequence, or adjust the execution order of resources in the second resource group so that the first resource and the second resource in the second resource group are executed in sequence.
[0016] In a second aspect, an embodiment of the present application provides a deadlock logic detection device based on distributed transactions, the device comprising: a first acquisition module, a second acquisition module and a detection module;
[0017] A first acquisition module, used to acquire link stack information of a target transaction;
[0018] A second acquisition module is used to acquire, according to the link stack information, a first resource group used in a first transaction phase of a target transaction, a second resource group used in a second transaction phase, and an execution order of each resource in the first resource group and the second resource group; wherein the first resource group and the second resource group both include at least a first resource and a second resource;
[0019] A detection module is used to determine that a target transaction has a deadlock risk when a first resource and a second resource in a first resource group are executed in sequence, a second resource and a first resource in a second resource group are executed in sequence, and a time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is less than a preset threshold.
[0020] Optionally, the second detection module is specifically used to extract SQL statements of the target transaction in the first transaction phase and the second transaction phase from the link stack information according to the start label statement and the end label statement of the target transaction in the first transaction phase and the second transaction phase; and obtain in the SQL statements the execution order of the first resource group and each resource in the first resource group used by the target transaction in the first transaction phase, and the execution order of the second resource group and each resource in the second resource group used in the second transaction phase.
[0021] Optionally, the first acquisition module is specifically configured to acquire link stack information of the target transaction from an application performance monitoring APM database according to the transaction code of the target transaction.
[0022] Optionally, the device further includes: an execution module;
[0023] The execution module is used to adjust the execution order of resources in the first resource group so that the second resource and the first resource in the first resource group are executed in sequence, or to adjust the execution order of resources in the second resource group so that the first resource and the second resource in the second resource group are executed in sequence.
[0024] In a third aspect, an embodiment of the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the deadlock logic detection method based on distributed transactions as described in any embodiment of the first aspect.
[0025] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on a terminal device, the terminal device executes a deadlock logic detection method based on distributed transactions as described in any embodiment of the first aspect.
[0026] The embodiment of the present application provides a deadlock logic detection method based on distributed transactions. First, the link stack information of the target transaction is obtained; then, according to the link stack information, the first resource group used in the first transaction stage of the target transaction, the second resource group used in the second transaction stage, and the execution order of each resource in the first resource group and the second resource group are obtained; wherein, the first resource group and the second resource group both include at least the first resource and the second resource; if the first resource and the second resource in the first resource group are executed in sequence, the second resource and the first resource in the second resource group are executed in sequence, and the time difference between the first resource in the first resource group and the second resource in the second resource group starting to be executed is less than a preset threshold, the target transaction has a deadlock risk. In the embodiment of the present application, by the order in which resources in different transaction stages are executed, it can be determined whether there is a deadlock risk, reduce the probability of deadlock, and thus reduce the probability of customers suffering losses due to deadlock. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0028] Figure 1 A flowchart of a deadlock logic detection method based on distributed transactions provided in an embodiment of the present application;
[0029] Figure 2 A schematic diagram of a deadlock logic detection device based on distributed transactions provided in an embodiment of the present application;
[0030] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0031] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0032] The terms "first" and "second" in the specification and claims of this application are used to distinguish different objects rather than to describe a specific order of the objects. For example, a first switching device and a second switching device are used to distinguish different switching devices rather than to describe a specific order of the switching devices.
[0033] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0034] Distributed transactions: Transaction participants, transaction-supporting servers, resource servers, and transaction managers are located on different nodes of different distributed systems. Transactions involve distributed operations across databases, components, and services.
[0035] TCC transaction model: TCC proposes a transaction definition method based on the business level. By controlling the lock granularity by the business itself, it solves the problem of large-granularity resource locking such as cross-table and cross-database in complex business. The compensation mechanism adopted by TCC registers a corresponding confirmation and compensation (cancellation) operation for each operation. It is divided into three stages: the Try stage is mainly to test the business system and reserve resources; the Confirm stage is mainly to confirm and submit the business system; the Cancel stage is mainly to cancel the business executed in the state of business execution error and need to roll back, and release the reserved resources.
[0036] APM tool: An application performance monitoring tool that tracks the internal call chain, memory objects and thread resolution of an application.
[0037] Deadlock: refers to a blocking phenomenon caused by competition for resources during the execution of two or more processes. Without external force, they will not be able to move forward. At this time, the system is said to be in a deadlock state or the system has a deadlock.
[0038] See also Figure 1 , which is a flowchart of a deadlock logic detection method based on distributed transactions provided in an embodiment of the present application.
[0039] like Figure 1 As shown, the method includes:
[0040] S110: Obtain link stack information of the target transaction.
[0041] In the embodiment of the present application, for the microservice application that needs to be monitored, the APM monitoring tool is deployed and monitoring is started. During the test process, APM collects and monitors the full-link program information of different dynamic account transactions in the microservice and saves it in the APM database. It should be noted that APM collects and monitors the full-link program information of different dynamic account transactions in the microservice after informing the user and the user agrees.
[0042] Exemplarily, the complete link stack information of different transaction codes is obtained according to the path information and stored in the database. The stack information is shown in Table 1 below:
[0043] Table 1
[0044] Serial number type Stack Information 1 Program Statements tcc try begin tag 2 SQL Statements update table_a set valuel='1'where account='a' 3 SQL Statements update table_b set value1='2'where account='b' 4 Program Statements tcc try end tag 5 Program Statements tcc confirm begin tag 6 SQL Statements update table_b set value2='2'where account='b' 7 SQL Statements update table_a set value2='1'where account='a' 8 Program Statements tcc confirm end tag 9 Program Statements tcc cancel begin tag 10 SQL Statements ... 11 Program Statements tcc cancel end tag
[0045] Combined with the three transaction phases in the aforementioned TCC transaction model, namely the "try", "confirm" and "cancel" phases. Among them, "tcc try begin tag", "tcc confirm begin tag" and "tcc cancel begin tag" are the start label statements of the three transaction phases respectively; "tcc try end tag", "tcc confirm end tag" and "tcc cancel end tag" are the end label statements of the three transaction phases respectively; "table_a" and "table_b" represent resource groups; "account='a'" and "account='b"' represent resource names; "1" and "2" represent transaction phase numbers, and the specific explanations are shown in Table 2 and Table 3 below respectively:
[0046] Table 2
[0047] Serial number Transaction Phase type Label Statement 1 TCC Phase 1Try start tcc try begin tag 2 TCC Phase 1Try Finish tcc try end tag 3 TCC Phase 2 Confirmation start tcc confirm begin tag 4 TCC Phase 2 Confirmation Finish tcc try end tag 5 TCC Cancel start tcc cancel begin tag 6 TCC Cancel Finish tcc cancel end tag
[0048] Table 3
[0049] trade Transaction Phase type SQL statement sequence number SQL Statements A TCC Phase 1Try start 1 update table_a set value1='1'where account='a' A TCC one-stage Trv Finish 2 update table_b set value1='2'where account='b' A TCC Phase 2 Confirmation start 1 update table_b set value2='2'where account='b' A TCC Phase 2 Confirmation Finish 2 update table_a set value2='1'where account='a' A TCC Cancel start 1 ... A TCC Cancel Finish 2 ...
[0050] S120: Acquire, according to the link stack information, a first resource group used in a first transaction phase of a target transaction, a second resource group used in a second transaction phase, and an execution order of resources in the first resource group and the second resource group; wherein the first resource group and the second resource group both include at least a first resource and a second resource.
[0051] Exemplarily, according to the start label statements (tcc try begin tag, tcc confirm begin tag, and tcc cancel begin tag) and end label statements (tcc try end tag, tcc confirm end tag, and tcc cancel end tag) of the target transaction in different transaction stages (tyr stage, confirm stage, and cancel stage), SQL statements (update table_a set value1='1'where account='a', update table_b set value2='2'where account='b', updatetable_a set value1='2'where account='b', and update table_b set value2='1'where account='a') of the target transaction in different transaction stages are extracted from the link stack information.
[0052] In the embodiment of the present application, the try phase is used as the first transaction phase, and the confirm phase is used as the second transaction phase. In the SQL statement, the first resource group used by the target transaction in the first transaction phase (including the first resource account='a' and the second resource account='b'), the second resource group used in the second transaction phase (including the first resource account='a' and the second resource account='b'), the order in which the first resource and the second resource are executed in the first resource group, and the order in which the first resource and the second resource are executed in the second resource group are obtained.
[0053] Exemplarily, the order in which the first resource account='a' and the second resource account='b' are executed in the first resource group and the order in which they are executed in the second resource group is shown in Table 4 below:
[0054] Table 4
[0055]
[0056] As shown in Table 4 above, the first resource account='a' and the second resource account='b' in the first resource group are executed sequentially, and the second resource account='b' and the first resource account='a' in the second resource group are executed sequentially.
[0057] Furthermore, the execution order and resource numbers of the first resource account='a' and the second resource account='b' in the first resource group in the first transaction phase are respectively shown in Table 5 below:
[0058] Table 5
[0059] Transaction Number Update order Resource Number 1 1 1 1 2 2
[0060] As shown in Table 5, in the first transaction phase, the first resource account='a' is updated first, and then the second resource account='b' is updated.
[0061] The execution order and resource numbers of the first resource account='a' and the second resource account='b' in the second resource group in the second transaction phase are respectively shown in Table 6 below:
[0062] Table 6
[0063] Resource Number Update order Transaction Number 2 1 2 1 2 2
[0064] As shown in Table 6, in the second transaction phase, the second resource account='b' is updated first, and then the first resource account='a' is updated.
[0065] S130: If the first resource and the second resource in the first resource group are executed sequentially, the second resource and the first resource in the second resource group are executed sequentially, and the time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is less than a preset threshold, there is a risk of deadlock in the target transaction.
[0066] In the embodiment of the present application, it is determined whether the target transaction has a deadlock risk based on the execution order of the first resource and the second resource in the SQL list of the first transaction stage and the second transaction stage.
[0067] Exemplarily, as shown in Table 5 above, in the first transaction phase, the first resource account='a' is updated first, and then the second resource account='b' is updated; as shown in Table 6 above, in the second transaction phase, the second resource account='b' is updated first, and then the first resource account='a' is updated. When high concurrency occurs and two processes may process the same account, if the time for operating the first resource account='a' in the first transaction phase and the time for operating the second resource account='b' in the second transaction phase are less than a preset threshold, the first transaction phase first updates the first resource account='a' and waits for the second resource account='b' to be updated, and the second transaction phase first updates the second resource account='b' and waits for the first resource account='a' to be updated. The two phases wait for resources from each other, causing a deadlock.
[0068] It should be noted that in the embodiment of the present application, the preset time is close to 0, that is, the time for operating the first resource account='a' in the first transaction phase is the same as the time for operating the second resource account='b' in the second transaction phase.
[0069] In the embodiment of the present application, through the resources in different transaction stages and the timing corresponding to the resources, it is possible to determine whether there is a deadlock risk, reduce the probability of deadlock, and thus reduce the probability of customers suffering losses due to deadlock. In addition, the method described in the embodiment of the present application no longer relies on online real-time monitoring tools to discover deadlock problems caused by program logic errors, and can check logical errors in advance to avoid production risks; by using APM monitoring tools to assist in parsing and analysis, manual troubleshooting can be avoided, and test quality and efficiency can be improved; this method can be applied to different types of logic detection, using APM to obtain program links, configure detection logic, and obtain analysis results, which has strong practicality, ease of use, flexibility and scalability.
[0070] In addition, when there is a risk of deadlock in the target transaction, the embodiments of the present application can adjust the execution order of resources in the first resource group so that the second resource and the first resource in the first resource group are executed in sequence, or adjust the execution order of resources in the second resource group so that the first resource and the second resource in the second resource group are executed in sequence.
[0071] Exemplarily, in the adjusted first transaction phase, the second resource account='b' is executed first, and then the first resource account='a' is executed, and in the second transaction phase, the second resource account='b' is executed first, and then the first resource account='a' is executed; or, in the first transaction phase, the first resource account='a' is executed first, and then the second resource account='b' is executed, and in the adjusted second transaction phase, the first resource account='a' is executed, and then the second resource account='b' is executed.
[0072] In addition, the embodiment of the present application can also adjust the execution time of the first resource in the first resource group, or the execution time of the second resource in the second resource group, so that the time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is greater than the preset threshold, thereby avoiding the risk of deadlock.
[0073] Exemplarily, after the first resource account='a' is executed in the first resource group, the second resource account='b' is executed in the second resource group; or, after the second resource account='b' is executed in the second resource group, the first resource group executes the first resource account='a'.
[0074] In the above-mentioned embodiment, a deadlock detection method based on distributed transactions is introduced. The following will introduce a deadlock detection device based on distributed transactions, and its corresponding schematic diagram is shown in FIG. Figure 2 shown.
[0075] like Figure 2 As shown, the device includes: a first acquisition module 210, a second acquisition module 220 and a detection module 230.
[0076] A first acquisition module 210, used to acquire link stack information of a target transaction;
[0077] The second acquisition module 220 is used to acquire, according to the link stack information, a first resource group used in the first transaction phase of the target transaction, a second resource group used in the second transaction phase, and an execution order of each resource in the first resource group and the second resource group; wherein the first resource group and the second resource group both include at least the first resource and the second resource;
[0078] The detection module 230 is used to determine that the target transaction has a deadlock risk when the first resource and the second resource in the first resource group are executed in sequence, the second resource and the first resource in the second resource group are executed in sequence, and the time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is less than a preset threshold.
[0079] Optionally, the second detection module 220 is specifically used to extract SQL statements of the target transaction in the first transaction phase and the second transaction phase from the link stack information according to the start label statement and the end label statement of the target transaction in the first transaction phase and the second transaction phase; and obtain in the SQL statements the execution order of the first resource group and each resource in the first resource group used by the target transaction in the first transaction phase, and the execution order of the second resource group and each resource in the second resource group used in the second transaction phase.
[0080] Optionally, the first acquisition module 210 is specifically configured to acquire link stack information of the target transaction from an application performance monitoring APM database according to the transaction code of the target transaction.
[0081] Optionally, the device further includes: an execution module;
[0082] The execution module is used to adjust the execution order of resources in the first resource group so that the second resource and the first resource in the first resource group are executed in sequence, or to adjust the execution order of resources in the second resource group so that the first resource and the second resource in the second resource group are executed in sequence. In the embodiment of the present application, through the resources in different transaction stages and the timing corresponding to the resources, it can be determined whether there is a deadlock risk, reduce the deadlock probability, and thus reduce the probability of customers suffering losses due to deadlock.
[0083] Optionally, the execution module is also used to adjust the execution time of the first resource in the first resource group, or the execution time of the second resource in the second resource group, so that the time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is greater than the preset threshold.
[0084] An embodiment of the present application provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the deadlock logic detection method based on distributed transactions described in the embodiment of the present application is implemented.
[0085] In practical applications, the computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present embodiment, the computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0086] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0087] The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0088] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0089] like Figure 3As shown, a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 3 The computer device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0090] like Figure 3 As shown, the computer device 12 is in the form of a general-purpose computing device. The components of the computer device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that connects various system components (including the system memory 28 and the processing unit 16).
[0091] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0092] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0093] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 3 not shown, usually called a "hard drive"). Although Figure 3 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.
[0094] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in the memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0095] The computer device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the computer device 12 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 20. Figure 3 As shown, the network adapter 20 communicates with other modules of the computer device 12 via the bus 18. It should be understood that although Figure 3 Not shown, other hardware and / or software modules may be used in conjunction with computer device 12, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0096] The processor unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the deadlock logic detection method based on distributed transactions provided in an embodiment of the present application.
[0097] It should also be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0098] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A deadlock logic detection method based on distributed transactions, characterized in that: The method comprises: Get the link stack information of the target transaction; According to the link stack information, a first resource group used in a first transaction phase of the target transaction, a second resource group used in a second transaction phase, and an execution order of each resource in the first resource group and the second resource group are acquired; wherein the first resource group and the second resource group both include at least a first resource and a second resource; If the first resource and the second resource in the first resource group are executed sequentially, the second resource and the first resource in the second resource group are executed sequentially, and the time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is less than a preset threshold, the target transaction has a deadlock risk.
2. The method according to claim 1, characterized in that The acquiring, according to the link stack information, a first resource group used in a first transaction phase of the target transaction, a second resource group used in a second transaction phase, and an execution order of each resource in the first resource group and the second resource group includes: Extracting SQL statements of the target transaction in the first transaction phase and the second transaction phase from the link stack information according to the start label statement and the end label statement of the target transaction in the first transaction phase and the second transaction phase; The first resource group used by the target transaction in the first transaction phase and the execution order of the resources in the first resource group, as well as the second resource group used by the second transaction phase and the execution order of the resources in the second resource group are obtained in the SQL statement.
3. The method according to claim 1 or 2, characterized in that: The step of obtaining link stack information of a target transaction includes: According to the transaction code of the target transaction, the link stack information of the target transaction is obtained from an application performance monitoring APM database.
4. The method according to claim 3, characterized in that: In the case where the target transaction has a deadlock risk, the method further includes: Adjust the execution order of the resources in the first resource group so that the second resource and the first resource in the first resource group are executed in sequence, or adjust the execution order of the resources in the second resource group so that the first resource and the second resource in the second resource group are executed in sequence.
5. The method according to claim 3, characterized in that: In the case where the target transaction has a deadlock risk, the method further includes: Adjust the execution time of the first resource in the first resource group, or the execution time of the second resource in the second resource group, so that the time difference between the start of execution of the first resource in the first resource group and the start of execution of the second resource in the second resource group is greater than the preset threshold.
6. A deadlock logic detection device based on distributed transactions, characterized in that: The device comprises: a first acquisition module, a second acquisition module and a detection module; The first acquisition module is used to acquire link stack information of the target transaction; The second acquisition module is used to acquire, according to the link stack information, a first resource group used in a first transaction phase of the target transaction, a second resource group used in a second transaction phase, and an execution order of each resource in the first resource group and the second resource group; wherein the first resource group and the second resource group both include at least a first resource and a second resource; The detection module is used to determine that the target transaction has a deadlock risk when the first resource and the second resource in the first resource group are executed in sequence, the second resource and the first resource in the second resource group are executed in sequence, and the time difference between the start of execution of the first resource in the first resource group and the second resource in the second resource group is less than a preset threshold.
7. The detection device according to claim 6, characterized in that: The second detection module is specifically used to extract the SQL statements of the target transaction in the first transaction phase and the second transaction phase from the link stack information according to the start label statement and the end label statement of the target transaction regarding the first transaction phase and the second transaction phase; and obtain from the SQL statements the execution order of the first resource group used by the target transaction in the first transaction phase and the execution order of each resource in the first resource group, and the execution order of the second resource group used by the target transaction in the second transaction phase and the execution order of each resource in the second resource group.
8. The device according to claim 6 or 7, characterized in that The first acquisition module is specifically configured to acquire the link stack information of the target transaction from an application performance monitoring APM database according to the transaction code of the target transaction.
9. A computer device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the deadlock logic detection method based on distributed transactions as described in any one of claims 1 to 5 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed on a terminal device, the terminal device executes the deadlock logic detection method based on distributed transactions as described in any one of claims 1 to 5.