Waiting relationship graph construction method and device, electronic device and storage medium
By dynamically determining the node type in the waiting relationship graph, a waiting relationship graph with high adaptability is constructed, which solves the problem of poor adaptability of the waiting relationship graph in the prior art, and improves the efficiency of deadlock detection.
Patent Information
- Application Number
- CN202411836391.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2044-12-12
AI Technical Summary
The waiting relationship diagrams constructed in the prior art have poor adaptability, resulting in low deadlock detection efficiency.
By responsive to the task of the to be executed, the requested resource occupied by the executed transaction fails to obtain the requested resource occupied by the transaction being executed, the new node type is determined based on the information in the waiting relationship graph, and the waiting relationship between the transaction node or the task node is dynamically constructed, so as to improve the adaptability of the waiting relationship graph.
The efficiency of deadlock detection is improved, and the scale and construction efficiency of the waiting relationship diagram are taken into account, which reduces the major problems of frequent communication and task granularity waiting relationship diagram.
Smart Images

Figure CN119292798B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a method and device for constructing a waiting relationship graph, an electronic device, and a storage medium. Background Art
[0002] Distributed databases often use the mechanism of transaction resource locking to control transaction concurrency. Due to the mutual exclusion, hold-and-wait, and non-preemption characteristics of the above mechanisms, during the transaction concurrency process, the contention for resources by transactions may result in a circular wait (commonly known as a deadlock). For example, after transaction A successfully locks data row 1, it attempts to lock data row 2. At the same time, after transaction B successfully locks data row 2, it attempts to lock data row 1. Due to the mutual exclusion and non-preemption characteristics, neither transaction A nor transaction B will give up the locks that have been successfully acquired, and then fall into a circular wait situation, causing a deadlock. In order to detect deadlock nodes in distributed databases, WFG (Wait-ForGraph, a mathematical model that represents the waiting relationship between transactions) can be used to construct a waiting relationship graph between transactions, and the waiting relationship graph can be detected using a detection algorithm to unlock the detected deadlock.
[0003] However, the wait relationship graph constructed in the related art has poor adaptability, resulting in low deadlock detection efficiency performed based on it. Summary of the invention
[0004] In view of this, one or more embodiments of the present specification provide a method and device for constructing a waiting relationship graph, an electronic device, and a storage medium.
[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a method for constructing a waiting relationship graph is proposed, the method comprising:
[0007] In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by the transaction being executed, determining a newly created node type based on information of the pending transaction and the requested resource in a waiting relationship graph, wherein the newly created node type is a transaction node or a task node;
[0008] If the newly created node type is a transaction node, then constructing a waiting relationship between the to-be-executed transaction and the executing transaction in the waiting relationship graph;
[0009] If the newly created node type is a task node, then the waiting relationship between the to-be-executed task and the executing transaction, and the waiting relationship between the to-be-executed transaction and the to-be-executed task are constructed in the waiting relationship graph.
[0010] In a possible embodiment of the present specification, in response to the failure of the to-be-executed task of the to-be-executed transaction to obtain the requested resource occupied by the transaction being executed, determining the type of the newly created node based on information of the to-be-executed transaction and the requested resource in the waiting relationship graph includes:
[0011] In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by an executing transaction and no node of the pending task exists in a waiting relationship graph, a newly created node type is determined based on information of the pending transaction and the requested resource in the waiting relationship graph.
[0012] In a possible embodiment of this specification, the method further includes:
[0013] In response to a pending task of a pending transaction failing to obtain a requested resource occupied by the executing transaction, and there is a node of the pending task in a waiting relationship graph, a waiting relationship between the pending task and the executing transaction is constructed in the waiting relationship graph.
[0014] In a possible embodiment of the present specification, in response to the failure of the to-be-executed task of the to-be-executed transaction to obtain the requested resource occupied by the transaction being executed, determining the type of the newly created node based on information of the to-be-executed transaction and the requested resource in the waiting relationship graph includes:
[0015] In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by the executing transaction, and the pending transaction and the pending task are located on different servers, a newly created node type is determined based on information of the pending transaction and the requested resource in a waiting relationship graph.
[0016] In a possible embodiment of the present specification, if the newly created node type is a transaction node, constructing a waiting relationship between the to-be-executed transaction and the executing transaction in the waiting relationship graph includes:
[0017] If the newly created node type is a transaction node, the server where the to-be-executed task is located sends a notification message to the server where the to-be-executed transaction is located, so that the server where the to-be-executed transaction is located constructs a waiting relationship between the to-be-executed transaction and the executing transaction in a local waiting relationship graph.
[0018] In a possible embodiment of the present specification, if the newly created node type is a task node, constructing a waiting relationship between the task to be executed and the transaction being executed, and a waiting relationship between the transaction to be executed and the task to be executed in the waiting relationship graph includes:
[0019] If the newly created node type is a task node, the server where the task to be executed is located constructs a waiting relationship between the task to be executed and the executing transaction in the local waiting relationship graph, and sends a notification message to the server where the transaction to be executed is located, so that the server where the transaction to be executed is located constructs a waiting relationship between the transaction to be executed and the task to be executed in the local waiting relationship graph.
[0020] In a possible embodiment of the present specification, determining the type of the newly created node based on the information of the to-be-executed transaction and the requested resource in the waiting relationship graph includes:
[0021] Determine the heat value of the requested resource based on the number of waiting nodes for the requested resource in the waiting relationship graph, the number of waiting relationships of transaction node types in the waiting relationship graph, and the number of waiting relationships of task node types in the waiting relationship graph;
[0022] Determine the node relationship complexity based on the number of waiting relationships of the pending transaction in the waiting relationship graph, the number of waiting relationships of all tasks of the pending transaction in the waiting relationship graph, and the heat value of the requested resource;
[0023] If the node relationship complexity is less than a preset threshold, the newly created node type is determined to be a transaction node type; if the node relationship complexity is not less than the preset threshold, the newly created node type is determined to be a transaction task type.
[0024] In a possible embodiment of the present specification, determining the type of the newly created node based on the information of the to-be-executed transaction and the requested resource in the waiting relationship graph includes:
[0025] Sending the to-be-executed transaction and the requested resource to a waiting relationship graph management module, so that the waiting relationship graph management module determines a newly created node type;
[0026] Receive the newly created node type sent by the waiting relationship graph management module.
[0027] In a possible embodiment of the present specification, determining the type of the newly created node based on the information of the to-be-executed transaction and the requested resource in the waiting relationship graph includes:
[0028] The newly created node type is determined based on the result obtained after adding the waiting relationship between the to-be-executed transaction and the executing transaction and the waiting relationship between the to-be-executed task and the executing transaction based on the information of the to-be-executed transaction and the requested resource in the waiting relationship graph.
[0029] According to a second aspect of one or more embodiments of this specification, a waiting relationship graph construction device is provided, the device comprising:
[0030] a type module, configured to determine, in response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by a pending transaction, a newly created node type based on information of the pending transaction and the requested resource in a waiting relationship graph, wherein the newly created node type is a transaction node or a task node;
[0031] A transaction module, configured to construct a waiting relationship between the to-be-executed transaction and the executing transaction in the waiting relationship graph if the newly-created node type is a transaction node;
[0032] The task module is used for constructing the waiting relationship between the task to be executed and the transaction in execution, and the waiting relationship between the transaction to be executed and the task to be executed in the waiting relationship graph if the newly created node type is a task node.
[0033] According to a third aspect of one or more embodiments of this specification, a computer program product is provided, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.
[0034] According to a fourth aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0035] processor;
[0036] a memory for storing processor-executable instructions;
[0037] The processor implements the method as described in the first aspect by running the executable instructions.
[0038] According to a fifth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.
[0039] The technical solutions provided by the embodiments of this specification may have the following beneficial effects:
[0040] The waiting relationship graph construction method provided in the embodiment of the specification first responds to the failure of the pending task of the pending transaction to obtain the requested resource occupied by the transaction being executed, and determines the type of the newly created node based on the information of the pending transaction and the requested resource in the waiting relationship graph; then, if the newly created node type is a transaction node, the waiting relationship of the pending transaction to the executing transaction is constructed in the waiting relationship graph, and if the newly created node type is a task node, the waiting relationship of the pending task to the executing transaction and the waiting relationship of the pending transaction to the pending task are constructed in the waiting relationship graph. When a waiting relationship occurs, the method determines the node type of the waiting relationship in real time and in a targeted manner, that is, constructs the waiting relationship in the waiting relationship graph with the transaction node, or constructs the waiting relationship in the waiting relationship graph with the task node, and dynamically determines the granularity of the node in each waiting relationship, thereby improving the adaptability of the waiting relationship graph, taking into account the construction efficiency and the scale of the waiting relationship graph, and at the same time solves the technical problems such as frequent communication in the process of constructing the waiting relationship graph of the transaction granularity and the large regularity of the waiting relationship graph of the task granularity, thereby improving the efficiency of deadlock detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 It is a schematic diagram of the architecture of a distributed database provided by an exemplary embodiment.
[0042] Figure 2 It is a flowchart of a waiting relationship graph construction method provided by an exemplary embodiment.
[0043] Figure 3 It is a schematic diagram of a waiting relationship graph management module provided by an exemplary embodiment.
[0044] Figure 4 It is a logical schematic diagram of a waiting relationship graph construction method provided by an exemplary embodiment.
[0045] Figure 5 It is a structural schematic diagram of a device provided by an exemplary embodiment.
[0046] Figure 6 It is a block diagram of a waiting relationship graph construction device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0047] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0048] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0049] Next, some concepts involved in this specification are explained.
[0050] Transaction: A collection of one or more tasks that is atomic. That is, from the perspective of transaction execution results, all tasks within a transaction are either successfully executed or not executed at all.
[0051] Resources: data rows, that is, data to be read and written by tasks within a transaction.
[0052] Waiting relationship: Transaction A has read and write permissions for resource R. If another transaction B wants to read and write resource R, it needs to wait for A to complete. Then B and A are said to have a waiting relationship, and B waits for A. Waiting relationships can be one-to-one, one-to-many, or many-to-one.
[0053] Granularity: The smallest unit of the waiting relationship, which can be a task or a transaction. When the granularity is a task, task A1 of transaction A can wait for transaction B or task B1 of transaction B.
[0054] Deadlock: Transactions are always blocked and no transaction can be successfully executed. Deadlock meets the following conditions: mutual exclusion of resources, that is, a resource can only be owned by one transaction at a time; requesting and holding resources, that is, when a transaction is blocked due to requesting resources, it holds on to the obtained resources; non-preemption, that is, before a transaction actively releases the resources, other transactions cannot forcibly seize the resources; circular waiting, that is, the waiting relationship between transactions forms a loop.
[0055] Deadlock detection: Identify deadlocked transactions through algorithms.
[0056] Waiting relationship graph (WFG): A graph consisting of the waiting relationships of all transactions in the system, whose nodes are transactions or tasks of transactions, and whose edges are waiting relationships.
[0057] Deadlock detection granularity: The granularity of the waiting relationship graph nodes in the deadlock detection algorithm, which can be a transaction or a task of a transaction.
[0058] In the related art, the waiting relationship graph of a distributed database uses transactions as nodes, and different transactions in a distributed database are often distributed on different servers, and multiple tasks within a transaction may also be distributed on multiple servers, which will lead to frequent communication during the construction of the waiting relationship graph, reducing the construction efficiency of the waiting relationship graph and system performance. For example, transaction A consists of task 1 and task 2, and transaction A is submitted to server 0. The transaction scheduler sends task 1 and task 2 to server 1 and server 2 respectively; if task 1 and other transactions have a waiting relationship, at this time, if the waiting relationship is constructed at the transaction granularity, task 1 needs to send a message to transaction A to update the waiting relationship between transaction A and other transactions. In the case of contention for hot data, the message transmission will be very frequent, which will affect the deadlock detection efficiency and system performance.
[0059] In the related art, if the waiting relationship graph of a distributed database uses tasks as nodes, the scale of the waiting relationship graph may be multiplied, affecting the deadlock detection efficiency and system performance, and even causing the system to crash.
[0060] Based on the above technical problems, at least one embodiment of the present specification provides a method for constructing a waiting relationship graph. The method can dynamically determine the node type when a waiting relationship occurs, and add the waiting relationship to the waiting relationship graph at the determined node granularity, i.e., transaction node or task node. This allows the granularity of each waiting relationship in the waiting relationship graph to adapt to related transactions, tasks and resources, as well as system status, so as to take into account the scale and construction efficiency of the waiting relationship graph, thereby improving the efficiency of deadlock detection.
[0061] For example, the method can be applied to Figure 1 In the distributed database shown as an example.
[0062] Please refer to the attached Figure 2 , which exemplarily shows a flowchart of a waiting relationship graph construction method, including steps S201 to S203.
[0063] In step S201, in response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by the executing transaction, a newly created node type is determined based on information of the pending transaction and the requested resource in a waiting relationship graph, wherein the newly created node type is a transaction node or a task node.
[0064] Among them, the requested resource is currently occupied by the executing transaction, and the pending task of the pending transaction also wants to access the requested resource. At this time, a waiting relationship occurs between the pending task of the pending transaction and the executing transaction. Therefore, it is necessary to add the waiting relationship to the waiting relationship graph to provide accurate data for subsequent retrieval detection; this step is to determine at what granularity to add the waiting relationship to the waiting relationship graph in this case.
[0065] It should be understood that this step can be performed when there is no node of the task to be executed in the current waiting relationship graph, because if there is already a node of the task to be executed in the waiting relationship graph, there is no need to rebuild the node. That is, in response to the failure of the task to be executed of the transaction to be executed to obtain the requested resource occupied by the transaction being executed, and there is no node of the task to be executed in the waiting relationship graph, the type of the newly created node is determined based on the information of the transaction to be executed and the requested resource in the waiting relationship graph.
[0066] Correspondingly, in response to the failure of the pending task of the pending transaction to obtain the requested resources occupied by the executing transaction, and there is a node of the pending task in the waiting relationship graph, the waiting relationship of the pending task to the executing transaction can be constructed in the waiting relationship graph.
[0067] It should be understood that this step can be performed when the pending transaction and the pending task are on different servers, because if the pending task notifies the pending transaction to build a waiting relationship, it needs to communicate across servers, which affects system performance. That is, in response to the pending task of the pending transaction failing to obtain the requested resource occupied by the executing transaction, and the pending transaction and the pending task are on different servers, the type of the newly created node is determined based on the information of the pending transaction and the requested resource in the waiting relationship graph.
[0068] Correspondingly, in response to the failure of the pending task of the pending transaction to obtain the requested resources occupied by the executing transaction, and the pending transaction and the pending task are on the same server, the server directly constructs the waiting relationship of the pending transaction to the executing transaction in the waiting relationship graph.
[0069] The above two examples can be combined with each other, namely: in response to the failure of the pending task of the pending transaction to obtain the requested resources occupied by the executing transaction, there is no node of the pending task in the waiting relationship graph on the server where the pending task is located, and the pending transaction and the pending task are on different servers, the type of the newly created node is determined based on the information of the pending transaction and the requested resources in the waiting relationship graph.
[0070] Exemplarily, the type of the newly created node may be determined in the following manner:
[0071] First, based on the number of waiting nodes of the requested resource in the waiting relationship graph, the number of waiting relationships of transaction node types in the waiting relationship graph, and the number of waiting relationships of task node types in the waiting relationship graph, the heat value of the requested resource is determined.
[0072] For example, the heat value h of the requested resource is determined according to the following formula:
[0073] h=r_number / (Transaction _number+Task_nember)
[0074] In the above formula, r_number is the number of waiting nodes of the requested resource, that is, the number of waiting nodes related to the requested resource. If a waiting relationship is for the requested resource, then both nodes of the waiting relationship are related to the requested resource; Transaction_number is the number of waiting relationships of the transaction node type in the waiting relationship graph; Task_nember is the number of waiting relationships of the task node type in the waiting relationship graph.
[0075] Next, the node relationship complexity is determined based on the number of waiting relationships of the pending transaction in the waiting relationship graph, the number of waiting relationships of all tasks of the pending transaction in the waiting relationship graph, and the heat value of the requested resource.
[0076] It should be understood that this step can determine the type of the newly created node based on the information of the pending transaction and the requested resource in the waiting relationship graph after adding the waiting relationship of the pending transaction to the executing transaction and the waiting relationship of the pending task to the executing transaction; to avoid the situation where the parameter is 0. For example, the number of waiting relationships of the pending transaction in the waiting relationship graph should be added by 1 based on the number of waiting relationships of the pending transaction in the current waiting relationship graph, and the number of waiting relationships of all tasks of the pending transaction in the waiting relationship graph should be added by 1 based on the number of waiting relationships of the pending task in the current waiting relationship graph.
[0077] For example, the node relationship complexity t is determined according to the following formula:
[0078] t=c*h / n
[0079] In the above formula, c is the number of waiting relationships of all tasks of the pending transaction in the waiting relationship graph, h is the heat value of the requested resource, and n is the number of waiting relationships of the pending transaction in the waiting relationship graph.
[0080] Finally, if the node relationship complexity is less than a preset threshold, the newly created node type is determined to be a transaction node type; if the node relationship complexity is not less than the preset threshold, the newly created node type is determined to be a transaction task type.
[0081] Exemplarily, the distributed database may be provided with a waiting relationship graph management module, and the newly created node type in this step may be determined by the waiting relationship graph management module. For example, if this step is performed by the server where the task to be executed is located, the task to be executed and the requested resource may be sent to the waiting relationship graph management module so that the waiting relationship graph management module determines the newly created node type; and receives the newly created node type sent by the waiting relationship graph management module.
[0082] The internal architecture of the waiting relationship graph management module can be as shown in the attached figure. Figure 3 As shown, it includes a transaction node list, a transaction waiting relationship calculator, a task node list, a task waiting relationship counter, a resource counter list, and a node information management unit corresponding to each node in the waiting relationship graph. The transaction node list is used to record the transaction nodes in the waiting relationship graph, the transaction waiting relationship counter is used to count the number of waiting relationships of the transaction node type in the waiting relationship graph, the task node list is used to record the task nodes in the waiting relationship graph, the task waiting relationship counter is used to count the number of waiting relationships of the task node type in the waiting relationship graph, and the resource counter list is used to count the waiting nodes and their numbers related to each resource being waited for in the waiting relationship graph. The node information management unit is used to record the number, node type, waiting relationship list (used to record the waiting relationship related to the corresponding node), and the waiting resource list (used to record the resources waited for by the corresponding node) of the corresponding node. If the two nodes of a waiting relationship are a transaction node and a task node respectively, then the waiting relationship is both a waiting relationship of the transaction node type and a waiting relationship of the task node type.
[0083] After receiving the pending transaction and the requested resource, the waiting relationship graph management module can calculate the heat value of the requested resource based on the number of waiting nodes related to the requested resource in the resource counter list, the number of waiting relationships of the transaction node type in the transaction waiting relationship counter, and the number of waiting relationships of the task node type in the task waiting relationship counter; and then calculate the node relationship complexity based on the number of waiting relationships related to the pending transaction and the number of waiting relationships related to all its tasks in the node information management unit corresponding to the pending transaction, and the above-mentioned heat value; finally, determine the new node type based on the comparison result of the node relationship complexity and the preset threshold.
[0084] In step S202, if the newly created node type is a transaction node, a waiting relationship between the to-be-executed transaction and the executing transaction is constructed in the waiting relationship graph.
[0085] For example, if the pending transaction and the pending task are located on different servers, the server where the pending task is located can send a notification message to the server where the pending transaction is located, so that the server where the pending transaction is located can construct a waiting relationship between the pending transaction and the executing transaction in a local waiting relationship graph.
[0086] In step S203, if the newly created node type is a task node, then the waiting relationship between the to-be-executed task and the executing transaction, and the waiting relationship between the to-be-executed transaction and the to-be-executed task are constructed in the waiting relationship graph.
[0087] For example, if the pending transaction and the pending task are located on different servers, the server where the pending task is located builds a waiting relationship between the pending task and the executing transaction in a local waiting relationship graph, and sends a notification message to the server where the pending transaction is located, so that the server where the pending transaction is located builds a waiting relationship between the pending transaction and the pending task in a local waiting relationship graph.
[0088] If the newly created node type is determined by the waiting relationship graph management module, the waiting relationship graph management module can respectively notify the server where the to-be-executed task is located and the server where the to-be-executed transaction is located to construct the corresponding waiting relationship in the above example.
[0089] Please refer to the attached Figure 4 , which exemplarily shows the process of the waiting relationship graph construction method obtained by combining the above-mentioned embodiments.
[0090] A task of a transaction is on server 1, and the transaction is on server 2.
[0091] If the task on the server fails to obtain resources, a waiting relationship is generated; then it is determined whether the task has a corresponding task node in the local waiting relationship graph.
[0092] If so, create a new waiting relationship locally.
[0093] If not, the transaction to which the task belongs and the resource to be locked are sent to the waiting relationship graph management module, so that the waiting relationship graph management module calculates the type of the newly created node.
[0094] If the newly created node type is a transaction node, the server 2 is notified to create a new waiting relationship with the transaction node.
[0095] If the newly created node type is a task node, the server 1 is notified to create a new task node and a waiting relationship, and the server 2 is notified to create a new waiting relationship with the waiting of the thing for the task as the content.
[0096] It can be seen that this method can perform adaptive granularity adjustment, that is, when a new waiting relationship needs to be established, the granularity of the newly created node can be dynamically adjusted according to the scale of the current waiting relationship graph and the resource heat, which limits the scale of the waiting relationship graph, ensures the efficiency of deadlock detection, and effectively reduces the overhead of frequent updates of waiting relationships between servers that require a large amount of message transmission, thereby providing effective guarantees for the quality and reliability of transaction services. Moreover, when a task in a transaction creates multiple waiting relationships, it only needs to communicate with the server where the transaction is located when the task node is first created, saving communication costs and improving the efficiency of deadlock detection.
[0097] This method can significantly reduce the deadlock detection overhead in distributed databases and improve deadlock detection efficiency. When using this method in situations with high resource contention, the system throughput is increased by 46%, the system evaluation response time is reduced by 47%, the system tail latency is reduced by 80%, and the number of deadlocks that can be detected is increased by 45%.
[0098] The waiting relationship graph construction method provided in the embodiment of the specification first responds to the failure of the pending task of the pending transaction to obtain the requested resource occupied by the transaction being executed, and determines the type of the newly created node based on the information of the pending transaction and the requested resource in the waiting relationship graph; then, if the newly created node type is a transaction node, the waiting relationship of the pending transaction to the executing transaction is constructed in the waiting relationship graph, and if the newly created node type is a task node, the waiting relationship of the pending task to the executing transaction and the waiting relationship of the pending transaction to the pending task are constructed in the waiting relationship graph. When a waiting relationship occurs, the method determines the node type of the waiting relationship in real time and in a targeted manner, that is, constructs the waiting relationship in the waiting relationship graph with the transaction node, or constructs the waiting relationship in the waiting relationship graph with the task node, and dynamically determines the granularity of the node in each waiting relationship, thereby improving the adaptability of the waiting relationship graph, taking into account the construction efficiency and the scale of the waiting relationship graph, and at the same time solves the technical problems such as frequent communication in the process of constructing the waiting relationship graph of the transaction granularity and the large regularity of the waiting relationship graph of the task granularity, thereby improving the efficiency of deadlock detection.
[0099] Figure 5 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 5At the hardware level, the device includes a processor 502, an internal bus 505, a network interface 506, a memory 508, and a non-volatile memory 510, and may also include hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 502 reading the corresponding computer program from the non-volatile memory 510 into the memory 508 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0100] Please refer to Figure 6 , the waiting relationship graph construction device can be applied to Figure 5 The device shown in the figure can be used to implement the technical solution of this specification. The waiting relationship graph construction device can include:
[0101] A type module 601 is used for determining a newly created node type based on information of the to-be-executed transaction and the requested resource in a waiting relationship graph in response to a failure of a to-be-executed task of a to-be-executed transaction to obtain a requested resource occupied by the to-be-executed transaction, wherein the newly created node type is a transaction node or a task node;
[0102] A transaction module 602 is configured to construct a waiting relationship between the to-be-executed transaction and the executing transaction in the waiting relationship graph if the newly-created node type is a transaction node;
[0103] The task module 603 is used to construct the waiting relationship between the to-be-executed task and the executing transaction, and the waiting relationship between the to-be-executed transaction and the to-be-executed task in the waiting relationship graph if the newly created node type is a task node.
[0104] In a possible embodiment of this specification, the type module is used to:
[0105] In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by an executing transaction and no node of the pending task exists in a waiting relationship graph, a newly created node type is determined based on information of the pending transaction and the requested resource in the waiting relationship graph.
[0106] In a possible embodiment of this specification, the task module is also used to:
[0107] In response to a pending task of a pending transaction failing to obtain a requested resource occupied by the executing transaction, and there is a node of the pending task in a waiting relationship graph, a waiting relationship between the pending task and the executing transaction is constructed in the waiting relationship graph.
[0108] In a possible embodiment of this specification, the type module is used to:
[0109] In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by the executing transaction, and the pending transaction and the pending task are located on different servers, a newly created node type is determined based on information of the pending transaction and the requested resource in a waiting relationship graph.
[0110] In a possible embodiment of the present specification, the transaction module is used to:
[0111] If the newly created node type is a transaction node, the server where the to-be-executed task is located sends a notification message to the server where the to-be-executed transaction is located, so that the server where the to-be-executed transaction is located constructs a waiting relationship between the to-be-executed transaction and the executing transaction in a local waiting relationship graph.
[0112] In a possible embodiment of this specification, the task module is used to:
[0113] If the newly created node type is a task node, the server where the task to be executed is located constructs a waiting relationship between the task to be executed and the executing transaction in the local waiting relationship graph, and sends a notification message to the server where the transaction to be executed is located, so that the server where the transaction to be executed is located constructs a waiting relationship between the transaction to be executed and the task to be executed in the local waiting relationship graph.
[0114] In a possible embodiment of this specification, the type module is used to:
[0115] Determine the heat value of the requested resource based on the number of waiting nodes for the requested resource in the waiting relationship graph, the number of waiting relationships of transaction node types in the waiting relationship graph, and the number of waiting relationships of task node types in the waiting relationship graph;
[0116] Determine the node relationship complexity based on the number of waiting relationships of the pending transaction in the waiting relationship graph, the number of waiting relationships of all tasks of the pending transaction in the waiting relationship graph, and the heat value of the requested resource;
[0117] If the node relationship complexity is less than a preset threshold, the newly created node type is determined to be a transaction node type; if the node relationship complexity is not less than the preset threshold, the newly created node type is determined to be a transaction task type.
[0118] In a possible embodiment of this specification, the type module is used to:
[0119] Sending the to-be-executed transaction and the requested resource to a waiting relationship graph management module, so that the waiting relationship graph management module determines a newly created node type;
[0120] Receive the newly created node type sent by the waiting relationship graph management module.
[0121] In a possible embodiment of this specification, the type module is used to:
[0122] The newly created node type is determined based on the result obtained after adding the waiting relationship between the to-be-executed transaction and the executing transaction and the waiting relationship between the to-be-executed task and the executing transaction based on the information of the to-be-executed transaction and the requested resource in the waiting relationship graph.
[0123] One or more embodiments of the present specification also provide a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the method provided in any of the above embodiments.
[0124] One or more embodiments of the present specification further provide a computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method provided in any of the above embodiments.
[0125] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0126] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0127] Memory may include non-permanent storage in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0128] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0129] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0130] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0131] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0132] 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, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0133] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0134] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.
Claims
1. A method for constructing a waiting relationship graph, the method comprising: In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by the transaction being executed, determining a newly created node type based on information of the pending transaction and the requested resource in a waiting relationship graph, wherein the newly created node type is a transaction node or a task node; If the newly created node type is a transaction node, then constructing a waiting relationship between the to-be-executed transaction and the executing transaction in the waiting relationship graph; If the newly created node type is a task node, then constructing a waiting relationship between the task to be executed and the transaction in execution, and a waiting relationship between the transaction to be executed and the task to be executed in the waiting relationship graph; The determining of the newly created node type based on the information of the to-be-executed transaction and the requested resource in the waiting relationship graph includes: Determine the heat value of the requested resource based on the number of waiting nodes for the requested resource in the waiting relationship graph, the number of waiting relationships of transaction node types in the waiting relationship graph, and the number of waiting relationships of task node types in the waiting relationship graph; Determine the node relationship complexity based on the number of waiting relationships of the pending transaction in the waiting relationship graph, the number of waiting relationships of all tasks of the pending transaction in the waiting relationship graph, and the heat value of the requested resource; If the node relationship complexity is less than a preset threshold, the newly created node type is determined to be a transaction node type; if the node relationship complexity is not less than the preset threshold, the newly created node type is determined to be a transaction task type.
2. The method for constructing a waiting relationship graph according to claim 1, wherein in response to the failure of the pending task of the pending transaction to obtain the requested resource occupied by the transaction being executed, determining the type of the newly created node based on the information of the pending transaction and the requested resource in the waiting relationship graph comprises: In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by an executing transaction and no node of the pending task exists in a waiting relationship graph, a newly created node type is determined based on information of the pending transaction and the requested resource in the waiting relationship graph.
3. The method for constructing a waiting relationship graph according to claim 2, further comprising: In response to a pending task of a pending transaction failing to obtain a requested resource occupied by the executing transaction, and there is a node of the pending task in a waiting relationship graph, a waiting relationship between the pending task and the executing transaction is constructed in the waiting relationship graph.
4. The method for constructing a waiting relationship graph according to claim 2, wherein in response to the failure of the pending task of the pending transaction to obtain the requested resource occupied by the transaction being executed, determining the type of the newly created node based on the information of the pending transaction and the requested resource in the waiting relationship graph comprises: In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by the executing transaction, and the pending transaction and the pending task are located on different servers, a newly created node type is determined based on information of the pending transaction and the requested resource in a waiting relationship graph.
5. The method for constructing a waiting relationship graph according to claim 4, wherein if the newly created node type is a transaction node, constructing a waiting relationship between the pending transaction and the executing transaction in the waiting relationship graph, comprising: If the newly created node type is a transaction node, the server where the to-be-executed task is located sends a notification message to the server where the to-be-executed transaction is located, so that the server where the to-be-executed transaction is located constructs a waiting relationship between the to-be-executed transaction and the executing transaction in a local waiting relationship graph.
6. The method for constructing a waiting relationship graph according to claim 4, wherein if the newly created node type is a task node, constructing the waiting relationship between the task to be executed and the transaction in execution, and the waiting relationship between the transaction to be executed and the task to be executed in the waiting relationship graph, comprising: If the newly created node type is a task node, the server where the task to be executed is located constructs a waiting relationship between the task to be executed and the executing transaction in the local waiting relationship graph, and sends a notification message to the server where the transaction to be executed is located, so that the server where the transaction to be executed is located constructs a waiting relationship between the transaction to be executed and the task to be executed in the local waiting relationship graph.
7. The method for constructing a waiting relationship graph according to claim 1, wherein determining the type of the newly created node based on the information of the pending transaction and the requested resource in the waiting relationship graph comprises: Sending the to-be-executed transaction and the requested resource to a waiting relationship graph management module, so that the waiting relationship graph management module determines a newly created node type; Receive the newly created node type sent by the waiting relationship graph management module.
8. The method for constructing a waiting relationship graph according to claim 1, wherein determining the type of the newly created node based on the information of the pending transaction and the requested resource in the waiting relationship graph comprises: The newly created node type is determined based on the result obtained after adding the waiting relationship between the to-be-executed transaction and the executing transaction and the waiting relationship between the to-be-executed task and the executing transaction based on the information of the to-be-executed transaction and the requested resource in the waiting relationship graph.
9. A waiting relationship graph construction device, the device comprising: a type module, configured to determine, in response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by a pending transaction, a newly created node type based on information of the pending transaction and the requested resource in a waiting relationship graph, wherein the newly created node type is a transaction node or a task node; A transaction module, configured to construct a waiting relationship between the to-be-executed transaction and the executing transaction in the waiting relationship graph if the newly-created node type is a transaction node; A task module, configured to construct, in the waiting relationship graph, a waiting relationship between the task to be executed and the transaction in execution, and a waiting relationship between the transaction to be executed and the task to be executed, if the newly created node type is a task node; The type module is used to: Determine the heat value of the requested resource based on the number of waiting nodes for the requested resource in the waiting relationship graph, the number of waiting relationships of transaction node types in the waiting relationship graph, and the number of waiting relationships of task node types in the waiting relationship graph; Determine the node relationship complexity based on the number of waiting relationships of the pending transaction in the waiting relationship graph, the number of waiting relationships of all tasks of the pending transaction in the waiting relationship graph, and the heat value of the requested resource; If the node relationship complexity is less than a preset threshold, the newly created node type is determined to be a transaction node type; if the node relationship complexity is not less than the preset threshold, the newly created node type is determined to be a transaction task type.
10. The waiting relationship graph construction device according to claim 9, wherein the type module is used for: In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by an executing transaction and no node of the pending task exists in a waiting relationship graph, a newly created node type is determined based on information of the pending transaction and the requested resource in the waiting relationship graph.
11. The device for constructing a waiting relationship graph according to claim 10, wherein the task module is further used for: In response to a pending task of a pending transaction failing to obtain a requested resource occupied by the executing transaction, and there is a node of the pending task in a waiting relationship graph, a waiting relationship between the pending task and the executing transaction is constructed in the waiting relationship graph.
12. The waiting relationship graph construction device according to claim 9, wherein the type module is used for: In response to a failure of a pending task of a pending transaction to obtain a requested resource occupied by the executing transaction, and the pending transaction and the pending task are located on different servers, a newly created node type is determined based on information of the pending transaction and the requested resource in a waiting relationship graph.
13. The device for constructing a waiting relationship graph according to claim 12, wherein the transaction module is used for: If the newly created node type is a transaction node, the server where the to-be-executed task is located sends a notification message to the server where the to-be-executed transaction is located, so that the server where the to-be-executed transaction is located constructs a waiting relationship between the to-be-executed transaction and the executing transaction in a local waiting relationship graph.
14. The waiting relationship graph construction device according to claim 12, wherein the task module is used for: If the newly created node type is a task node, the server where the task to be executed is located constructs a waiting relationship between the task to be executed and the executing transaction in the local waiting relationship graph, and sends a notification message to the server where the transaction to be executed is located, so that the server where the transaction to be executed is located constructs a waiting relationship between the transaction to be executed and the task to be executed in the local waiting relationship graph.
15. A computer program product, comprising a computer program / instruction, which, when executed by a processor, implements the steps of the method according to any one of claims 1 to 8.
16. An electronic device, comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 8 by running the executable instructions.
17. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Distributed transactional deadlock detection
US20080282244A1
System for detecting global deadlocks using wait-for graphs and identifiers of transactions related to the deadlocks in a distributed transaction processing system and a method of use therefore
US5835766A