A distributed deadlock detection method, device and electronic equipment
By selecting a transaction that is not the starting transaction in the distributed system as the current transaction, performing transaction traversal and detecting untraveled paths, the problem of high computational complexity in distributed deadlock detection is solved, and fast and effective deadlock detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
- Filing Date
- 2021-09-13
- Publication Date
- 2026-07-03
AI Technical Summary
In existing technologies, distributed deadlock problems exist in distributed systems, causing transactions to fail. Existing detection methods have high computational complexity and low efficiency.
By obtaining the transaction dependencies in the distributed system, selecting the transaction that is not the starting transaction as the current transaction, performing transaction traversal, detecting whether the untraveled target path has been traversed in other traversal processes, and performing different operations based on the detection results, the system avoids duplicate detection and missed detection of loops.
It reduces computational overhead, enables fast and effective detection of distributed deadlocks, and improves detection efficiency.
Smart Images

Figure CN115809150B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer application technology, and in particular to a distributed deadlock detection method, apparatus, and electronic device. Background Technology
[0002] Distributed locks are a means of controlling mutually exclusive access to shared resources in a distributed system, thereby avoiding uncontrollable results caused by parallelism. The implementation principle of distributed locks is consistent with that of single-process locks: uniqueness is determined by a shared identifier, and modifications to the shared identifier guarantee atomicity and visibility to the lock service caller.
[0003] In existing technologies, distributed locks are typically used to manage distributed transactions in distributed systems. However, in distributed systems, there may be two or more transactions executing concurrently. Each transaction is waiting for system resources held by other transactions and cannot continue running, which leads to any transaction being unable to proceed (i.e., an infinite loop), resulting in a distributed deadlock.
[0004] Therefore, how to quickly and effectively detect distributed deadlocks, thereby providing a foundation for resolving infinite loops in transaction execution, is an urgent problem to be solved. Summary of the Invention
[0005] The purpose of this invention is to provide a distributed deadlock detection method to achieve fast and effective detection of distributed deadlocks. The specific technical solution is as follows:
[0006] In a first aspect, embodiments of the present invention provide a distributed deadlock detection method, the method comprising:
[0007] To obtain the dependencies between various transactions in a distributed system;
[0008] From all transactions, select the transaction that was not the starting transaction and use it as the current transaction;
[0009] Starting from the current transaction, transactions are traversed according to the dependencies. Whenever a transaction is traversed, it is determined whether the target path has been traversed in other traversal processes. The target path is the path from the current transaction to the transactions that the current transaction depends on, and the other traversal processes are traversal processes that start from other transactions.
[0010] If the judgment result is yes, return to the process of selecting a transaction that was not used as the starting transaction from each transaction; otherwise, after recording the target path as having been traversed in the specified traversal process, continue traversing until the traversal is completed, and then return to the process of selecting a transaction that was not used as the starting transaction from each transaction; wherein, the specified traversal process is a traversal process with the current transaction as the starting transaction.
[0011] Furthermore, if a path is traversed during the transaction traversal and forms a loop, the loop is determined to be a distributed deadlock.
[0012] Optionally, recording the target path as traversed during a specified traversal includes:
[0013] Set the tag information corresponding to the current transaction for the target path; wherein, the tag information corresponding to any transaction is used to indicate that the path is traversed when the transaction is the starting transaction;
[0014] The determination of whether the target path has been traversed in other traversal processes includes:
[0015] Check if the target path has any tag information corresponding to other transactions;
[0016] If so, it is determined that the target path has already been traversed in other traversal processes.
[0017] Optionally, the tag information corresponding to the current transaction includes: the transaction identifier of the current transaction and a specified identifier, wherein the specified identifier is used to indicate that the path has been traversed;
[0018] The detection of whether the target path has tag information corresponding to other transactions includes:
[0019] Determine whether the target path has the specified identifier set;
[0020] If so, determine whether the transaction identifier set for the target path is the same as the transaction identifier of the current transaction. If they are the same, determine that the target path does not have tag information corresponding to other transactions; if they are different, determine that the target path has identifier information corresponding to other transactions.
[0021] If not, it is determined that the target path does not have tag information corresponding to other transactions.
[0022] Optionally, the dependencies are stored in the form of an adjacency list or an adjacency matrix;
[0023] The step of taking the current transaction as the starting transaction and performing transaction traversal according to the dependency relationship includes: taking the current transaction as the starting transaction and performing transaction traversal according to the dependency relationship represented by the adjacency list or adjacency matrix.
[0024] Optionally, the transaction traversal method is a depth-first traversal method.
[0025] Optionally, obtaining the dependencies between transactions in the distributed system includes:
[0026] Obtain lock wait information for each branch transaction reported by each shard node in the distributed system, for each transaction's branch transaction;
[0027] Based on the acquired lock wait information, the dependencies between various transactions are determined.
[0028] Secondly, embodiments of the present invention provide a distributed deadlock detection device, comprising:
[0029] The acquisition module is used to acquire the dependencies between various transactions in a distributed system;
[0030] The selection module is used to select a transaction that was not the starting transaction from among all transactions and to use it as the current transaction.
[0031] The first processing module is used to traverse transactions according to the dependency relationship starting from the current transaction. Whenever a transaction is traversed, it is determined whether the target path has been traversed in other traversal processes. The target path is the path from the current transaction to the transaction that the current transaction depends on, and the other traversal processes are traversal processes that start from other transactions.
[0032] The second processing module is configured to, if the judgment result is yes, trigger the selection module to select a transaction that was not used as a starting transaction from each transaction; otherwise, after recording the target path as having been traversed in the specified traversal process, continue traversing until the traversal is completed, and then trigger the selection module to select a transaction that was not used as a starting transaction from each transaction; wherein, the specified traversal process is a traversal process with the current transaction as the starting transaction;
[0033] The detection module is used to determine a distributed deadlock if the path traversed during transaction traversal forms a loop.
[0034] Optionally, the second processing module records the target path as having been traversed during the specified traversal in the following ways:
[0035] Set the tag information corresponding to the current transaction for the target path; wherein, the tag information corresponding to any transaction is used to indicate that the path is traversed when the transaction is the starting transaction;
[0036] The first processing module determines whether the target path has been traversed in other traversal processes, including:
[0037] Check if the target path has any tag information corresponding to other transactions;
[0038] If so, it is determined that the target path has already been traversed in other traversal processes.
[0039] Optionally, the tag information corresponding to the current transaction includes: the transaction identifier of the current transaction and a specified identifier, wherein the specified identifier is used to indicate that the path has been traversed;
[0040] The first processing module detects whether the target path has tag information corresponding to other transactions, including:
[0041] Determine whether the target path has the specified identifier set;
[0042] If so, determine whether the transaction identifier set for the target path is the same as the transaction identifier of the current transaction. If they are the same, determine that the target path does not have tag information corresponding to other transactions; if they are different, determine that the target path has identifier information corresponding to other transactions.
[0043] If not, it is determined that the target path does not have tag information corresponding to other transactions.
[0044] Optionally, the dependencies are stored in the form of an adjacency list or an adjacency matrix;
[0045] The first processing module takes the current transaction as the starting transaction and performs transaction traversal according to the dependency relationship, including: taking the current transaction as the starting transaction and performing transaction traversal according to the dependency relationship represented by the adjacency list or adjacency matrix.
[0046] Optionally, the transaction traversal method is a depth-first traversal method.
[0047] Optionally, the acquisition module is specifically used for:
[0048] Obtain lock wait information for each branch transaction reported by each shard node in the distributed system, for each transaction's branch transaction;
[0049] Based on the acquired lock wait information, the dependencies between various transactions are determined.
[0050] Thirdly, embodiments of the present invention provide an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0051] Memory, used to store computer programs;
[0052] When the processor executes a program stored in memory, it implements any of the steps of the distributed deadlock detection method described above.
[0053] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the steps of the distributed deadlock detection method described above.
[0054] Beneficial effects of the embodiments of the present invention:
[0055] In the solution provided by this embodiment of the invention, after obtaining the dependencies between various transactions, a transaction that is not the starting transaction is selected from among the transactions and designated as the current transaction. Starting from the current transaction, transaction traversal is performed according to the dependencies between distributed transactions. Whenever a transaction is traversed, if it is determined that the target path has been traversed in other traversal processes, a new current transaction is selected. Otherwise, after recording the target path as having been traversed in the specified traversal process, traversal continues until the traversal is completed and a new current transaction is selected. Furthermore, if the traversed path forms a loop during the transaction traversal process, the loop is determined to be a distributed deadlock.
[0056] As can be seen, this scheme detects whether an untraveled target path has been visited in other traversals and performs different operations based on different detection results. This avoids duplicate detection of the same loop and prevents missed detection of loops. Compared to existing technologies that require a complete traversal for each transaction, this scheme can significantly reduce computational overhead, thereby achieving fast and effective detection of distributed deadlocks.
[0057] Of course, implementing any product or method of the present invention does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0058] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0059] Figure 1 This is a schematic diagram illustrating the principle of processing multiple transactions in a distributed system.
[0060] Figure 2 This is a schematic diagram illustrating the dependencies between transactions in a distributed deadlock scenario during an implementation of this invention.
[0061] Figure 3 This is a flowchart of the distributed deadlock detection method in an embodiment of the present invention;
[0062] Figure 4 A schematic diagram of a directed graph representing inter-transaction dependencies;
[0063] Figure 5 For storage Figure 4 The adjacency matrix representing the inter-transaction dependencies;
[0064] Figure 6 This is a schematic diagram of a directed graph showing the dependencies between transactions in an embodiment of the present invention;
[0065] Figure 7 This is a schematic diagram of the structure of the distributed deadlock detection device in an embodiment of the present invention;
[0066] Figure 8 This is a schematic diagram of the structure of an electronic device in an embodiment of the present invention. Detailed Implementation
[0067] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of the present invention.
[0068] In a distributed system, at least one compute node and multiple storage nodes are deployed. Each storage node, also called a shard node, is used to store data; while the compute nodes, also called management nodes, are used to execute transactions based on the data in each storage node and to manage the storage nodes themselves.
[0069] Transactions executed by compute nodes can be called distributed transactions, and distributed transactions can be read transactions or write transactions; read transactions are generated in response to read requests, while write transactions are generated in response to write requests.
[0070] Furthermore, during transaction execution, compute nodes can split the transaction into multiple branch transactions and distribute them to different storage nodes, which then execute the branch transactions. The compute nodes then aggregate the execution results from each storage node to obtain the transaction's final result. Simply put, a large operation consists of different smaller operations distributed across different storage nodes and belonging to different applications. It's necessary to ensure that these smaller operations either all succeed or all fail. Distributed locks are a means of controlling mutually exclusive access to shared resources in a distributed system, thereby preventing uncontrollable results caused by parallelism. The basic implementation principle of distributed locks is consistent with that of single-process locks, using a shared identifier to determine uniqueness. Modifications to the shared identifier guarantee atomicity and visibility to the lock service caller. Existing technologies typically use distributed locks to manage distributed transactions in distributed systems. However, in distributed systems, two or more transactions may execute concurrently, each waiting for system resources occupied by other transaction processes and unable to continue running, resulting in any transaction process being unable to proceed (i.e., an infinite loop), leading to a distributed deadlock. Distributed deadlock occurs when two or more transactions are waiting for locks on different storage nodes. What appears as a normal lock wait on a single storage node is a distributed deadlock observed globally.
[0071] To facilitate understanding of distributed deadlock, the following explanation is provided with reference to the accompanying diagram:
[0072] Take two transactions waiting for each other as an example: Figure 1 As shown, transaction a (Trx-a) includes branch transaction a1 and branch transaction a2, and transaction b (Trx-b) includes branch transaction b1 and branch transaction b2.
[0073] The computation layer (DS) summarizes the lock wait information of branches a1 and a2 of transaction a, as well as the lock wait information of branches b1 and b2 of transaction b, that is: Figure 1 The statements `Trx-b1 wait Trx-a1-lock` and `Trx-a2 wait Trx-b1-lock` are used. `Trx-b1 wait Trx-a1-lock` indicates that branch transaction b1 depends on branch transaction a1, meaning branch transaction b1 is waiting for branch transaction a1; `Trx-a2 wait Trx-b1-lock` indicates that branch transaction a2 depends on branch transaction b1, meaning branch transaction a2 is waiting for branch transaction b1. The computation layer refers to the computation nodes mentioned above, and the storage layer refers to the storage nodes mentioned above.
[0074] Based on the above Trx-b1 wait Trx-a1-lock, we know that transaction b depends on transaction a, that is, From "transaction a" to "transaction b"; and based on the above Trx-a2 wait Trx-b1-lock, we know that transaction a depends on transaction b, that is, From "transaction b" to "transaction a".
[0075] It is evident that transactions a and b are interdependent. Interdependence means that transaction a needs to wait for transaction b to complete before it can complete, and transaction b needs to wait for transaction a to complete before it can complete. Therefore, transactions a and b are mutually waiting. If no other intervention occurs, and a distributed deadlock occurs between transactions a and b, this mutually waiting state will persist indefinitely.
[0076] In addition, the dependencies between multiple transactions are often more complex, but distributed deadlocks often manifest as infinite loops in the dependencies between transactions (hereinafter referred to as loops).
[0077] For example, such as Figure 2 As shown, transaction A depends on transaction B, transaction B depends on transaction C, transaction C depends on transaction D, transaction D depends on transaction F, and transaction F depends on transaction A. Therefore, transactions A, B, C, D, E, and F form a loop, which means that a distributed deadlock occurs between transactions A, B, C, D, E, and F.
[0078] In existing technologies, the main steps of distributed deadlock detection methods are as follows: starting from each transaction sequentially, a depth-first traversal is performed based on the dependencies between transactions. If a cycle is found in the dependencies between transactions during the traversal, it is determined to be a distributed deadlock. Assuming the number of traversals starting from each transaction node is n, then a complete distributed deadlock detection process requires n steps. 2 This nth iteration. 2 The numerous repeated traversals during the traversal process result in high computational complexity, which not only increases the system's computational load but also reduces the efficiency of distributed deadlock detection.
[0079] To quickly and effectively detect distributed deadlocks, this invention provides a distributed deadlock detection method.
[0080] The distributed deadlock retrieval method can be applied to the computing nodes of a distributed system.
[0081] The specific steps of the distributed deadlock detection method are as follows:
[0082] To obtain the dependencies between various transactions in a distributed system;
[0083] From all transactions, select the transaction that was not the starting transaction and use it as the current transaction;
[0084] Starting from the current transaction, transactions are traversed according to the dependencies. Whenever a transaction is traversed, it is determined whether the target path has been traversed in other traversal processes. The target path is the path from the current transaction to the transactions that the current transaction depends on, and the other traversal processes are traversal processes that start from other transactions.
[0085] If the judgment result is yes, return to the process of selecting a transaction that was not used as the starting transaction from each transaction; otherwise, after recording the target path as having been traversed in the specified traversal process, continue traversing until the traversal is completed, and then return to the process of selecting a transaction that was not used as the starting transaction from each transaction; wherein, the specified traversal process is a traversal process with the current transaction as the starting transaction.
[0086] Furthermore, if a path is traversed during the transaction traversal and forms a loop, the loop is determined to be a distributed deadlock.
[0087] As can be seen, this scheme detects whether an untraveled target path has been visited in other traversals and performs different operations based on different detection results. This avoids duplicate detection of the same loop and prevents missed detection of loops. Compared to existing technologies that require a complete traversal for each transaction, this scheme can significantly reduce computational overhead, thereby achieving fast and effective detection of distributed deadlocks.
[0088] The following description, in conjunction with the accompanying drawings, introduces a distributed deadlock detection method provided by an embodiment of the present invention.
[0089] like Figure 3 As shown, a distributed deadlock detection method provided in this embodiment of the invention may include the following steps:
[0090] S301: Obtain the dependencies between transactions in a distributed system.
[0091] When the triggering conditions for distributed deadlock detection are met, the computing node can obtain the dependencies between various transactions in the distributed system, and then perform distributed deadlock detection based on the obtained dependencies. For example, the triggering conditions may include: reaching a predetermined time point, receiving a detection instruction for distributed deadlock detection, or the execution time of an incomplete transaction exceeding a predetermined time, etc.
[0092] For example, obtaining the dependencies between various transactions in a distributed system includes:
[0093] Obtain lock wait information for each branch transaction reported by each shard node in the distributed system, for each transaction's branch transaction;
[0094] Based on the acquired lock wait information, the dependencies between various transactions are determined.
[0095] Specifically, the lock wait information for any branch transaction can characterize the target branch transaction that the branch transaction needs to wait for, that is, the target branch transaction that the branch transaction depends on. This invention does not limit the specific form of the lock wait information.
[0096] Furthermore, after obtaining the lock wait information for any branch transaction, it is possible to determine the transaction to which that branch transaction belongs and the transaction it needs to wait for: the transaction to which the target branch transaction belongs. For example, if the lock wait information indicates that branch transaction b1 depends on branch transaction a1, then based on this lock wait information, it can be determined that branch transaction b1 belongs to transaction b, which depends on branch transaction a1 to transaction a, meaning transaction b depends on transaction a, and transaction b waits for transaction a. Additionally, there are various ways to store the dependencies between transactions; for example, the dependencies are stored in the form of an adjacency list or adjacency matrix, but this is not a limitation.
[0097] To better understand the solution, we will introduce the adjacency matrix used to store dependencies, using an example dependency relationship as an example.
[0098] Assume the dependencies between the transactions are as follows:
[0099] Transaction A depends on transactions B, C, and D; transaction B depends on transaction C; transaction C depends on transactions A and E; transaction D depends on transaction C; and transaction E does not depend on any transaction.
[0100] For ease of understanding, the dependencies between various transactions can be illustrated using... Figure 4 The directed graph representation shown is shown.
[0101] At this point, the adjacency matrix used to store the dependencies between various transactions can be as follows: Figure 5 As shown in the diagram. In the adjacency matrix, the value of a[i][j] is 1 or 0. If the value is 1, it means that transaction i depends on transaction j, which corresponds to the fact that transaction i and transaction j are connected in the directed graph and the arrow points from i to j; if the value is 0, it means that transaction i does not depend on transaction j. The values of i and j are A, B, C, D and E.
[0102] S302: Select the transaction that was not the starting transaction from all the transactions and use it as the current transaction;
[0103] In the process of developing this invention, the inventors discovered that when detecting distributed deadlocks in various transactions, the identification of existing loops can be maximized during a single transaction traversal; furthermore, transactions within a loop are interconnected, and any transaction entering the loop can traverse it, meaning that if a transaction has been traversed, all loops associated with it have been traversed. For ease of understanding, let's consider... Figure 6 For example: A→B indicates that transaction A depends on transaction B, and so on, indicating the dependency relationship between each transaction. If we start from transaction A and traverse the transactions according to the dependency relationship, we can detect the loops A→B→C→D→E→F→A and A→B→C→D→N→F→A. In this way, we can maximize the identification of existing loops during this traversal. Furthermore, when starting from any other transaction within each loop, we can traverse each loop.
[0104] Based on the above findings, in order to quickly and effectively detect distributed deadlocks, in this embodiment, after obtaining the dependencies between various transactions, a transaction that was not used as the starting transaction can be selected as the current transaction, and a traversal process can be performed according to S303-S304 below; after the traversal is completed, a new current transaction is selected again until all transactions have been used as starting transactions. That is, when traversing transactions starting from any transaction, for any path that is about to be traversed, it is checked whether the path has been traversed in other traversal processes, and different operations are performed according to different detection results, thereby avoiding repeated detection of a loop and missing detection of loops.
[0105] It should be noted that the entire traversal process with a single transaction as the current transaction can be called the inner loop, while the traversal process with different transactions as the current transactions can be called the outer loop. Thus, by combining the outer loop with a specific inner loop, all traversals of each transaction can be achieved. The specific inner loop is the traversal process implemented through S303-S304. Furthermore, due to the existence of overlapping and nested loops, in order to ensure that distributed deadlocks associated with a transaction can be detected to the greatest extent possible within an inner loop, a second traversal is allowed after the target path is identified within the inner loop.
[0106] In the initial selection of transactions from among all transactions that were not used as starting transactions, since none of the transactions were used as starting transactions, a transaction can be randomly selected as the current transaction. However, in subsequent selections, since there are both transactions that were used as starting transactions and those that were not, a transaction can be selected from the transactions that were not used as starting transactions to become the current transaction. For example, let's continue with... Figure 6Taking the directed graph shown as an example, we can first select transaction A as the current transaction; subsequently, we can select B, C, D, E, F, N, P and Q in sequence as the current transactions.
[0107] S303: Starting from the current transaction, perform transaction traversal according to the aforementioned dependency relationship. Whenever a transaction is traversed, determine whether the target path has been traversed in other traversal processes. If the result is yes, return to S302; otherwise, execute S304.
[0108] Wherein, the target path is the path from the transaction to the transaction that the transaction depends on, that is, the target path is the path that is about to be passed but has not yet been passed; the other traversal process is the traversal process with other transactions as the starting transactions. S304: After recording the target path as being passed in the specified traversal process, continue traversing until the traversal is completed, and return to step S302;
[0109] The specified traversal process is a traversal process that takes the current transaction as the starting transaction.
[0110] It should be noted that in this embodiment, for any transaction, when traversing to that transaction, the other transaction that the transaction depends on is the next transaction to be traversed. The path from the transaction to the other transaction is an untraveled path, which is the target path. For example, if transaction A depends on transaction B, and transaction B depends on transaction C, then during the traversal process, when traversing to transaction A, the next transaction to be traversed is transaction B, and the path from A to B is the target path in this embodiment. Similarly, when traversing to transaction B, the next transaction to be traversed is transaction C, and the path from B to C is the target path in this embodiment. Taking a directed graph as an example, if transaction A depends on transaction B, and the arrow points from A to B, then the direction of the arrow is the traversal direction.
[0111] Regardless of the starting transaction, when traversing any transaction, it is determined whether the target path has already been traversed in other traversal processes. If the result is yes, it indicates that all related loops for the transactions that this transaction depends on have been traversed. In this case, the current traversal can be stopped, a new current transaction can be selected, and the next traversal process can begin. If the result is no, the target path can be recorded, and traversal can continue. Furthermore, there are multiple specific implementations for recording the target path as traversed in a specified traversal process, which will be described later in conjunction with other embodiments. Additionally, it can be understood that if the target path has already been recorded as traversed in a specified traversal process, traversal can continue directly.
[0112] Additionally, for example, the transaction traversal process in S303 can be a depth-first traversal, but it is not limited to this.
[0113] S305: If a path is traversed during transaction traversal and forms a loop, the loop will be considered a distributed deadlock.
[0114] Steps S305 and S303-S304 do not have a strict sequential relationship. During the traversal, if a path is found to form a cycle, a distributed deadlock is detected, and the traversed cycle is classified as a distributed deadlock. In other words, starting from any transaction, if a path forms a cycle during the current traversal, the traversed cycle is classified as a distributed deadlock. A path forming a cycle means that duplicate transactions are traversed in a single traversal. Let's continue with... Figure 6 For example, starting from transaction A, transactions are traversed according to dependencies, i.e., traversed according to the arrow directions. The paths traversed will form loops such as A→B→C→D→E→F→A, and also loops such as A→B→C→D→N→F→A. In each loop, A represents the repeated transaction traversed. It should be emphasized that the embodiments of the present invention do not limit the conditions that need to be met for the formation of loops. The conditions that need to be met for the formation of loops are the same as those required for the formation of loops in the prior art, i.e., the formation of distributed deadlocks.
[0115] In addition, after detecting a distributed deadlock using the above method, this invention can further obtain a victim transaction from the loop and notify each storage node to roll back the corresponding victim transaction and perform unlocking processing.
[0116] In this embodiment, there are many methods for selecting the victim transaction. It can be based on weighting the least important distributed transaction, or on chronological order, selecting the newest or oldest distributed transaction, or on the number of records scanned by the distributed transaction, selecting the distributed transaction with the smallest impact on the number of records, and so on. For example, it can select transactions in the loop that simultaneously carry other loops as the victim transaction, or select the transaction with the lowest thread priority in the loop as the victim transaction, or select the transaction with the most subsequent waiting transactions in the loop as the victim transaction; or select the newest or oldest transaction in the loop according to chronological order as the victim transaction; or select the transaction with the smallest impact on the number of records in the loop as the node of the victim transaction, and so on. In practical applications, other strategies can also be used to select the victim transaction and notify each storage node to roll back the corresponding victim transaction, thereby performing the unlocking process.
[0117] To better understand the solution provided in this embodiment, the following explanation is provided with reference to examples:
[0118] For example, such as Figure 5As shown, after obtaining the dependencies between distributed transactions, these dependencies are stored in the form of an adjacency matrix. According to... Figure 5 The adjacency matrix in the table identifies dependencies between transactions, such as... Figure 4 As shown, transaction A depends on transactions B, C, and D; transaction B depends on transaction C; transaction C depends on transactions A and E; transaction D depends on transaction C; and transaction E does not depend on any transaction.
[0119] (1) The traversal process will be explained below using transaction B as the current transaction as an example:
[0120] Transaction B depends on transaction C, meaning that transaction B can only be completed if transaction C is completed. Therefore, when traversing to transaction B, it is necessary to jump to transaction C. The target path is B->C. It is determined that the target path B->C has not been passed through in other traversal processes. After recording the target path B->C as having been passed through in the specified traversal process, the traversal continues after jumping to transaction C.
[0121] After jumping to transaction C, according to the adjacency matrix, transaction C depends on transactions A and E. Therefore, according to the depth-first traversal rule, E is first taken as the next transaction to be traversed. It is determined whether the target path C->E has been passed in other traversals. If the result is no, the target path C->E is recorded as having been passed in the specified traversal. Then, A is taken as the next transaction to be traversed. Since the target path C->A has not been passed in other traversals, the target path C->A is recorded as having been passed in the specified traversal. Then, transaction A is traversed.
[0122] When traversing to transaction A, since transaction A depends on transactions B, C, and D, we can follow the depth-first traversal rule and first set B as the next transaction to be traversed. Since the target path A->B has not been passed in other traversal processes, we record the target path A->B as having been passed in the specified traversal process. After traversing to transaction B, we find that transaction B is a transaction that has been traversed repeatedly in this traversal process. Therefore, we get the loop B->C->A->B, which is a distributed deadlock.
[0123] According to the depth-first traversal rule, when traversing to transaction A, transaction D can be the next transaction to be traversed. Therefore, it can be determined whether the target path A->D has been passed through in other traversals. If the result is no, the target path A->D is recorded as passed through the specified traversal, and traversal continues to transaction D. When traversing to transaction D, it can be determined whether the target path D->C has been passed through in other traversals. If the result is no, the target path D->C is recorded as passed through the specified traversal, and traversal continues to transaction C. When traversing to transaction C, transaction A is selected as the next transaction to be traversed. The target path C->A has not been passed through in other traversals, so traversal continues to A. At this time, A is a repeatedly traversed transaction, thus resulting in a loop A->D->C->A, which is a distributed deadlock. When traversing to transaction C, C->E has been passed through in the specified traversal, so traversal continues to E. E has no dependent transactions, so the traversal ends.
[0124] According to the depth-first traversal rule, when traversing to transaction A, transaction C can be considered the next transaction to be traversed. Therefore, it can be determined whether the target path A->C has been traversed in other traversal processes. If the result is no, the target path A->C is recorded as having been traversed in the specified traversal process, and traversal continues to transaction C. When traversing to transaction C, since transaction C depends on transactions A and E, according to the depth-first traversal rule, transaction A can be considered the next transaction to be traversed. Since the target path C->A has not been traversed in other traversal processes, but has been recorded as having been traversed in the specified traversal process, it can be left unrecorded and traversal continues directly to transaction A, forming a loop A->C->A, which constitutes a distributed deadlock. When traversing to transaction C, C->E has been traversed in the specified traversal process, so traversal continues to transaction E. Transaction E has no dependent transactions, so the traversal ends.
[0125] Thus, one traversal starting with transaction B is complete. Through the depth-first traversal in this embodiment, distributed deadlocks are detected to the maximum extent possible when starting from transaction B. In this traversal process, the traversal process is specified as starting from transaction B.
[0126] (2) After starting from transaction B, transaction C can be selected as the current transaction. Starting from transaction C, since both transaction E and transaction A are transactions that transaction C depends on, according to the depth-first traversal rule, E can be selected as the next transaction to be traversed. It is then determined whether the target path C->E has been passed through in other traversal processes. If the result is yes, the current traversal process starting from transaction C can be terminated. In this traversal process, the traversal process is specified as the traversal process starting from transaction C.
[0127] (3) After starting from transaction C, you can start from transaction E. Transaction E has no dependent transactions and ends.
[0128] (4) After starting from transaction E, transaction A can be selected as the current transaction. Starting from transaction A, since transactions B, C, and D are all transactions that transaction A depends on, according to the depth-first traversal rule, D can be selected as the next transaction to be traversed. It is then determined whether the target path A->D has been passed through in other traversal processes. If the result is yes, the current traversal process starting from transaction A can be terminated. In this traversal process, the traversal process is specified as the traversal process starting from transaction A.
[0129] (5) After starting from transaction A, transaction D can be selected as the current transaction. Starting from transaction D, since transaction D depends on transaction C, and transaction C can be the next transaction to be traversed, the target path D->C is passed through in other traversal processes, and the current traversal process starting from transaction D can be ended. In this traversal process, the traversal process is the traversal process starting from transaction D. When transactions A, B, C, D, and E have all been traversed as current transactions, the entire traversal is completed. Through this embodiment, the repeated calculation process in the traversal process can be avoided to the greatest extent. In the prior art, if completing the entire traversal requires O*(n 2 The computational complexity of distributed deadlock detection is reduced from O*n times to O*n times using this embodiment.
[0130] As can be seen, this scheme detects whether an untraveled target path has been visited in other traversals and performs different operations based on different detection results. This avoids duplicate detection of the same loop and prevents missed detection of loops. Compared to existing technologies that require a complete traversal for each transaction, this scheme can significantly reduce computational overhead, thereby achieving fast and effective detection of distributed deadlocks.
[0131] Optionally, in another embodiment of the present invention, recording the target path as traversed during a specified traversal includes:
[0132] Set the tag information corresponding to the current transaction for the target path; wherein, the tag information corresponding to any transaction is used to indicate that the path is traversed when the transaction is the starting transaction;
[0133] The determination of whether the target path has been traversed in other traversal processes includes:
[0134] Check if the target path has any tag information corresponding to other transactions;
[0135] If so, it is determined that the target path has already been traversed in other traversal processes.
[0136] There are multiple ways to implement the tag information corresponding to the current transaction.
[0137] For example, each transaction corresponds to a specific piece of information, and different transactions correspond to different specific pieces of information; therefore, the tag information corresponding to the current transaction can be the specific information corresponding to that transaction. This specific information can be a specified numerical value, or a specified color identifier, etc.
[0138] For example, the target path can also be labeled with tags corresponding to the current transaction using a "coloring" method. Specifically, different colors are used to "color" the traversed paths. Different starting transactions "color" the paths during the traversal process with different colors; that is, different starting transactions correspond to different colors. When the target path is "colored," it indicates that the target path has been traversed. Further, the color of the target path is judged. If the color of the target path is different from the color corresponding to the current transaction, it indicates that the target path has been traversed in other traversal processes; if the color of the target path is the same as the color corresponding to the current transaction, it indicates that the target path has not been traversed in other traversal processes. The following section combines... Figure 6 The dependencies represented will be illustrated again by example:
[0139] like Figure 6 As shown, transactions A, B, C, D, E, and F depend on each other in sequence. Transaction F depends on transaction A. Transaction D also depends on transaction N. Transaction N depends on transaction F. Transaction P depends on transaction Q. Transaction Q depends on transaction N.
[0140] Taking transaction A as the current transaction as an example, the traversal process is explained. Transaction A depends on transaction B and needs to jump to transaction B. The target path is A->B. After determining that the target path A->B has not been traversed in other traversal processes, the label information corresponding to the current transaction, that is, the label information corresponding to transaction A, is set for the target path A->B.
[0141] After jumping to B, the traversal continues. Transaction B depends on transaction C, so a jump to transaction C is required. The target path is B->C. It is determined whether the target path B->C has already been traversed in other traversal processes. Specifically, the target path B->C is compared with the stored tag information. First, it is checked whether the stored tag information contains the target path B->C. If it does not exist, it means that the target path B->C has not been traversed. If the stored tag information contains the target path B->C, it is further determined whether the current transaction corresponding to the target path B->C in the stored tag information is the same as the current transaction in this traversal process. If they are the same, the traversal continues; otherwise, the traversal in this direction ends.
[0142] In this embodiment, by setting tag information corresponding to the current transaction for the target path, the target path is recorded as having been traversed during a specified traversal. Furthermore, by detecting whether the target path has tag information corresponding to other transactions, it can be determined whether the target path has been traversed in other traversal processes. By utilizing tag information, judgment and analysis can be performed simply and quickly, thereby ensuring rapid and effective detection of distributed deadlocks.
[0143] In another embodiment of the present invention, the tag information corresponding to the current transaction includes: the transaction identifier of the current transaction and a specified identifier, wherein the specified identifier is used to indicate that the path has been traversed;
[0144] The detection of whether the target path has tag information corresponding to other transactions includes:
[0145] Determine whether the target path has the specified identifier set;
[0146] If so, determine whether the transaction identifier set for the target path is the same as the transaction identifier of the current transaction. If they are the same, determine that the target path does not have tag information corresponding to other transactions; if they are different, determine that the target path has identifier information corresponding to other transactions.
[0147] If not, it is determined that the target path does not have tag information corresponding to other transactions.
[0148] For example, the specified identifier can be 0 or 1, or of course other identifiers. This embodiment of the invention does not limit this.
[0149] In this embodiment, a tag information containing the transaction identifier of the current transaction and a specified identifier is added to the path. This allows identification of whether the path has been traversed using the specified identifier, and identification of which transaction the path was traversed during its traversal. This implementation method allows for quick and convenient analysis of whether the target path has been traversed in other traversal processes. Furthermore, another embodiment of the present invention discloses a tag style for the tag information, which is: a path with an identifier corresponding to a transaction. For example,... Figure 6For example, during the traversal process with transaction A as the current transaction, the target path is A->B, and the label information set for the target path is A1->B1, where the letters A and B indicate a jump from transaction A to transaction B, and the Arabic numeral "1" corresponds to transaction A as the current transaction. During the traversal process with transaction B as the current transaction, the traversal path is A->B, and the label information set for the target path A->B can be A2->B2; and so on. With F as the current transaction, the target path is A->B, and the label information set for the target path A->B can be A6->B6. The symbols corresponding to the current transaction are not limited to Arabic numerals; they can be any other symbols, as long as the symbol forms a one-to-one mapping relationship with each current transaction. Using the label style of this embodiment, given that the target path has label information, it is only necessary to determine whether the target path has been traversed in other traversal processes by judging whether the identifier in the target path's label information matches the identifier corresponding to the current transaction. This saves system computing power to a certain extent and improves system detection efficiency.
[0150] Another embodiment of the present invention also provides a distributed deadlock detection device, such as... Figure 7 The distributed deadlock detection device includes:
[0151] The acquisition module 710 is used to acquire the dependency relationships between various transactions in a distributed system;
[0152] The selection module 720 is used to select, from among all transactions, a transaction that was not the starting transaction and to be the current transaction;
[0153] The first processing module 730 is configured to traverse transactions according to the dependencies, starting from the current transaction. Each time a transaction is encountered, it determines whether the target path has already been traversed in other traversal processes. The target path is the path from the current transaction to the transactions it depends on, and the other traversal processes are those that use other transactions as starting transactions. The second processing module 740 is configured to, if the determination result is yes, trigger the selection module to select transactions that were not used as starting transactions from among the various transactions; otherwise, after recording the target path as having been traversed in the specified traversal process, continue traversing until the traversal is completed, then trigger the selection module to select transactions that were not used as starting transactions from among the various transactions. The specified traversal process is a traversal process that uses the current transaction as the starting transaction.
[0154] The detection module 750 is used to determine a distributed deadlock if the path traversed during the transaction traversal forms a loop.
[0155] Optionally, the second processing module records the target path as having been traversed during the specified traversal in the following ways:
[0156] Set the tag information corresponding to the current transaction for the target path; wherein, the tag information corresponding to any transaction is used to indicate that the path is traversed when the transaction is the starting transaction;
[0157] The first processing module determines whether the target path has been traversed in other traversal processes, including:
[0158] Check if the target path has any tag information corresponding to other transactions;
[0159] If so, it is determined that the target path has already been traversed in other traversal processes.
[0160] Optionally, the tag information corresponding to the current transaction includes: the transaction identifier of the current transaction and a specified identifier, wherein the specified identifier is used to indicate that the path has been traversed;
[0161] The first processing module detects whether the target path has tag information corresponding to other transactions, including:
[0162] Determine whether the target path has the specified identifier set;
[0163] If so, determine whether the transaction identifier set for the target path is the same as the transaction identifier of the current transaction. If they are the same, determine that the target path does not have tag information corresponding to other transactions; if they are different, determine that the target path has identifier information corresponding to other transactions.
[0164] If not, it is determined that the target path does not have any tag information corresponding to other transactions. Furthermore, the dependency relationships are stored in the form of an adjacency list or adjacency matrix.
[0165] The first processing module takes the current transaction as the starting transaction and performs transaction traversal according to the dependency relationship, including: taking the current transaction as the starting transaction and performing transaction traversal according to the dependency relationship represented by the adjacency list or adjacency matrix.
[0166] Optionally, the transaction traversal method is a depth-first traversal method.
[0167] Optionally, the acquisition module is specifically used for:
[0168] Obtain lock wait information for each branch transaction reported by each shard node in the distributed system, for each transaction's branch transaction;
[0169] Based on the acquired lock wait information, the dependencies between various transactions are determined.
[0170] This invention also provides an electronic device, such as... Figure 8 As shown, it includes a processor 801, a communication interface 802, a memory 803, and a communication bus 804. The processor 801, communication interface 802, and memory 803 communicate with each other via the communication bus 804.
[0171] Memory 803 is used to store computer programs;
[0172] When the processor 801 executes the program stored in the memory 803, it implements the steps of any of the distributed deadlock detection methods in the above embodiments.
[0173] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0174] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0175] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0176] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0177] In another embodiment of the present invention, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described distributed deadlock detection methods.
[0178] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the distributed deadlock detection methods described above.
[0179] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0180] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0181] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0182] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A distributed deadlock detection method, characterized in that, The method includes: To obtain the dependencies between various transactions in a distributed system; From all transactions, select the transaction that was not the starting transaction and use it as the current transaction; Starting from the current transaction, transactions are traversed according to the dependencies. Whenever a transaction is traversed, it is determined whether the target path has been traversed in other traversal processes. The target path is the path from the current transaction to the transactions that the current transaction depends on, and the other traversal processes are traversal processes that start from other transactions. If the judgment result is yes, return to the process of selecting a transaction that was not used as the starting transaction from each transaction; otherwise, after recording the target path as having been traversed in the specified traversal process, continue traversing until the traversal is completed, and then return to the process of selecting a transaction that was not used as the starting transaction from each transaction; wherein, the specified traversal process is a traversal process with the current transaction as the starting transaction. Furthermore, if a path is traversed during the transaction traversal and forms a loop, the loop is determined to be a distributed deadlock.
2. The method according to claim 1, characterized in that, Recording the target path as traversed during a specified traversal includes: Set the tag information corresponding to the current transaction for the target path; wherein, the tag information corresponding to any transaction is used to indicate that the path is traversed when the transaction is the starting transaction; The determination of whether the target path has been traversed in other traversal processes includes: Check if the target path has tag information corresponding to other transactions; If so, it is determined that the target path has already been traversed in other traversal processes.
3. The method according to claim 2, characterized in that, The tag information corresponding to the current transaction includes: the transaction identifier of the current transaction and a specified identifier, wherein the specified identifier is used to indicate that the path has been traversed; The detection of whether the target path has tag information corresponding to other transactions includes: Determine whether the target path has the specified identifier set; If so, determine whether the transaction identifier set for the target path is the same as the transaction identifier of the current transaction. If they are the same, determine that the target path does not have tag information corresponding to other transactions; if they are different, determine that the target path has identifier information corresponding to other transactions. If not, it is determined that the target path does not have tag information corresponding to other transactions.
4. The method according to any one of claims 1-3, characterized in that, The dependencies are stored in the form of an adjacency list or an adjacency matrix; The step of taking the current transaction as the starting transaction and performing transaction traversal according to the dependency relationship includes: taking the current transaction as the starting transaction and performing transaction traversal according to the dependency relationship represented by the adjacency list or adjacency matrix.
5. The method according to any one of claims 1-3, characterized in that, The transaction traversal method is a depth-first traversal method.
6. The method according to any one of claims 1-3, characterized in that, The process of obtaining the dependencies between various transactions in a distributed system includes: Obtain lock wait information for each branch transaction reported by each shard node in the distributed system, for each transaction's branch transaction; Based on the acquired lock wait information, the dependencies between various transactions are determined.
7. A distributed deadlock detection device, characterized in that, include: The acquisition module is used to acquire the dependencies between various transactions in a distributed system; The selection module is used to select a transaction that was not the starting transaction from among all transactions and to use it as the current transaction. The first processing module is used to traverse transactions according to the dependency relationship starting from the current transaction. Whenever a transaction is traversed, it is determined whether the target path has been traversed in other traversal processes. The target path is the path from the current transaction to the transaction that the current transaction depends on, and the other traversal processes are traversal processes that start from other transactions. The second processing module is configured to, if the judgment result is yes, trigger the selection module to select a transaction that was not used as a starting transaction from each transaction; otherwise, after recording the target path as having been traversed in the specified traversal process, continue traversing until the traversal is completed, and then trigger the selection module to select a transaction that was not used as a starting transaction from each transaction; wherein, the specified traversal process is a traversal process with the current transaction as the starting transaction; The detection module is used to determine a distributed deadlock if the path traversed during transaction traversal forms a loop.
8. The apparatus according to claim 7, characterized in that, The second processing module records the target path as being traversed during a specified traversal in the following ways: Set the tag information corresponding to the current transaction for the target path; wherein, the tag information corresponding to any transaction is used to indicate that the path is traversed when the transaction is the starting transaction; The first processing module determines whether the target path has been traversed in other traversal processes, including: Check if the target path has tag information corresponding to other transactions; If so, it is determined that the target path has already been traversed in other traversal processes.
9. The apparatus according to claim 8, characterized in that, The tag information corresponding to the current transaction includes: the transaction identifier of the current transaction and a specified identifier, wherein the specified identifier is used to indicate that the path has been traversed; The first processing module detects whether the target path has tag information corresponding to other transactions, including: Determine whether the target path has the specified identifier set; If so, determine whether the transaction identifier set for the target path is the same as the transaction identifier of the current transaction. If they are the same, determine that the target path does not have tag information corresponding to other transactions; if they are different, determine that the target path has identifier information corresponding to other transactions. If not, it is determined that the target path does not have tag information corresponding to other transactions.
10. The apparatus according to any one of claims 7-9, characterized in that, The dependencies are stored in the form of an adjacency list or an adjacency matrix; The first processing module takes the current transaction as the starting transaction and performs transaction traversal according to the dependency relationship, including: taking the current transaction as the starting transaction and performing transaction traversal according to the dependency relationship represented by the adjacency list or adjacency matrix.
11. The apparatus according to any one of claims 7-9, characterized in that, The transaction traversal method is a depth-first traversal method.
12. The apparatus according to any one of claims 7-9, characterized in that, The acquisition module is specifically used for: Obtain lock wait information for each branch transaction reported by each shard node in the distributed system, for each transaction's branch transaction; Based on the acquired lock wait information, the dependencies between various transactions are determined.
13. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-6.
14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-6.