Distributed database deadlock detection method, device, and equipment

By building lock dependencies in distributed databases and updating lock dependencies, the problems of large amount of deadlock detection and heavy hardware burden in the existing technology are solved, and the response speed and user experience are improved.

CN118796949BActive Publication Date: 2025-01-10SUZHOU JIBEISI DATA TECHNOLOGY CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411275749.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-12
Publication Date
2025-01-10
Estimated Expiration
2044-09-12

AI Technical Summary

Technical Problem

When detecting deadlocks, existing distributed databases have large computing volume and heavy hardware facilities, which affect response speed and user experience.

Method used

The cluster center node obtains lock attribute information and lock dependency information of all nodes, builds lock dependencies, determines the lock dependencies to be deleted, updates the lock dependencies, reduces the calculation amount of deadlock detection, and improves the response speed.

Benefits of technology

It effectively reduces the computing volume of deadlock detection, reduces the computing burden of hardware devices, and improves the response speed and user experience of distributed databases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796949B_ABST
    Figure CN118796949B_ABST
Patent Text Reader

Abstract

The present invention provides a distributed database deadlock detection method, device, and equipment. The method includes: in response to a received deadlock detection request, obtaining lock attribute information and lock dependency information of multiple nodes, the lock dependency information representing the dependency relationship between transactions holding locks; constructing multiple lock dependency relationships based on the lock attribute information and the lock dependency information; determining lock dependencies to be deleted based on the multiple lock dependencies; updating the lock dependencies based on the lock dependencies to be deleted, and obtaining a detection result, the detection result representing the existence of a deadlock in the distributed database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and more specifically to a distributed database deadlock detection method, device and equipment. Background Art

[0002] Locking is a concurrency control technology used by most database systems. Before a transaction accesses a resource, it must apply for the lock corresponding to the resource. Only after obtaining the corresponding lock can it access the corresponding resource. When a distributed database deadlock occurs, the corresponding transaction will remain in a waiting state, and users will be unable to operate on the transaction, which will affect the user experience.

[0003] In the related art, when checking for deadlock, all lock information is generally collected to construct a global directed graph. Figure 1 Starting from a point, all connected edges are traversed to determine whether there is a deadlock cycle, but this method has a large amount of calculation and a heavy burden on hardware facilities. Summary of the invention

[0004] In view of the above problems, the present invention provides a distributed database deadlock detection method, device, and equipment.

[0005] According to a first aspect of the present invention, a distributed database deadlock detection method is provided, the method is applied to a central node of a cluster, the cluster also includes multiple nodes except the central node, the method includes: in response to a received deadlock detection request, obtaining lock attribute information and lock dependency information of the multiple nodes, the lock dependency information characterizing the dependency relationship between transactions holding locks; constructing multiple lock dependencies based on the lock attribute information and lock dependency information, the lock dependency relationships characterizing the relationship between locks of mutually dependent transactions, a first transaction corresponding to a current lock is processed depending on the processing result of a second transaction; determining a lock dependency to be deleted based on the multiple lock dependencies, the lock dependency to be deleted includes at most one lock dependency; updating the lock dependency based on the lock dependency to be deleted to obtain a detection result, the detection result characterizing the existence of a deadlock in the distributed database.

[0006] According to an embodiment of the present invention, the above-mentioned lock dependency is updated based on the above-mentioned lock dependency to be deleted, and the detection result obtained includes: updating the above-mentioned lock dependency based on the above-mentioned lock dependency to be deleted to obtain an updated lock dependency; when the above-mentioned updated lock dependency does not meet the first preset condition, returning to execute the operation of determining the lock dependency to be deleted based on the above-mentioned multiple lock dependencies, the above-mentioned first preset condition characterizes that the updated lock dependency is not empty and includes at least two lock dependencies for any lock dependency; when the above-mentioned lock dependency meets the first preset condition, the detection result is obtained.

[0007] According to an embodiment of the present invention, after the above-mentioned lock dependency is updated based on the above-mentioned lock dependency to be deleted and the detection result is obtained, the above-mentioned method also includes: based on the above-mentioned detection result, processing the transaction holding the lock corresponding to the lock dependency in the above-mentioned detection result, so that the resource blocking state in the above-mentioned distributed database disappears.

[0008] According to an embodiment of the present invention, the lock attribute information includes a database identifier corresponding to the lock, lock type information, and lock level information;

[0009] The above-mentioned construction of multiple lock dependencies based on the above-mentioned lock attribute information and lock waiting information includes:

[0010] According to the above-mentioned database identifier, the lock attribute information of the above-mentioned multiple nodes are grouped to obtain multiple groups of lock attribute information to be processed; for each group of lock attribute information to be processed, the candidate lock attribute information is grouped according to the above-mentioned lock type information; based on the above-mentioned lock level information, the candidate lock attribute information is sorted to obtain sorted lock attribute information; when the above-mentioned sorted lock attribute information meets the preset order, multiple lock dependency relationships are constructed based on the above-mentioned lock waiting information and the above-mentioned candidate lock attribute information.

[0011] According to an embodiment of the present invention, the lock attribute information also includes: transaction information corresponding to the lock, and based on the detection result, the transaction holding the lock corresponding to the lock dependency in the detection result is processed, including: generating a deadlock log based on the detection result; storing the deadlock log in the distributed database; and determining the transaction to be rolled back from the transaction information corresponding to the updated lock dependency based on the detection result; and rolling back the transaction to be rolled back.

[0012] According to an embodiment of the present invention, the above-mentioned transaction information includes: resource occupancy; the above-mentioned determination of the transaction to be rolled back from the transaction information corresponding to the above-mentioned updated lock dependency based on the above-mentioned detection result includes: when the resource occupancy of the above-mentioned transaction exceeds a predetermined threshold, the above-mentioned transaction is determined as a transaction to be rolled back.

[0013] According to an embodiment of the present invention, the above-mentioned transaction information includes: modified data volume information; the above-mentioned determination of the transactions to be rolled back from the transaction information corresponding to the above-mentioned updated lock dependency based on the above-mentioned detection results includes: sorting the above-mentioned transactions based on the above-mentioned modified data volume information to obtain sorted transactions; and determining a preset number of transactions as transactions to be rolled back.

[0014] According to an embodiment of the present invention, the above method also includes: in response to the timing detection task being triggered, performing multiple deadlock detections on the above distributed database to obtain multiple deadlock detection results; when it is determined that the above multiple deadlock detection results are the same, obtaining a target detection result.

[0015] A second aspect of the present invention provides a distributed database deadlock detection device, comprising: an acquisition module, for obtaining lock attribute information and lock dependency information of the above-mentioned multiple nodes in response to a received deadlock detection request, wherein the above-mentioned lock dependency information represents the dependency relationship between transactions holding locks; a construction module, for constructing multiple lock dependency relationships based on the above-mentioned lock attribute information and lock dependency information, wherein the above-mentioned lock dependency relationships represent the relationship between locks of mutually dependent transactions, and the first transaction corresponding to the current lock is processed depending on the processing result of the second transaction; a determination module, for determining the lock dependency relationship to be deleted based on the above-mentioned multiple lock dependency relationships, wherein the above-mentioned lock dependency relationship to be deleted includes at most one lock dependency relationship;

[0016] The detection module is used to update the lock dependency relationship based on the lock dependency relationship to be deleted to obtain a detection result, wherein the detection result indicates that a deadlock exists in the distributed database.

[0017] According to an embodiment of the present invention, the above-mentioned detection module includes: a dependency update sub-module, which is used to update the above-mentioned lock dependency based on the above-mentioned lock dependency to be deleted to obtain an updated lock dependency; a return execution sub-module, which is used to return to execute the operation of determining the lock dependency to be deleted based on the above-mentioned multiple lock dependencies when the above-mentioned updated lock dependency does not meet the first preset condition, and the above-mentioned first preset condition represents that the updated lock dependency is not empty and includes at least two lock dependencies for any lock dependency; a detection result sub-module, which is used to obtain the detection result when the above-mentioned lock dependency meets the first preset condition.

[0018] According to an embodiment of the present invention, the above-mentioned device also includes: a processing submodule, which is used to process the lock-holding transaction corresponding to the lock dependency in the above-mentioned detection result based on the above-mentioned detection result, so that the resource blocking state in the above-mentioned distributed database disappears.

[0019] According to an embodiment of the present invention, the lock attribute information includes a database identifier, lock type information, and lock level information that have a corresponding relationship with the lock; the construction module includes: a grouping submodule, which is used to group the lock attribute information of the above-mentioned multiple nodes according to the above-mentioned database identifier to obtain multiple groups of lock attribute information to be processed; a candidate lock attribute information submodule, which is used to group each group of lock attribute information to be processed according to the above-mentioned lock type information to obtain candidate lock attribute information; a sorting submodule, which is used to sort the above-mentioned candidate lock attribute information based on the above-mentioned lock level information to obtain sorted lock attribute information; a lock dependency relationship construction submodule, which is used to lock when the above-mentioned sorted lock attribute information meets a preset order, and construct multiple lock dependencies based on the above-mentioned lock waiting information and the above-mentioned candidate lock attribute information.

[0020] According to an embodiment of the present invention, the lock attribute information also includes: transaction information corresponding to the lock, and the processing submodule includes: a log generation unit for generating a deadlock log based on the detection result; a log storage unit for storing the deadlock log in the distributed database; and a transaction determination unit for determining the transaction to be rolled back from the transaction information corresponding to the updated lock dependency based on the detection result; and a rollback unit for rolling back the transaction to be rolled back.

[0021] According to an embodiment of the present invention, the transaction information includes: resource occupancy; the transaction determination unit includes: a threshold determination subunit, which is used to determine the transaction as a transaction to be rolled back when the resource occupancy of the transaction exceeds a predetermined threshold.

[0022] According to an embodiment of the present invention, the above-mentioned transaction information includes: modified data volume information; the above-mentioned transaction determination unit includes: a sorting subunit, used to sort the above-mentioned transactions based on the above-mentioned modified data volume information to obtain sorted transactions; a to-be-rolled-back transaction determination subunit, used to determine a preset number of transactions as to-be-rolled-back transactions.

[0023] According to an embodiment of the present invention, the above-mentioned device also includes: a timing detection module, which is used to perform multiple deadlock detections on the above-mentioned distributed database in response to the timing detection task being triggered, and obtain multiple deadlock detection results; a target detection result module, which is used to obtain the target detection result when it is determined that the above-mentioned multiple deadlock detection results are the same.

[0024] A third aspect of the present invention provides an electronic device, comprising: one or more processors; a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the above method.

[0025] The fourth aspect of the present invention further provides a computer-readable storage medium on which a computer program or instruction is stored, and the steps of the above method are implemented when the above computer program or instruction is executed by a processor.

[0026] The fifth aspect of the present invention also provides a computer program product, including a computer program or instructions, which implement the steps of the above method when executed by a processor.

[0027] According to an embodiment of the present invention, the lock attribute information and lock dependency information stored in all nodes in the entire cluster are obtained through the central node of the cluster to generate a lock dependency relationship, find the lock dependency relationship to be deleted and delete it, and obtain a deadlock detection result, thereby reducing the amount of calculation for judging whether there is a deadlock in the database after the lock dependency relationship is built. Further, the computing burden of the hardware device is reduced, thereby improving the response speed of the distributed database and improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The above contents and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:

[0029] Figure 1 An application scenario diagram of a distributed database deadlock detection method according to an embodiment of the present invention is shown;

[0030] Figure 2 A flowchart of a distributed database deadlock detection method according to an embodiment of the present invention is shown;

[0031] Figure 3 A schematic diagram showing a lock dependency relationship constructed according to an embodiment of the present invention is shown;

[0032] Figure 4 A schematic diagram of a deadlock constructed according to an embodiment of the present invention is shown;

[0033] Figure 5 A schematic diagram of determining the dependency of locks to be deleted according to an embodiment of the present invention is shown;

[0034] Figure 6 A schematic diagram showing an updated lock dependency relationship according to an embodiment of the present invention is shown;

[0035] Figure 7 A flowchart of deadlock processing according to an embodiment of the present invention is shown;

[0036] Figure 8 It shows a structural block diagram of a distributed database deadlock detection device according to an embodiment of the present invention; and

[0037] Fig. 9A block diagram of an electronic device suitable for implementing a distributed database deadlock detection method according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0038] Below, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of embodiments of the present invention. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of concepts of the present invention.

[0039] The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.

[0040] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.

[0041] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0042] In most database systems, locks are a common concurrency control technology used to ensure data consistency and integrity. When multiple transactions need to access the same resource, they compete to obtain the lock corresponding to the resource to ensure that no data conflicts occur during access. If a transaction cannot obtain the required lock, it will be blocked until the lock is available. However, deadlock occurs when multiple transactions are stuck in a state of waiting for each other because they hold the locks required by each other. In related technologies, a method of constructing a global directed graph is usually used to check whether there is a deadlock. In this method, the system collects the relationship information between all transactions and locks, and then constructs a directed graph in which nodes represent transactions and edges represent the dependencies of locks. By traversing this directed graph, the system can detect whether there is a path that forms a closed loop, that is, a deadlock loop, but this method requires a large amount of calculation and a heavy burden on hardware facilities because it needs to collect and process a large amount of lock information.

[0043] In view of this, an embodiment of the present invention provides a distributed database deadlock detection method, the method is applied to the central node of a cluster, the cluster also includes multiple nodes except the central node, the method includes: in response to a received deadlock detection request, obtaining lock attribute information and lock dependency information of multiple nodes, the lock dependency information represents the dependency relationship between transactions holding locks; constructing multiple lock dependencies based on the lock attribute information and the lock dependency information, the lock dependency relationships represent the relationship between locks of mutually dependent transactions, and the first transaction corresponding to the current lock is processed depending on the processing result of the second transaction; determining the lock dependency to be deleted based on the multiple lock dependencies, the lock dependency to be deleted represents that the lock dependency includes at most one lock dependency; updating the lock dependency based on the lock dependency to be deleted to obtain a detection result, and the detection result represents that a deadlock exists in the distributed database.

[0044] Figure 1 An application scenario diagram of a distributed database deadlock detection method according to an embodiment of the present invention is shown.

[0045] like Figure 1 As shown, the application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used to provide a medium for a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.

[0046] The user can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only for example).

[0047] The first terminal device 101, the second terminal device 102, and the third terminal device 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0048] The server 105 may be a server that provides various services, such as a background management server (only as an example) that provides support for websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.

[0049] It should be noted that the distributed database deadlock detection method provided in the embodiment of the present invention can generally be executed by the server 105. Accordingly, the distributed database deadlock detection device provided in the embodiment of the present invention can generally be set in the server 105. The distributed database deadlock detection method provided in the embodiment of the present invention can also be executed by a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105. Accordingly, the distributed database deadlock detection device provided in the embodiment of the present invention can also be set in a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105.

[0050] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only . According to the implementation requirements, there can be any number of terminal devices, networks and servers.

[0051] The following will be based on Figure 1 The scene described by Figure 2~Figure 7 The distributed database deadlock detection method of the embodiment of the invention is described in detail.

[0052] Figure 2 A flow chart of a distributed database deadlock detection method according to an embodiment of the present invention is shown.

[0053] like Figure 2 As shown, the distributed database deadlock detection method of this embodiment includes operations S210 to S240.

[0054] It should be noted that the above method can be applied to the central node of the cluster, and the cluster also includes multiple nodes except the central node.

[0055] In operation S210, in response to a received deadlock detection request, lock attribute information and lock dependency information of a plurality of nodes are acquired.

[0056] The lock dependency information represents the dependency relationship between transactions holding locks.

[0057] According to an embodiment of the present invention, the lock attribute information may include information such as the lock node, the lock database, the lock type, and the lock identification information, and the lock dependency information may include information such as waiting lock transactions and holding lock transactions.

[0058] In operation S220, a plurality of lock dependency relationships are constructed based on the lock attribute information and the lock dependency information.

[0059] The lock dependency relationship represents the relationship between locks of mutually dependent transactions, and the first transaction corresponding to the current lock is processed depending on the processing result of the second transaction.

[0060] Figure 3 A schematic diagram of a lock dependency relationship constructed according to an embodiment of the present invention is shown.

[0061] like Figure 3 As shown in the figure, there are three transactions, namely T1, T2, and T3. Transaction T2 holds lock S1, and transaction T3 holds lock S2. If transaction T1 waits for lock S1, and transaction T2 waits for lock S2, there is a lock dependency relationship between transactions T1, T2, and T3, which can be constructed as follows Figure 3 Lock dependencies shown.

[0062] Figure 4 A schematic diagram of a deadlock constructed according to an embodiment of the present invention is shown.

[0063] like Figure 4 As shown in the figure, there are three transactions, namely T1, T2, and T3. Transaction T1 holds lock S3, transaction T2 holds lock S1, and transaction T3 holds lock S2. If transaction T1 waits for lock S1, transaction T2 waits for lock S2, and transaction T3 waits for lock S3, there is a deadlock between transactions T1, T2, and T3, which can be constructed as follows Figure 4 Lock dependencies shown.

[0064] In operation S230 , a lock dependency to be deleted is determined based on the plurality of lock dependencies.

[0065] The lock dependency to be deleted includes at most one lock dependency.

[0066] According to an embodiment of the present disclosure, the lock dependency may include a pre-lock dependency and a post-lock dependency. The lock dependency to be deleted may include a pre-lock dependency or a post-lock dependency. Figure 5 Let's explain the above-mentioned pre-lock dependency and post-lock dependency.

[0067] Figure 5 A schematic diagram of determining the dependency of locks to be deleted according to an embodiment of the present invention is shown.

[0068] like Figure 5 As shown in the figure, for ease of understanding, we first explain the in-degree and out-degree of the edges in the directed graph. Figure 5 As shown in the figure, for the edge b23 from T2 to T3, there is an edge b12 from T1 to T2, so it is considered that the edge b23 has an in-degree; for the edge b12, there is an edge b23, so it is considered that the edge b12 has an out-degree. For the edge b23, its predecessor dependency lock relationship can be expressed as Figure 5 The post-dependency lock relationship of the middle edge b34 can be expressed as Figure 5 For edge b12, since edge b23 has both a preceding dependent lock relationship (out-degree) b34 and a following dependent lock relationship (in-degree) b12, it does not meet the above conditions of including a preceding dependent lock relationship or a following dependent lock relationship, so edge b23 is not determined as a lock dependency relationship to be deleted. However, for edge b12, only a preceding dependent lock relationship b23 exists, so it can be determined as a lock dependency relationship to be deleted.

[0069] In operation S240, the lock dependency is updated based on the lock dependency to be deleted, and a detection result is obtained.

[0070] Among them, the detection result indicates that deadlock exists in the distributed database.

[0071] Figure 6 A schematic diagram showing an updated lock dependency relationship according to an embodiment of the present invention is shown.

[0072] like Figure 6 As shown, in the updated lock dependency, since b56, b67, and b75 all have both a preceding dependent lock relationship and a succeeding dependent lock relationship, b56, b67, and b75 cannot be determined as lock dependencies to be deleted in operation S230, that is, they constitute a deadlock, and the detection result is obtained.

[0073] According to an embodiment of the present invention, the lock attribute information and lock dependency information stored in all nodes in the entire cluster are obtained through the central node of the cluster to generate a lock dependency relationship, and the lock dependency relationships that do not simultaneously exist in the pre-dependency lock relationship and the post-dependency lock relationship are found and deleted to obtain a deadlock detection result, thereby reducing the amount of calculation for determining whether a deadlock exists in the database after the lock dependency relationship is built. Further, the computing burden of the hardware device is reduced, thereby improving the response speed of the distributed database and improving the user experience.

[0074] According to an embodiment of the present invention, the above-mentioned updating of lock dependencies based on the lock dependencies to be deleted and obtaining the detection results include: updating the lock dependencies based on the lock dependencies to be deleted to obtain updated lock dependencies; when the updated lock dependencies do not meet the first preset condition, returning to perform the operation of determining the lock dependencies to be deleted based on multiple lock dependencies, the first preset condition characterizing that the updated lock dependencies are not empty and include at least two lock dependencies for any lock dependency; when the lock dependencies meet the first preset condition, obtaining the detection results.

[0075] According to an embodiment of the present invention, the above operation will continuously search for lock dependencies including predecessor-dependent lock relationships or successor-dependent lock relationships in the lock dependency relationships for deletion until the lock dependency relationship is empty in the lock dependency relationship or the lock dependency relationship is not empty after reaching a predetermined number of iterations, and each lock dependency relationship includes a predecessor-dependent lock relationship and a successor-dependent lock relationship.

[0076] According to an embodiment of the present invention, by continuously updating lock dependencies, lock dependencies that do not meet the conditions are deleted to obtain detection results, which can reduce the amount of calculated data in the process of determining whether a database is deadlocked, thereby improving the response speed of the device.

[0077] According to an embodiment of the present invention, after the lock dependency is updated based on the lock dependency to be deleted and the detection result is obtained, the method also includes: based on the detection result, processing the transaction holding the lock corresponding to the lock dependency in the detection result to eliminate the resource blocking state in the distributed database.

[0078] Figure 7 A flowchart of deadlock processing according to an embodiment of the present invention is shown.

[0079] like Figure 7 As shown, the deadlock processing flow of this embodiment includes operations S710 to S740.

[0080] It should be noted that the above lock attribute information also includes transaction information corresponding to the lock.

[0081] In operation S710 , a deadlock log is generated based on the detection result.

[0082] According to an embodiment of the present invention, a deadlock log is a log file that records deadlock situations in a database system. When a database system detects a deadlock, it records relevant information in a deadlock log, which includes transaction information of each transaction in the deadlock loop, node information of the transaction, query statements involved in the transaction, and other information.

[0083] In operation S720, the deadlock log is stored in a distributed database.

[0084] In operation S730 , a transaction to be rolled back is determined from transaction information corresponding to the updated lock dependency based on the detection result.

[0085] According to an embodiment of the present invention, the transaction information may include: resource occupancy. When the resource occupancy of a transaction exceeds a predetermined threshold, the transaction may be determined as a transaction to be rolled back.

[0086] According to an embodiment of the present invention, the transaction information may further include: modified data volume information, based on which transactions may be sorted to obtain sorted transactions; and a preset number of transactions may be determined as transactions to be rolled back.

[0087] According to an embodiment of the present invention, the preset number may be, for example, 1.

[0088] According to an embodiment of the present invention, the transaction to be rolled back may also be determined according to the start time of the transaction. It should be noted that although the present invention only mentions the above-mentioned conditions for determining the transaction to be rolled back, the transaction to be rolled back may be determined according to specific circumstances, and the present application does not limit this.

[0089] In operation S740 , the transaction to be rolled back is rolled back.

[0090] According to an embodiment of the present invention, when an error occurs during the execution of a transaction, a constraint condition is violated, or the user actively cancels the transaction, the database system will perform a transaction rollback operation to ensure the consistency and integrity of the data.

[0091] According to an embodiment of the present invention, by saving the deadlock log in a distributed database, relevant staff can obtain the deadlock situation based on the deadlock log query and determine the transaction to be rolled back through various conditions. This can more flexibly adapt to the transaction processing requirements in different situations, thereby improving the adaptability and flexibility of the distributed database.

[0092] According to an embodiment of the present invention, the above-mentioned lock attribute information includes a database identifier, lock type information, and lock level information that have a corresponding relationship with the lock; constructing multiple lock dependency relationships based on the lock attribute information and lock waiting information includes: grouping the lock attribute information of multiple nodes according to the database identifier to obtain multiple groups of lock attribute information to be processed; for each group of lock attribute information to be processed, grouping according to the lock type information to obtain candidate lock attribute information; sorting the candidate lock attribute information based on the lock level information to obtain sorted lock attribute information; when the sorted lock attribute information satisfies a preset order, constructing multiple lock dependency relationships based on the lock waiting information and the candidate lock attribute information.

[0093] According to an embodiment of the present invention, building a lock dependency requires that the databases to which the locks corresponding to the transactions belong are the same, the lock type information is the same, and the lock levels meet the conditions in the following table.

[0094] Table 1

[0095] Lock level Dependency lock level 1 8 2 7、8 3 5、6、7、8 4 4、5、6、7、8 5 3、4、5、6、7、8 6 3、4、5、6、7、8 7 2、3、4、5、6、7、8 8 1、2、3、4、5、6、7、8

[0096] That is, for a level 1 lock, the lock that forms a dependent relationship with it needs to be a level 8 lock. For a level 2 lock, the locks that form a dependent relationship with it need to be level 7 locks and level 8 locks, and so on.

[0097] According to the embodiment of the present invention, limiting the construction of lock dependencies through lock levels can provide a more precise control granularity for the distributed database, further optimize the concurrent processing capability of the database system, and improve the stability and reliability of the system.

[0098] According to an embodiment of the present invention, the method further includes: in response to the timing detection task being triggered, performing multiple deadlock detections on the distributed database to obtain multiple deadlock detection results; and obtaining a target detection result when it is determined that the multiple deadlock detection results are the same.

[0099] According to an embodiment of the present invention, the accuracy of deadlock detection can be ensured through multiple deadlock detections. Because the present invention is applied to distributed databases, when the central node obtains lock dependency information, there may be a deadlock between the lock dependency information on the obtained node and the lock dependency information on other nodes, but the corresponding transaction has been executed, thereby causing a false deadlock. The false deadlock can be avoided by performing deadlock detection multiple times and comparing the detection results to see if they are consistent.

[0100] According to an embodiment of the present invention, deadlock detection can be performed regularly to avoid multiple transactions waiting due to deadlock in the database, thereby improving the efficiency and reliability of the distributed database, and resolving deadlock in a timely manner when it occurs, maintaining the stability and response speed of the system.

[0101] Based on the above distributed database deadlock detection method, the present invention also provides a distributed database deadlock detection device. Figure 8 The device is described in detail.

[0102] Figure 8 A structural block diagram of a distributed database deadlock detection device according to an embodiment of the present invention is shown.

[0103] like Figure 8 As shown, the distributed database deadlock detection device 800 of this embodiment includes an acquisition module 810 , a construction module 820 , a determination module 830 and a detection module 840 .

[0104] The acquisition module 810 is used to respond to the received deadlock detection request and acquire lock attribute information and lock dependency information of multiple nodes, wherein the lock dependency information represents the dependency relationship between transactions holding locks. In one embodiment, the acquisition module 810 can be used to perform the operation S210 described above, which will not be described in detail here.

[0105] The construction module 820 is used to construct multiple lock dependency relationships based on the lock attribute information and the lock dependency information, wherein the lock dependency relationship represents the relationship between the locks of mutually dependent transactions, and the first transaction corresponding to the current lock is processed depending on the processing result of the second transaction. In one embodiment, the construction module 820 can be used to perform the operation S220 described above, which will not be repeated here.

[0106] The determination module 830 is used to determine the lock dependency to be deleted based on multiple lock dependencies, and the lock dependency to be deleted includes at most one lock dependency. In one embodiment, the determination module 830 can be used to perform the operation S230 described above, which will not be repeated here.

[0107] The detection module 840 is used to update the lock dependency relationship based on the lock dependency relationship to be deleted to obtain a detection result, which indicates that a deadlock exists in the distributed database. In one embodiment, the detection module 840 can be used to perform the operation S240 described above, which will not be repeated here.

[0108] According to an embodiment of the present invention, the above-mentioned detection module includes: a dependency update sub-module, which is used to update the above-mentioned lock dependency based on the above-mentioned lock dependency to be deleted to obtain an updated lock dependency; a return execution sub-module, which is used to return to execute the operation of determining the lock dependency to be deleted based on the above-mentioned multiple lock dependencies when the above-mentioned updated lock dependency does not meet the first preset condition, and the above-mentioned first preset condition represents that the updated lock dependency is not empty and includes at least two lock dependencies for any lock dependency; a detection result sub-module, which is used to obtain the detection result when the above-mentioned lock dependency meets the first preset condition.

[0109] According to an embodiment of the present invention, the above-mentioned device also includes: a processing submodule, which is used to process the lock-holding transaction corresponding to the lock dependency in the above-mentioned detection result based on the above-mentioned detection result, so that the resource blocking state in the above-mentioned distributed database disappears.

[0110] According to an embodiment of the present invention, the lock attribute information includes a database identifier, lock type information, and lock level information that have a corresponding relationship with the lock; the construction module includes: a grouping submodule, which is used to group the lock attribute information of the above-mentioned multiple nodes according to the above-mentioned database identifier to obtain multiple groups of lock attribute information to be processed; a candidate lock attribute information submodule, which is used to group each group of lock attribute information to be processed according to the above-mentioned lock type information to obtain candidate lock attribute information; a sorting submodule, which is used to sort the above-mentioned candidate lock attribute information based on the above-mentioned lock level information to obtain sorted lock attribute information; a lock dependency relationship construction submodule, which is used to lock when the above-mentioned sorted lock attribute information meets a preset order, and construct multiple lock dependencies based on the above-mentioned lock waiting information and the above-mentioned candidate lock attribute information.

[0111] According to an embodiment of the present invention, the lock attribute information also includes: transaction information corresponding to the lock, and the processing submodule includes: a log generation unit for generating a deadlock log based on the detection result; a log storage unit for storing the deadlock log in the distributed database; and a transaction determination unit for determining the transaction to be rolled back from the transaction information corresponding to the updated lock dependency based on the detection result; and a rollback unit for rolling back the transaction to be rolled back.

[0112] According to an embodiment of the present invention, the transaction information includes: resource occupancy; the transaction determination unit includes: a threshold determination subunit, which is used to determine the transaction as a transaction to be rolled back when the resource occupancy of the transaction exceeds a predetermined threshold.

[0113] According to an embodiment of the present invention, the above-mentioned transaction information includes: modified data volume information; the above-mentioned transaction determination unit includes: a sorting subunit, used to sort the above-mentioned transactions based on the above-mentioned modified data volume information to obtain sorted transactions; a to-be-rolled-back transaction determination subunit, used to determine a preset number of transactions as to-be-rolled-back transactions.

[0114] According to an embodiment of the present invention, the above-mentioned device also includes: a timing detection module, which is used to perform multiple deadlock detections on the above-mentioned distributed database in response to the timing detection task being triggered, and obtain multiple deadlock detection results; a target detection result module, which is used to obtain the target detection result when it is determined that the above-mentioned multiple deadlock detection results are the same.

[0115] According to an embodiment of the present invention, any multiple modules among the acquisition module 810, the construction module 820, the determination module 830 and the detection module 840 can be combined in one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present invention, at least one of the acquisition module 810, the construction module 820, the determination module 830 and the detection module 840 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in any appropriate combination of any of them. Alternatively, at least one of the acquisition module 810, the construction module 820, the determination module 830 and the detection module 840 can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be executed.

[0116] Fig. 9 A block diagram of an electronic device suitable for implementing a distributed database deadlock detection method according to an embodiment of the present invention is shown.

[0117] like Fig. 9 As shown, the electronic device 900 according to an embodiment of the present invention includes a processor 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 to a random access memory (RAM) 903. The processor 901 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 901 may also include an onboard memory for caching purposes. The processor 901 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.

[0118] In RAM 903, various programs and data required for the operation of electronic device 900 are stored. Processor 901, ROM 902 and RAM 903 are connected to each other via bus 904. Processor 901 performs various operations of the method flow according to the embodiment of the present invention by executing the program in ROM 902 and / or RAM 903. It should be noted that the program can also be stored in one or more memories other than ROM 902 and RAM 903. Processor 901 can also perform various operations of the method flow according to the embodiment of the present invention by executing the program stored in the one or more memories.

[0119] According to an embodiment of the present invention, the electronic device 900 may further include an input / output (I / O) interface 905, which is also connected to the bus 904. The electronic device 900 may further include one or more of the following components connected to the I / O interface 905: an input portion 906 including a keyboard, a mouse, etc.; an output portion 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 908 including a hard disk, etc.; and a communication portion 909 including a network interface card such as a LAN card, a modem, etc. The communication portion 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage portion 908 as needed.

[0120] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiment; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present invention is implemented.

[0121] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, it may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 902 and / or RAM 903 described above and / or one or more memories other than ROM 902 and RAM 903.

[0122] The embodiment of the present invention also includes a computer program product, which includes a computer program, and the computer program includes a program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the distributed database deadlock detection method provided by the embodiment of the present invention.

[0123] The computer program executes the above functions defined in the system / device of the embodiment of the present invention when it is executed by the processor 901. According to the embodiment of the present invention, the system, device, module, unit, etc. described above can be implemented by a computer program module.

[0124] In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of a signal on a network medium, and downloaded and installed through the communication part 909, and / or installed from a removable medium 911. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0125] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the processor 901, the above functions defined in the system of the embodiment of the present invention are performed. According to the embodiment of the present invention, the system, device, means, module, unit, etc. described above can be implemented by a computer program module.

[0126] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).

[0127] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0128] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present invention may be combined and / or combined in various ways, even if such combinations and / or combinations are not explicitly described in the present invention. In particular, the features described in the various embodiments and / or claims of the present invention may be combined and / or combined in various ways without departing from the spirit and teachings of the present invention. All of these combinations and / or combinations fall within the scope of the present invention.

[0129] The embodiments of the present invention are described above. However, these embodiments are only for the purpose of illustration, and are not intended to limit the scope of the present invention. Although each embodiment is described above, it does not mean that the measures in each embodiment cannot be used in combination. The scope of the present invention is defined by the attached claims and their equivalents. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.

Claims

1. A distributed database deadlock detection method, characterized in that: The method is applied to a central node of a cluster, wherein the cluster further comprises a plurality of nodes other than the central node, and the method comprises: In response to the received deadlock detection request, acquiring lock attribute information and lock dependency information of the plurality of nodes, wherein the lock dependency information represents a dependency relationship between transactions holding locks; Building a plurality of lock dependency relationships based on the lock attribute information and the lock dependency information, wherein the lock dependency relationships represent the relationship between locks of mutually dependent transactions, and a first transaction corresponding to the current lock is processed depending on a processing result of a second transaction; Determine a lock dependency to be deleted based on the multiple lock dependencies, wherein the lock dependency to be deleted includes at most one lock dependency; The lock dependency relationship is updated based on the lock dependency relationship to be deleted, and a detection result is obtained, wherein the detection result indicates that a deadlock exists in the distributed database; The lock attribute information includes a database identifier corresponding to the lock, lock type information, and lock level information; The constructing a plurality of lock dependency relationships based on the lock attribute information and the lock dependency information comprises: According to the database identifier, the lock attribute information of the multiple nodes is grouped to obtain multiple groups of lock attribute information to be processed; For each group of lock attribute information to be processed, grouping is performed according to the lock type information to obtain candidate lock attribute information; sorting the candidate lock attribute information based on the lock level information to obtain sorted lock attribute information; In a case where the sorted lock attribute information satisfies a preset order, a plurality of lock dependency relationships are constructed based on the lock dependency information and the candidate lock attribute information.

2. The method according to claim 1, characterized in that The updating of the lock dependency relationship based on the lock dependency relationship to be deleted to obtain the detection result includes: Based on the lock dependency to be deleted, the lock dependency is updated to obtain an updated lock dependency; If the updated lock dependency does not satisfy a first preset condition, returning to perform an operation of determining a lock dependency to be deleted based on the multiple lock dependencies, wherein the first preset condition indicates that the updated lock dependency is not empty and includes at least two lock dependencies for any lock dependency; When the lock dependency relationship satisfies the first preset condition, a detection result is obtained.

3. The method according to claim 2, characterized in that After the lock dependency relationship is updated based on the lock dependency relationship to be deleted and a detection result is obtained, the method further includes: Based on the detection result, the lock-holding transaction corresponding to the lock dependency in the detection result is processed to eliminate the resource blocking state in the distributed database.

4. The method according to claim 3, characterized in that The lock attribute information also includes: transaction information having a corresponding relationship with the lock, and the processing of the lock-holding transaction corresponding to the lock dependency in the detection result based on the detection result includes: Generate a deadlock log based on the detection result; Storing the deadlock log in the distributed database; and Determine the transaction to be rolled back from the transaction information corresponding to the updated lock dependency based on the detection result; Roll back the transaction to be rolled back.

5. The method according to claim 4, characterized in that The transaction information includes: resource occupancy; the determining of the transaction to be rolled back from the transaction information having a corresponding relationship with the updated lock dependency relationship based on the detection result includes: When the resource occupation of the transaction exceeds a predetermined threshold, the transaction is determined as a transaction to be rolled back.

6. The method according to claim 4, characterized in that The transaction information includes: modified data volume information; the determining of the transaction to be rolled back from the transaction information corresponding to the updated lock dependency based on the detection result includes: sorting the transactions based on the modified data volume information to obtain sorted transactions; A preset number of transactions are determined as transactions to be rolled back.

7. The method according to claim 1, characterized in that The method further comprises: In response to the timing detection task being triggered, performing multiple deadlock detections on the distributed database to obtain multiple deadlock detection results; When it is determined that the multiple deadlock detection results are the same, a target detection result is obtained.

8. A distributed database deadlock detection device, characterized in that: The device comprises: An acquisition module, configured to acquire lock attribute information and lock dependency information of multiple nodes in response to a received deadlock detection request, wherein the lock dependency information represents a dependency relationship between transactions holding locks; A construction module, configured to construct a plurality of lock dependency relationships based on the lock attribute information and the lock dependency information, wherein the lock dependency relationships represent the relationship between locks of mutually dependent transactions, and a first transaction corresponding to a current lock is processed depending on a processing result of a second transaction; A determination module, configured to determine a lock dependency to be deleted based on the multiple lock dependencies, wherein the lock dependency to be deleted includes at most one lock dependency; A detection module, configured to update the lock dependency relationship based on the lock dependency relationship to be deleted, and obtain a detection result, wherein the detection result indicates that a deadlock exists in the distributed database; The lock attribute information includes a database identifier corresponding to the lock, lock type information, and lock level information; the construction module includes: A grouping submodule, used for grouping the lock attribute information of the plurality of nodes according to the database identifier to obtain a plurality of groups of lock attribute information to be processed; A candidate lock attribute information submodule, for grouping each group of lock attribute information to be processed according to the lock type information to obtain candidate lock attribute information; A sorting submodule, configured to sort the candidate lock attribute information based on the lock level information to obtain sorted lock attribute information; The lock dependency relationship building submodule is used to build multiple lock dependency relationships based on the lock dependency information and the candidate lock attribute information when the sorted lock attribute information meets a preset order.

9. An electronic device, comprising: one or more processors; a memory for storing one or more computer programs, It is characterized in that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Deadlock detection method, node and system

    CN103455368A

  • Distributed deadlock detection method and device, computer equipment and readable medium

    CN110442459A