CN116244089A - Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium - Google Patents

Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium Download PDF

Info

Publication number
CN116244089A
CN116244089A CN202310246604.3A CN202310246604A CN116244089A CN 116244089 A CN116244089 A CN 116244089A CN 202310246604 A CN202310246604 A CN 202310246604A CN 116244089 A CN116244089 A CN 116244089A
Authority
CN
China
Prior art keywords
target
transactions
deadlock
transaction
script
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310246604.3A
Other languages
Chinese (zh)
Inventor
徐双
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Pingan Payment Technology Service Co Ltd
Original Assignee
Pingan Payment Technology Service Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Pingan Payment Technology Service Co Ltd filed Critical Pingan Payment Technology Service Co Ltd
Priority to CN202310246604.3A priority Critical patent/CN116244089A/en
Publication of CN116244089A publication Critical patent/CN116244089A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application discloses a deadlock risk detection method, a device, computer equipment and a readable storage medium, wherein the method comprises the following steps: acquiring a plurality of opening transactions corresponding to a database to be operated in a preset time period; acquiring a plurality of pieces of script information of a plurality of scripts in each opening transaction, wherein the plurality of pieces of script information comprise a plurality of script types, a plurality of data resources and a plurality of script execution times corresponding to the plurality of scripts; and judging whether deadlock risks exist among a plurality of open transactions according to the script information. By the method, on one hand, the possible deadlock risk items can be exposed before the database operation, so that the stability of the database system is improved; on the other hand, a plurality of open transactions are detected in a targeted manner, whether the deadlock risk exists or not is judged, the method is light and simple, the deadlock detection amount of a data volume system is reduced, and the deadlock risk detection efficiency is effectively improved.

Description

Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium
Technical Field
The present disclosure relates to the field of database technologies, and in particular, to a deadlock risk detection method, apparatus, computer device, and readable storage medium.
Background
In a computer program, to ensure data consistency, when one database transaction is modifying certain data, the database management system will lock that data so that other database transactions cannot modify that data. When any one of the two database transactions is currently required data of the other database transaction which is currently modified, the two database transactions form a phenomenon of waiting for each other, so that the database is deadlocked. In the related art, in order to avoid the occurrence of deadlock, a method of making a specification to check a code to be executed is generally adopted to detect the deadlock risk in advance, and the problem code is found to be reformed immediately.
In carrying out the present application, the applicant has found that the related art has at least the following problems:
when a plurality of transactions are executed concurrently, the new code opens the new transaction and the old transaction to cause resource contention and deadlock, and the mode of checking the code in advance is difficult to cover all the new and old codes, so that the deadlock risk still exists when the plurality of transactions are executed concurrently, and the detection accuracy is lower.
Disclosure of Invention
In view of this, the present application provides a deadlock risk detection method, apparatus, computer device and readable storage medium, and mainly aims to solve the problem that it is difficult to cover all new and old codes in a code early checking manner, so that a deadlock risk still exists when a plurality of transactions are executed concurrently, and detection accuracy is low.
According to a first aspect of the present application, there is provided a deadlock risk detection method, the method comprising:
acquiring a plurality of opening transactions corresponding to a database to be operated in a preset time period;
acquiring a plurality of pieces of script information of a plurality of scripts in each opening transaction, wherein the plurality of pieces of script information comprise a plurality of script types, a plurality of data resources and a plurality of script execution times corresponding to the plurality of scripts;
and judging whether deadlock risks exist among a plurality of open transactions according to the script information.
Optionally, the step of acquiring a plurality of open transactions corresponding to the database to be operated in the preset time period specifically includes:
responding to a deadlock risk detection request, and acquiring database connection of a database to be operated;
acquiring a plurality of transaction states of a plurality of transactions connected with a database in a preset time period;
a plurality of open transactions in the database connection are determined based on the plurality of transaction states.
Optionally, the step of determining whether there is a risk of deadlock between the plurality of open transactions according to the plurality of script information specifically includes:
judging whether a plurality of script types of a plurality of opening transactions comprise update sentences or not;
in the case that the plurality of script types do not include the update statement, determining that there is no deadlock risk between the plurality of open transactions;
In the case that the plurality of script types comprise the update statement, determining at least one target transaction corresponding to the update statement in a plurality of open transactions;
in the case that the number of at least one target transaction is one, determining that there is no deadlock risk between a plurality of open transactions;
under the condition that the number of at least one target transaction is a plurality of target scripts, acquiring a plurality of target script information of a plurality of target scripts corresponding to the update statement in the plurality of target transactions;
and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of target script information.
Optionally, the step of determining whether there is a deadlock risk between the plurality of target transactions according to the plurality of target script information specifically includes:
acquiring the number of target scripts corresponding to each target transaction;
determining whether a single target transaction exists in a plurality of target transactions;
if so, determining that deadlock risks exist between the target transaction and a plurality of other target transactions;
if the target transaction does not exist, acquiring a plurality of data resources of a plurality of target scripts of a plurality of target transactions;
and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of data resources.
Optionally, the step of determining, according to the plurality of data resources, whether there is a risk of deadlock between the plurality of target transactions specifically includes:
determining an execution sequence among a plurality of data resources according to a plurality of target script execution times of a plurality of target scripts;
judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different;
if so, determining that deadlock risks exist between at least two target transactions.
Optionally, after determining that there is no risk of deadlock between the target transaction and the plurality of other target transactions, if present, the method further includes:
among the plurality of target transactions, excluding the target script number as a single target transaction;
acquiring a plurality of target data resources of a plurality of target scripts of a plurality of target transactions after being excluded and an execution sequence of the plurality of target data resources;
judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different;
If so, determining that deadlock risks exist between at least two target transactions.
Optionally, after determining that there is a risk of deadlock between at least two target transactions, if present, further comprising:
acquiring a transaction identifier of each target transaction;
generating deadlock risk prompt information according to the transaction identifier, a plurality of target script types corresponding to the plurality of target scripts, a plurality of target data resources and a plurality of target script execution times;
and sending a deadlock risk prompt message.
According to a second aspect of the present application, there is provided a deadlock risk detection device, the device comprising:
the first acquisition module is used for acquiring a plurality of opening transactions corresponding to the database to be operated in a preset time period;
the second acquisition module is used for acquiring a plurality of pieces of script information of a plurality of scripts in each opening transaction, wherein the plurality of pieces of script information comprise a plurality of script types, a plurality of data resources and a plurality of script execution times corresponding to the plurality of scripts;
and the judging module is used for judging whether deadlock risks exist among a plurality of opening transactions according to the script information.
Optionally, the first obtaining module is specifically configured to:
responding to a deadlock risk detection request, and acquiring database connection of a database to be operated;
Acquiring a plurality of transaction states of a plurality of transactions connected with a database in a preset time period;
a plurality of open transactions in the database connection are determined based on the plurality of transaction states.
Optionally, the judging module is specifically configured to:
judging whether a plurality of script types of a plurality of opening transactions comprise update sentences or not;
in the case that the plurality of script types do not include the update statement, determining that there is no deadlock risk between the plurality of open transactions;
in the case that the plurality of script types comprise the update statement, determining at least one target transaction corresponding to the update statement in a plurality of open transactions;
in the case that the number of at least one target transaction is one, determining that there is no deadlock risk between a plurality of open transactions;
under the condition that the number of at least one target transaction is a plurality of target scripts, acquiring a plurality of target script information of a plurality of target scripts corresponding to the update statement in the plurality of target transactions;
and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of target script information.
Optionally, the apparatus further comprises:
and the third acquisition module is used for acquiring the number of the target scripts corresponding to each target transaction.
A first determining module, configured to determine whether a single target transaction exists among a plurality of target transactions;
And the second determining module is used for determining that the deadlock risk exists between the target transaction and a plurality of other target transactions if the deadlock risk exists.
Optionally, the apparatus further comprises:
and the fourth acquisition module is used for acquiring a plurality of data resources of a plurality of target scripts of a plurality of target transactions if the target scripts do not exist.
Optionally, the judging module is further configured to:
and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of data resources.
Optionally, the apparatus further comprises:
and the third determining module is used for determining the execution sequence among the plurality of data resources according to the execution time of the plurality of target scripts.
Optionally, the judging module is further configured to:
judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources and the execution sequence of the plurality of target data resources.
Optionally, the apparatus further comprises:
and the fourth determining module is used for determining that deadlock risks exist between at least two target transactions if the deadlock risks exist.
Optionally, the apparatus further comprises:
and the exclusion module is used for excluding the single target transaction from the target script number in the plurality of target transactions.
And a fifth acquisition module, configured to acquire a plurality of target data resources of a plurality of target scripts of the plurality of target transactions after the exclusion and an execution order of the plurality of target data resources.
Optionally, the judging module is further configured to:
judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different.
Optionally, the apparatus further comprises:
and a fifth determining module, configured to determine that there is a risk of deadlock between at least two target transactions, if there is any.
Optionally, the apparatus further comprises:
a sixth acquisition module, configured to acquire a transaction identifier of each target transaction;
the generation module is used for generating deadlock risk prompt information according to the transaction identification, a plurality of target script types corresponding to the plurality of target scripts, a plurality of target data resources and a plurality of target script execution times;
and the sending module is used for sending the deadlock risk prompt information.
According to a third aspect of the present application there is provided a computer device comprising a memory storing a computer program and a processor implementing the steps of the method of any one of the first aspects when the computer program is executed by the processor.
According to a fourth aspect of the present application there is provided a readable storage medium having stored thereon a computer program which when executed by a processor implements the steps of the method of any of the first aspects.
By means of the technical scheme, the deadlock risk detection method, the deadlock risk detection device, the computer equipment and the readable storage medium are characterized in that firstly, a plurality of opening transactions corresponding to a database to be operated are obtained, and a plurality of scripts in each opening transaction are analyzed to obtain script types, a plurality of data resources and execution sequences among the plurality of data resources of each script. On one hand, the possible deadlock risk item can be exposed before the database operation, and the stability of the database system is improved; on the other hand, compared with the mode of carrying out deadlock risk detection on all codes in the prior art, a large number of meaningless deadlock detections exist, the database system CPU (central processing unit ) resources are wasted, and the problem of low deadlock risk detection efficiency is solved.
The foregoing description is only an overview of the technical solutions of the present application, and may be implemented according to the content of the specification in order to make the technical means of the present application more clearly understood, and in order to make the above-mentioned and other objects, features and advantages of the present application more clearly understood, the following detailed description of the present application will be given.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the application. Also, like reference numerals are used to designate like parts throughout the figures. In the drawings:
fig. 1 shows a schematic flow chart of a deadlock risk detection method provided in an embodiment of the present application;
fig. 2 shows a schematic structural diagram of a deadlock risk detection device according to an embodiment of the present application.
Detailed Description
Exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
The embodiment of the application provides a deadlock risk detection method, as shown in fig. 1, which comprises the following steps:
101. and acquiring a plurality of opening transactions corresponding to the database to be operated in a preset time period.
The application provides a deadlock risk detection method, wherein a database transaction refers to a program execution unit which accesses and possibly updates various data items in a database. Transaction logic is an open transaction, executing a set of SQL statements, committing or rollback transactions. However, a transaction is exclusive to the allocated resources, i.e., one resource can only be occupied by one transaction until the transaction is released, and any other transaction cannot rob it of occupation until no one is released by the transaction. Thus, if a database transaction needs to modify a piece of data, it is necessary to lock on the piece of data to ensure that only one database transaction can perform the modification operation at the same time. And unlocking the data after the database transaction is executed and the transaction is submitted. When any one of the two database transactions is currently required data of the other database transaction which is currently modified, the two database transactions form a phenomenon of waiting for each other, so that the database is deadlocked. For example, database transaction A requires the data currently modified by database transaction B, while database transaction B also requires the data currently modified by database transaction A, thereby causing database deadlock to occur. When a database deadlock occurs, it typically results in a service breakdown of the entire computer program. In order to avoid database deadlock in the process of executing a plurality of concurrent transactions, the method and the device provided by the invention analyze scripts in the plurality of transactions before the concurrent execution of the plurality of transactions so as to realize timely discovery of deadlock risks before the execution of the transactions.
Specifically, for a database that is to serve a plurality of transactions, a plurality of open transactions within a preset time period are acquired prior to a data operation. It should be noted that the database to be operated is a database state in which the database has already established a data connection and has not performed a data operation. Opening a transaction refers to a transaction that is open but not yet executed. The preset time period is a time range for detecting whether deadlock risks exist among a plurality of open transactions, and can be set by a worker or a random time period, for example, whether deadlock risks exist in the time period from 12 to 16 times when detection is needed.
By the method, before data operation is performed, the open transactions to be executed concurrently in a plurality of preset time periods are determined, and then scripts of the open transactions are analyzed, so that deadlock risk detection is performed before database operation data is achieved, and a database system can expose possible deadlock risk items before the data operation, so that the stability of the database system is improved.
102. And acquiring a plurality of pieces of script information of a plurality of scripts in each opening transaction, wherein the plurality of pieces of script information comprise a plurality of script types, a plurality of data resources and a plurality of script execution times corresponding to the plurality of scripts.
In this step, the transaction is a section of atomic service that needs to be executed actually, and the script refers to a layout mode of a group of atomic services, and the transaction is laid out through a plurality of step scripts. Therefore, before database operation, after determining a plurality of open transactions in a preset time period, script information of a plurality of scripts in each open transaction is obtained, and script type of each script, data resources corresponding to the script and script execution time are analyzed to judge whether deadlock risks exist among the plurality of open transactions.
By the method, all script information of all open transactions is obtained, the script information is used as a basic parameter of deadlock risk detection, the deadlock risk detection is carried out on a plurality of open transactions in a targeted manner, and on one hand, the accuracy of a deadlock risk detection result is improved; on the other hand, a large number of codes are not required to be detected, the method is light and simple, possible deadlock risks can be detected in the process of test operation, and the deadlock risk detection efficiency is improved.
103. And judging whether deadlock risks exist among a plurality of open transactions according to the script information.
In this step, the flow analysis performed on the transactions finds that if there are two or more resources within one transaction that also exist in another transaction, and the execution order of the same resources in different transactions is not consistent, there is a risk of deadlock between the several concurrently executing transactions. Based on the above reasons, the present application proposes comparing, according to script information of a plurality of scripts in each open transaction, a plurality of data resources of the plurality of scripts in the plurality of open transactions and execution sequences among the plurality of data resources, detecting whether two or more data resources which are the same and have different execution sequences are used in the plurality of open transactions, and further determining whether deadlock risks exist among the plurality of open transactions.
According to the deadlock risk detection method, firstly, a plurality of opening transactions corresponding to a database to be operated are obtained, and a plurality of scripts in each opening transaction are analyzed to obtain script types, a plurality of data resources and execution sequences among the plurality of data resources of each script. On one hand, the possible deadlock risk item can be exposed before the database operation, and the stability of the database system is improved; on the other hand, compared with the mode of carrying out deadlock risk detection on all codes in the prior art, a large number of meaningless deadlock detections exist, the database system CPU resources are wasted, and the problem of low deadlock risk detection efficiency is solved.
Further, as a refinement and extension of the foregoing embodiment, in order to fully describe a specific implementation procedure of the embodiment, the embodiment of the present application provides another deadlock risk detection method, where the method includes:
201. And responding to the deadlock risk detection request, and acquiring database connection of the database to be operated.
In this step, when the database is operated, the database is attached first, and then SQL (Structured Query Language ) statements are executed. Executing an SQL statement has one transaction commit and there can be countless transactions under the same database connection. That is, transactions are connection-based, and no matter how many transactions are originally, how many database operations can share a connection. Therefore, when the deadlock risk detection is carried out on the database to be operated, the connection information of the current database connection of the database to be operated is obtained in response to the deadlock risk detection request, and whether an opening transaction exists in the database connection is further judged.
202. A plurality of transaction states of a plurality of transactions of the database connection within a preset time period are acquired.
203. A plurality of open transactions in the database connection are determined based on the plurality of transaction states.
In the step, after the current database connection is obtained, the transaction state of each transaction of the current database connection in a preset time period is obtained to judge whether an open transaction exists in the database connection.
Alternatively, the database transaction is a sequence of operations performed by a single logical unit of work, such as open, execute, commit, etc. If it is desired to detect whether there is a deadlock risk before the data operation, it is necessary to detect a deadlock risk for a plurality of scripts in a plurality of open transactions before the data operation. If it is determined that there are no open transactions in the database connection according to all the transaction states, it is indicated that the plurality of transactions in the database connection may be executed transactions or committed transactions in the preset time period, that is, there is no data operation that has not yet been executed in the preset time period, and deadlock risk detection is not required.
Further, if only one open transaction is judged in the database connection according to the transaction states, the deadlock condition of one open transaction does not occur, and at the moment, deadlock risk detection on the database to be operated is not needed.
Optionally, in practical application, a transaction snoop plug-in "deadlock_rolling. Jar" to be used for deadlock risk detection is introduced in the traffic engineering. When a developer wants to perform deadlock risk detection, a 'deadlock_warning. Jar' plugin intercepts a current database request to intercept operations such as adding, deleting, modifying or viewing data in a database. And acquiring the connection information of the current database connection to judge whether a plurality of opening transactions exist in the current database connection within a preset time period. If a plurality of open transactions exist in the database connection, deadlock risk detection is carried out on the plurality of open transactions; and if the database connection has no open transaction or only one open transaction, releasing interception and continuing to execute data operation.
By the method, the database request is intercepted before the data is executed, the database connection is obtained, whether a plurality of opening transactions exist in the database connection is judged, and if the plurality of opening transactions exist, deadlock risk detection is carried out; if a plurality of open transactions do not exist, the interception is released to continue to execute the data operation, so that the deadlock problem is found in time before the data is executed, the possibility of deadlock during the data execution is greatly reduced, and the system stability is effectively improved.
204. Whether the plurality of script types of the plurality of open transactions include an update statement is determined, if yes, step 206 is entered, and if no, step 205 is entered.
In this step, the SQL used to manipulate the database is generally divided into two types, one is a query Statement (SELECT) and the other is an UPDATE statement (UPDATE), also known as a data manipulation statement. The update statement in the SQL statement is one of the most commonly used statements to modify data. In the execution of multiple concurrent transactions, there is typically an update operation in one transaction, and a deadlock situation occurs when there is an update operation to the same data resource in another transaction. Therefore, after determining a plurality of open transactions within a preset time, a plurality of script types of a plurality of scripts in each open transaction are obtained, whether the plurality of script types contain UPDATE statement UPDATE is judged, and whether deadlock risk detection is needed for the plurality of open transactions is further judged.
205. It is determined that there is no risk of deadlock between the plurality of open transactions.
206. At least one target transaction corresponding to the update statement is determined among the plurality of open transactions.
In step 205 and step 206, the script types of the plurality of scripts in each open transaction are analyzed, and if there is no UPDATE statement UPDATE in the script type in each open transaction, it is indicated that there is no deadlock risk between the plurality of open transactions. Further, if there is an open transaction of the UPDATE script in the plurality of open transactions, such open transaction is taken as a target transaction, at least one target transaction is acquired in the plurality of open transactions.
207. In the case that the number of at least one target transaction is one, it is determined that there is no risk of deadlock between the plurality of open transactions.
In this step, the number of at least one target transaction is obtained, and if there is only one target transaction, it is indicated that, among the plurality of open transactions, only the script in one open transaction includes a plurality of UPDATE script types, that is, the scripts in other open transactions are of the type such as query data, and there is no deadlock risk between the plurality of open transactions, that is, deadlock risk detection is not required for the plurality of open transactions.
208. And under the condition that the number of at least one target transaction is a plurality of target scripts, acquiring a plurality of target script information of a plurality of target scripts corresponding to the update statement in the plurality of target transactions.
In this step, the number of at least one target transaction is obtained, if the number of target transactions is multiple, the script type containing multiple update data in the multiple target transactions is described, and at this time, when the data is updated between the multiple target transactions, a deadlock condition may occur, and then deadlock risk detection needs to be performed on the multiple target transactions. Therefore, the method and the device acquire the plurality of target script information of the plurality of target scripts with the script types of the update sentences in the plurality of target transactions, and are convenient for taking the plurality of target script information as deadlock risk detection parameters.
209. And judging whether deadlock risks exist among the plurality of target transactions according to the plurality of target script information.
In the step, after a plurality of target transactions containing target scripts are determined, target script information of the target scripts in each target transaction is acquired, and whether deadlock risks exist among the plurality of target transactions or not is judged by taking the target script information as a detection parameter. It should be noted that, the target script information of each target script includes a target script type, a data resource corresponding to the target script, and an execution sequence of a plurality of data resources corresponding to a plurality of target scripts. Wherein the script type of each target script is known as UPDATE.
Through the method, after the current database connection is obtained, a plurality of open target transactions which are connected with the database and contain updated statement scripts in a preset time period are screened, and then deadlock risk detection is carried out on the plurality of target transactions so as to judge whether deadlock risks exist in the subsequent data operation process, on one hand, the dead lock risk items can be exposed before the program executes the data operation, and the stability of a database system is improved; on the other hand, the deadlock risk detection is carried out by screening the transactions which are started and contain the update statement script, all codes are not required to be detected, the method is light and simple, and the deadlock risk detection efficiency is effectively improved.
In this embodiment of the present application, optionally, in step 209, that is, according to the plurality of target script information, whether there is a deadlock risk between the plurality of target transactions is determined, which specifically includes: acquiring the number of target scripts corresponding to each target transaction; determining whether a single target transaction exists in a plurality of target transactions; if so, determining that deadlock risks exist between the target transaction and a plurality of other target transactions; if the target transaction does not exist, acquiring a plurality of data resources of a plurality of target scripts of a plurality of target transactions; and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of data resources.
In this embodiment, the flow analysis for the execution of transactions finds that if there are two or more resources within one transaction that are also present in another transaction, and the execution order of the same resources in different transactions is not consistent, there is a risk of deadlock between the several concurrently executing transactions. Therefore, the number of the target scripts corresponding to the update statement in each target transaction is obtained, and if only one update statement script exists in any target transaction, the condition that deadlock risks exist between the target transaction and other target transactions is indicated. Further, if the target script data corresponding to the update statement in any target transaction is greater than or equal to two, it is indicated that the target transaction has a deadlock risk in the execution process. Therefore, a plurality of data resources of a plurality of target scripts in a plurality of target transactions are acquired, and whether deadlock risks exist among the plurality of target transactions is judged according to the data resources corresponding to the update sentences of all the target transactions.
In this embodiment of the present application, optionally, determining, according to a plurality of data resources, whether a deadlock risk exists between a plurality of target transactions includes: determining an execution sequence among a plurality of data resources according to a plurality of target script execution times of a plurality of target scripts; judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different; if so, determining that deadlock risks exist between at least two target transactions.
In this embodiment, after determining a plurality of data resources corresponding to the update statement in each target transaction, a plurality of target script execution times of a plurality of target scripts are acquired in the script information, and then, an execution order of the plurality of data resources is determined according to the plurality of target script execution times. If the same at least two target data resources exist in any at least two target transactions in the plurality of target transactions and the execution sequences of the at least two target data resources are different in different target transactions, determining that deadlock risks exist between the two target transactions.
Optionally, in the practical application, the data resources related to the update statement in the target transaction 1 are screened to include a resource a, a resource C, a resource D and a resource B, the data resources related to the update statement in the target transaction 2 are screened to include a resource G, a resource H, a resource B and a resource a, the analysis finds that the data resources related to the update statement in the target transaction 1 and the target transaction 2 both include a resource a and a resource B, and according to the script execution time, it is determined that the execution sequence in the target transaction 1 is from the resource a to the resource B, and the execution sequence in the target transaction 2 is from the resource B to the resource a, and then it is determined that a deadlock risk exists between the target transaction 1 and the target transaction 2.
By the method, a plurality of target data resources which are the same and have different execution sequences can be rapidly screened out from the target transactions, and then, in a plurality of opening transactions, at least two target transactions which possibly have deadlock risks are determined.
In an embodiment of the present application, optionally, after determining that there is no risk of deadlock between the target transaction and a plurality of other target transactions, if any, the method further includes: among the plurality of target transactions, excluding the target script number as a single target transaction; acquiring a plurality of target data resources of a plurality of target scripts of a plurality of target transactions after being excluded and an execution sequence of the plurality of target data resources; judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different; if so, determining that deadlock risks exist between at least two target transactions.
In this embodiment, after a target transaction containing a single update statement script is screened out from a plurality of target transactions, it is determined that there is no deadlock risk between the target transaction and other target transactions, where the target transaction is excluded from the plurality of target transactions, and where the remaining plurality of target transactions after the exclusion are all transactions containing the plurality of update statement scripts. And then, acquiring a plurality of target data resources and execution sequences of a plurality of target scripts corresponding to the update statement in each other target transaction, and if the same at least two target data resources exist in any at least two target transactions in the rest target transactions and the execution sequences of the at least two target data resources are different in different target transactions, determining that deadlock risks exist between the two target transactions.
210. A transaction identification for each target transaction is obtained.
211. And generating deadlock risk prompt information according to the transaction identifier, a plurality of target script types corresponding to the plurality of target scripts, a plurality of target data resources and a plurality of target script execution times.
212. And sending a deadlock risk prompt message.
In steps 210 to 212, after determining at least two target transactions with deadlock risk in a plurality of open transactions, transaction identifiers of the at least two target transactions with deadlock risk are obtained respectively, and then according to the at least two transaction identifiers of the at least two target transactions with deadlock risk, a plurality of target data resources and a plurality of target script execution times which are the same as those of other target transactions in each target transaction are generated, deadlock risk prompt information is generated, and the deadlock risk prompt information is sent to a developer to inform the developer to check the target script with deadlock risk, and timely correction is performed after the deadlock problem is confirmed. All possible deadlock risk items can be exposed before database operation, and the stability of a database system is improved.
Optionally, in practical application, a plug-in "dead_rolling. Jar" for transaction monitoring for deadlock risk detection is referenced in the database system, when a database request arrives at a database layer, the database is immediately operated, the database request is intercepted, the database connection is acquired, transaction information of a plurality of open transactions in the database connection within a preset time, such as transaction identification, script type, data resource and script execution time, is extracted, and the extracted transaction information is imported into a preset data table. As shown in table 1, a transaction information data table for a plurality of open transactions. The method comprises the steps of acquiring a unique transaction identifier of each opening transaction from connection information of a database connection, generating the transaction identifier of the opening transaction if the transaction identifier of the opening transaction is not acquired, and recording the transaction identifier of the opening transaction in an attribute file of the database connection. Then, the "deadlock_rolling.jar" plug-in provides an interface for querying the information data table of the data transaction, and through the interface, whether two or more identical data resources corresponding to the update statement exist in the multiple open transactions or not can be queried, and the execution sequence of the identical data resources in different transactions is different, if the data resources AB to BA in the table 1, it is determined that the open transaction "uuid1" and the open transaction "uuid2" are transactions in which deadlock may occur. The script of the possible deadlock in the program is marked in the mode, and then deadlock risk prompt information is generated to remind a developer. It should be noted that, since the plug-in is only used to detect the deadlock risk and cannot interrupt the normal operation of the system, after detecting the script with the deadlock risk in the plurality of open transactions, the blocking is released.
Transaction identification Script type Data resource Script execution time
uuid1 update A 12:00
uuid1 update C 12:01
uuid1 update D 12:03
uuid1 update B 12:05
uuid2 update G 12:10
uuid2 update H 12:15
uuid2 update B 12:18
uuid2 update A 12:20
TABLE 1
Further, as a specific implementation of the method shown in fig. 1, an embodiment of the present application provides a deadlock risk detection apparatus 300, as shown in fig. 2, including:
the first obtaining module 301 is configured to obtain a plurality of open transactions corresponding to a database to be operated in a preset time period;
a second obtaining module 302, configured to obtain a plurality of script information of a plurality of scripts in each open transaction, where the plurality of script information includes a plurality of script types, a plurality of data resources, and a plurality of script execution times corresponding to the plurality of scripts;
the judging module 303 is configured to judge whether a deadlock risk exists between a plurality of open transactions according to a plurality of script information.
Optionally, the first obtaining module 301 is specifically configured to:
responding to a deadlock risk detection request, and acquiring database connection of a database to be operated;
acquiring a plurality of transaction states of a plurality of transactions connected with a database in a preset time period;
a plurality of open transactions in the database connection are determined based on the plurality of transaction states.
Optionally, the judging module 303 is specifically configured to:
judging whether a plurality of script types of a plurality of opening transactions comprise update sentences or not;
In the case that the plurality of script types do not include the update statement, determining that there is no deadlock risk between the plurality of open transactions;
in the case that the plurality of script types comprise the update statement, determining at least one target transaction corresponding to the update statement in a plurality of open transactions;
in the case that the number of at least one target transaction is one, determining that there is no deadlock risk between a plurality of open transactions;
under the condition that the number of at least one target transaction is a plurality of target scripts, acquiring a plurality of target script information of a plurality of target scripts corresponding to the update statement in the plurality of target transactions;
and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of target script information.
Optionally, the apparatus further comprises:
and a third obtaining module 304, configured to obtain the number of target scripts corresponding to each target transaction.
A first determining module 305, configured to determine whether there are a single target transaction among a plurality of target transactions;
a second determining module 306 is configured to determine that there is no risk of deadlock between the target transaction and a plurality of other target transactions, if any.
Optionally, the apparatus further comprises:
a fourth obtaining module 307, configured to obtain, if not, a plurality of data resources of a plurality of target scripts of a plurality of target transactions.
Optionally, the judging module 303 is further configured to:
and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of data resources.
Optionally, the apparatus further comprises:
a third determining module 308, configured to determine an execution order among the plurality of data resources according to a plurality of target script execution times of the plurality of target scripts.
Optionally, the judging module 303 is further configured to:
judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources and the execution sequence of the plurality of target data resources.
Optionally, the apparatus further comprises:
a fourth determining module 309 is configured to determine that there is a risk of deadlock between at least two target transactions, if any.
Optionally, the apparatus further comprises:
the exclusion module 310 is configured to exclude, from among the plurality of target transactions, a single target transaction from the number of target scripts.
A fifth obtaining module 311 is configured to obtain the plurality of target data resources of the plurality of target scripts of the plurality of target transactions after the excluding and the execution order of the plurality of target data resources.
Optionally, the judging module 303 is further configured to:
judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different.
Optionally, the apparatus further comprises:
a fifth determining module 312 is configured to determine that there is a risk of deadlock between at least two target transactions, if any.
Optionally, the apparatus further comprises:
a sixth acquiring module 313, configured to acquire a transaction identifier of each target transaction;
a generating module 314, configured to generate deadlock risk prompt information according to the transaction identifier, a plurality of target script types corresponding to the plurality of target scripts, a plurality of target data resources, and a plurality of target script execution times;
a sending module 315, configured to send the deadlock risk prompt information.
The deadlock risk detection device 300 provided in the embodiment of the present application first obtains a plurality of open transactions corresponding to a database to be operated, and analyzes a plurality of scripts in each open transaction to obtain a script type, a plurality of data resources, and an execution sequence among the plurality of data resources of each script. On one hand, the possible deadlock risk item can be exposed before the database operation, and the stability of the database system is improved; on the other hand, compared with the mode of carrying out deadlock risk detection on all codes in the prior art, a large number of meaningless deadlock detections exist, the database system CPU resources are wasted, and the problem of low deadlock risk detection efficiency is solved.
In an exemplary embodiment, the present application also provides a computer device including a memory and a processor. The memory stores a computer program and a processor for executing the program stored on the memory to perform the deadlock risk detection method in the above embodiment.
In an exemplary embodiment, the present application also provides a readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the deadlock risk detection method.
From the above description of the embodiments, it will be apparent to those skilled in the art that the present application may be implemented in hardware, or may be implemented by means of software plus necessary general hardware platforms. Based on such understanding, the technical solution of the present application may be embodied in the form of a software product, which may be stored in a non-volatile storage medium (may be a CD-ROM, a U-disk, a mobile hard disk, etc.), and includes several instructions for causing a computer device (may be a personal computer, a server, or a network device, etc.) to perform the methods described in various implementation scenarios of the present application.
Those skilled in the art will appreciate that the drawings are merely schematic illustrations of one preferred implementation scenario, and that the modules or flows in the drawings are not necessarily required to practice the present application.
Those skilled in the art will appreciate that modules in an apparatus in an implementation scenario may be distributed in an apparatus in an implementation scenario according to an implementation scenario description, or that corresponding changes may be located in one or more apparatuses different from the implementation scenario. The modules of the implementation scenario may be combined into one module, or may be further split into a plurality of sub-modules.
The foregoing application serial numbers are merely for description, and do not represent advantages or disadvantages of the implementation scenario.
The foregoing disclosure is merely a few specific implementations of the present application, but the present application is not limited thereto and any variations that can be considered by a person skilled in the art shall fall within the protection scope of the present application.

Claims (10)

1. A method for detecting risk of deadlock, comprising:
acquiring a plurality of opening transactions corresponding to a database to be operated in a preset time period;
acquiring a plurality of pieces of script information of a plurality of scripts in each opening transaction, wherein the plurality of pieces of script information comprise a plurality of script types, a plurality of data resources and a plurality of script execution times corresponding to the plurality of scripts;
and judging whether deadlock risks exist among the plurality of opening transactions according to the plurality of script information.
2. The method of claim 1, wherein the step of obtaining a plurality of open transactions corresponding to the database to be operated in the preset time period specifically includes:
Responding to a deadlock risk detection request, and acquiring database connection of the database to be operated;
acquiring a plurality of transaction states of a plurality of transactions connected with the database in the preset time period;
and determining the plurality of open transactions in the database connection according to the plurality of transaction states.
3. The method according to claim 1, wherein the step of determining whether there is a risk of deadlock between the plurality of open transactions according to the plurality of script information, specifically comprises:
judging whether a plurality of script types of the plurality of opening transactions comprise update sentences or not;
determining that there is no deadlock risk between the plurality of open transactions if no update statement is included in the plurality of script types;
determining at least one target transaction corresponding to the update statement in the plurality of open transactions under the condition that the plurality of script types comprise the update statement;
determining that there is no risk of deadlock between the plurality of open transactions if the number of the at least one target transaction is one;
acquiring a plurality of target script information of a plurality of target scripts corresponding to the update statement in the plurality of target transactions under the condition that the number of the at least one target transaction is a plurality of;
And judging whether deadlock risks exist among the plurality of target transactions according to the plurality of target script information.
4. The method according to claim 3, wherein the step of determining whether there is a risk of deadlock between the plurality of target transactions according to the plurality of target script information, specifically comprises:
acquiring the number of target scripts corresponding to each target transaction;
determining whether a single target transaction exists in the target transactions;
if so, determining that deadlock risks exist between the target transaction and a plurality of other target transactions;
if not, acquiring a plurality of data resources of a plurality of target scripts of the plurality of target transactions;
and judging whether deadlock risks exist among the plurality of target transactions according to the plurality of data resources.
5. The method of claim 4, wherein the step of determining whether there is a risk of deadlock between the plurality of target transactions based on the plurality of data resources, specifically comprises:
determining an execution sequence among the plurality of data resources according to a plurality of target script execution times of the plurality of target scripts;
Judging whether at least two target transactions exist in the plurality of target transactions, wherein the at least two target transactions comprise the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different;
if so, determining that deadlock risks exist between the at least two target transactions.
6. The method of claim 4, wherein after determining that there is no risk of deadlock between the target transaction and a plurality of other target transactions if present, further comprising:
among the plurality of target transactions, excluding a single target transaction from the number of target scripts;
acquiring a plurality of target data resources of a plurality of target scripts of a plurality of target transactions after being excluded and an execution sequence of the plurality of target data resources;
judging whether at least two target transactions exist in a plurality of target transactions, wherein the at least two target transactions contain the same plurality of target data resources, and the execution sequences of the plurality of target data resources are different;
if so, determining that deadlock risks exist between the at least two target transactions.
7. The method of claim 6, wherein after determining that there is a risk of deadlock between the at least two target transactions if present, further comprising:
Acquiring a transaction identifier of each target transaction;
generating deadlock risk prompt information according to the transaction identifier, a plurality of target script types corresponding to the plurality of target scripts, a plurality of target data resources and a plurality of target script execution times;
and sending the deadlock risk prompt information.
8. A deadlock risk detection device, comprising:
the first acquisition module is used for acquiring a plurality of opening transactions corresponding to the database to be operated in a preset time period;
the second acquisition module is used for acquiring a plurality of pieces of script information of a plurality of scripts in each opening transaction, wherein the plurality of pieces of script information comprise a plurality of script types, a plurality of data resources and a plurality of script execution times corresponding to the plurality of scripts;
and the judging module is used for judging whether deadlock risks exist among the plurality of opening transactions according to the plurality of script information.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 7 when the computer program is executed.
10. A readable storage medium having stored thereon a computer program, which when executed by a processor realizes the steps of the method according to any of claims 1 to 7.
CN202310246604.3A 2023-03-06 2023-03-06 Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium Pending CN116244089A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310246604.3A CN116244089A (en) 2023-03-06 2023-03-06 Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310246604.3A CN116244089A (en) 2023-03-06 2023-03-06 Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN116244089A true CN116244089A (en) 2023-06-09

Family

ID=86634893

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310246604.3A Pending CN116244089A (en) 2023-03-06 2023-03-06 Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN116244089A (en)

Similar Documents

Publication Publication Date Title
US7284238B2 (en) Multithread tracing method and apparatus
US7636919B2 (en) User-centric policy creation and enforcement to manage visually notified state changes of disparate applications
US9306889B2 (en) Method and device for processing messages
CN106934274B (en) Weak password detection method, device and system
EP2860657B1 (en) Determining a security status of potentially malicious files
CN109413016B (en) Rule-based message detection method and device
WO2023123943A1 (en) Interface automation testing method and apparatus, and medium, device and program
KR101620601B1 (en) Method for conducting security check, Computer program for the same, and Recording medium storing computer program for the same
US20070039000A1 (en) Lock order determination method and system
CN107920067B (en) Intrusion detection method on active object storage system
CN116244089A (en) Deadlock risk detection method, deadlock risk detection device, computer equipment and readable storage medium
CN115309515B (en) Cross-chain transaction processing method, device and equipment based on block chain
JP2005234661A (en) Access policy creation system, method and program
CN116662426A (en) Database connection establishment method, device, equipment and medium
CN116319421A (en) Fault detection method and device based on cloud platform, fault detection system and medium
CN111026574A (en) Method and device for diagnosing Elasticissearch cluster problems
CN110472409A (en) A kind of process management method and system based on white list mechanism
WO2022126918A1 (en) Method and apparatus for automatically synchronizing associated scripts, and computer device and storage medium
CN114329486A (en) Asset vulnerability management method and device, electronic equipment and storage medium
CN111752819B (en) Abnormality monitoring method, device, system, equipment and storage medium
US8407531B2 (en) Method of collecting and correlating locking data to determine ultimate holders in real time
CN106302436A (en) The method that independently finds, device and the equipment of a kind of attack message characteristics
CN113051329B (en) Data acquisition method, device, equipment and storage medium based on interface
CN111324846B (en) Information processing method, information processing device, electronic equipment and computer readable storage medium
CN114035970B (en) Data concurrent competition conflict detection analysis method and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination