CN113296965A - Deadlock processing method and device, electronic equipment and computer storage medium - Google Patents

Deadlock processing method and device, electronic equipment and computer storage medium Download PDF

Info

Publication number
CN113296965A
CN113296965A CN202010251759.2A CN202010251759A CN113296965A CN 113296965 A CN113296965 A CN 113296965A CN 202010251759 A CN202010251759 A CN 202010251759A CN 113296965 A CN113296965 A CN 113296965A
Authority
CN
China
Prior art keywords
deadlock
strong
strongly connected
connected component
component
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
CN202010251759.2A
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.)
Alibaba Group Holding Ltd
Original Assignee
Alibaba Group Holding 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 Alibaba Group Holding Ltd filed Critical Alibaba Group Holding Ltd
Priority to CN202010251759.2A priority Critical patent/CN113296965A/en
Publication of CN113296965A publication Critical patent/CN113296965A/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/21Design, administration or maintenance of databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention provides a deadlock processing method, a deadlock processing device, electronic equipment and a computer storage medium, wherein the deadlock processing method comprises the following steps: acquiring a lock waiting chart in the database operation process; detecting a strong connected component of the lock waiting graph to obtain the strong connected component existing in the lock waiting graph; and determining information of the strong connectivity removing operation to be performed according to the strong connectivity component in the lock waiting graph, and removing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation. By the embodiment of the invention, only the transaction related to deadlock can be interrupted or cancelled and the transaction unrelated to deadlock can not be affected in the GDD deadlock processing process.

Description

Deadlock processing method and device, electronic equipment and computer storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a deadlock processing method and device, electronic equipment and a computer storage medium.
Background
The transaction in the database is a basic unit for concurrency control of the database, and one or a group of statements related to one transaction are executed successfully or all successfully to modify some data in the database; or all unsuccessful, the data in the database reverts to the state before the statements were executed.
To ensure the integrity and concurrency of transaction execution, a locking mechanism may be applied to the execution of database transactions. For example, a transaction can be guaranteed to execute smoothly by locking the SQL statement involved in the transaction and/or data such as records, fields, or files for which the SQL statement is directed. Although the integrity and concurrency of transaction execution are guaranteed by the locking mechanism, the deadlock problem is also brought about.
Deadlock refers to a blocking phenomenon that two or more transaction processes are in the process of executing due to competing resources or due to communicating with each other. In order to solve the deadlock, a deadlock detection mechanism is arranged in most database systems. In some database scenarios, such as the cross-partition segment database scenario, a GDD (Global Deadlock Detector) mechanism is also introduced. The GDD can detect a deadlock scenario that occurs across multiple segments and break the deadlock cycle according to certain rules.
Currently, when a GDD is used to break a deadlock cycle, a mode of repeatedly trying to remove a vertex corresponding to a maximum session value causing a deadlock is adopted, and then performing a Reduce removal operation. However, this method may cause the execution of the unrelated session to be cancelled by interruption, thereby causing the user query to be interrupted without any reason, and seriously affecting the user experience.
Disclosure of Invention
Embodiments of the present invention provide a deadlock handling scheme to at least partially solve the above problems.
According to a first aspect of the embodiments of the present invention, there is provided a deadlock processing method, including: acquiring a lock waiting chart in the database operation process; detecting a strong connected component of the lock waiting graph to obtain the strong connected component existing in the lock waiting graph; and determining information of the strong connectivity removing operation to be performed according to the strong connectivity component in the lock waiting graph, and removing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation.
According to a second aspect of the embodiments of the present invention, there is provided a deadlock processing apparatus including: the first acquisition module is used for acquiring a lock waiting chart in the database operation process; the second acquisition module is used for detecting the strongly connected component of the lock waiting graph to acquire the strongly connected component existing in the lock waiting graph; and the release module is used for determining information of the strong connectivity release operation to be performed according to the strong connectivity component in the lock waiting graph and releasing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity release operation.
According to a third aspect of embodiments of the present invention, there is provided an electronic apparatus, including: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus; the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the deadlock processing method according to the first aspect.
According to a fourth aspect of embodiments of the present invention, there is provided a computer storage medium having stored thereon a computer program which, when executed by a processor, implements the deadlock handling method according to the first aspect.
According to the deadlock processing scheme provided by the embodiment of the invention, in the database operation process, the transaction generating the deadlock corresponds to the strongly connected component in the lock waiting graph, namely, each strongly connected component in the lock waiting graph corresponds to a deadlock. Based on this, the operation of removing the strong connectivity on the strong connectivity component means breaking the deadlock. Since the strongly connected component is only relevant to the transaction that generated the deadlock, transactions that are not relevant to the deadlock are not involved. Therefore, only the transaction related to the deadlock can be interrupted or cancelled and the transaction unrelated to the deadlock can not be affected in the GDD deadlock processing process, so that the user query corresponding to the transaction unrelated to the deadlock can not be interrupted without any reason, and the user experience is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments described in the embodiments of the present invention, and it is also possible for a person skilled in the art to obtain other drawings based on the drawings.
FIG. 1A is a flowchart illustrating a deadlock handling method according to an embodiment of the present invention;
FIG. 1B is a diagram illustrating an example of a scenario in the embodiment shown in FIG. 1A;
FIG. 2A is a flowchart illustrating a deadlock handling method according to a second embodiment of the present invention;
FIG. 2B is a diagram illustrating a lock wait diagram in the embodiment of FIG. 2A;
FIG. 2C is a schematic diagram of a strong communication release operation performed on the lock wait map shown in FIG. 2B;
FIG. 2D is a diagram illustrating the result of the operation of performing a strong communication release operation on the lock wait diagram shown in FIG. 2B;
FIG. 3 is a block diagram of a deadlock handling device according to a third embodiment of the invention;
FIG. 4 is a block diagram of a deadlock processing apparatus according to a fourth embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to a fifth embodiment of the present invention.
Detailed Description
In order to make those skilled in the art better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all embodiments. All other embodiments obtained by a person skilled in the art based on the embodiments of the present invention shall fall within the scope of the protection of the embodiments of the present invention.
The following further describes specific implementation of the embodiments of the present invention with reference to the drawings.
Example one
Referring to fig. 1A, a flowchart illustrating steps of a deadlock handling method according to a first embodiment of the present invention is shown.
The deadlock processing method of the embodiment comprises the following steps:
step S102: and acquiring a lock waiting graph in the database running process.
For a database system involving transactions and locking mechanisms, a corresponding lock wait graph can be generated during operation to represent resource requirement relationships between the operating database transactions. As can be seen, the lock wait graph is a directed graph. The lock wait graph may be generated by those skilled in the art according to actual requirement trigger, such as periodic trigger, or according to appropriate trigger instructions, etc.
From a database system perspective, database transactions may be implemented through session sessions. Based on the method, the established sessions can be used as vertexes, and the resource demand relation among the sessions is used as a directed edge, so that a lock waiting graph in the database running process is generated.
Step S104: and detecting the strong connected component of the lock waiting graph to obtain the strong connected component existing in the lock waiting graph.
In the directed graph G, if there is a directed edge from Vi to Vj between two vertices (Vi, Vj) and there is a directed edge from Vj to Vi, then the two vertices (Vi, Vj) are said to be strongly connected. Among them, the extremely strongly connected subgraphs of the directed graph G are called strongly connected components.
Specifically, in this embodiment, when there is a strongly connected component in the lock waiting graph, it means that sessions corresponding to two vertices wait for resources, and it can be determined that a deadlock occurs in a database transaction according to the resource waiting status. That is, if a strongly connected component appears in the lock wait graph, the database transaction may be considered to be deadlocked and need to be processed. It should be noted that the detection of the strongly connected component may be triggered and executed periodically, or may be triggered and executed by any suitable triggering condition set by a person skilled in the art according to actual needs.
In this step, the strong connected component detection is performed on the lock waiting graph to obtain one or more (two or more) strong connected components existing in the lock waiting graph, so that the information of the session in which the deadlock occurs can also be determined.
Step S106: and determining information of the strong connectivity removing operation to be performed according to the strong connectivity component in the lock waiting graph, and removing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation.
The information of the to-be-performed strong-connected releasing operation may be, for example, to remove a certain node or nodes from the strong-connected component, so that the lock waits for the strong-connected component to no longer exist in the graph. Because each node corresponds to a database transaction session, the deadlock can be removed through the session corresponding to the termination node.
In an actual operation, information of a to-be-performed strong connectivity release operation may be determined according to a strong connectivity component in the lock waiting graph, for example, a certain node or certain nodes are removed, and after the release operation is performed on the lock waiting graph, a deadlock corresponding to the strong connectivity component is released according to an operation result of the release operation. Or, the information of the node related to the strong connectivity release operation to be performed may be determined according to the strong connectivity component in the lock waiting graph, the corresponding session is terminated based on the information of the node to release the deadlock corresponding to the session, and then the lock waiting graph is operated to release the strong connectivity component in the lock waiting graph. Or, the information of the node involved in the strong connectivity release operation to be performed and the information of the session corresponding to the node may be determined according to the strong connectivity component in the lock waiting graph, and then the lock waiting graph and the session are operated in parallel to perform the strong connectivity release operation and the deadlock release operation of the lock waiting graph at the same time.
If there are a plurality of strongly connected components in the lock wait map, it is necessary to perform a strong connection releasing operation for each strongly connected component. The strongly connected release operation for a plurality of strongly connected components may be performed in parallel or may be performed serially one by one. Similarly, the operation of terminating the session may be performed in parallel or in series.
Fig. 1B shows a scenario of the above process, where in fig. 1B, it is assumed that a user a requests to update a record Y according to a record X in a database, and the record Y is implemented by a session 1 established between a client where the user a is located and the database; meanwhile, the user B requests to update the record X according to the record Y in the database, which is implemented by the session 2 established between the client where the user B is located and the database. If the write lock is performed on record Y for the user A request, the write lock is performed on record X for the user B request. User A waits for user B to release record X, which in turn waits for user A to release record Y, thereby causing a deadlock between session 1 and session 2. Further, suppose that user C requests to read the data of record X through session 3, the lock wait diagram formed among the three is shown in the first box of fig. 1B. And detecting the strong connected component of the lock waiting graph to obtain the strong connected component, wherein the strong connected component is shown as a dotted line part in a second box. Further, a strong connectivity release operation is performed on the strong connectivity component, which is set to be performed by removing the vertex corresponding to the session 1 in this example, and the deadlock release corresponding to the strong connectivity component is realized by terminating the session 1. The dismissed result is shown in the third box.
It can be seen that, with this embodiment, during the database operation process, a transaction that generates a deadlock may correspond to strongly connected components in the lock wait graph, that is, each strongly connected component in the lock wait graph corresponds to a deadlock. Based on this, the operation of removing the strong connectivity on the strong connectivity component means breaking the deadlock. Since the strongly connected component is only relevant to the transaction that generated the deadlock, transactions that are not relevant to the deadlock are not involved. Therefore, only the transaction related to the deadlock can be interrupted or cancelled and the transaction unrelated to the deadlock can not be affected in the GDD deadlock processing process, so that the user query corresponding to the transaction unrelated to the deadlock can not be interrupted without any reason, and the user experience is improved.
The deadlock handling method of the present embodiment may be performed by any suitable electronic device having data processing capabilities, including but not limited to: servers, PCs, etc.
Example two
Referring to fig. 2A, a flowchart illustrating steps of a deadlock handling method according to a second embodiment of the present invention is shown.
The deadlock processing method of the embodiment comprises the following steps:
step S202: and establishing a lock waiting graph for the data in the running process.
As previously described, a database involving transactions and locking mechanisms may generate a lock wait graph during runtime. The process of specifically generating the lock waiting graph may be generated by any appropriate manner according to actual needs by those skilled in the art, and the embodiment of the present invention is not limited thereto.
For example, for a pg (postgre) database system using GDD, GDD may execute SELECT FROM pg _ locks to obtain lock waiting information, and then traverse the scan lock waiting information with the established session as the graph vertex. During the period, if a certain lock held by session 1 waiting for session 2 is found, then session 1 is considered to be waiting for session 2, and at this time, an edge from session 1 to session 2 is established in the graph.
In a specific example, taking a postgreSQL database system as an example, the postgreSQL database system is an analytic database system built based on a source database greenplus. In a postgreSQL database system, the lock waiting graph can be constructed periodically, each time a session (corresponding to a link one-to-one, which can be regarded as a numerical value identifying a link in greenplus, monotonically increasing) acquires a specified object (e.g., each table, each row in the table is regarded as an object in the database, and each object can be uniquely identified by an integer value, i.e., obj _ id), or when a session waits for acquiring a lock of a specified object, a row of records is inserted into a system table, e.g., a lock _ table, where the system table has the following fields:
session _ id: recording a corresponding session currently;
granted: if the value is 1, the session _ id is indicated to successfully take the lock on the obj _ id specified object; if the value is 0, it indicates that the session _ id is waiting to acquire the lock on the obj _ id specified object.
obj _ id: and currently recording the corresponding object.
By scanning the lock _ table, if a row a: { session _ id ═ session 1, granted ═ 0, obj _ id ═ obj1}, and a row B: { session _ id ═ session 2, granted ═ 1, obj _ id ═ obj1}, it is found that session 1 is waiting for session 2 to release the lock held on obj 1. Then, session 1 and session 2 are inserted into the lock waiting graph as vertices (if session 1 and session 2 already exist in the graph, they are ignored), and then an edge pointing to session 2 is created in the graph from session 1. When the lock _ table scan is complete, the lock waits for the graph, i.e., the setup is complete.
One constructed lock wait graph is shown, for example, in FIG. 2B, which illustrates a lock wait graph having 5 sessions as vertices, each identified by an identification value of a session, including 519, 520, 521, 522, and 523. As can be seen in FIG. 2B, session 519 and session 520 wait for each other's lock, and session 521 and session 522 wait for each other's lock.
Step S204: judging whether a deadlock processing enabling instruction is received or not; if yes, go to step S206; if not, deadlock processing is carried out according to a preset rule.
The deadlock handling enabling instruction may be any suitable form of instruction, such as an electrical signal instruction, an indicator instruction, and the like, which is not limited by the embodiment of the present invention. The deadlock processing enabling instruction may be triggered by the user, thereby providing the user with a more flexible deadlock processing option.
When the deadlock processing enabling instruction is not received, deadlock processing can be performed according to a preset rule, wherein the preset rule can be set by a person skilled in the art appropriately according to actual needs, such as a traditional GDD processing mode which may involve deadlock irrelevant sessions, and the like.
It should be noted that this step is an optional step. In practical applications, step S206 may be directly performed after step S202.
Step S206: and acquiring a lock waiting graph in the database running process.
The lock wait map generated by step S202 may be obtained in any suitable manner.
Step S208: and detecting the strong connected component of the lock waiting graph to obtain the strong connected component existing in the lock waiting graph.
The specific implementation of the strongly connected component detection on the lock wait graph can also be detected by those skilled in the art in any appropriate manner according to actual needs. In one possible approach, the strongly connected components in the lock wait graph may be obtained by a graph strongly connected component algorithm, such as the Kosaraju-Sharir algorithm, the Tarjan algorithm, or the like. In a further alternative, the lock waiting graph may be further cut according to the detected strongly connected components, and a sub-graph corresponding to each strongly connected component is obtained. Subsequently, the operation can be directly performed on the subgraph.
Step S210: and determining information of the strong connectivity removing operation to be performed according to the strong connectivity component in the lock waiting graph, and removing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation.
When determining the information of the strong connectivity release operation to be performed according to the strong connectivity component in the lock waiting graph, determining the information of the node in the strong connectivity component to be removed according to the strong connectivity component in the lock waiting graph, and determining the information of the strong connectivity release operation to be performed on the lock waiting graph according to the information of the node. Since the strongly connected component is composed of nodes and corresponding edges, the strongly connected release operation can be quickly realized by removing the nodes.
The lock wait graph has at least one strongly connected component, and each strongly connected component represents a deadlock, so that each strongly connected component needs to be subjected to a strongly connected releasing operation.
Based on this, after determining the information of the strong connectivity release operation to be performed, in one possible manner, the lock wait map may be first subjected to the strong connectivity release operation. Performing a strongly connected release operation on a strongly connected component in the lock wait graph may be implemented as: and for each strongly connected component, removing nodes to be removed from the nodes forming the current strongly connected component so as to perform the strong connection releasing operation of the current strongly connected component. For each strongly connected component, which will typically consist of two or more nodes, for the case of two nodes, removing one of the nodes releases the strong connection; in the case of more than two nodes, strong connectivity may be released after removing one node, but other strong connectivity may also exist. Thus, effective release of the strongly connected component in the lock wait map can be ensured.
In a possible implementation manner, for each strongly connected component, removing a node to be removed from nodes constituting a current strongly connected component, so as to perform a strongly connected releasing operation of the current strongly connected component may include: for each strongly connected component, removing a node to be removed from the nodes forming the current strongly connected component; judging whether a sub strong connected component exists in the current strong connected component after the nodes are removed; if not, determining to finish the strong connectivity removing operation of the current strong connectivity component; and if so, continuing removing the nodes of the sub strongly connected components until the sub strongly connected components do not exist in the current strongly connected components. When the node removal is continued on the sub strongly connected components, the operation of returning to each strongly connected component and removing a node to be removed from the nodes forming the current strongly connected component can be adopted to continue to be executed until the strongly connected components do not exist any more. That is, one node removes one node by one node. But not limited thereto, in practical applications, the node removal operation continued on the sub strongly connected component may also be implemented in other manners, for example, determining one or more nodes to be removed first, then removing the nodes together, and so on. And the removal mode of the nodes one by one enables the removal of the strongly connected component to be more accurate and safer, and can avoid the sudden change of multiple services and ensure the stability of the system operation.
When the lock waiting graph adopts the session as the graph vertex, the nodes in the lock waiting graph correspond to the database transaction sessions, and each database transaction session has a session identification value to uniquely identify one session. In this case, the removing a node to be removed from the nodes constituting the current strongly connected component may include: determining a node with the largest session identification value of the corresponding database transaction session in the nodes forming the current strongly-connected component; the node with the largest session identification value is removed from the current strongly connected component. The node with the largest session identification value represents the link established recently, and the node with the largest session value is selected to be removed, so that the influence of session termination on the use of the database by the user can be effectively reduced, and the use experience of the user is improved. But not limited to, removing nodes corresponding to other session identification values is also applicable, and the strong connection can be released.
After the information of the strong connectivity release operation is determined, the database transaction session corresponding to the node to be removed can be terminated according to the information of the node to be removed, so that the deadlock corresponding to the strong connectivity component is released.
In this embodiment, after the lock waiting graph is subjected to the strongly connected component release according to the information of the strongly connected release operation, the database transaction session corresponding to the removed node is terminated, and the deadlock corresponding to the strongly connected component is released. However, as described in the first embodiment, the strong connection releasing operation on the lock wait graph may be performed later than the deadlock releasing operation, or performed in parallel with the deadlock releasing operation.
In another possible manner, determining information of the strongly-connected releasing operation to be performed according to the strongly-connected component in the lock waiting graph, and releasing a deadlock corresponding to the strongly-connected component according to the information of the strongly-connected releasing operation may include: recording the information of at least one strong connected component obtained by detection and the information of the node corresponding to each strong connected component; determining nodes to be removed of each strongly connected component from the recorded nodes corresponding to each strongly connected component; and removing the nodes to be removed in the lock waiting graph and terminating the database transaction session corresponding to the nodes to be removed so as to remove the deadlock corresponding to the strongly connected component. In this way, the node to be removed in the lock waiting graph can be removed at one time, and the node to be removed can be determined first, so that the lock waiting graph and the database transaction session can be operated simultaneously, the deadlock can be processed, and the processing speed can be increased.
Still taking the pg database system using GDD as an example, after the graph strongly connected component algorithm is run to find all strongly connected components in the lock wait graph, each strongly connected component can be taken as a sub graph. At the subgraph level, repeated attempts are made to remove the vertex with the largest session value, followed by Reduce operations until there are no more strongly connected components in the subgraph. The session values removed during execution are collected to form a set, which is recorded as sessions, and then the execution of related session SQL is cancelled through SELECT pg _ cancel _ backsaid (pid) FROM pg _ stat _ activity WHERE session _ id IN (sessions), so that the sessions actively release the held lock, thereby breaking the deadlock cycle.
All the strongly connected components in the lock waiting graph are found out by running a graph strongly connected component algorithm, and the operation of breaking the deadlock is run at the strongly connected component level, so that the query in the deadlock cycle can be accurately cancelled, and other irrelevant queries are prevented from being influenced.
In one specific example, and again taking the aforementioned postgreSQL database system as an example, one strongly connected component in the full lock-waiting graph may be represented by G ═ N, E, where N represents all vertices and E represents all edges in the strongly connected component. Reduce operations on certain strongly connected components may be implemented as:
(1) the vertex with the largest session value is removed from G, along with all outgoing edges from that vertex and all incoming edges to that vertex.
(2) Judging whether the G still contains the strong connection component, if so, returning to the step (1) to continue executing; otherwise, ending the Reduce operation and executing (3).
(3) The session values for all vertices removed in the above process are returned, and then kill drops (i.e., terminates) these sessions.
Taking the lock waiting diagram shown in fig. 2B as an example, a strong connectivity releasing operation is schematically illustrated in fig. 2C, for the strong connectivity component formed by 519 and 520, the vertex with the largest session value, i.e. 520 and the corresponding edge, are removed; and for the strongly connected components formed by 521 and 522, the vertex with the largest session value, namely 522 and the corresponding edge thereof, are removed. The vertices and edges to be removed are shown in dashed lines in fig. 2C.
Removing vertices 520 and 522 and their respective edges releases the strongly connected components in the lock wait graph of FIG. 2B, and a lock wait graph with released strongly connected components is shown in FIG. 2D.
In the conventional method, when a deadlock cycle is broken, a vertex with the maximum session value is repeatedly tried to be cancelled at the whole lock waiting graph level, so that the SQL execution in the unrelated session is cancelled. For example, taking the lock wait graph shown in fig. 2B as an example, when the deadlock release operation is performed on the lock wait graph in the conventional manner, since each vertex in the lock wait graph has an out edge and an in edge, the Reduce operation cannot remove any vertex, and the GDD can only solve the deadlock problem by canceling three sessions, 523, 522, and 520 in sequence. By the scheme provided by the embodiment of the invention, in the operation of breaking the deadlock cycle based on the graph strong connected component algorithm, the executing session is cancelled at the level of the strong connected component, so that the irrelevant session, namely the execution of the session which does not appear in any deadlock cycle, is not influenced, in the lock waiting graph example shown in fig. 2B, only two sessions 522 and 520 are cancelled, and the execution of the session corresponding to 523 is not influenced.
Thus, with the present embodiment, during the database operation process, the transaction that generates the deadlock may correspond to the strongly connected components in the lock wait graph, that is, each strongly connected component in the lock wait graph corresponds to a deadlock. Based on this, the operation of removing the strong connectivity on the strong connectivity component means breaking the deadlock. Since the strongly connected component is only relevant to the transaction that generated the deadlock, transactions that are not relevant to the deadlock are not involved. Therefore, only the transaction related to the deadlock can be interrupted or cancelled and the transaction unrelated to the deadlock can not be affected in the GDD deadlock processing process, so that the user query corresponding to the transaction unrelated to the deadlock can not be interrupted without any reason, and the user experience is improved.
The deadlock handling method of the present embodiment may be performed by any suitable electronic device having data processing capabilities, including but not limited to: servers, PCs, etc.
EXAMPLE III
Referring to fig. 3, a block diagram of a deadlock processing apparatus according to a third embodiment of the present invention is shown.
The deadlock processing apparatus of the present embodiment includes: a first obtaining module 302, configured to obtain a lock waiting map in a database operation process; a second obtaining module 304, configured to perform strong connected component detection on the lock waiting map, and obtain a strong connected component existing in the lock waiting map; and the removing module 306 is configured to determine information of a to-be-performed strong connectivity removing operation according to the strong connectivity component in the lock waiting graph, and remove a deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation.
The deadlock processing apparatus of this embodiment is used to implement the corresponding deadlock processing method in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which are not described herein again. In addition, the functional implementation of each module in the deadlock processing apparatus of this embodiment can refer to the description of the corresponding part in the foregoing method embodiment, and is not described herein again.
Example four
Referring to fig. 4, a block diagram of a deadlock processing apparatus according to a fourth embodiment of the present invention is shown.
The deadlock processing apparatus of the present embodiment includes: a first obtaining module 402, configured to obtain a lock waiting map in a database operation process; a second obtaining module 404, configured to perform strong connected component detection on the lock waiting graph, and obtain a strong connected component existing in the lock waiting graph; and the removing module 406 is configured to determine information of a to-be-performed strong connectivity removing operation according to the strong connectivity component in the lock waiting graph, and remove a deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation.
Optionally, the removing module 406 is configured to determine, according to the strongly connected component in the lock waiting graph, information of a node in the strongly connected component to be removed, determine, according to the information of the node, information of performing a strongly connected removing operation on the lock waiting graph, and remove, according to the information of the strongly connected removing operation, a deadlock corresponding to the strongly connected component.
Optionally, the strongly connected component in the lock wait graph includes at least one; the removing module 406 is further configured to, after determining information of a strong connectivity removing operation to be performed according to the strong connectivity components in the lock waiting graph, remove, for each strong connectivity component, a node to be removed from nodes constituting the current strong connectivity component, so as to perform the strong connectivity removing operation on the current strong connectivity component.
Optionally, the removing module 406 is configured to, for each strongly connected component, remove one node to be removed from the nodes forming the current strongly connected component; judging whether a sub strong connected component exists in the current strong connected component after the nodes are removed; if not, determining to finish the strong connectivity removing operation of the current strong connectivity component; and if so, continuing removing the nodes of the sub strongly connected components until the sub strongly connected components do not exist in the current strongly connected components.
Optionally, the node in the lock wait graph corresponds to a database transaction session, and the database transaction session has a session identification value; a removing module 406, configured to determine, for each strongly connected component, a node with a largest session identifier value of a corresponding database transaction session among nodes forming a current strongly connected component; removing the node with the maximum session identification value from the current strongly-connected component; judging whether a sub strong connected component exists in the current strong connected component after the nodes are removed; if not, determining to finish the strong connectivity removing operation of the current strong connectivity component; and if so, continuing removing the nodes of the sub strongly connected components until the sub strongly connected components do not exist in the current strongly connected components.
Optionally, the removing module 406 is configured to determine information of a to-be-performed strong connectivity removing operation according to the strong connectivity component in the lock waiting graph, and terminate the database transaction session corresponding to the to-be-removed node according to the information of the to-be-removed node in the information of the strong connectivity removing operation, so as to remove the deadlock corresponding to the strong connectivity component.
Optionally, the removing module 406 is configured to record information of the at least one strongly connected component obtained through detection and information of a node corresponding to each strongly connected component; determining nodes to be removed of each strongly connected component from the recorded nodes corresponding to each strongly connected component; and removing the node to be removed in the lock waiting graph, and terminating the database transaction session corresponding to the node to be removed so as to remove the deadlock corresponding to the strongly connected component.
Optionally, the deadlock processing apparatus further includes: an enabling module 408, configured to determine whether a deadlock processing enabling instruction is received before the first obtaining module 402 obtains the lock waiting map in the database running process; if yes, the first obtaining module 402 executes the process.
The deadlock processing apparatus of this embodiment is used to implement the corresponding deadlock processing method in the foregoing multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which are not described herein again. In addition, the functional implementation of each module in the deadlock processing apparatus of this embodiment can refer to the description of the corresponding part in the foregoing method embodiment, and is not described herein again.
EXAMPLE five
Referring to fig. 5, a schematic structural diagram of an electronic device according to a fifth embodiment of the present invention is shown, and the specific embodiment of the present invention does not limit the specific implementation of the electronic device.
As shown in fig. 5, the electronic device may include: a processor (processor)502, a Communications Interface 504, a memory 506, and a communication bus 508.
Wherein:
the processor 502, communication interface 504, and memory 506 communicate with one another via a communication bus 508.
A communication interface 504 for communicating with other electronic devices or servers.
The processor 502 is configured to execute the program 510, and may specifically execute the relevant steps in the deadlock processing method embodiment described above.
In particular, program 510 may include program code that includes computer operating instructions.
The processor 502 may be a central processing unit CPU, or an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits configured to implement an embodiment of the present invention. The intelligent device comprises one or more processors which can be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs.
And a memory 506 for storing a program 510. The memory 506 may comprise high-speed RAM memory, and may also include non-volatile memory (non-volatile memory), such as at least one disk memory.
The program 510 may specifically be used to cause the processor 502 to perform the following operations: acquiring a lock waiting chart in the database operation process; detecting a strong connected component of the lock waiting graph to obtain the strong connected component existing in the lock waiting graph; and determining information of the strong connectivity removing operation to be performed according to the strong connectivity component in the lock waiting graph, and removing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation.
In an alternative embodiment, program 510 is further configured to cause processor 502, when determining information of a strong connectivity release operation to be performed based on the strong connectivity component in the lock wait map: and determining the information of the nodes in the strongly connected components to be removed according to the strongly connected components in the lock waiting graph, and determining the information for performing the strongly connected releasing operation on the lock waiting graph according to the information of the nodes.
In an alternative embodiment, the strongly connected component in the lock wait graph includes at least one; program 510 is also configured to cause processor 502 to, after determining information of a strongly connected component to be performed from strongly connected components in the lock wait map, remove, for each strongly connected component, a node to be removed from nodes constituting a current strongly connected component to perform a strongly connected release operation of the current strongly connected component.
In an alternative embodiment, program 510 is further configured to cause processor 502, when removing, for each strongly connected component, a node to be removed from the nodes constituting the current strongly connected component to perform a strongly connected releasing operation of the current strongly connected component: for each strongly connected component, removing a node to be removed from the nodes forming the current strongly connected component; judging whether a sub strong connected component exists in the current strong connected component after the nodes are removed; if not, determining to finish the strong connectivity removing operation of the current strong connectivity component; and if so, continuing removing the nodes of the sub strongly connected components until the sub strongly connected components do not exist in the current strongly connected components.
In an alternative embodiment, the nodes in the lock wait graph correspond to database transaction sessions, the database transaction sessions having session identification values; program 510 is further configured to cause processor 502, when removing a node to be removed from the nodes constituting the current strongly connected component: determining a node with the largest session identification value of the corresponding database transaction session in the nodes forming the current strongly-connected component; the node with the largest session identification value is removed from the current strongly connected component.
In an alternative embodiment, the program 510 is further configured to cause the processor 502, when releasing the deadlock corresponding to the strongly connected component according to the information of the strongly connected release operation: and terminating the database transaction session corresponding to the node to be removed according to the information of the node to be removed so as to remove the deadlock corresponding to the strongly connected component.
In an alternative embodiment, the program 510 is further configured to cause the processor 502, when determining information of a to-be-performed strong connectivity release operation according to a strong connectivity component in the lock waiting map, and releasing a deadlock corresponding to the strong connectivity component according to the information of the strong connectivity release operation: recording the information of at least one strong connected component obtained by detection and the information of the node corresponding to each strong connected component; determining nodes to be removed of each strongly connected component from the recorded nodes corresponding to each strongly connected component; and removing the node to be removed in the lock waiting graph, and terminating the database transaction session corresponding to the node to be removed so as to remove the deadlock corresponding to the strongly connected component.
In an alternative embodiment, the program 510 is further configured to enable the processor 502 to determine whether a deadlock handling enabling instruction is received before acquiring a lock waiting map during database operation; and if so, executing the operation of acquiring the lock waiting graph in the database running process.
For specific implementation of each step in the program 510, reference may be made to corresponding steps and corresponding descriptions in units in the foregoing deadlock processing method embodiment, which are not described herein again. It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described devices and modules may refer to the corresponding process descriptions in the foregoing method embodiments, and are not described herein again.
With the electronic device of this embodiment, during the database operation process, a transaction that generates a deadlock may correspond to strongly connected components in the lock wait graph, that is, each strongly connected component in the lock wait graph corresponds to a deadlock. Based on this, the operation of removing the strong connectivity on the strong connectivity component means breaking the deadlock. Since the strongly connected component is only relevant to the transaction that generated the deadlock, transactions that are not relevant to the deadlock are not involved. Therefore, only the transaction related to the deadlock can be interrupted or cancelled and the transaction unrelated to the deadlock can not be affected in the GDD deadlock processing process, so that the user query corresponding to the transaction unrelated to the deadlock can not be interrupted without any reason, and the user experience is improved.
It should be noted that, according to the implementation requirement, each component/step described in the embodiment of the present invention may be divided into more components/steps, and two or more components/steps or partial operations of the components/steps may also be combined into a new component/step to achieve the purpose of the embodiment of the present invention.
The above-described method according to an embodiment of the present invention may be implemented in hardware, firmware, or as software or computer code storable in a recording medium such as a CD ROM, a RAM, a floppy disk, a hard disk, or a magneto-optical disk, or as computer code originally stored in a remote recording medium or a non-transitory machine-readable medium downloaded through a network and to be stored in a local recording medium, so that the method described herein may be stored in such software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware such as an ASIC or FPGA. It will be appreciated that the computer, processor, microprocessor controller or programmable hardware includes memory components (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code that, when accessed and executed by the computer, processor or hardware, implements the deadlock handling method described herein. Further, when a general-purpose computer accesses code for implementing the deadlock handling method shown herein, execution of the code transforms the general-purpose computer into a special-purpose computer for performing the deadlock handling method shown herein.
Those of ordinary skill in the art will appreciate that the various illustrative elements and method steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present embodiments.
The above embodiments are only for illustrating the embodiments of the present invention and not for limiting the embodiments of the present invention, and those skilled in the art can make various changes and modifications without departing from the spirit and scope of the embodiments of the present invention, so that all equivalent technical solutions also belong to the scope of the embodiments of the present invention, and the scope of patent protection of the embodiments of the present invention should be defined by the claims.

Claims (11)

1. A deadlock handling method comprising:
acquiring a lock waiting chart in the database operation process;
detecting a strong connected component of the lock waiting graph to obtain the strong connected component existing in the lock waiting graph;
and determining information of the strong connectivity removing operation to be performed according to the strong connectivity component in the lock waiting graph, and removing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity removing operation.
2. The method of claim 1, wherein the determining information of the strong connectivity release operation to be performed according to the strong connectivity component in the lock waiting map comprises:
and determining the information of the nodes in the strongly connected components to be removed according to the strongly connected components in the lock waiting graph, and determining the information for performing the strongly connected releasing operation on the lock waiting graph according to the information of the nodes.
3. The method of claim 2, wherein the strongly connected component comprises at least one;
after the determining information of the strong connectivity release operation to be performed according to the strong connectivity component in the lock waiting map, the method further includes:
and for each strongly connected component, removing nodes to be removed from the nodes forming the current strongly connected component so as to perform the strong connection releasing operation of the current strongly connected component.
4. The method according to claim 3, wherein for each strongly connected component, removing nodes to be removed from nodes constituting the current strongly connected component to perform the operation of releasing the strong connection of the current strongly connected component comprises:
for each strongly connected component, removing a node to be removed from the nodes forming the current strongly connected component;
judging whether a sub strong connected component exists in the current strong connected component after the nodes are removed;
if not, determining to finish the strong connectivity removing operation of the current strong connectivity component;
and if so, continuing removing the nodes of the sub strongly connected components until the sub strongly connected components do not exist in the current strongly connected components.
5. The method of claim 4, wherein a node in the lock wait graph corresponds to a database transaction session, the database transaction session having a session identification value;
the removing a node to be removed from nodes forming the current strongly connected component includes:
determining a node with the largest session identification value of the corresponding database transaction session in the nodes forming the current strongly-connected component;
the node with the largest session identification value is removed from the current strongly connected component.
6. The method according to any one of claims 2-5, wherein the releasing deadlock corresponding to the strongly connected component according to the information of the strongly connected release operation comprises:
and terminating the database transaction session corresponding to the node to be removed according to the information of the node to be removed so as to remove the deadlock corresponding to the strongly connected component.
7. The method according to any one of claims 1 to 5, wherein the determining, according to the strong connectivity component in the lock waiting graph, information of a strong connectivity release operation to be performed, and releasing, according to the information of the strong connectivity release operation, a deadlock corresponding to the strong connectivity component includes:
recording the information of at least one strong connected component obtained by detection and the information of the node corresponding to each strong connected component;
determining nodes to be removed of each strongly connected component from the recorded nodes corresponding to each strongly connected component;
and removing the node to be removed in the lock waiting graph, and terminating the database transaction session corresponding to the node to be removed so as to remove the deadlock corresponding to the strongly connected component.
8. The method of any of claims 1-5, wherein prior to the obtaining a lock wait map during database operation, the method further comprises:
judging whether a deadlock processing enabling instruction is received or not;
and if so, executing the operation of acquiring the lock waiting graph in the database running process.
9. A deadlock processing apparatus comprising:
the first acquisition module is used for acquiring a lock waiting chart in the database operation process;
the second acquisition module is used for detecting the strongly connected component of the lock waiting graph to acquire the strongly connected component existing in the lock waiting graph;
and the release module is used for determining information of the strong connectivity release operation to be performed according to the strong connectivity component in the lock waiting graph and releasing the deadlock corresponding to the strong connectivity component according to the information of the strong connectivity release operation.
10. An electronic device, comprising: the system comprises a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface complete mutual communication through the communication bus;
the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to execute the operation corresponding to the deadlock processing method according to any one of claims 1 to 8.
11. A computer storage medium having stored thereon a computer program which, when executed by a processor, implements the deadlock handling method according to any one of claims 1 to 8.
CN202010251759.2A 2020-04-01 2020-04-01 Deadlock processing method and device, electronic equipment and computer storage medium Pending CN113296965A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010251759.2A CN113296965A (en) 2020-04-01 2020-04-01 Deadlock processing method and device, electronic equipment and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010251759.2A CN113296965A (en) 2020-04-01 2020-04-01 Deadlock processing method and device, electronic equipment and computer storage medium

Publications (1)

Publication Number Publication Date
CN113296965A true CN113296965A (en) 2021-08-24

Family

ID=77317957

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010251759.2A Pending CN113296965A (en) 2020-04-01 2020-04-01 Deadlock processing method and device, electronic equipment and computer storage medium

Country Status (1)

Country Link
CN (1) CN113296965A (en)

Similar Documents

Publication Publication Date Title
US5623670A (en) Method and apparatus for crash safe enforcement of mutually exclusive access to shared resources in a multitasking computer system
CN110675255B (en) Method and apparatus for concurrently executing transactions in a blockchain
US11281441B2 (en) Method and apparatus for compiling source code object, and computer
US7185339B2 (en) Victim selection for deadlock detection
CN113421073A (en) Method and apparatus for concurrently executing transactions in a blockchain
US6304938B1 (en) Detecting a state change in a lock structure to validate a potential deadlock
CN110908968B (en) Method, device, equipment and storage medium for avoiding frightened groups during file lock unlocking
CN110689344B (en) Method and apparatus for concurrently executing transactions in a blockchain
CN113296965A (en) Deadlock processing method and device, electronic equipment and computer storage medium
CN115809150A (en) Distributed deadlock detection method and device and electronic equipment
CN114679464B (en) Data rollback method, device, equipment and storage medium based on distributed lock
CN112711419A (en) Data comparison method and device
CN113342500B (en) Task execution method, device, equipment and storage medium
CN115878336A (en) Information processing method and device in lock operation and computing equipment
CN109962861B (en) Message statistical method and device
CN112579275A (en) Task execution method, device, equipment and storage medium
CN112612597A (en) Method and device for generating linear task queue
CN104657507A (en) Distributed system-based mode detection method and device of image data
CN116700996B (en) Memory allocation method, device, equipment and medium of neural network
CN112905609B (en) Data insertion method, device, execution unit, system, equipment and storage medium
US8526326B1 (en) Lock-less access of pre-allocated memory buffers used by a network device
CN115827260A (en) Method and device for detecting abnormal use of lock resources
CN117707798A (en) Deadlock elimination method, device, equipment and medium in multi-thread concurrency state
CN117349143A (en) Performance test method, device and storage medium
CN117950956A (en) Lock monitoring method, device, equipment and storage medium

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
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40057900

Country of ref document: HK