Deadlock processing method and apparatus, computer device, and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2022-08-26
- Publication Date
- 2026-08-07
AI Technical Summary
[0004]基于此,有必要针对无法及时、有效地解决死锁的技术问题,提供一种死锁处理方法、装置、计算机设备、计算机可读存储介质和计算机程序产品
[0046]上述死锁处理方法、装置、计算机设备、存储介质和计算机程序产品,通过数据库中发生死锁的死锁信息,在预设的场景库中匹配最合适的死锁处理方式,若场景库中匹配不到,则根据死锁信息中死锁的特征信息从死锁场景决策树中匹配处理代价小的处理方式,完成对死锁的处理,达到了发生死锁时能够及时、有效,并且以更小的代价解决死锁的效果,避免事务和资源长期处于不可用状态。
Smart Images

Figure CN115373864B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of artificial intelligence and intelligent operation and maintenance technology, and in particular to a deadlock handling method, apparatus, computer equipment, storage medium and computer program product. Background Technology
[0002] With the development of computer technology, the computing power of computer processors is becoming stronger and stronger, and computers can process more and more transactions concurrently. The concurrency of multiple transactions brings about the deadlock problem in databases, which leads to various deadlock handling methods, such as setting resource priorities or randomly forcing a transaction to release locked resources.
[0003] However, in real-world business scenarios, the causes of deadlocks are often quite complex. Current deadlock handling methods do not consider the cost of resolving deadlocks and cannot solve the problem in a timely and effective manner, resulting in transactions remaining unavailable for extended periods. Summary of the Invention
[0004] Therefore, it is necessary to provide a deadlock handling method, apparatus, computer equipment, computer-readable storage medium, and computer program product to address the technical problem of the inability to resolve deadlocks in a timely and effective manner.
[0005] Firstly, this application provides a deadlock handling method. The method includes:
[0006] If a database deadlock is detected, the deadlock information of the database is obtained; the deadlock information includes the multiple transactions that caused the deadlock and the wait information between the multiple transactions;
[0007] Based on the deadlock information, a target deadlock scenario and a first processing method corresponding to the target deadlock scenario are determined from a pre-established deadlock scenario library, and the deadlock information is processed according to the first processing method.
[0008] If the target deadlock scenario is not identified from the deadlock scenario library, the deadlock information is used to query the pre-built deadlock scenario decision tree to obtain the second processing method corresponding to the deadlock information, and the deadlock information is processed according to the second processing method.
[0009] In one embodiment, the deadlock information includes a transaction wait graph, which is a directed graph representing the wait relationships between transactions;
[0010] The step of determining the target deadlock scenario and the corresponding first processing method from a pre-established deadlock scenario library based on the deadlock information includes:
[0011] Deadlock loop information is identified from the transaction wait graph included in the deadlock information; the deadlock loop information represents the loop information formed by at least two transactions that caused the deadlock, and each transaction in the deadlock loop information is waiting for the resources occupied by the next transaction;
[0012] Based on the deadlock loop information, a target deadlock scenario and a first processing method corresponding to the target deadlock scenario are determined from the pre-established deadlock scenario library.
[0013] In one embodiment, the step of querying a pre-built deadlock scenario decision tree based on the deadlock information to obtain the second processing method corresponding to the deadlock information includes:
[0014] Based on the deadlock information, multiple deadlock feature information corresponding to the target transaction among the multiple transactions that caused the deadlock is obtained; the target transaction represents any one of the multiple transactions that caused the deadlock.
[0015] The deadlock scenario decision tree is sequentially searched according to the importance of each deadlock feature information from high to low to obtain the processing method for the target transaction, which serves as the second processing method corresponding to the deadlock information.
[0016] In one embodiment, obtaining multiple deadlock feature information corresponding to the target transaction among the multiple transactions causing the deadlock based on the deadlock information includes:
[0017] Based on the deadlock information, the number of waiting transactions, execution time, remaining execution time, type of occupied resource, and processing level value corresponding to the resources occupied by the target transaction are obtained; the number of waiting transactions represents the number of transactions waiting to use the resources occupied by the target transaction, and the processing level value represents the degree to which forcibly releasing the resources occupied by the target transaction helps resolve the deadlock problem;
[0018] The number of waiting transactions corresponding to the resources occupied by the target transaction, the execution time, the remaining execution time, the type of occupied resources, and the processing level value are determined as the multiple deadlock feature information.
[0019] In one embodiment, the processing level value is determined in the following manner:
[0020] Based on the deadlock information, obtain the number of resources occupied by the target transaction and the preset empirical coefficient;
[0021] The processing level value is obtained based on the number of waiting transactions corresponding to the resources occupied by the transaction, the remaining execution time, the number of resources occupied by the transaction, and the empirical coefficient.
[0022] In one embodiment, the step of sequentially searching the deadlock scenario decision tree according to the importance of each deadlock feature information from high to low, to obtain the processing method for the target transaction, as the second processing method corresponding to the deadlock information, includes:
[0023] Determine the current deadlock characteristics;
[0024] If the current deadlock feature information meets the judgment condition corresponding to the current deadlock feature information, then the second processing method is determined based on the current deadlock feature information;
[0025] If the current deadlock feature information does not meet the judgment condition corresponding to the current deadlock feature information, then the next deadlock feature information with a lower importance than the current deadlock feature information is taken as the new deadlock feature information, and the second processing method is determined based on the new deadlock feature information.
[0026] In one embodiment, obtaining the deadlock information of the database includes:
[0027] Obtain the execution status of each transaction and the resource information occupied by each transaction in the database at the deadlock point;
[0028] Based on the execution status of each transaction and the resource information occupied by each transaction, a transaction wait graph corresponding to the deadlock point in the database is generated.
[0029] The deadlock information is obtained based on the transaction wait graph, the execution status of each transaction, and the resource information occupied by each transaction.
[0030] Secondly, this application also provides a deadlock handling apparatus. The apparatus includes:
[0031] The deadlock acquisition module is used to acquire deadlock information of the database when a deadlock is detected; the deadlock information includes multiple transactions that caused the deadlock and the waiting information between the multiple transactions;
[0032] The first processing module is used to determine a target deadlock scenario and a first processing method corresponding to the target deadlock scenario from a pre-established deadlock scenario library based on the deadlock information, and process the deadlock information according to the first processing method.
[0033] The second processing module is used to, when no target deadlock scenario is determined from the deadlock scenario library, query a pre-built deadlock scenario decision tree based on the deadlock information to obtain a second processing method corresponding to the deadlock information, and process the deadlock information according to the second processing method.
[0034] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0035] If a database deadlock is detected, the deadlock information of the database is obtained; the deadlock information includes the multiple transactions that caused the deadlock and the wait information between the multiple transactions;
[0036] Based on the deadlock information, a target deadlock scenario and a first processing method corresponding to the target deadlock scenario are determined from a pre-established deadlock scenario library, and the deadlock information is processed according to the first processing method.
[0037] If the target deadlock scenario is not identified from the deadlock scenario library, the deadlock information is used to query the pre-built deadlock scenario decision tree to obtain the second processing method corresponding to the deadlock information, and the deadlock information is processed according to the second processing method.
[0038] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0039] If a database deadlock is detected, the deadlock information of the database is obtained; the deadlock information includes the multiple transactions that caused the deadlock and the wait information between the multiple transactions;
[0040] Based on the deadlock information, a target deadlock scenario and a first processing method corresponding to the target deadlock scenario are determined from a pre-established deadlock scenario library, and the deadlock information is processed according to the first processing method.
[0041] If the target deadlock scenario is not identified from the deadlock scenario library, the deadlock information is used to query the pre-built deadlock scenario decision tree to obtain the second processing method corresponding to the deadlock information, and the deadlock information is processed according to the second processing method.
[0042] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0043] If a database deadlock is detected, the deadlock information of the database is obtained; the deadlock information includes the multiple transactions that caused the deadlock and the wait information between the multiple transactions;
[0044] Based on the deadlock information, a target deadlock scenario and a first processing method corresponding to the target deadlock scenario are determined from a pre-established deadlock scenario library, and the deadlock information is processed according to the first processing method.
[0045] If the target deadlock scenario is not identified from the deadlock scenario library, the deadlock information is used to query the pre-built deadlock scenario decision tree to obtain the second processing method corresponding to the deadlock information, and the deadlock information is processed according to the second processing method.
[0046] The aforementioned deadlock handling methods, devices, computer equipment, storage media, and computer program products use deadlock information from a database to match the most suitable deadlock handling method from a preset scenario library. If no match is found in the scenario library, a low-cost handling method is matched from the deadlock scenario decision tree based on the deadlock feature information in the deadlock information to complete the deadlock handling. This achieves the effect of resolving deadlocks in a timely and effective manner with lower costs, avoiding transactions and resources from being unavailable for a long time. Attached Figure Description
[0047] Figure 1 This is a flowchart illustrating a deadlock handling method in one embodiment;
[0048] Figure 2 This is a flowchart illustrating a deadlock handling method in another embodiment;
[0049] Figure 3 This is a flowchart illustrating the deadlock handling method of this application executed by the system in one embodiment;
[0050] Figure 4 Here is an example diagram of a transaction wait graph in one embodiment;
[0051] Figure 5 Here is an example diagram of a decision tree for a deadlock scenario in one embodiment;
[0052] Figure 6 This is a structural block diagram of a deadlock handling device in one embodiment;
[0053] Figure 7 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0054] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0055] In one embodiment, such as Figure 1As shown, a deadlock handling method is provided. This embodiment illustrates the method applied to a terminal, but it is understood that the method can also be applied to a server, and to a system including both a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0056] Step 101: If a deadlock is detected in the database, obtain the deadlock information of the database; the deadlock information includes the multiple transactions that caused the deadlock and the waiting information between the multiple transactions.
[0057] Among them, the wait information between multiple transactions represents information about resources that a transaction is waiting for to be held by other transactions.
[0058] It should be noted that the execution of a transaction requires the acquisition of the corresponding resource. If the corresponding resource has already been acquired and occupied by another transaction, the transaction needs to wait for the corresponding resource to be released before acquiring and occupying it.
[0059] Specifically, after a database deadlock is detected by other systems or methods, the deadlock identifier in the database is obtained, and deadlock information is retrieved based on the deadlock identifier (the corresponding deadlock scenario can be fully reproduced based on the deadlock information). For example, after obtaining the deadlock identifier in the database, the transaction identifier causing the deadlock is found, and the execution status of the transaction is obtained (i.e., the transaction execution time, the resources occupied by the transaction, and the resources the transaction is waiting for, etc.). Simultaneously, data information in the database is obtained (i.e., resource information, including resource identifiers, their occupied status, and the identifiers of the occupying transactions, etc.). Deadlock information is composed of the transaction identifier, the transaction execution status, and the data information.
[0060] Step 102: Based on the deadlock information, determine the target deadlock scenario and the first processing method corresponding to the target deadlock scenario from the pre-established deadlock scenario library, and process the deadlock information according to the first processing method.
[0061] Among them, the handling methods in the deadlock scenario library can be the best handling methods obtained by users based on statistics of historical deadlock scenarios.
[0062] Specifically, based on the feature information of the deadlock as expressed in the deadlock information, the deadlock scenario database is traversed and searched to match the target deadlock scenario. According to the mapping relationship between the target deadlock scenario and the handling method, the corresponding first handling method is found. Based on the obtained first handling method, the deadlock in the current database is handled to resolve the deadlock problem. For example, deadlock information can be expressed by image information, which can be a transaction wait graph generated based on the deadlock information. Image recognition technology is used to match the target deadlock scenario that matches the image information features from the deadlock scenario database.
[0063] Step 103: If the target deadlock scenario is not identified from the deadlock scenario library, query the pre-built deadlock scenario decision tree based on the deadlock information to obtain the second processing method corresponding to the deadlock information, and process the deadlock information according to the second processing method.
[0064] Among them, the decision tree for deadlock scenarios can be the decision steps trained by the user based on historical deadlock scenarios, or it can be the decision steps directly set by the user.
[0065] Specifically, if the target deadlock scenario and its corresponding first handling method cannot be found in the deadlock scenario database, then based on the feature information in the deadlock information, each feature information is matched with a corresponding second handling method from the decision tree in descending order of importance. Based on the obtained second handling method, the deadlock in the current database is handled, resolving the deadlock problem. For example, the feature information in the deadlock information used to match the second handling method in the decision tree could be the transaction's execution time, the type of resources occupied by the transaction, etc., matched with the corresponding second handling method in descending order of importance. If the current feature information cannot be matched, the next feature information is used for matching until a second handling method is obtained.
[0066] In the aforementioned deadlock handling method, deadlock information from the database is used to match the most suitable deadlock handling method from a pre-defined scenario library. If no match is found in the scenario library, the method with the lowest processing cost is selected from the decision tree based on the deadlock's characteristic information, ranked from highest to lowest importance, to resolve the deadlock. This achieves timely and effective deadlock resolution at a lower cost, preventing transactions and resources from remaining unavailable for extended periods.
[0067] In one embodiment, step 101 above, which obtains deadlock information from the database, can be further implemented through the following steps:
[0068] Step 1: Obtain the execution status of each transaction and the resource information occupied by each transaction at the point of deadlock in the database.
[0069] Step 2: Based on the execution status of each transaction and the resource information occupied by each transaction, generate a transaction wait graph corresponding to the deadlock point in the database.
[0070] Step 3: Based on the transaction wait graph, the execution status of each transaction, and the resource information occupied by each transaction, deadlock information is obtained.
[0071] The transaction wait graph is a directed graph representing the waiting relationships between transactions, which can express the resources already occupied by the transaction, the resources being waited for, and the state information of the resources. Furthermore, if the directed graph of waiting relationships between transactions forms a closed loop, it represents a deadlock loop in a deadlock scenario.
[0072] As an example, when the server detects a database deadlock, it saves the information at the current deadlock point in time. This information includes the execution status of each transaction (including the transaction's execution time and remaining execution time) and the resource information used by each transaction (including information on resources already used and resources the transaction is waiting for, such as resource identifiers and types). Based on this information, the current deadlock scenario can be reproduced. A corresponding transaction wait graph is generated, representing the relationships between transactions based on resources. The transaction wait graph, the execution status of each transaction, and the resource information used by each transaction together constitute the deadlock information for the current deadlock.
[0073] In this embodiment, by saving the state information of transactions and resources at the current point in time when deadlock occurs, the deadlock information can be obtained by forming a corresponding transaction wait graph. Subsequently, the deadlock scenario can be matched according to the deadlock information to obtain a handling method, thereby handling the deadlock problem in a timely and effective manner.
[0074] In one embodiment, the deadlock information includes a transaction wait graph, which is a directed graph representing the waiting relationships between transactions; step 102 above, which determines the target deadlock scenario and the corresponding first processing method from a pre-established deadlock scenario library based on the deadlock information, can also be implemented through the following steps:
[0075] Step 1: Identify deadlock loop information from the transaction wait graph included in the deadlock information; deadlock loop information represents the loop information formed by at least two transactions that caused the deadlock, and each transaction in the deadlock loop information is waiting for the resources held by the next transaction;
[0076] Step 2: Based on the deadlock loop information, determine the target deadlock scenario and the corresponding first handling method from the pre-established deadlock scenario library.
[0077] Among them, a deadlock loop is a directed loop formed in the transaction wait graph by the waiting relationships between transactions that cause deadlock.
[0078] As an example, the server identifies the deadlock loop in the transaction wait graph from the deadlock information, extracts the deadlock loop's feature information as an image, matches the target deadlock scenario that matches the feature information from a pre-established deadlock scenario library, and obtains the corresponding first processing method based on the mapping relationship between the target scenario information and the first processing method.
[0079] In this embodiment, deadlock loop information in the transaction wait graph is used to retrieve matching deadlock scenarios and corresponding second processing methods from the deadlock scenario database using image recognition technology. This achieves the goal of resolving deadlock problems in a timely and efficient manner.
[0080] In one embodiment, step 103 above queries a pre-built deadlock scenario decision tree based on the deadlock information to obtain the second processing method corresponding to the deadlock information. Specifically, this can also be achieved through the following steps:
[0081] Step 1: Based on the deadlock information, obtain multiple deadlock characteristic information corresponding to the target transaction among the multiple transactions that caused the deadlock; the target transaction refers to any one of the multiple transactions that caused the deadlock.
[0082] Step 2: According to the order of importance of each deadlock feature information from high to low, sequentially search the deadlock scenario decision tree to obtain the processing method for the target transaction, which serves as the second processing method corresponding to the deadlock information.
[0083] Among them, deadlock feature information can be used to fully reproduce deadlock scenarios.
[0084] As an example, the server, based on deadlock information, obtains multiple deadlock feature information corresponding to any one of the multiple transactions causing the deadlock. These deadlock feature information includes the type of resources used by the transaction and the transaction's execution time, among others. Based on the importance of each deadlock feature information, from highest to lowest, the server sequentially matches the corresponding handling method using a scenario decision tree. If no match is found for the current deadlock feature information, the matching continues with the next deadlock feature information until a matching handling method is found. The obtained handling method is then used as the second handling method for the current deadlock information.
[0085] In this embodiment, based on the deadlock feature information of any transaction that causes the deadlock, the corresponding second processing method is matched from the scenario decision tree, which can solve the deadlock problem in a timely, effective and less costly manner.
[0086] In one embodiment, the above steps, based on deadlock information, obtain multiple deadlock feature information corresponding to the target transaction among the multiple transactions causing the deadlock. This can be further implemented through the following steps:
[0087] Step 1: Based on the deadlock information, obtain the number of waiting transactions, execution time, remaining execution time, type of resource occupied, and processing level value corresponding to the resources occupied by the target transaction; the number of waiting transactions represents the number of transactions waiting to use the resources occupied by the target transaction, and the processing level value represents the degree to which forcibly releasing the resources occupied by the target transaction helps resolve the deadlock problem;
[0088] Step two: The number of waiting transactions, execution time, remaining execution time, type of resource occupied, and processing level value corresponding to the resources occupied by the target transaction are determined as multiple deadlock characteristic information.
[0089] The resource types include core resources and non-core resources. The resource type is determined based on the specific scenario.
[0090] As an example, the server determines multiple deadlock characteristics based on the number of waiting transactions corresponding to the resources occupied by the target transaction, the execution time (determined by different scenarios to see if the execution time is too long), the remaining execution time, the type of resource occupied (whether it is a core resource depending on different scenarios), and the processing level value.
[0091] In this embodiment, based on the different deadlock feature information of any transaction that causes deadlock, the second processing method with the lowest deadlock cost can be matched from the scenario decision tree, so as to achieve the goal of solving the deadlock problem in a timely, effective and less costly manner.
[0092] In one embodiment, the above-mentioned processing level value can also be determined in the following manner:
[0093] Step 1: Based on the deadlock information, obtain the number of resources occupied by the target transaction and the preset empirical coefficient;
[0094] Step two: Based on the number of waiting transactions corresponding to the resources occupied by the transaction, the remaining execution time, the number of resources occupied by the transaction, and the empirical coefficient, obtain the processing level value.
[0095] The experience coefficient is determined based on the specific tasks in different scenarios and is preset by the user.
[0096] As an example, the server can use the formula The processing level value is calculated, where D(R) represents the processing level value, R represents the total resources occupied by the target transaction, n is the number of waiting transactions for resource R, AVG(T)-t is the remaining execution time of the transaction, T is the execution time of all transactions from start to finish, t is the remaining execution time of the target transaction, X is the number of table record rows occupied by R, and k is an empirical coefficient.
[0097] In this embodiment, the processing degree value is calculated by using the deadlock feature information of the target transaction. Based on the processing degree value, the second processing method with the lowest processing cost can be matched from the decision tree, thereby resolving the deadlock problem in a timely and cost-effective manner.
[0098] In one embodiment, the above steps, in descending order of importance of each deadlock feature, sequentially search the deadlock scenario decision tree to obtain the processing method for the target transaction, which serves as the second processing method corresponding to the deadlock information. This can also be achieved through the following steps:
[0099] Step 1: Determine the current deadlock characteristics;
[0100] Step 2: If the current deadlock feature information meets the judgment condition corresponding to the current deadlock feature information, then determine the second processing method based on the current deadlock feature information;
[0101] Step 3: If the current deadlock feature information does not meet the judgment condition corresponding to the current deadlock feature information, then the next deadlock feature information with a lower importance than the current deadlock feature information is taken as the new deadlock feature information, and the second processing method is determined based on the new deadlock feature information.
[0102] As an example, after the server obtains the deadlock feature information of the target transaction, it selects deadlock feature information from high to low according to the importance of the deadlock feature information, and sequentially matches the corresponding second processing method from the deadlock decision tree. If the current deadlock feature information cannot match the corresponding second processing method, the next deadlock feature information is used to continue matching until the corresponding second processing method is obtained.
[0103] In this embodiment, by matching the second processing method according to the order of importance of deadlock feature information, the deadlock problem can be solved in a timely manner and at a lower cost.
[0104] In another embodiment, such as Figure 2 The diagram shows a complete flowchart of a deadlock handling method. In this embodiment, the method includes the following steps:
[0105] Step 201: If a database deadlock is detected, obtain the execution status of each transaction and the resource information occupied by each transaction at the point of deadlock.
[0106] Step 202: Generate a transaction wait graph corresponding to the deadlock point in the database based on the execution status of each transaction and the resource information occupied by each transaction; obtain deadlock information based on the transaction wait graph, the execution status of each transaction, and the resource information occupied by each transaction.
[0107] Step 203: Identify deadlock loop information from the transaction wait graph included in the deadlock information.
[0108] Step 204: Based on the deadlock loop information, determine the target deadlock scenario and the first processing method corresponding to the target deadlock scenario from the pre-established deadlock scenario library.
[0109] Step 205: Based on the deadlock information, obtain the number of waiting transactions, execution time, remaining execution time, type of occupied resources, number of occupied resources, and preset empirical coefficients corresponding to the resources occupied by the target transaction.
[0110] Step 206: Based on the number of waiting transactions corresponding to the resources occupied by the transaction, the remaining execution time, the number of resources occupied by the transaction, and the empirical coefficient, obtain the processing level value.
[0111] Step 207: The number of waiting transactions, execution time, remaining execution time, type of resource occupied, and processing level value corresponding to the resources occupied by the target transaction are determined as multiple deadlock characteristic information.
[0112] Step 208: Search the deadlock scenario decision tree sequentially according to the importance of each deadlock feature information from high to low, and obtain the processing method for the target transaction, which is used as the second processing method corresponding to the deadlock information.
[0113] As an example, after detecting a deadlock in the database, the server retrieves the execution status and resource information of each transaction at the deadlock point in time. The transaction execution status includes the transaction's execution time and the resources it uses, while the resource information includes the resource's identifier and type. Based on the execution status and resource information of each transaction, a transaction wait graph corresponding to the deadlock point is generated. This transaction wait graph is a directed graph representing the waiting relationships between transactions, expressing the resources used, the resources being waited for, and the resource status information. Furthermore, if the directed graph of waiting relationships between transactions forms a closed loop, it represents a deadlock loop in the deadlock scenario. Based on the transaction wait graph, the execution status of each transaction, and the resource information used by each transaction, deadlock information is obtained. The server identifies the deadlock loop information from the transaction wait graph, extracts features from the deadlock loop using image recognition technology, determines the target deadlock scenario and its corresponding first processing method from a pre-established deadlock scenario library, and resolves the deadlock problem according to the first processing method. If no matching target deadlock scenario and corresponding first-line handling method can be found, then based on the deadlock information, the following are obtained: the number of waiting transactions corresponding to the resources occupied by the target transaction (representing the number of transactions waiting to use the resources occupied by the target transaction), the execution time, the remaining execution time, the type of occupied resource, the number of occupied resources, and a preset empirical coefficient. The empirical coefficient is pre-set based on different transactions in different scenarios. Then, based on the number of waiting transactions corresponding to the resources occupied by the transaction, the remaining execution time, the number of resources occupied by the transaction, and the empirical coefficient, a handling degree value is obtained. This handling degree value indicates the degree to which forcibly releasing the resources occupied by the target transaction helps resolve the deadlock problem. The number of waiting transactions, execution time, remaining execution time, resource type, and processing level corresponding to the resources occupied by the target transaction are identified as multiple deadlock characteristics. These characteristics are then sequentially searched in a deadlock scenario decision tree, ranked from highest to lowest importance, to obtain a second handling method for the target transaction. Specifically, the current deadlock characteristic is determined. If the current deadlock characteristic meets the corresponding judgment criteria, the second handling method is determined based on it. If the current deadlock characteristic does not meet the judgment criteria, the next deadlock characteristic with lower importance is taken as the new deadlock characteristic, and the second handling method is determined based on the new deadlock characteristic. The deadlock problem is then resolved using the obtained second handling method.
[0114] In this embodiment, deadlock information from the database is used to match the most suitable deadlock handling method from a preset scenario library. If no match is found in the scenario library, a low-cost handling method is selected from the decision tree based on the deadlock characteristics in the deadlock information to resolve the deadlock. This achieves timely and effective deadlock resolution at a lower cost, preventing transactions and resources from remaining unavailable for extended periods.
[0115] To facilitate understanding of the embodiments of this application by those skilled in the art, the following will use a system providing the deadlock handling method of this application as an example, and describe the application in conjunction with specific examples in the accompanying drawings. The steps of this system executing the deadlock handling method of this application are as follows: Figure 3 As shown, it includes:
[0116] Step 301: A deadlock problem was detected in the database.
[0117] Step 302: Record the detected deadlock scenarios.
[0118] Step 303: Match deadlock scenario library.
[0119] Step 304: Determine if a deadlock scenario is matched.
[0120] Step 305: If a deadlock scenario is matched, resolve the deadlock according to the handling method corresponding to the matched deadlock scenario.
[0121] Step 306: If no deadlock scenario is found, then match the deadlock scenario decision tree.
[0122] Step 307: Execute the final deadlock resolution according to the decision tree sequence of the deadlock scenario.
[0123] In specific implementations, the server records deadlock scenario information, including the process execution status and resource information at that point in time, and also includes data generated based on the process execution status and resource information, such as... Figure 4 The transaction wait graph shown is illustrated, where solid lines represent resources occupied by transactions, and dashed lines represent resources being waited for. Resources can be rows of data from tables in a database. Further, based on the transaction wait graph, features are extracted using image recognition technology, and the corresponding target deadlock scenario and first processing method are matched from a deadlock scenario library. The deadlock scenario library pre-determines the optimal processing method for each deadlock scenario through historical deadlock scenario statistics, and the deadlock scenarios are stored in the deadlock scenario library in the form of a transaction wait graph. When a target deadlock scenario cannot be matched in the deadlock scenario library, the corresponding second processing step is matched from a pre-set deadlock decision tree based on the deadlock feature information in the deadlock scenario information. After matching through the decision tree, a method to successfully resolve the deadlock will definitely be found. The deadlock decision tree is as follows: Figure 5 shown. Specifically,
[0124] Rule 501: Determine the number of waiting transactions (i.e., the number of transactions waiting to use the resources occupied by the target transaction, which can be obtained from the transaction wait graph). If the number is equal to 1, proceed to the left subtree; if it is greater than 1, proceed to the right subtree.
[0125] Rule 502: After entering the left subtree, determine the order in which the target transaction occupied the resource. If the resource was occupied first, recommit or roll back the target transaction to release the resource lock; if the resource was occupied later, notify the system to forcibly release the transaction that occupied the resource first.
[0126] Rule 503: After entering the right subtree, determine whether core resources are occupied (the criteria for determining core resources vary depending on the scenario). If not, resubmit or roll back the target transaction to release the resources; if so, enter the right subtree.
[0127] Rule 504: After entering the right subtree, determine if it is a long transaction (a long transaction is a transaction that has been executed for too long; the criteria for judgment may vary depending on the scenario). If not, enter the left subtree; if yes, enter the right subtree.
[0128] Rule 505: After entering the left subtree, increase the experience coefficient k and use the formula to calculate the processing degree value to obtain D(R). When D(R) is greater than 1, notify the system to forcibly release the transaction that has occupied the resource; otherwise, recommit or roll back the target transaction to release the resource lock.
[0129] Rule 506: After entering the right subtree, use the formula to calculate the processing degree value to obtain D(R). If D(R) is greater than or equal to 1, notify the system to forcibly release the transaction that has occupied the resources; otherwise, recommit or roll back the target transaction to release the resources.
[0130] The treatment level value can be expressed by the formula. The calculations show that D(R) represents the processing level value, R represents the total resources occupied by the target transaction, n is the number of waiting transactions for resource R, AVG(T)-t is the remaining execution time of the transaction, T is the execution time of all transactions from start to finish, t is the remaining execution time of the target transaction, X is the number of table record rows occupied by R, and k is an empirical coefficient.
[0131] In this embodiment, deadlock information from the database is used to match the most suitable deadlock handling method from a preset scenario library. If no match is found in the scenario library, a low-cost handling method is selected from the decision tree based on the deadlock's characteristic information, ranked from highest to lowest importance, to resolve the deadlock. This achieves timely and effective deadlock resolution at a lower cost, preventing transactions and resources from remaining unavailable for extended periods.
[0132] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0133] Based on the same inventive concept, this application also provides a deadlock handling apparatus for implementing the deadlock handling method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more deadlock handling apparatus embodiments provided below can be found in the limitations of the deadlock handling method described above, and will not be repeated here.
[0134] In one embodiment, such as Figure 6 As shown, a deadlock handling device is provided, comprising: a deadlock acquisition module, a first processing module, and a second processing module, wherein:
[0135] The deadlock acquisition module 601 is used to acquire deadlock information of the database when a deadlock is detected; the deadlock information includes the multiple transactions that caused the deadlock and the waiting information between the multiple transactions;
[0136] The first processing module 602 is used to determine the target deadlock scenario and the first processing method corresponding to the target deadlock scenario from a pre-established deadlock scenario library based on the deadlock information, and process the deadlock information according to the first processing method.
[0137] The second processing module 603 is used to query a pre-built deadlock scenario decision tree based on the deadlock information when the target deadlock scenario is not determined from the deadlock scenario library, obtain the second processing method corresponding to the deadlock information, and process the deadlock information according to the second processing method.
[0138] In one embodiment, the deadlock acquisition module 601 is further configured to acquire the execution status of each transaction and the resource information occupied by each transaction at the deadlock time point; generate a transaction wait graph corresponding to the deadlock time point based on the execution status of each transaction and the resource information occupied by each transaction; and obtain deadlock information based on the transaction wait graph, the execution status of each transaction and the resource information occupied by each transaction.
[0139] In one embodiment, the first processing module 602 is further configured to identify deadlock loop information from the transaction wait graph included in the deadlock information; the deadlock loop information represents the loop information formed by at least two transactions that cause a deadlock, and each transaction in the deadlock loop information is waiting for the resources occupied by the next transaction; based on the deadlock loop information, the target deadlock scenario and the first processing method corresponding to the target deadlock scenario are determined from a pre-established deadlock scenario library.
[0140] In one embodiment, the second processing module 603 is further configured to obtain multiple deadlock feature information corresponding to the target transaction among the multiple transactions causing the deadlock based on the deadlock information; the target transaction represents any one of the multiple transactions causing the deadlock; and sequentially search the deadlock scenario decision tree according to the order of importance of each deadlock feature information from high to low to obtain the processing method for the target transaction, which is used as the second processing method corresponding to the deadlock information.
[0141] In one embodiment, the second processing module 603 is further configured to obtain, based on the deadlock information, the number of waiting transactions, the execution time, the remaining execution time, the type of resource occupied, and the processing degree value corresponding to the resources occupied by the target transaction; the number of waiting transactions represents the number of transactions waiting to use the resources occupied by the target transaction, and the processing degree value represents the degree to which the forced release of the resources occupied by the target transaction helps to resolve the deadlock problem; and the number of waiting transactions, the execution time, the remaining execution time, the type of resource occupied, and the processing degree value corresponding to the resources occupied by the target transaction are determined as multiple deadlock feature information.
[0142] In one embodiment, the second processing module 603 is further configured to obtain the number of resources occupied by the target transaction and a preset experience coefficient based on the deadlock information; and to obtain a processing degree value based on the number of waiting transactions corresponding to the resources occupied by the transaction, the remaining execution time, the number of resources occupied by the transaction, and the experience coefficient.
[0143] In one embodiment, the second processing module 603 is further configured to determine current deadlock feature information; if the current deadlock feature information meets the judgment condition corresponding to the current deadlock feature information, then a second processing method is determined based on the current deadlock feature information; if the current deadlock feature information does not meet the judgment condition corresponding to the current deadlock feature information, then the next deadlock feature information with a lower importance than the current deadlock feature information is taken as the new deadlock feature information, and the second processing method is determined based on the new deadlock feature information.
[0144] The modules in the aforementioned deadlock handling device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0145] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 7 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores a deadlock scenario library and deadlock decision tree data. The network interface communicates with external terminals via a network connection. When executed by the processor, the computer program implements a deadlock handling method.
[0146] Those skilled in the art will understand that Figure 7 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0147] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0148] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0149] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0150] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0151] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0152] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0153] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A deadlock handling method, characterized in that, The method includes: If a database deadlock is detected, the deadlock information of the database is obtained; the deadlock information includes the multiple transactions that caused the deadlock and the wait information between the multiple transactions; Based on the deadlock information, a target deadlock scenario and a corresponding first processing method are determined from a pre-established deadlock scenario library, and the deadlock information is processed according to the first processing method; if no target deadlock scenario is determined from the deadlock scenario library, a pre-built deadlock scenario decision tree is queried based on the deadlock information to obtain a corresponding second processing method, and the deadlock information is processed according to the second processing method; wherein, the processing methods in the deadlock scenario library are the best processing methods obtained by the user based on historical deadlock scenario statistics; The deadlock information includes a transaction wait graph, which is a directed graph representing the waiting relationships between transactions; the step of determining a target deadlock scenario and a corresponding first processing method from a pre-established deadlock scenario library based on the deadlock information includes: Deadlock loop information is identified from the transaction wait graph included in the deadlock information; the deadlock loop information represents the loop information formed by at least two transactions that caused the deadlock, and each transaction in the deadlock loop information is waiting for the resources occupied by the next transaction; based on the deadlock loop information, a target deadlock scenario and a first processing method corresponding to the target deadlock scenario are determined from the pre-established deadlock scenario library; The step of querying a pre-built deadlock scenario decision tree based on the deadlock information to obtain the second processing method corresponding to the deadlock information includes: Based on the deadlock information, the number of waiting transactions, execution time, remaining execution time, type of occupied resource, and processing level value corresponding to the resources occupied by the target transaction are obtained. The number of waiting transactions represents the number of transactions waiting to use the resources occupied by the target transaction, and the processing level value represents the degree to which forcibly releasing the resources occupied by the target transaction helps resolve the deadlock problem. The number of waiting transactions, execution time, remaining execution time, type of occupied resource, and processing level value corresponding to the resources occupied by the target transaction are determined as multiple deadlock characteristic information. The target transaction represents any one of the multiple transactions that caused the deadlock. Determine the current deadlock feature information; if the current deadlock feature information meets the judgment condition corresponding to the current deadlock feature information, then determine the second processing method based on the current deadlock feature information; if the current deadlock feature information does not meet the judgment condition corresponding to the current deadlock feature information, then take the next deadlock feature information with a lower importance than the current deadlock feature information as the new deadlock feature information, and determine the second processing method based on the new deadlock feature information.
2. The method according to claim 1, characterized in that, The processing level value is determined in the following manner: Based on the deadlock information, obtain the number of resources occupied by the target transaction and the preset empirical coefficient; The processing level value is obtained based on the number of waiting transactions corresponding to the resources occupied by the transaction, the remaining execution time, the number of resources occupied by the transaction, and the empirical coefficient.
3. The method according to claim 1, characterized in that, The step of obtaining deadlock information from the database includes: Obtain the execution status of each transaction and the resource information occupied by each transaction in the database at the deadlock point; Based on the execution status of each transaction and the resource information occupied by each transaction, a transaction wait graph corresponding to the deadlock point in the database is generated. The deadlock information is obtained based on the transaction wait graph, the execution status of each transaction, and the resource information occupied by each transaction.
4. A deadlock handling device, characterized in that, The device includes: The deadlock acquisition module is used to acquire deadlock information of the database when a deadlock is detected; the deadlock information includes multiple transactions that caused the deadlock and the waiting information between the multiple transactions; The first processing module is used to determine a target deadlock scenario and a first processing method corresponding to the target deadlock scenario from a pre-established deadlock scenario library based on the deadlock information, and process the deadlock information according to the first processing method; wherein, the processing method in the deadlock scenario library is the best processing method obtained by the user based on historical deadlock scenario statistics; The second processing module is used to, when no target deadlock scenario is determined from the deadlock scenario library, query a pre-built deadlock scenario decision tree based on the deadlock information to obtain a second processing method corresponding to the deadlock information, and process the deadlock information according to the second processing method. The deadlock information includes a transaction wait graph, which is a directed graph representing the waiting relationships between transactions; the first processing module is further configured to identify deadlock loop information from the transaction wait graph included in the deadlock information; the deadlock loop information represents the loop information formed by at least two transactions that caused the deadlock, and each transaction in the deadlock loop information is waiting for the resources occupied by the next transaction; based on the deadlock loop information, a target deadlock scenario and a first processing method corresponding to the target deadlock scenario are determined from the pre-established deadlock scenario library; The second processing module is further configured to obtain, based on the deadlock information, the number of waiting transactions, the execution time, the remaining execution time, the type of resource occupied, and the processing degree value corresponding to the resources occupied by the target transaction; the number of waiting transactions represents the number of transactions waiting to use the resources occupied by the target transaction, and the processing degree value represents the degree to which forcibly releasing the resources occupied by the target transaction helps resolve the deadlock problem; the number of waiting transactions, the execution time, the remaining execution time, the type of resource occupied, and the processing degree value corresponding to the resources occupied by the target transaction are determined as multiple deadlock feature information; the target transaction represents any one of the multiple transactions that caused the deadlock; the current deadlock feature information is determined; if the current deadlock feature information meets the judgment condition corresponding to the current deadlock feature information, the second processing method is determined based on the current deadlock feature information; if the current deadlock feature information does not meet the judgment condition corresponding to the current deadlock feature information, the next deadlock feature information with a lower importance than the current deadlock feature information is taken as the new deadlock feature information, and the second processing method is determined based on the new deadlock feature information.
5. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 3.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 3.
7. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Deadlock processing method and system
CN105740079A
Distributed deadlock detection method and device, computer equipment and readable medium
CN110442459A