Database deadlock avoidance method, apparatus, device, medium, and program product
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA MOBILE FINANCIAL TECHNOLOGY CO LTD
- Filing Date
- 2026-04-16
- Publication Date
- 2026-08-04
AI Technical Summary
[0004]本发明的目的是提供一种数据库死锁规避方法、装置、设备、介质和程序产品,用于解决现有技术既无法在单个锁等待请求发起时即时判断潜在风险,又难以保证在高并发场景下对锁等待请求的干预,因此导致死锁概率高的问题
上述方案中,提供一种数据库死锁规避方法,首先,在接收到锁请求且锁请求所请求的第一资源被占用的情况下,获取第一事务的事务优先级和锁请求对应的特征数组,特征数组包括第一事务的事务状态特征和第一资源的资源状态特征;然后,调用预先构建的动态链接库对锁请求的特征数组进行风险识别,获得锁请求的风险等级,其中,动态链接库用于分析特征数组中的多个特征与数据库死锁之间的因果关系,生成锁请求的风险等级;最后,根据风险等级、事务优先级和预先定义的策略映射表对锁请求进行干预处理,生成锁请求的干预记录,上述方法通过动态链接库来实时识别锁请求的潜在风险,实现低开销、高准确率和高效的死锁风险识别,还根据风险等级和事务优先级及时采取干预,有效降低了死锁概率,此外,本发明实施例还设置了动态链接库的自适应更新机制,根据干预记录,对动态链接库进行自适应更新,形式动态链接库的离线高置信度学习,实现完整闭环。
Smart Images

Figure CN122507529A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database transaction scheduling technology, and in particular to a database deadlock avoidance method, apparatus, device, medium and program product. Background Technology
[0002] In existing technologies, most deadlock handling mechanisms rely on wait graph traversal or preemptive timestamp strategies, which are typical post-event detection and passive cleanup models. When concurrency increases and waiting edges surge, periodic loop searches consume considerable CPU and memory bandwidth. Once the detection cycle is lengthened, the deadlock duration also increases. Static locking order or timestamp-based preemption rules used to reduce detection costs lack flexibility due to their inability to perceive business evolution, and are prone to excessive rollbacks during load fluctuations, affecting throughput. Online threshold monitoring methods that have emerged in recent years are driven by blocking duration or queue length, but the thresholds rely on empirical parameter tuning, making it difficult to control the false positive rate in different scenarios. At the same time, this method only provides an overall congestion signal and cannot pinpoint which specific wait is most likely to evolve into a deadlock. Offline pattern mining techniques can discover high-frequency conflict combinations, but they bring large-scale rule tables into online hot paths, increasing additional table lookup and interpretation overhead, and the results often quickly become invalid as business changes occur.
[0003] Overall, existing solutions lack a precise characterization of the deadlock causal chain. They cannot immediately assess potential risks when a single lock is waiting for a request to be initiated, nor can they guarantee constant-level judgment and intervention delays in high-concurrency scenarios, thus leading to a high probability of deadlock. Summary of the Invention
[0004] The purpose of this invention is to provide a database deadlock avoidance method, apparatus, device, medium, and program product to solve the problem that the existing technology cannot immediately judge potential risks when a single lock wait request is initiated, and it is difficult to guarantee intervention in lock wait requests in high-concurrency scenarios, thus leading to a high probability of deadlock.
[0005] To address the aforementioned technical problems, embodiments of the present invention provide a database deadlock avoidance method, comprising: Upon receiving a lock request from a first transaction and finding that the first resource requested by the lock request is already occupied, the transaction priority of the first transaction and a feature array corresponding to the lock request are obtained. The feature array includes the transaction status features of the first transaction and the resource status features of the first resource. A pre-built dynamic link library is invoked to perform risk identification on the feature array of the lock request to obtain the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock to generate the risk level of the lock request. The lock request is intervened based on the risk level, the transaction priority, and the predefined strategy mapping table, and an intervention record for the lock request is generated. The dynamic link library is updated based on the intervention record.
[0006] This invention also provides a database deadlock avoidance device, comprising: The first acquisition module is configured to, upon receiving a lock request from a first transaction and finding that the first resource requested by the lock request is occupied, acquire the transaction priority of the first transaction and a feature array corresponding to the lock request, wherein the feature array includes the transaction status features of the first transaction and the resource status features of the first resource. The first identification module is used to call a pre-built dynamic link library to perform risk identification on the feature array of the lock request and obtain the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock to generate the risk level of the lock request. The first intervention module is used to intervene in the lock request according to the risk level, the transaction priority and the predefined strategy mapping table, and generate an intervention record for the lock request; The first update module is used to update the dynamic link library based on the intervention record.
[0007] This invention also provides a network device, including: a processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the database deadlock avoidance method as described in any of the preceding embodiments.
[0008] This invention also provides a readable storage medium, comprising: a program stored on the readable storage medium, wherein when the program is executed by a processor, it implements the steps of the database deadlock avoidance method as described in any of the preceding claims.
[0009] This invention also provides a computer program product, including computer instructions, which, when executed by a processor, implement the steps of the database deadlock avoidance method as described in any of the preceding embodiments.
[0010] At least one of the above technical solutions of the present invention has the following beneficial effects: The above scheme provides a database deadlock avoidance method. First, upon receiving a lock request and finding that the requested resource is already occupied, the transaction priority of the first transaction and the feature array corresponding to the lock request are obtained. The feature array includes the transaction status features of the first transaction and the resource status features of the first resource. Then, a pre-built dynamic link library is invoked to identify the risks of the lock request's feature array, obtaining the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock, generating the risk level of the lock request. Finally, the lock request is intervened based on the risk level, transaction priority, and a predefined strategy mapping table, generating an intervention record for the lock request. This method uses a dynamic link library to identify potential risks of lock requests in real time, achieving low-overhead, high-accuracy, and efficient deadlock risk identification. It also takes timely intervention based on the risk level and transaction priority, effectively reducing the probability of deadlock. Furthermore, this embodiment of the invention also sets up an adaptive update mechanism for the dynamic link library. Based on the intervention record, the dynamic link library is adaptively updated, forming an offline high-confidence learning of the dynamic link library, achieving a complete closed loop. Attached Figure Description
[0011] Figure 1 This is a flowchart illustrating the database deadlock avoidance method according to an embodiment of the present invention; Figure 2 This is one of the flowcharts illustrating the database deadlock avoidance method according to an embodiment of the present invention; Figure 3 This is a second flowchart illustrating the database deadlock avoidance method according to an embodiment of the present invention. Figure 4 This is the third flowchart illustrating the database deadlock avoidance method according to an embodiment of the present invention; Figure 5 This is the fourth flowchart illustrating the database deadlock avoidance method according to an embodiment of the present invention; Figure 6 This is the fifth flowchart illustrating the database deadlock avoidance method according to an embodiment of the present invention; Figure 7 This is a schematic diagram of the database deadlock avoidance device according to an embodiment of the present invention. Detailed Implementation
[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0013] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0014] like Figure 1 As shown, this embodiment of the invention provides a database deadlock avoidance method, including: Step S101: When a lock request from a first transaction is received and the first resource requested by the lock request is occupied, the transaction priority of the first transaction and the feature array corresponding to the lock request are obtained. The feature array includes the transaction status features of the first transaction and the resource status features of the first resource. Step S102: Call a pre-built dynamic link library to perform risk identification on the feature array of the lock request and obtain the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock to generate the risk level of the lock request. Step S103: Intervene in the lock request according to the risk level, the transaction priority and the predefined strategy mapping table, and generate an intervention record for the lock request; Step S104: Update the dynamic link library according to the intervention record.
[0015] In this embodiment of the invention, the lock manager is transformed from a passive detector into a decision-maker with predictive capabilities. First, when the lock manager receives a lock request and the first resource requested by the lock request is occupied, it obtains the transaction priority of the first transaction and the feature array corresponding to the lock request. The feature array includes the transaction status features of the first transaction and the resource status features of the first resource. Then, a pre-built dynamic link library is invoked to identify the risks of the lock request's feature array and obtain the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock to generate the risk level of the lock request. Finally, the lock request is intervened according to the risk level, transaction priority, and a predefined strategy mapping table to generate an intervention record for the lock request. The above method uses a dynamic link library to identify the potential risks of lock requests in real time, achieving low-overhead, high-accuracy, and efficient deadlock risk identification. It also takes timely intervention based on the risk level and transaction priority, effectively reducing the probability of deadlock. In addition, this embodiment of the invention also sets up an adaptive update mechanism for the dynamic link library. Based on the intervention record, the dynamic link library is adaptively updated, which is a form of offline high-confidence learning of the dynamic link library, realizing a complete closed loop.
[0016] In one embodiment, optionally, before invoking the pre-built dynamic link library to perform risk identification on the feature array of the lock request, the method further includes: Based on multiple historical events, a sample vector library is constructed, wherein the sample vector library includes feature vectors and deadlock labels corresponding to the feature vectors, one feature vector corresponds to one historical event, and the deadlock label is used to indicate whether the historical event triggers deadlock resolution within a preset future time window; Based on the deadlock label, feature filtering and causal graph learning are performed on the feature vectors in the sample vector library to obtain the causal graph of the sample vector library. The causal graph includes multiple causal paths, which are composed of multiple nodes and directed edges to represent the causal relationships between the nodes. Risk screening and discrete compression are performed on the causal paths in the causal graph to construct a dynamic link library.
[0017] In this embodiment of the invention, the process of constructing the dynamic link library corresponds to the offline process. First, a sample vector library is constructed based on historical events and deadlock labels. Then, feature filtering and causal graph learning are performed on the sample vector library to obtain the causal graph of the sample vector library. Finally, risk screening and discrete compression processing are performed on the causal paths in the causal graph to construct the dynamic link library. The above method, through causal learning, risk screening, and discrete compression, can retain causal chains with higher risks, improve interpretability and the accuracy of risk identification, and also achieve effective compression of volume.
[0018] It should be noted that the database deadlock avoidance method provided in this embodiment of the invention is not limited to row-level locking scenarios. It is also applicable to other systems that require high-density concurrent scheduling and have the risk of circular dependencies. For example, in distributed file systems or object storage, the leasing and releasing of block devices have a similar resource mutual exclusion relationship. Introducing this method can classify the risk of locking requests between data nodes without increasing input / output (I / O) latency. In the fields of container orchestration and cloud resource scheduling, node drift and quota competition can easily lead to deadlock-like hanging. The path-level prediction framework provided by this method helps the scheduler avoid resource ring occupation in advance. Even in the implementation of spinlocks and read-write locks in the operating system kernel or in the high-performance computing (HPC) task queuer, as long as the necessary event collection interface exists, the idea of offline causal mining and online path compression can still be reused, thereby improving overall throughput while ensuring predictable latency.
[0019] In one implementation, the historical events may optionally include at least one of the following: Event types, including but not limited to any one of lock wait, deadlock resolution, and transaction commit; Timestamp , used to indicate the time when the historical event occurred; Transaction ID , used to represent the target transaction corresponding to the historical event; Resource Identifier , is used to indicate the resource that the target transaction is currently requesting or releasing.
[0020] In this embodiment of the invention, the lock manager has trigger points for its wait determination entry point, deadlock detection and resolution entry point, and transaction commit process exit point. The wait determination entry point corresponds to a lock wait event, the deadlock detection and resolution entry point corresponds to a deadlock resolution event, and the deadlock resolution event indicates the result of rolling back or aborting the affected transaction after deadlock detection. The transaction commit process exit point corresponds to a transaction commit event, and the transaction commit event indicates that the transaction has been successfully committed and has left the concurrent competition state. When any trigger point is triggered, an event record will be generated and written in memory. Each event record includes, but is not limited to, at least one of the following: event type, timestamp, transaction identifier, and resource identifier.
[0021] It should be noted that the main samples in the sample vector library are historical events corresponding to lock wait events, while deadlock resolution events and transaction commit events are used as label alignment and sample truncation when constructing the sample vector library.
[0022] In one embodiment, the feature vector may optionally include at least one of the following: system state features, transaction state features of the target transaction corresponding to the historical event, and resource state features of the target resource requested by the historical event. The transaction state characteristics include at least one of the following: transaction type, transaction duration, and number of currently held locks: The resource status characteristics include at least one of the following: the hierarchical type to which the resource belongs and the resource contention intensity: The system state characteristics include at least one of the central processing unit (CPU) load and global concurrent transactions.
[0023] In one implementation method, optionally, the step of constructing a sample vector library based on multiple historical events includes: Obtain the system state characteristics of each historical event, the transaction state characteristics of the target transaction corresponding to the historical event, and the resource state characteristics of the target resource requested by the historical event; Based on the system state characteristics, transaction state characteristics, and resource state characteristics of the historical events, feature annotation processing is performed on the vector frame to obtain the feature vector of each historical event; For each feature vector, the deadlock label of the feature vector is determined based on whether the deadlock is resolved within a preset future time window. A sample vector library is constructed based on the feature vectors and the deadlock labels of the feature vectors.
[0024] In this embodiment of the invention, three types of historical events—lock wait events, deadlock resolution events, and transaction commit events—are used when constructing the sample vector library. However, their purposes differ. The historical events corresponding to lock wait events serve as the main samples in the sample vector library, while deadlock resolution events and transaction commit events are used for label alignment and sample truncation during the construction of the sample vector library. The specific method is as follows: First, a blank vector frame is instantiated for each historical event. The vector length of the vector frame is fixed once before deployment based on all feature slots that need to be injected later. Through this operation, each historical event has a complete carrier at the moment of generation.
[0025] Then, the system state characteristics, the transaction state characteristics of the target transaction corresponding to the historical event, and the resource state characteristics of the target resource requested by the historical event are obtained. Based on the above, feature annotation processing is performed on the vector framework to obtain the feature vector of each historical event. The specific operation method includes: The first step is to annotate the vector frame with the transaction state features of the transaction layer. Specifically, the transaction type is written into the slot of the vector frame. This is used to differentiate the different ways locks are used in different business logics; the duration of a transaction from its start time to the current trigger point is written to the slot. This time feature is used to characterize the position in the transaction's lifecycle, thereby determining its tolerance threshold for subsequent waiting; the number of locks currently held by the transaction is written to the slot. This is used to reflect the potential impact of this transaction on the system. Through the above progressive injection actions, it is possible to... This creates a directly traceable profile at the transaction level, providing support for subsequent non-global fuzzy statistics that focus on specific transaction behaviors.
[0026] One alternative implementation is a slot. The injected transaction type code can be a 16-bit unsigned integer, with the high 8 bits representing the business domain number and the low 8 bits representing the operation category within that domain. The specific 0x00 and 0xFF segments are reserved in advance for system debugging and future expansion. During deployment, a "business domain → number" mapping table is maintained in the data serialization language (YAML) file. For example, the e-commerce domain is denoted as 0x01, and the financial settlement domain as 0x02. Each domain is further subdivided into common operations, such as "Placing an order" as 0x01, "Inventory deduction" as 0x02, and "Payment confirmation" as 0x03, etc. Therefore, e-commerce - placing an order is coded as 0x0101, and e-commerce - inventory deduction is coded as 0x0102. The difference in lock usage between the two types of transactions is reflected in the encoding. For the former, e-commerce - placing an order, the user table is locked first, and then the order table is locked. For the latter, e-commerce - inventory, the product table is locked first, and then the inventory table vector slot read is locked. Then these two typical links can be distinguished in causal search without the need for additional parsing of Structured Query Language (SQL) text.
[0027] The second step is to continue injecting resource state characteristics and system state characteristics of the resource layer into the same vector. Specifically, the logical level type of the resource whose lock is requested is written into the slot. This is used to characterize the current hierarchical position of the resource; within a fixed observation window, the resource contention intensity is calculated and written to the slot. This is used to reveal recent conflict trends for the resource; the global concurrent transaction count is written to the slot. And write the current CPU load to the slot. Together, they characterize the system-level concurrency intensity.
[0028] One alternative implementation method for calculating resource contention intensity within a fixed observation window includes: Fixed observation window length Set as And it is discretized to the nearest multiple of 100ms within the 0.5–5s range to accommodate both short bursts and long background transactions. This indicates the median online wait time. Resource contention intensity. This is achieved by combining sliding counting with exponential decay: within a length of... The number of waiting events is recorded in real time in the circular buffer. At each time granularity It updates in real time, providing a sensitive response to recent conflicts while smoothing out occasional jitter, ultimately... Writing to vector slots provides continuously differentiable resource layer signals for causal graph learning, including resource contention intensity. The update formula is as follows: ,in .
[0029] Once all the above fields are in place, the feature vectors corresponding to the historical events are obtained. and the feature vector Push in only the continuous output channel This sequential injection process ensures that each concurrent event enters the analysis chain in a complete, unified, and loosely coupled structure, enabling accurate tracing of high-risk waiting scenarios.
[0030] Secondly, for each feature vector v, the deadlock label of the feature vector is determined based on whether deadlock resolution is triggered within a preset future time window. Specific methods include: Based on the deadlock resolution log generated by the lock manager and timestamp Perform window-based time synchronization inference, and adjust the output channel based on whether the feature vector triggers deadlock resolution within a preset future time window. Each feature vector v is appended with a deadlock label. In an optional implementation, the deadlock label is a Boolean label. If a deadlock occurs within a preset future time window, the deadlock label is set to 1; otherwise, the deadlock label is set to 0. This action strictly separates whether a deadlock has occurred from the concurrent state before the trigger in the time dimension, thereby ensuring that the subsequent causal direction only points from the past to the future and avoiding cross-interference between features and results.
[0031] It should be noted that, in addition to labeling the feature vectors corresponding to lock wait events with deadlock labels, the feature vectors corresponding to deadlock resolution events and transaction commit events also need to be labeled with deadlock labels. However, the deadlock labels for deadlock resolution events and transaction commit events do not need to be determined through time windows. Deadlock resolution events naturally correspond to positive outcomes, with a deadlock label of 1; transaction commit events correspond to negative outcomes, with a deadlock label of 0. These are used to identify which transactions complete normally and serve as negative sample boundaries. Therefore, when constructing the sample vector library, the feature vectors corresponding to lock wait events are usually used as the main samples for which risks need to be identified in advance, while "deadlock resolution events" and "transaction commit events" are used as the basis for label alignment and sample truncation.
[0032] In one implementation, optionally, the step of performing feature filtering and causal graph learning on the feature vectors in the sample vector library based on the deadlock label to obtain the causal graph of the sample vector library includes: The feature vectors in the sample vector library are divided into feature dimensions to obtain multiple first feature data. Based on the causal relationship between the first feature data and the deadlock label within a preset multi-scale time window, the first feature data is filtered to obtain multiple target feature data. According to the causal graph learning algorithm, the directed causal relationships between multiple target feature data in the feature vector and the directed causal relationships between the target feature data and the deadlock label are searched respectively to obtain the causal graph of the sample vector library; The effectiveness of each causal path in the causal graph is validated and filtered using the instrumental variable method, and the causal graph is then updated.
[0033] In this embodiment of the invention, the feature data of the sample vectors in the sample vector library are first pre-screened, and then a causal graph is constructed based on the screened features. The specific method is as follows: First, the sample vectors in the sample vector library are divided into feature dimensions to obtain multiple first feature data. Then, based on the causal relationship between the first feature data and the deadlock label within the preset multi-scale time window, the first feature data is filtered, and the first feature that stably appears before the deadlock time within the multi-scale time window is retained to obtain multiple target feature data and effectively eliminate occasional co-occurrence noise. Secondly, using a causal graph learning algorithm, the directed causal relationships between multiple target feature data in the sample vector, as well as the directed causal relationships between target features and deadlock labels, are searched to obtain the causal graph of the sample vector library. Among them, cause-effect graph It includes nodes, directed edges, and causal paths. Nodes correspond to target features, directed edges indicate causal directions, and causal paths consist of multiple nodes and directed edges, intuitively presenting the business process of how multiple feature factors jointly trigger deadlock in a specific order. Finally, the instrumental variable method was used to analyze the cause-effect graph. Each causal path in the data is validated and screened for effectiveness. Specifically, the instrumental variable method is used, introducing signals that are not directly related to the database's business strategy but can externally influence the target characteristics as instrumental variables. Each directed edge in the graph undergoes a penetration test on its direction and strength. If an edge passes the test, it is retained; if the causal assumption is not satisfied, it is immediately deleted; if a node is proven to only co-occur with the deadlock label but does not contribute to the derivation, its entire node is removed. Finally, the causal graph is processed... Update to output a sparse and stable refined directed acyclic graph. This ensures that only the core relationships that play a decisive role in the generation of deadlock remain in the graph.
[0034] It should be noted that the instrumental variables used in the above methods must meet two criteria: zero correlation with the deadlock label and significant correlation with the target features.
[0035] One optional implementation method introduces exogenous signals as instrumental variables. After offline verification using a two-phase least squares method, the exogenous signals that meet the discrimination criteria include: 1. Millisecond-level random entropy carried in the high-order bits of the transaction identity (ID), which can provide a natural perturbation to the lock request strength without changing the locking order; 2. Round-Trip Time (RTT) jitter reported in real time by the ingress gateway, which only affects the thread concurrency rhythm; 3. Instantaneous frequency limiting events of CPU control groups (cgroups), which can change the execution rhythm but do not determine the lock holding order; 4. Periodic trigger pulses of Write-Ahead Logging (WAL) flush or checkpoint, which can introduce input / output (IO) contention slot drift but do not directly cause circular waits. The above four types of exogenous signals are weak instrumental variables after two-phase least squares verification. All statistics are greater than 15, which meets the validity requirement.
[0036] In one alternative implementation, the refined directed acyclic graph The output is in the form of a node dictionary and a sparse edge table. Specifically, nodes are mapped to a metadata table using a 32-bit index, which records... Equal feature slot combinations, edges are saved as triples in compressed line format. ,in For node indexing, The causal strength is normalized by the Wald-F statistic; the above structure facilitates the online phase... Complexity read path and weight, while maintaining file-level portability and persistence efficiency.
[0037] In one implementation, optionally, the step of filtering the first feature data based on the causal relationship between the first feature data and the deadlock label within a preset multi-scale time window to obtain multiple target feature data includes: The first feature data is subjected to pulse coding processing to obtain pulse sequences of various first feature data; For each type of the first feature data, according to the pulse sequence, the number of times the first feature data and the deadlock label satisfy a causal relationship is counted within a multi-scale time window, wherein the causal relationship is used to indicate that the occurrence time of the first feature data is earlier than the trigger time of deadlock resolution. Based on the number of times the first feature data and the deadlock label satisfy a causal relationship within the multi-scale time window, the first feature data is filtered to obtain multiple second feature data. Based on the scene label and feature level corresponding to the second feature data, the second feature data is grouped and filtered to obtain multiple target feature data.
[0038] In this embodiment of the invention, a feature filtering method is provided. First, to facilitate subsequent calculations, the first feature data is... Pulse coding processing is performed to obtain pulse sequences of various primary feature data. ; Then, for each type of first feature data, based on the pulse sequence, the number of times the first feature data and the deadlock label satisfy a causal relationship is counted within a multi-scale time window, that is, the number of times the feature pulse leads the deadlock label within the multi-scale window is counted. The number of times, among which, the multi-scale time window includes a fixed short window Window Long windows Three scales; Secondly, based on the number of times the first feature data and the deadlock label satisfy a causal relationship within the multi-scale time window, the cross-window consistency index is calculated. The calculation formula is as follows: in, This is a cross-window consistency index, with a value range of... This is a stability metric used to measure whether the first feature data always appears earlier than the deadlock label within a multi-scale time window. Window length, occupies one of three; Used to indicate in ( Whether a characteristic pulse occurs at time ) takes a value of 0 / 1. When, it indicates the appearance of a characteristic pulse, in When the characteristic pulse is not present, it indicates that no characteristic pulse has been observed. Used to indicate at time Whether a deadlock has occurred is determined by a value of 0 or 1. When =1, it indicates a deadlock has occurred. When =0, it indicates that no deadlock has occurred. If A value close to 1 indicates that the first feature data consistently precedes deadlock across all window scales; a value close to 0 indicates that the leading relationship between the first feature data and the deadlock label is inconsistent or only occasionally synchronized.
[0039] Based on the cross-window consistency index To filter the first feature data, firstly, based on a pre-set threshold... Determine whether to perform offline filtering on the first feature data: only if Only when the threshold is reached is the corresponding first feature data determined as candidate feature data; then, based on the threshold... Online screening of candidate feature data is performed if and only if When the corresponding candidate feature data is determined as the second feature data, it is ensured that it maintains a leading advantage in all time steps and eliminates occasional co-occurrence noise.
[0040] It should be noted that the threshold ε belongs to the offline leading feature screening stage and is used to judge the "cross-window consistency index". "Whether the leading position is stable enough determines whether a certain feature data enters the subsequent causal mining. The goal is to filter out occasional co-occurrences and noisy features before they enter the subsequent causal graph learning, thereby reducing the subsequent search space and reducing the source of false causal edges." The policy threshold, which is part of the operational feasibility strategy, determines whether "screened candidate feature data" is ultimately selected as the second feature data. It also participates in the solidification of subsequent risk level judgment rules and the selection of dynamic link library versions under different business loads. The threshold is obtained by performing a grid search on the training set with performance metrics as the target and is written into the configuration for runtime hot updates. The two screening processes address two different levels of uncertainty: the first addresses whether the feature possesses stable leading characteristics, and the second addresses "how stringent the threshold should be among the leading characteristics to achieve an operational balance between false positives and false negatives." Therefore, they need to be set separately and executed twice.
[0041] Finally, the second feature data is grouped and filtered according to the scene label and feature level corresponding to the second feature data to obtain multiple target feature data.
[0042] Optionally, the scene tags include transaction type tags and resource level tags; The step of grouping and filtering the second feature data according to the scene label and feature level corresponding to the second feature data to obtain multiple target feature data includes: The second feature data is grouped according to the transaction type label and the resource level label to obtain multiple first feature groups. Each first feature group includes multiple second feature data. The transaction type label and the resource level label corresponding to multiple second feature data belonging to the same first feature group are the same. The transaction type label and / or the resource level label corresponding to the second feature data in different first feature groups are different. Second feature data that does not belong to any of the first feature groups are identified as cross-layer feature data, and the cross-layer feature data are grouped according to feature level to obtain multiple second feature groups. Among them, at least one cross-layer feature data belonging to the same second feature group corresponds to the same feature level, and the feature level includes at least one of transaction layer, resource layer and system layer. According to the multivariate Granger test method, the second feature data in each of the first feature groups are filtered to obtain multiple first target feature data. According to the pre-set second threshold, the cross-layer feature data in each of the second feature groups are filtered to obtain multiple second target feature data, wherein the second thresholds corresponding to different second feature groups are different; The target feature data is obtained by performing a union calculation on the plurality of first target feature data and the plurality of second target feature data.
[0043] In this embodiment of the invention, the second feature data is grouped, and then the feature data in each group is filtered. The specific grouping method includes: First, read the transaction type label and resource level label of each second feature data. Group multiple second feature data with the same transaction type label and resource level label into the same first feature group. For example, the transaction type label of first feature group 1 is "e-commerce - order placement", the resource level label is row-level inventory resource, and first feature group 1 includes: resource contention heat - data 1, resource contention heat - data 2, and transaction runtime - data 1. The transaction type label of first feature group 2 is "payment confirmation", the resource level label is table-level resource, and first feature group 2 includes: resource contention heat - data 3, transaction runtime - data 2, and transaction runtime - data 3.
[0044] Second feature data that does not belong to any of the first feature groups are identified as cross-layer feature data. For example, resource contention heat - data 4 does not belong to any of the first feature groups, so it is identified as cross-layer feature data.
[0045] For cross-layer feature data, it is grouped according to its corresponding feature level. Cross-layer feature data with the same feature level are grouped into the same second feature group. The feature level includes at least one of the transaction layer, resource layer and system layer. For example, the feature level of features such as transaction type code, transaction runtime, and number of locks held belongs to the transaction layer, the feature level of features such as the logical level type of the requested lock and the resource contention heat belongs to the resource layer, and the feature level of features such as the number of global concurrent transactions and the current CPU load belongs to the system layer.
[0046] Then, the feature data in the first feature group and the second feature group are filtered separately, and the specific methods are as follows: For each first feature group, an improved multivariate Granger test is used to filter the second feature data in the first feature group, retaining only those that pass the directionality test and whose causal lag order falls within the range of... Features within the same layer are used to generate a candidate set at the same level. Candidate set at the same level This includes the first target feature data; among which, the improved multivariate Granger test method is as follows: In this embodiment of the invention, the multivariate Granger test is implemented using a vector autoregression (VAR) framework. The vector sequence is fed into the system after being stationary through the Augmented Dickey-Fuller Test (ADF) or after first-order differencing. ; The initial value is min(Akaike Information Criterion (AIC), Bayesian Information Criterion (BIC)) at... The value is automatically selected within the range and then fixed at 2 to maintain consistency with the lag order constraint, where k represents the lag order.
[0047] For the causality test process, for any candidate edge (i.e., whether variable x causes variable y via Granger causation), construct a structure containing The unconstrained model with first-order lags and the constrained model with zero-order response coefficients were tested using the heteroscedastic Wald-F statistic; the significance level was set to [value missing]. And based on the assumed quantity, a Bonferroni correction is applied. If the corrected quantity... Then it is believed Granger leads to, given other covariates The corresponding edges are preserved.
[0048] Furthermore, it should be noted that the causal lag order is limited to... The reason lies in the extremely fast propagation speed of lock waits in Online Transaction Processing (OLTP) scenarios: with a vectorized step size of 100ms, the first-level lag already covers the local thread scheduling time, and the second-level lag, by tracing back further, can encompass more than 95% of the actual trigger chain depth. On offline samples... A grid scan was performed, and it was found that The AIC improvement was less than 1%, while the number of model parameters increased linearly, leading to multicollinearity and overfitting during the DAG learning phase. Simultaneously, lock inheritance exceeding two hops was extremely rare in practical applications, and retaining longer lags did not provide substantial causal explanatory power. Therefore, in a trade-off between accuracy, sparsity, and computational cost, the lag order was constrained to [value missing]. It is the optimal choice.
[0049] For each second feature group, a second threshold is pre-set for each second feature group. Then, the cross-layer feature data in the second feature group is filtered using the corresponding second threshold, retaining only the cross-layer feature data greater than the second threshold, thus generating a cross-layer candidate set. By using layered processing, we can avoid missed detections caused by cross-layer variables masking each other.
[0050] Finally, for the candidate set at the same level The first target feature data and cross-layer candidate set The union of the second target feature data is taken to obtain the final required set. and will The target feature data, along with its corresponding window configuration and transaction role labels, are output to the structured modeling engine to achieve high confidence and low redundancy input for the root cause of deadlock.
[0051] In one embodiment, optionally, the step of performing risk screening and discrete compression processing on the causal paths in the causal graph to construct a dynamic link library includes: For each of the causal paths, sequential multiplication is performed and a large sum path penalty is calculated to obtain the risk score of each causal path; The causal paths are sorted in descending order of risk scores to obtain a first sequence; The first K causal paths in the first sequence are determined as target causal paths, and the target causal paths are stored in the configuration library, where K is an integer greater than 0; Based on a preset boundary threshold, the target causal path is discretized to determine the risk level of each target causal path; Construct a target decision tree based on the target causal path and the risk level of the target causal path; The target decision tree is compiled into a dynamic link library.
[0052] In this embodiment of the invention, after obtaining the causal graph Next, the risk score of the causal path is obtained first, then the causal path is filtered based on the risk score, and finally, the filtered causal path is compiled to obtain a dynamic link library. The specific method is as follows: First, sequential multiplication and path penalty calculation are performed on each causal path to obtain the risk score of each causal path. The specific operation is as follows: The first step is to Each causal path is denoted as ;right The causal strength of each directed edge is read according to the order of business triggering. and to Perform sequential multiplication to obtain the basic contribution value. This operation fully preserves the layer-by-layer contributing effect of each link in the causal path on the generation of deadlock, so that the subsequent risk ranking closely follows the actual triggering logic. In one optional implementation, the method for performing sequential multiplication of causal paths includes: first determining... Each directed edge in initial causal strength , specifically Determined by the Wald-F statistic, and then, to reduce long-tail interference, At the 99th percentile of the sample After truncation, it is mapped to ,like Then discard it directly. The mapping formula is as follows: Then, define the causal path. Its basic contribution value Defined as sequential multiplication Large factorials will be introduced and distributed during online evaluation. ( The average resource heat of the path nodes. (after offline calibration) and length penalty ( Thus, a comprehensive risk score is obtained. .
[0053] Finally, the above sequential multiplication method is applied to the validation set of the sample vector library to determine the first threshold; and the first threshold is used to... Filter the causal paths in the data and retain the remaining ones. The causal path at the first threshold is updated. For example: the first threshold is 0.05, retain The causal path can simultaneously guarantee a recall limit of less than 0.1% for high-risk paths and a marginal false alarm rate of less than 1.5%, thereby completing the quantification, screening, and standardized evaluation of causal strength.
[0054] The second step is to update the first step. Each causal path Perform concurrent large-scale processing, specifically for each path. First, read the number of chained waits that appear in the offline logs. That is, reading the number of times the "lock wait chain pattern" is observed in the offline log within this path, and then using a mapping function to... The formula for converting to amplified weights is as follows: in, Representing causal paths amplification weight, Representing causal paths The number of chained waits appearing in offline logs. The above method explicitly emphasizes the persistent damage caused by recurring chains during high-concurrency periods by amplifying the weight, ensuring that the real business pain points are prioritized.
[0055] The third step is to update the steps from the first step. Each causal path Path penalty processing is applied, specifically for each causal path. First read number of sides For example, if a causal path follows the node order "node 1 to node 2 to node 3", then this causal path contains 2 directed edges, therefore the number of edges is 2; a penalty function is then applied to... Perform calculations to generate penalty factors. The formula is as follows: in, express The number of sides, Represents a constant penalty coefficient. Representing causal paths The penalty factor, which monotonically decreases as the path length increases, is used to reduce the relative weight of excessively long but low-probability-of-trigger chains.
[0056] In one optional implementation, the value of η is obtained through offline grid search. And the harmonic mean of precision and recall (F1-Measure) is used to calculate the overall metric. The objective function is determined by methods including testing on three representative production logs (e.g., transaction concurrency of 512, 768, and 1024). The curve is The interval forms a plateau; if it's too small, it will lead to an increase in false alarms for long chains; if it's too large, it will... The actual deadlock path is excessively weakened; therefore, considering both platform peak performance and model simplicity, the default value is set to [value missing]. To accommodate business differences, η can be adjusted in the YAML configuration. Within the effective range, experiments show that within this interval... The change will not exceed 2%.
[0057] The fourth step is to combine the above three factors ( , By performing comprehensive calculations, the causal path can be obtained. Final risk score The formula is as follows: in, causal path Directed edges inside; For the edge The causal strength; causal path The number of chained waits observed in the offline logs; causal path The number of sides; Here, is the length penalty coefficient, and is a constant determined before deployment; causal path Risk score.
[0058] Then, after obtaining the risk score of the causal path, the causal path is filtered according to the risk score. The specific operation is as follows: The first step is to classify them in descending order of risk score. The causal paths in the data are sorted to obtain the first sequence. The top M causal paths in the first sequence are selected as candidate causal paths. The node sequence, business meaning of each node, and risk score of each candidate causal path are recorded. This constitutes a set of high-risk routes; The second step involves sequentially numbering the candidate causal paths in the high-risk path set, and serializing the node sequence, node business meaning, and edge strength value for each candidate causal path; subsequently, the serialization results are combined with... Write it to the configuration library together The offline output is compressed to a size that can be solidified and maintained, and then used as the sole input for the subsequent lightweight decision-making compilation stage.
[0059] Secondly, the causal path is discretized. Specifically, the first step is to preprocess the causal path, including the following operations: First, configure the library The serialization results of the high-risk path set in the data and Merge them; then, based on actual needs, categorize them according to risk scores. The size of the path determines the selection of K candidate causal paths as the target causal path. Where K is an integer less than or equal to M; finally, for each target causal path Record at least one of the following in sequence: Node order ; Comparison Field Index Set This is a "field position index table" automatically generated by the system during offline compilation. Specifically, it means that for each target causal path, the feature slots, node attributes, or comparison items that need to be used during online determination are uniformly mapped to a set of fixed index numbers. Subsequently, the dynamic link library only needs to retrieve values from the fixed-length feature array according to these indices and perform sequential comparisons. It does not need to parse the path text or node semantics. Its function is to convert the "business meaning of path nodes" into machine-executable data retrieval and comparison positions, thereby supporting risk code output with constant overhead and providing constraints to maintain the consistency of interface field order during hot replacement. Auxiliary threshold constant set It is a threshold table generated and solidified by the discretization process. It usually corresponds one-to-one with the set of comparison dictionary indexes and is used for branch comparison thresholds during online judgment. Its function is to allow dynamic link libraries to reproduce the judgment boundary of offline high-risk paths by performing only a few fixed threshold comparisons at runtime, thereby compressing the complex offline path scoring and sorting results into a lightweight set of rules that can be hot-replaced and stably executed. Through the above actions, the scope of the online lock manager is limited to at most... Avoid traversing redundant paths at high-risk links while waiting for a decision point.
[0060] The second step is to apply the preset boundary threshold. For the preprocessed target causal path Risk discretization is performed to determine the risk level of each target causal path. The operational methods include: Based on the preset boundary target causal path Risk score Mapped to integer risk level number ,in, =0 represents the security level. =1 represents a medium-risk level. =2 represents a high-risk level; and a unique error code is statically assigned to each risk level. Description of the default retry policy And write the path metadata to the intermediate configuration file synchronously. .
[0061] In one alternative implementation, the boundary It was determined through a two-step process: offline one-time calibration and online sliding fine-tuning. The method included: first, performing offline calibration on data from the past three months... When performing kernel density estimation, using the 40th, 85th, and 97th percentiles as initial thresholds, the typical mapping falls on... Nearby; after running, each cumulative The new path then recalculates the candidate thresholds based on the same tertile of the current sample and uses exponentially smoothed weights. Rolling updates, while maintaining and To avoid level collapse, the final judgment rule is: Recorded as security level , Classified as medium risk , Classified as high-risk This adaptive strategy has maintained a high-risk deadlock recall rate of over 94% in the Transaction Processing Performance Council Benchmark C (TPC-C) and multiple production benchmarks, while the overall false positive rate is less than 3%, and it can automatically converge with load fluctuations without manual readjustment.
[0062] Finally, based on the target causal path and target causal path Based on the risk level, a decision is made to compile and build a dynamic link library.
[0063] In this embodiment of the invention, weak features are first filtered out using cross-window leadership, then instrumental variables are introduced to perform direction and strength tests on the DAG, and finally chain frequency and length penalties are superimposed to retain only a very small number of causal paths that are significant at all time scales and have the highest risk. This can significantly compress the rule size, avoid putting a large number of low-confidence paths into lock management hot paths, and achieve simultaneous improvement in model volume reduction and offline computation interpretability.
[0064] In one implementation, optionally, constructing a target decision tree based on the target causal path and the risk level of the target causal path includes: Based on the common prefix folding method and the risk level of the target causal path, each target causal path is sequentially inserted into the prefix trie to obtain an initial decision tree. In the case where the prefix of the currently inserted target causal path overlaps with the prefix of the target causal path already inserted in the prefix trie, for the same prefix, the target causal path with the lower risk level is deleted. The risk level is proportional to the risk degree of the target causal path. For each leaf node in the initial decision tree, the leaf node's hidden node label is determined based on the leaf node's risk level, the risk level of the leaf node's ancestor nodes, and the node type of the ancestor nodes. The hidden node label is used to indicate whether the leaf node needs to be deleted. Based on the hidden label of the leaf node, the leaf node in the initial decision tree is deleted to obtain the first decision tree; The paths in the first decision tree are truncated according to the preset path depth to obtain the target decision tree.
[0065] In this embodiment of the invention, a method for constructing a target decision tree is described. Through three methods—common prefix folding, risk-inclusive hidden element removal, and depth truncation—the target causal path is compressed into a structurally stable and node-depth-controlled compact decision tree. The specific method is as follows: Common prefix folding: folding each target causal path Node sequence Insert the prefix trie in sequence During the insertion process, for any existing prefix branch, if the inserted path and the existing path are at any depth... If the previous nodes are completely identical, then the current branch node is reused. If the end of the branch is reached and a leaf node already exists at that end position, then the target causal path of the currently inserted node is compared. Risk level number Risk level sequence of the existing target causal path Only the larger of the two values is retained, thus preserving the highest-risk chain under the same prefix, and then constructing the initial decision tree. Simply put, when constructing the initial decision tree, shared prefixes are merged, and for multiple paths under the same prefix, only the one with the higher risk level is retained to reduce redundant branches.
[0066] Risk inclusion and hidden risk elimination: Traverse all leaf nodes in the initial decision tree. For each leaf node u, read its uplink path and risk level index, and search for its first ancestor node from bottom to top. According to ancestor nodes The node type and risk level number are used to determine whether to retain leaf nodes. Leaf nodes that need to be deleted are deleted to obtain the first decision statement, ensuring that high-risk short chains can directly cover low-risk long chains and reduce redundant jumps.
[0067] Deep truncation: Residual causal paths after risk inclusion and concealment processing According to the preset path depth The target causal path in the first decision tree is truncated to obtain the target decision tree. Specifically, if a certain remaining causal path... depth Greater than the preset path depth Then retain the one closest to the root cause. The target decision tree is obtained by truncating subsequent branches of each node, with the total number of nodes and maximum depth fixed to constant levels. Alternatively, after the depth truncation operation, a prefix comparison with existing paths in the policy tree is triggered again. If completely duplicated prefixes are found, the path with the higher risk level number is retained, and the path with the lower risk level number is deleted, ultimately obtaining the target decision tree.
[0068] In summary, the three methods mentioned above—common prefix folding, risk-inclusive caching, and deep truncation—combined to achieve the following coverage minimization objective: in, causal path The node sequence; causal path The number of nodes; express for The prefix; causal path Risk level number; This is the subset of causal paths retained after pruning.
[0069] The objective function above shows that pruning minimizes the total number of nodes in the decision tree while ensuring that each original causal path is covered by a prefix path with a risk no lower than its own, thus achieving structural compression and providing predictable input for subsequent template generation.
[0070] In one implementation, optionally, determining the hidden label of each leaf node in the initial decision tree based on the risk level of the leaf node, the risk level of its ancestor nodes, and the node type of its ancestor nodes includes: For a leaf node in the current initial decision tree, if the risk level of the leaf node is less than or equal to the risk level of its ancestor node, and the ancestor node is a leaf node, then the leaf node's hidden label is determined to indicate that the leaf node needs to be deleted. For a leaf node in the current initial decision tree, if the risk level of the leaf node is greater than the risk level of its ancestor node or the node type of the ancestor node is not a leaf node, the leaf node's hidden label is determined to indicate that the leaf node does not need to be deleted.
[0071] In this embodiment of the invention, the method for determining whether to retain leaf nodes in the above-mentioned risk inclusion and concealment operation is further explained. For the currently processed leaf node u, if the first ancestor node of leaf node u is... The node type is leaf node, and the ancestor node is... Risk level number Risk level number greater than or equal to leaf node u If the leaf node's first ancestor node is not explicitly declared as a hidden node, then the leaf node's hidden label indicates that the leaf node needs to be deleted. Conversely, if the leaf node's first ancestor node is explicitly declared as a hidden node, then the leaf node's hidden label indicates that the leaf node needs to be deleted. The node type is not a leaf node or an ancestor node. Risk level number Risk level number less than leaf node u The leaf node does not need to be deleted, ensuring that high-risk short chains can directly cover low-risk long chains, reducing redundant jumps.
[0072] It should be noted that the leaf node in this embodiment of the invention specifically refers to the path termination node, that is, the termination mark placed on the last node when inserting a causal path, rather than the structural leaf with a degree of 0 in traditional tree theory. In a prefix-shared trie, the termination node of a shorter causal path is often still extended downwards by a longer path, so a node can have child branches while still carrying a termination mark. One of the conditions for the above-mentioned risk-inclusive hidden node removal operation is the ancestor node. It is also a leaf node. Based on this mark, it ensures that only ancestor nodes that have been regarded as complete risk chains and have a sufficiently large risk level number are included in the culling process. If the ancestor node is just a pure internal transit node (without a termination mark), the culling process will not be triggered.
[0073] In one implementation, optionally, compiling the target decision tree into a dynamic link library includes: The nodes in the target decision tree are processed by hierarchical linearization to obtain the node vector of the target decision tree; Based on the depth and position information of the nodes in the node vector, position mapping is performed on each node in the node vector to obtain the position number of each node in the node vector. According to the position number in ascending order, each node in the node vector is filled in sequentially to obtain the linear instruction set of the target decision tree. The linear instruction set includes the position number of each node in the node vector and the sequential instruction corresponding to the position number. The linear instruction set is compiled to generate a dynamic link library.
[0074] In this embodiment of the invention, a method for compiling a target decision tree into a dynamic link library is described. The pruned target decision tree is translated into a dynamic link library through hierarchical linearization, line number mapping, and placeholder padding. The specific method is as follows: Hierarchical linearization involves traversing the target decision tree from the root node in hierarchical order, generating node vectors for each node in the target decision tree. Furthermore, within the same depth, the node vectors are reordered from smallest to largest by field index to ensure that the locality of runtime memory access conforms to the cache line alignment rules, thus creating a monotonic address space for subsequent line number mapping.
[0075] Row number mapping, based on the depth and position information of nodes in the node vector, employs a layered cardinality and intra-layer offset strategy to map each node in the node vector. Perform position mapping processing separately to obtain the position number of each node in the node vector. The formula is as follows: in, For nodes The depth; For depth The number of nodes in the layer; For nodes Starting from position zero in this layer; For nodes The corresponding position number (unique and monotonic). Using the above method, the conversion from the hierarchical index to the physical row number (i.e., the position number) can be completed in one step, and all subsequent jump targets can directly reference this constant. Eliminate runtime branch prediction.
[0076] Placeholder filling, traversing the node vector in position number order. ; For the currently processed node ,like To determine the node, write the ternary placeholder ⟨ field index, integer threshold, and target location number >, where the target location number is taken as... , ,in, Indicates the position number of the left subtree entrance. This indicates the position number of the right subtree entry point. In application, if the node is a judgment node, it will first take the value from the fixed-length feature array according to the comparison dictionary index and perform a sequential comparison. If the comparison result is true, it will jump to the corresponding entry line of the left subtree to continue execution; if it is false, it will jump to the entry line of the right subtree to continue execution. Therefore, the left subtree and the right subtree correspond to the next code segment position of the two branch paths, respectively. The purpose of the above design is to flatten the tree structure into linear code and use fixed line numbers to achieve unconditional jumps, ensuring that there will be no complex interpretation execution overhead in the hot path of the lock manager.
[0077] For the currently processed node ,like If it is a leaf node, then write the binary placeholder ⟨ risk level number. Error code >, and add a single-line return statement.
[0078] Through the above operations, a linear instruction set (i.e., intermediate code framework) containing only the target decision tree of sequential comparison and unconditional jump labels can be obtained, ensuring that the entire logic can pass smoothly through the processor pipeline.
[0079] Finally, the linear instruction set is compiled to generate a dynamic link library.
[0080] In one embodiment, optionally, the step of compiling the linear instruction set to generate a dynamic link library includes: Obtain metadata information, wherein the metadata information includes current version information, timestamp of the current version information, and hash information of the target decision tree; The source file for generating the target decision tree is generated based on the metadata information and the linear instruction set; The source file is compiled to generate a dynamic link library and an external interface for the dynamic link library. The external interface allows the dynamic link library to be called for risk identification.
[0081] In this embodiment of the invention, a method for compiling a linear instruction set to generate a dynamic link library is described. First, based on the linear instruction set, the decision tree is solidified into a source file, and then the source file is compiled. The specific method is as follows: First, obtain metadata information, including but not limited to current version information. Timestamp of current version information Hash information of the target decision tree ,in, The configuration is externally configured to increase monotonically, and is used for grayscale distribution. Record the start time of compilation, that is, the moment when the offline compilation pipeline starts generating this version of the dynamic link library, to facilitate problem backtracking; By analyzing the vector nodes of the target decision tree Hash aggregation is used to generate hashes for integrity verification before hot replacement.
[0082] Then, metadata information is injected into the linear instruction set to generate the source file of the target decision tree. A uniform return statement template is appended to the end of the file to ensure that the lock manager can obtain the final risk code with a single function call. Based on this, the abstract decision tree is solidified into the source file, laying an immutable execution skeleton for subsequent compilation and online mounting.
[0083] Finally, the source files are compiled using the compiler's highest level of optimization options to generate a single dynamic link library; version information and a timestamp are written to the library header. In conjunction with root cause summaries, consistency checks are performed during heating system replacement. Simultaneously, an external interface is exposed that accepts only a fixed-length feature array and synchronously returns a single-byte risk level index. And write its declaration into a dedicated header file so that the database kernel can perform static link checks at compile time.
[0084] In one embodiment, optionally, the step of calling a pre-built dynamic link library to perform risk identification on the feature array of the lock request and obtain the risk level of the lock request includes: calling the external interface of the dynamic link library to perform risk identification on the feature array of the lock request and obtain the risk level of the lock request.
[0085] In this embodiment of the invention, the method for risk identification of lock requests when calling dynamic link libraries is described as follows: First, load the dynamic link library along with the database instance startup script, and register a callback for the lock manager's wait determination entry point. ; Then, the lock request is intercepted at the lock manager's native wait determination entry point, and this lock request represents the first transaction. Request by the second transaction Upon acquiring the first resource, the lock manager immediately writes multiple fixed-length fields in a predefined order to construct a fixed-length feature array x. This feature array includes, but is not limited to, the transaction status features of the first transaction and the resource status features of the first resource. The transaction status features include, but are not limited to, the first transaction... Business type code First matter runtime (Unit: milliseconds), First Transaction Number of locks held Resource status features include, but are not limited to, the resource logical level corresponding to the first resource in the feature vector. .
[0086] Finally, the feature array External interfaces directly passed to dynamic link libraries This interface executes pre-generated code lines sequentially within the calling thread, without stack expansion or object construction, and returns a single-byte risk level number immediately upon completion of the call. , and, according to the first transaction Based on the business type and a predefined rule mapping table, determine the corresponding lock request. Transaction priority .
[0087] In the above risk identification process, the lock manager only needs to construct a feature array and return a single-byte risk code in O(1) without traversing the wait graph or adjusting the dynamic threshold, which can effectively eliminate branch prediction failure and cache jitter.
[0088] In one optional implementation, a policy mapping table is pre-built before intervening in the lock request. Specifically, the policy mapping table is built using a static table compilation method, and updated and maintained using hot-swap pointers. This method can completely decouple the offline policies in the policy mapping table from the online lock scheduling, allowing any business party to adjust the intervention action without downtime by simply modifying the external configuration file. The specific method is as follows: The method for constructing a policy mapping table using static table compilation includes: loading the YAML configuration file in the startup directory into the initialization routine, and reading three lines (risk level numbers). ) and rule mapping table ( (Column) (Transaction Priority) An integer matrix is formed, and a strategy number is written into each cell. Its meaning is uniformly defined in external documents. After parsing is complete, the matrix is serialized into a one-dimensional constant array in row-major order. It is placed in a read-only segment to build a policy mapping table; this layout allows direct indexing at runtime using linear address offsets, without the need for two-dimensional subscript splitting.
[0089] It should be noted that the YAML configuration file maintains a three-level nested structure corresponding to the memory matrix. Specifically, the top-level key, risk-policy, lists three ordered sequences, with indices 0, 1, and 2 corresponding to risk codes respectively. Within each sequence, further priorities are set according to business function. From 0 to Permutation Integer Strategy Code The parser reads the three sequences into a two-dimensional matrix during the startup phase. Then, it is linearly flattened and mapped to a read-only segment, achieving the desired result. The O(1) speed retrieval does not involve string comparison or additional hashing throughout the process.
[0090] It should also be noted that transaction priority The categories are divided based on two indicators: business timeliness and compensation cost. For asynchronous or batch jobs, For ordinary online transactions, For user interface synchronization requests, This is reserved for millisecond-level critical paths such as payment and matching; in most production systems It already covers 99% of scenarios. If the business has a more granular Service Level Agreement (SLA), it can be expanded in powers of 2. And there is no need to modify the search formula, because the array index still maintains a 32-bit integer range; actual tests show that when... When priority differentiation and scheduling benefits approach saturation, and YAML size and cache miss costs begin to rise significantly, the specification recommends that... The range is limited to a closed interval of 4–8, and an even number is selected based on the SLA density, but this invention does not limit this.
[0091] The method of updating and maintaining the policy mapping table through hot-swapping pointers includes: further adapting to constantly changing online business needs, maintaining a global array of pointers. read-only pointer When the operations and maintenance personnel update the YAML file and trigger the hot reload script, the initialization routine regenerates the new array. And it uses a one-time operation to switch the read-only pointer. The specific process for hot-swapping is as follows: Step 1: After the management script parses the latest YAML, it first generates a new array Z′, and does not expose references to it during the generation process; Step 2: After the new array Z′ is generated, the compare-and-swap instruction is used to replace ptz with the starting address of Z′ in one go. The CPU primitive ensures that the replacement process is atomic and lock-free, and all concurrent threads will automatically switch to the new data on the next read. Step 3: The old array is recycled in the background after the last read thread leaves through the Read-Copy-Update (RCU) counter. There are no write locks or pauses throughout the process, which maintains transaction continuity and meets the requirements of online dynamic parameter tuning.
[0092] Furthermore, before intervening in a lock request, the target intervention policy needs to be queried in the policy mapping table. The lock manager always addresses the policy mapping table through this pointer, and the switching process does not require stopping writing or locking, ensuring that real-time transactions are not blocked. The old array is recycled by the background after the last concurrent reference count reaches zero. The entire mapping logic maintains a single addressing path, which meets the deterministic latency requirements of high-concurrency scenarios. An online hot replacement only requires overwriting the old file with the new YAML and triggering a single frame read. The old matrix is automatically recycled. The format is intuitive and meets the low latency requirements at runtime.
[0093] It should be noted that, to ensure atomicity and consistency, a single atomic pointer ptz can be used to point to a read-only array Z.
[0094] In one implementation, optionally, the step of intervening in the lock request based on the risk level, the transaction priority, and a predefined strategy mapping table, and generating an intervention record for the lock request, includes: Based on the risk level and the transaction priority, the strategy mapping table is queried to obtain the target strategy for the lock request; The lock request is intervened in according to the target strategy, and an intervention record for the lock request is generated. The intervention record includes the target strategy and the intervention result of the first transaction corresponding to the lock request.
[0095] In this embodiment of the invention, after obtaining the risk level and transaction priority of the lock request, a target strategy for intervening in the lock request is determined through a pre-built strategy mapping table. Specifically, a constant-level addressing method is used to determine the target strategy for intervening in the lock request in the strategy mapping table, so that the lock management thread always maintains a definite latency for a single array read operation. The specific method is as follows: First, the lock manager obtains the risk level number of the lock request from the risk assessment interface of the dynamic link library. And the transaction priority is known. Immediately calculate the array offset and read the corresponding target strategy number. The addressing process is completed with a single CPU instruction, without any branching or judgment. The calculation formula is as follows: in, Single-byte risk level sequence number for lock requests The values are 0 (safe), 1 (medium risk), and 2 (high risk). The number of priority levels supported by the system is determined as a constant at startup; For transaction priority, the range of values is... ; It is a one-dimensional read-only array that stores the policy numbers in the policy mapping table; The output target strategy is numbered and used to drive subsequent differentiated interventions.
[0096] Then, based on the target strategy number The corresponding target strategy intervenes in lock requests and generates an intervention record for the lock requests. Based on this, offline causal inference is translated into an online real-time intervention mechanism with zero inference overhead, and the risk of deadlock in high-concurrency scenarios is pre-probabilistically pruned.
[0097] It should be noted that, in one optional implementation, if the dynamic link library identifies a lock request with a risk level... If the risk level is high, the corresponding target strategy number can be directly determined. .
[0098] In one embodiment, the target strategy may optionally include any one of a first strategy, a second strategy, and a third strategy; The process of intervening in the lock request according to the target strategy and generating an intervention record for the lock request includes: When the target strategy is the first strategy, the lock request is inserted at the end of the current request waiting queue, and the lock request is marked with a first tag to generate an intervention record for the lock request. The first tag is used to indicate that the lock request cannot be scheduled in the current request waiting queue. If the target strategy is the second strategy, a rollback operation is performed on the first transaction corresponding to the lock request, and an intervention record for the lock request is generated. When the target strategy is the third strategy, the lock request is inserted into the end of the current request waiting queue and kept in a yielding state according to the preset yielding duration. If the first resource requested by the lock request is released, and the first concession time of the lock request being inserted at the end of the current request waiting queue is less than or equal to the preset concession time, the lock request is switched from the concession state to the normal ordering state. If the first resource requested by the lock request has not been released, and the first concession duration of the lock request inserted at the end of the current request waiting queue is greater than the preset concession duration, the dynamic link library is invoked to re-identify the risk of the lock request and obtain the risk level of the lock request.
[0099] In this embodiment of the invention, the target strategy is numbered. The lock request executes the first strategy, namely the zero-level intervention strategy. Specifically, the lock request is inserted at the end of the current request waiting queue, and the lock request is marked with a first label. The first label is used to indicate that the lock request cannot be scheduled in the current request waiting queue. For example, the lock request skips the priority promotion logic in the queue, ensuring that the benign waiting path fully reuses the existing implementation and does not interfere with normal business. Finally, an intervention record for the lock request is generated, which includes the first strategy and the final result of the lock request after the execution of the first strategy.
[0100] Number the target strategy The lock request executes the third strategy, namely the first-level intervention strategy. Specifically, the lock request is inserted at the end of the current request waiting queue and marked as a yield state. In addition, a timer is needed to set the preset yield duration for the lock request to move to the end. If the first resource requested by the lock request is released, and the first concession time of the lock request inserted at the end of the current request waiting queue is less than or equal to the preset concession time, the lock request will be switched from the concession state to the normal ordering state, the lock requests will be ordered normally, and the transaction will continue normally. If the first resource requested by the lock request has not been released, and the first concession duration of the lock request inserted at the end of the current request waiting queue is greater than the preset concession duration, then the dynamic link library is invoked to re-identify the risk of the lock request and obtain the risk level of the lock request. The third strategy mentioned above reduces the probability of potential circular waiting by combining concession and timeout. After the third strategy is executed, a corresponding intervention record will be generated. The intervention record includes the third strategy and the final result of the lock request after the third strategy is executed.
[0101] Number the target strategy The lock request executes the second strategy, also known as the secondary intervention strategy. Specifically, it immediately rolls back the first transaction corresponding to the lock request. Release all locks it holds and return a preset error code to the client. It includes a retry option; simultaneously, it writes a record of a deadlock-high-risk link being severed in the internal audit log, containing the first transaction. The identifier and trigger path fingerprint are used to enable the operations and maintenance side to quickly locate the source of the business. Based on this, high-risk conflict links are proactively disconnected in advance, and the probability of database deadlock is substantially reduced. After executing the second strategy, a corresponding intervention record is generated, which includes the second strategy and the final result of the lock request after executing the second strategy. In one optional implementation, the intervention record specifically includes: the lock manager executing Operation number generated after any target strategy First Transaction Number With instant result code The above information should be added to the intervention outcome table. This creates an intervention record; specifically, it involves continuous scanning using a cursor-fetching mode in an independent listening thread. When the same transaction is detected Immediately complete the event upon final commit or rollback. The ending field of the corresponding record This forms a closed loop corresponding to intervention actions and transaction finality, ensuring that any intervention can be fully traceable at the storage layer.
[0102] In one implementation, optionally, the intervention record includes the intervention result of the first transaction corresponding to the lock request; The step of updating the dynamic link library based on the intervention record includes: Based on the intervention results in the intervention record, the first transaction that meets the preset conditions is labeled with a second label to construct a first sample set, wherein the preset conditions include the intervention result of the first transaction being a successful submission; Real-time monitoring of the deadlock resolution log to obtain multiple second transactions that triggered deadlock resolution; A third label is assigned to the second transaction that does not have the aforementioned intervention record, and a second sample set is constructed; The dynamic link library is updated based on the first sample set, the second sample set, and pre-configured weight coefficients of the first and second sample sets.
[0103] This invention provides a method for updating dynamic link libraries, specifically based on online real-time generated intervention records and deadlock resolution log streams. A positive sample set and a negative sample set are constructed separately. Then, based on the positive sample set, the negative sample set, and the pre-configured weights, the sample vector library is updated, and subsequently, the dynamic link library is updated. The method is as follows: If the intervention result corresponds to the outcome field in the intervention record after the monitoring thread completes the intervention record... If an intervention was initiated and subsequent retry was successful, the intervention record will be labeled with a second tag. and the first information of the current lock request. With tags Concatenate into an extended vector And write them sequentially to the high-priority log channels. By explicitly labeling the proven effective blocking scenarios, we provide directly alignable positive samples for subsequent causal chain examination, thus constructing the first sample set, i.e., the positive sample set.
[0104] In addition, the deadlock resolution log stream output by the lock manager Perform real-time monitoring; if the sequence of transactions involved in a deadlock is detected... exist If there are no intervention records, a third label is generated for each transaction. An online feature array that captures the instant a deadlock occurs. and Concatenate into an extended vector And write to the same high-priority channel A second sample set, namely the negative sample set, is constructed to highlight the risk blind spots that the model has not yet covered.
[0105] Finally, a weighted delivery strategy is adopted to... The extended vectors are synchronously pushed to the historical event collection entry point of S101; the weight field is written during transmission. Weight field In subsequent causal mining statistical processes, this data is directly read to amplify the influence of proven effective and uncovered records, including the weight field. The determination logic is as follows: in, For delivery weights; The weight for successful scenarios is configured as a constant before deployment; To avoid missing scenario weights, configure them as constants before deployment; The label takes the value 1 (success) or 0 (omission). Based on this, high-value feedback information is seamlessly fed back into the original collection chain, updating the dynamic link library and providing more targeted input for the next round of causal sparsity and path scoring.
[0106] One optional implementation method uses a two-level weight configuration: success scenario weight. Taking 1 as the baseline, the weight of the missing pain scenario The range is 2–3; the upper limit of 3 comes from the inflection point of the marginal contribution of the missed pain samples in the offline data to the overall benefit, while the lower limit of 2 ensures consistency with... This results in at least a doubling of the discrimination. The weights only change the gradient amplification factor and do not introduce additional feature calculations, therefore having almost no impact on the wall-breaking point in a single training round; however... The larger the value, the more obvious the difference in the update magnitude of positive and negative samples. The early convergence will be faster, but a smaller learning rate is needed in the later stage to prevent oscillation. Therefore, it is recommended to fine-tune it within the range of 1-3 as needed after going live, but this invention does not limit it to this.
[0107] In another optional implementation, after the first sample set and the second sample set are returned, the dynamic link library is not updated immediately based on the first sample set and the second sample set. Instead, steps S101-S103 are executed when the triggering conditions are met. The triggering conditions include, but are not limited to, the number of samples in the first sample set and / or the second sample set being greater than the sample threshold, the sample growth rate in the second sample set being greater than the first rate, etc.
[0108] like Figure 2 As shown, one optional implementation method, using the database deadlock avoidance method provided in this embodiment of the invention, has the following specific implementation process: Step S201: Obtain the feature vector of the historical event. The feature vector includes, but is not limited to, at least one of the following: system state features, transaction state features of the target transaction corresponding to the historical event, and resource state features of the target resource requested by the historical event. Step S202: Construct a sample vector library based on the feature vector and the deadlock labels of historical events. The deadlock labels are used to indicate whether the historical event triggers deadlock resolution within a preset future time window. Step S203: Based on the deadlock label, perform feature filtering and causal graph learning on the feature vectors in the sample vector library to obtain the causal graph; Step S204: Perform risk screening and discrete compression on the causal paths in the causal graph, and construct a dynamic link library; Step S205: Expose the external interface of the dynamic link library and mount the dynamic link library; Step S206: Upon receiving a lock request and finding that the first resource requested is already occupied, the dynamic link library is invoked to generate the risk level of the lock request. Step S207: Execute the corresponding intervention strategy according to the risk level of the lock request and generate an intervention record; Step S208: Generate a first sample set and a second sample set based on the intervention records; Step S209: If the triggering conditions are met, update the dynamic link library based on the first and second sample sets. Specifically, the first and second sample sets are treated as historical events and flow back to step S201 to obtain the feature vectors corresponding to each sample in the first and second sample sets. If the triggering conditions are met (e.g., the number of samples in the first and / or second sample sets is greater than a sample threshold, the sample growth rate in the second sample set is greater than a first rate, etc.), execute steps S202-S204 to update the dynamic link library. After step S209, proceed to step S205 to mount the updated dynamic link library and perform hot replacement without interrupting service.
[0109] For step S203 above, as Figure 3 As shown, one optional implementation method involves performing feature filtering and causal graph learning on feature vectors in the sample vector library based on deadlock labels to obtain the causal graph. The specific implementation process is as follows: Step S301: Based on the deadlock label and cross-window consistency, perform feature filtering on the feature vectors in the sample vector library to obtain target feature data; Step S302: Based on the causal graph learning algorithm, search for the directed causal relationships between multiple target feature data in the feature vector and the directed causal relationships between the target feature data and the deadlock label respectively to obtain the causal graph of the sample vector library. Step S303: Using the instrumental variable method, validate and filter the validity of each causal path in the causal graph, and update the causal graph.
[0110] For step S204 above, as Figure 4 As shown, one optional implementation method involves risk screening and discrete compression of the causal paths in the causal graph, constructing a dynamic link library, and obtaining the causal graph through the following specific implementation process: Step S401: Perform sequential multiplication and path penalty calculation on each causal path in the causal graph to obtain the risk score of each causal path. Step S402: Sort the causal paths in descending order of risk score, and determine the top K causal paths as the target causal paths; Step S403: Discretize the target causal path according to the preset boundary threshold, determine the risk level of each target causal path, and bind the error code and default retry strategy. In step S404, based on the risk level of the target causal path, the discretized target causal path in step S403 is compressed using common prefix folding, risk inclusion culling, and deep truncation techniques to obtain the target decision tree. In addition, during the compression process, prefix folding feedback can be performed on step S403 for iterative optimization. Step S405: Perform hierarchical linearization, position mapping, and placeholder filling on the target decision tree to obtain a linear instruction set. Step S406: Inject metadata information and compile the linear instruction set to generate a dynamic link library. The metadata information includes the current version information, the timestamp of the current version information, and the hash information of the target decision tree. Step S407 exposes the interface of the dynamic link library for easy subsequent calls; Step S408: Determine if the dynamic link library version is updated. If yes, generate a new template and proceed to S402 based on the new template. If not, continue to step S407.
[0111] For steps S206-S207 above, as follows Figure 5 As shown, in one optional implementation, when a lock request is received and the requested first resource is occupied, the dynamic link library is invoked to generate the risk level of the lock request, and the corresponding intervention strategy is executed according to the risk level of the lock request. The specific implementation process for generating the intervention record is as follows: Step S501: The lock manager receives lock requests in real time. If the first resource requested by the received lock request is occupied, it obtains the transaction priority of the first transaction and the feature array corresponding to the lock request. Step S502: Call the external interface of the dynamic link library to identify the risk of the lock request feature array and obtain the risk level of the lock request; Step S503: Based on the risk level, transaction priority, and predefined strategy mapping table, determine the intervention strategy to intervene in the lock request and generate an intervention record for the lock request. Step S504: Intervene in the lock request according to the determined intervention strategy and generate an intervention record for the lock request.
[0112] For steps S208-S209 above, as follows Figure 6 As shown, one optional implementation method involves generating a first sample set and a second sample set based on intervention records, and updating the dynamic link library based on the first sample set and the second sample set when a trigger condition is met. The specific implementation process is as follows: Step S601: Obtain the intervention record, which includes the intervention result of the requested transaction; Step S602: Label transactions with successful submission results with a second label to construct the first sample set, i.e., the positive sample set; Step S603: Label transactions that trigger deadlock and do not have intervention records with a third label to construct a second sample set, i.e., a negative sample set; In step S604, based on the pre-configured weight coefficients of the first and second sample sets, the first and second sample sets are returned to step S201 as historical events. Then, if the triggering conditions are met, steps S202-S204 are executed to update the dynamic link library.
[0113] like Figure 7 As shown, this embodiment of the invention also provides a database deadlock avoidance device, comprising: The first acquisition module 701 is used to acquire the transaction priority of the first transaction and the feature array corresponding to the lock request when receiving a lock request of the first transaction and the first resource requested by the lock request is occupied. The feature array includes the transaction status features of the first transaction and the resource status features of the first resource. The first identification module 702 is used to call a pre-built dynamic link library to perform risk identification on the feature array of the lock request and obtain the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock to generate the risk level of the lock request. The first intervention module 703 is used to intervene in the lock request according to the risk level, the transaction priority and the predefined strategy mapping table, and generate an intervention record for the lock request; The first update module 704 is used to update the dynamic link library based on the intervention record.
[0114] Optionally, the device further includes: The first construction module is used to construct a sample vector library based on multiple historical events. The sample vector library includes feature vectors and deadlock labels corresponding to the feature vectors. Each feature vector corresponds to one historical event. The deadlock label is used to indicate whether the historical event triggers deadlock resolution within a preset future time window. The first processing module is used to perform feature filtering and causal graph learning on the feature vectors in the sample vector library according to the deadlock label, and obtain the causal graph of the sample vector library. The causal graph includes multiple causal paths, and the causal path is composed of multiple nodes and directed edges to represent the causal relationship between the nodes. The second processing module is used to perform risk screening and discrete compression processing on the causal paths in the causal graph, and construct a dynamic link library. Optionally, the feature vector in the first construction module includes at least one of the following: system state features, transaction state features of the target transaction corresponding to the historical event, and resource state features of the target resource requested by the historical event. The transaction state characteristics include at least one of the following: transaction type, transaction duration, and number of currently held locks: The resource status characteristics include at least one of the following: the hierarchical type to which the resource belongs and the resource contention intensity: The system state characteristics include at least one of the central processing unit (CPU) load and global concurrent transactions.
[0115] Optionally, the first processing module includes: The first partitioning submodule is used to partition the feature vectors in the sample vector library according to feature dimensions to obtain multiple first feature data. The first filtering submodule is used to filter the first feature data according to the causal relationship between the first feature data and the deadlock label within a preset multi-scale time window to obtain multiple target feature data. The first search submodule is used to search for the directed causal relationships between multiple target feature data in the feature vector and the directed causal relationships between the target feature data and the deadlock label respectively, according to the causal graph learning algorithm, to obtain the causal graph of the sample vector library; The first update submodule is used to perform validity verification and filtering on each causal path in the causal graph using the instrumental variable method, and then update the causal graph.
[0116] Optionally, the first filtering submodule includes: The first processing unit is used to perform pulse coding processing on the first feature data to obtain pulse sequences of various first feature data. The first statistical unit is used to count, within a multi-scale time window, the number of times the first feature data and the deadlock label satisfy a causal relationship for each type of the first feature data, based on the pulse sequence, wherein the causal relationship is used to indicate that the occurrence time of the first feature data is earlier than the trigger time of deadlock resolution. The first filtering unit is used to filter the first feature data based on the number of times the first feature data and the deadlock label satisfy a causal relationship within a multi-scale time window, thereby obtaining multiple second feature data. The second filtering unit is used to group and filter the second feature data according to the scene label and feature level corresponding to the second feature data to obtain multiple target feature data.
[0117] Optionally, the scenario tags in the second filtering unit include transaction type tags and resource level tags; The second filtering unit includes: The first grouping unit is used to group the second feature data according to the transaction type label and the resource level label to obtain multiple first feature groups. Each first feature group includes multiple second feature data. The transaction type label and the resource level label corresponding to multiple second feature data belonging to the same first feature group are the same. The transaction type label and / or the resource level label corresponding to the second feature data in different first feature groups are different. The second grouping unit is used to determine the second feature data that does not belong to any of the first feature groups as cross-layer feature data, and to group the cross-layer feature data according to the feature level to obtain multiple second feature groups. Among them, at least one of the cross-layer feature data belonging to the same second feature group corresponds to the same feature level. The feature level includes at least one of the transaction layer, resource layer and system layer. The third screening unit is used to screen the second feature data in each of the first feature groups according to the multivariate Granger test method to obtain multiple first target feature data. The fourth filtering unit is used to filter the cross-layer feature data in each of the second feature groups according to a preset second threshold to obtain multiple second target feature data, wherein the second thresholds corresponding to different second feature groups are different; The first calculation unit is used to perform a union calculation on the plurality of first target feature data and the plurality of second target feature data to obtain the target feature data.
[0118] Optionally, the second processing module includes: The first calculation submodule is used to perform sequential multiplication and maximization path penalty calculation on each of the causal paths in turn to obtain the risk score of each of the causal paths; The first sorting submodule is used to sort the causal paths in descending order of risk scores to obtain a first sequence; The second determining submodule is used to determine the first K causal paths in the first sequence as target causal paths and store the target causal paths in a configuration library, where K is an integer greater than 0; The second processing submodule is used to discretize the target causal path according to a preset boundary threshold and determine the risk level of each target causal path. The second construction submodule is used to construct a target decision tree based on the target causal path and the risk level of the target causal path; The first compilation submodule is used to compile the target decision tree into a dynamic link library.
[0119] Optionally, the second construction submodule includes: The first construction unit is used to insert each target causal path into the prefix trie in sequence according to the common prefix folding method and the risk level of the target causal path to obtain an initial decision tree. In the case that the prefix of the currently inserted target causal path overlaps with the prefix of the target causal path already inserted in the prefix trie, for the same prefix, the target causal path with the lower risk level is deleted. The risk level is proportional to the risk degree of the target causal path. The first determining unit is configured to, for each leaf node in the initial decision tree, determine the hidden node label of the leaf node based on the risk level of the leaf node, the risk level of the ancestor node of the leaf node, and the node type of the ancestor node, wherein the hidden node label is used to indicate whether the leaf node needs to be deleted. The first deletion unit is used to delete the leaf nodes in the initial decision tree according to the hidden label of the leaf nodes, so as to obtain the first decision tree; The first truncation unit is used to truncate the path in the first decision tree according to the preset path depth to obtain the target decision tree.
[0120] Optionally, the first determining unit includes: The second determining unit is used to determine, for a leaf node in the currently processed initial decision tree, if the risk level of the leaf node is less than or equal to the risk level of the ancestor node of the leaf node, and the node type of the ancestor node is a leaf node, that the leaf node's hidden label indicates that the leaf node needs to be deleted. The third determining unit is used to determine, for a leaf node in the currently processed initial decision tree, that if the risk level of the leaf node is greater than the risk level of the ancestor node of the leaf node or the node type of the ancestor node is not a leaf node, that the leaf node's hidden label indicates that the leaf node does not need to be deleted.
[0121] Optionally, the first compilation submodule includes: The second processing unit is used to perform hierarchical linearization processing on the nodes in the target decision tree to obtain the node vector of the target decision tree; The third processing unit is used to perform position mapping processing on each node in the node vector according to the depth information and position information of the nodes in the node vector, so as to obtain the position number of each node in the node vector. The first filling unit is used to fill each node in the node vector in ascending order of the position number to obtain the linear instruction set of the target decision tree. The linear instruction set includes the position number of each node in the node vector and the sequential instruction corresponding to the position number. The first compilation unit is used to compile the linear instruction set and generate a dynamic link library.
[0122] Optionally, the first compilation unit includes: The first acquisition unit is used to acquire metadata information, wherein the metadata information includes current version information, timestamp of the current version information, and hash information of the target decision tree; The first generation unit is used to generate the source file of the target decision tree based on the metadata information and the linear instruction set; The second compilation unit is used to compile the source file to generate a dynamic link library and an external interface for the dynamic link library, wherein the external interface enables the dynamic link library to be called for risk identification. Optionally, the first intervention module 703 includes: The first query submodule is used to query the strategy mapping table according to the risk level and the transaction priority to obtain the target strategy of the lock request; The first intervention submodule is used to intervene in the lock request according to the target strategy and generate an intervention record for the lock request. The intervention record includes the target strategy and the intervention result of the first transaction corresponding to the lock request.
[0123] Optionally, the target strategy in the first query submodule includes any one of the first strategy, the second strategy, and the third strategy; The first intervention submodule includes: The first intervention unit is configured to insert the lock request into the end of the current request waiting queue when the target strategy is the first strategy, and to mark the lock request with a first tag to generate an intervention record for the lock request, wherein the first tag is used to indicate that the lock request cannot be scheduled in the current request waiting queue. The second intervention unit is used to perform a rollback operation on the first transaction corresponding to the lock request when the target strategy is the second strategy, and generate an intervention record for the lock request. The third intervention unit is used to insert the lock request into the end of the current request waiting queue and maintain the concession state according to a preset concession duration when the target strategy is the third strategy. The fourth intervention unit is used to switch the lock request from the yield state to the normal ordering state when the first resource requested by the lock request is released and the first yield time of the lock request being inserted at the end of the current request waiting queue is less than or equal to the preset yield time. The fifth intervention unit is used to call the dynamic link library to re-identify the risk of the lock request and obtain the risk level of the lock request when the first resource requested by the lock request has not been released and the first concession duration of the lock request inserted at the end of the current request waiting queue is greater than the preset concession duration.
[0124] Optionally, the intervention record generated by the first intervention module 703 includes the intervention result of the first transaction corresponding to the lock request; The first update module 704 includes: The third construction submodule is used to label the first transaction that meets the preset conditions with a second label based on the intervention results in the intervention record, and construct a first sample set, wherein the preset conditions include the intervention result of the first transaction being a successful submission; The first monitoring submodule is used to monitor the deadlock resolution log in real time and obtain multiple second transactions that trigger deadlock resolution. The fourth construction submodule is used to label the second transactions that do not have the intervention record with a third label, thereby constructing a second sample set; The second update submodule is used to update the dynamic link library according to the first sample set, the second sample set, and the pre-configured weight coefficients of the first sample set and the second sample set.
[0125] It should be noted that the embodiments of this device are devices corresponding to the embodiments of the above methods. All implementations in the embodiments of the above methods are applicable to the embodiments of this device and can achieve the same technical effect.
[0126] This invention also provides a network device, including: a processor, a memory, and a program stored in the memory and executable on the processor. When the program is executed by the processor, it implements the database deadlock avoidance method described in any of the preceding claims and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0127] This invention also provides a readable storage medium, comprising: a program stored on the readable storage medium, wherein when the program is executed by a processor, it implements the steps of the database deadlock avoidance method described in any of the preceding claims, and achieves the same technical effect; to avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0128] This invention also provides a computer program product, including computer instructions. When the computer instructions are executed by a processor, they implement the steps of the database deadlock avoidance method described in any of the preceding claims and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0129] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0130] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A database deadlock avoidance method, characterized by, include: Upon receiving a lock request from a first transaction and finding that the first resource requested by the lock request is already occupied, the transaction priority of the first transaction and a feature array corresponding to the lock request are obtained. The feature array includes the transaction status features of the first transaction and the resource status features of the first resource. A pre-built dynamic link library is invoked to perform risk identification on the feature array of the lock request to obtain the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock to generate the risk level of the lock request. The lock request is intervened based on the risk level, the transaction priority, and the predefined strategy mapping table, and an intervention record for the lock request is generated. The dynamic link library is updated based on the intervention record.
2. The database deadlock avoidance method of claim 1, wherein, Before invoking the pre-built dynamic link library to perform risk identification on the feature array of the lock request, the method further includes: Based on multiple historical events, a sample vector library is constructed, wherein the sample vector library includes feature vectors and deadlock labels corresponding to the feature vectors, one feature vector corresponds to one historical event, and the deadlock label is used to indicate whether the historical event triggers deadlock resolution within a preset future time window; Based on the deadlock label, feature filtering and causal graph learning are performed on the feature vectors in the sample vector library to obtain the causal graph of the sample vector library. The causal graph includes multiple causal paths, which are composed of multiple nodes and directed edges to represent the causal relationships between the nodes. Risk screening and discrete compression are performed on the causal paths in the causal graph to construct a dynamic link library.
3. The database deadlock avoidance method of claim 2, wherein, The feature vector includes at least one of the following: system state features, transaction state features of the target transaction corresponding to the historical event, and resource state features of the target resource requested by the historical event. The transaction state characteristics include at least one of the following: transaction type, transaction duration, and number of currently held locks: The resource status characteristics include at least one of the following: the hierarchical type to which the resource belongs and the resource contention intensity: The system state characteristics include at least one of the central processing unit (CPU) load and global concurrent transactions.
4. The database deadlock avoidance method of claim 2, wherein, The step of performing feature filtering and causal graph learning on the feature vectors in the sample vector library based on the deadlock label to obtain the causal graph of the sample vector library includes: The feature vectors in the sample vector library are divided into feature dimensions to obtain multiple first feature data. Based on the causal relationship between the first feature data and the deadlock label within a preset multi-scale time window, the first feature data is filtered to obtain multiple target feature data. According to the causal graph learning algorithm, the directed causal relationships between multiple target feature data in the feature vector and the directed causal relationships between the target feature data and the deadlock label are searched respectively to obtain the causal graph of the sample vector library; The effectiveness of each causal path in the causal graph is validated and filtered using the instrumental variable method, and the causal graph is then updated.
5. The database deadlock avoidance method of claim 4, wherein, The first feature data is filtered based on the causal relationship between the first feature data and the deadlock label within a preset multi-scale time window to obtain multiple target feature data, including: The first feature data is subjected to pulse coding processing to obtain pulse sequences of various first feature data; For each type of the first feature data, according to the pulse sequence, the number of times the first feature data and the deadlock label satisfy a causal relationship is counted within a multi-scale time window, wherein the causal relationship is used to indicate that the occurrence time of the first feature data is earlier than the trigger time of deadlock resolution. Based on the number of times the first feature data and the deadlock label satisfy a causal relationship within the multi-scale time window, the first feature data is filtered to obtain multiple second feature data. Based on the scene label and feature level corresponding to the second feature data, the second feature data is grouped and filtered to obtain multiple target feature data.
6. The database deadlock avoidance method of claim 5, wherein, The scenario tags include transaction type tags and resource level tags; The step of grouping and filtering the second feature data according to the scene label and feature level corresponding to the second feature data to obtain multiple target feature data includes: The second feature data is grouped according to the transaction type label and the resource level label to obtain multiple first feature groups. Each first feature group includes multiple second feature data. The transaction type label and the resource level label corresponding to multiple second feature data belonging to the same first feature group are the same. The transaction type label and / or the resource level label corresponding to the second feature data in different first feature groups are different. Second feature data that does not belong to any of the first feature groups are identified as cross-layer feature data, and the cross-layer feature data are grouped according to feature level to obtain multiple second feature groups. Among them, at least one cross-layer feature data belonging to the same second feature group corresponds to the same feature level, and the feature level includes at least one of transaction layer, resource layer and system layer. According to the multivariate Granger test method, the second feature data in each of the first feature groups are filtered to obtain multiple first target feature data. According to the pre-set second threshold, the cross-layer feature data in each of the second feature groups are filtered to obtain multiple second target feature data, wherein the second thresholds corresponding to different second feature groups are different; The target feature data is obtained by performing a union calculation on the plurality of first target feature data and the plurality of second target feature data.
7. The database deadlock avoidance method of claim 2, wherein, The step of performing risk screening and discrete compression on the causal paths in the causal graph, and constructing a dynamic link library, includes: For each of the causal paths, sequential multiplication is performed and a large sum path penalty is calculated to obtain the risk score of each causal path; The causal paths are sorted in descending order of risk scores to obtain a first sequence; The first K causal paths in the first sequence are determined as target causal paths, and the target causal paths are stored in the configuration library, where K is an integer greater than 0; Based on a preset boundary threshold, the target causal path is discretized to determine the risk level of each target causal path; Construct a target decision tree based on the target causal path and the risk level of the target causal path; The target decision tree is compiled into a dynamic link library.
8. The database deadlock avoidance method of claim 7, wherein, The step of constructing a target decision tree based on the target causal path and the risk level of the target causal path includes: Based on the common prefix folding method and the risk level of the target causal path, each target causal path is sequentially inserted into the prefix trie to obtain an initial decision tree. In the case where the prefix of the currently inserted target causal path overlaps with the prefix of the target causal path already inserted in the prefix trie, for the same prefix, the target causal path with the lower risk level is deleted. The risk level is proportional to the risk degree of the target causal path. For each leaf node in the initial decision tree, the leaf node's hidden node label is determined based on the leaf node's risk level, the risk level of the leaf node's ancestor nodes, and the node type of the ancestor nodes. The hidden node label is used to indicate whether the leaf node needs to be deleted. Based on the hidden label of the leaf node, the leaf node in the initial decision tree is deleted to obtain the first decision tree; The paths in the first decision tree are truncated according to the preset path depth to obtain the target decision tree.
9. The database deadlock avoidance method of claim 8, wherein, For each leaf node in the initial decision tree, the step of determining the hidden label of the leaf node based on the risk level of the leaf node, the risk level of the ancestor nodes of the leaf node, and the node type of the ancestor nodes includes: For a leaf node in the current initial decision tree, if the risk level of the leaf node is less than or equal to the risk level of its ancestor node, and the ancestor node is a leaf node, then the leaf node's hidden label is determined to indicate that the leaf node needs to be deleted. For a leaf node in the current initial decision tree, if the risk level of the leaf node is greater than the risk level of its ancestor node or the node type of the ancestor node is not a leaf node, the leaf node's hidden label is determined to indicate that the leaf node does not need to be deleted.
10. The database deadlock avoidance method of claim 7, wherein, The step of compiling the target decision tree into a dynamic link library includes: The nodes in the target decision tree are processed by hierarchical linearization to obtain the node vector of the target decision tree; Based on the depth and position information of the nodes in the node vector, position mapping is performed on each node in the node vector to obtain the position number of each node in the node vector. According to the position number in ascending order, each node in the node vector is filled in sequentially to obtain the linear instruction set of the target decision tree. The linear instruction set includes the position number of each node in the node vector and the sequential instruction corresponding to the position number. The linear instruction set is compiled to generate a dynamic link library.
11. The database deadlock avoidance method of claim 10, wherein, The process of compiling the linear instruction set to generate a dynamic link library includes: Obtain metadata information, wherein the metadata information includes current version information, timestamp of the current version information, and hash information of the target decision tree; The source file for generating the target decision tree is generated based on the metadata information and the linear instruction set; The source file is compiled to generate a dynamic link library and an external interface for the dynamic link library. The external interface allows the dynamic link library to be called for risk identification.
12. The database deadlock avoidance method of claim 1, wherein, The step of intervening in the lock request based on the risk level, the transaction priority, and a predefined strategy mapping table, and generating an intervention record for the lock request, includes: Based on the risk level and the transaction priority, the strategy mapping table is queried to obtain the target strategy for the lock request; The lock request is intervened in according to the target strategy, and an intervention record for the lock request is generated. The intervention record includes the target strategy and the intervention result of the first transaction corresponding to the lock request.
13. The database deadlock avoidance method of claim 12, wherein, The target strategy includes any one of the first strategy, the second strategy, and the third strategy; The process of intervening in the lock request according to the target strategy and generating an intervention record for the lock request includes: When the target strategy is the first strategy, the lock request is inserted at the end of the current request waiting queue, and the lock request is marked with a first tag to generate an intervention record for the lock request. The first tag is used to indicate that the lock request cannot be scheduled in the current request waiting queue. If the target strategy is the second strategy, a rollback operation is performed on the first transaction corresponding to the lock request, and an intervention record for the lock request is generated. When the target strategy is the third strategy, the lock request is inserted into the end of the current request waiting queue and kept in a yielding state according to the preset yielding time. If the first resource requested by the lock request is released, and the first concession time of the lock request being inserted at the end of the current request waiting queue is less than or equal to the preset concession time, the lock request is switched from the concession state to the normal ordering state. If the first resource requested by the lock request has not been released, and the first concession duration of the lock request inserted at the end of the current request waiting queue is greater than the preset concession duration, the dynamic link library is invoked to re-identify the risk of the lock request and obtain the risk level of the lock request.
14. The database deadlock avoidance method of claim 2, wherein, The intervention record includes the intervention result of the first transaction corresponding to the lock request; The step of updating the dynamic link library based on the intervention record includes: Based on the intervention results in the intervention record, the first transaction that meets the preset conditions is labeled with a second label to construct a first sample set, wherein the preset conditions include the intervention result of the first transaction being a successful submission; Real-time monitoring of the deadlock resolution log to obtain multiple second transactions that triggered deadlock resolution; A third label is assigned to the second transaction that does not have the aforementioned intervention record, and a second sample set is constructed; The dynamic link library is updated based on the first sample set, the second sample set, and pre-configured weight coefficients of the first and second sample sets.
15. A database deadlock avoidance apparatus, characterized by, include: The first acquisition module is configured to, upon receiving a lock request from a first transaction and finding that the first resource requested by the lock request is occupied, acquire the transaction priority of the first transaction and a feature array corresponding to the lock request, wherein the feature array includes the transaction status features of the first transaction and the resource status features of the first resource. The first identification module is used to call a pre-built dynamic link library to perform risk identification on the feature array of the lock request and obtain the risk level of the lock request. The dynamic link library is used to analyze the causal relationship between multiple features in the feature array and database deadlock to generate the risk level of the lock request. The first intervention module is used to intervene in the lock request according to the risk level, the transaction priority and the predefined strategy mapping table, and generate an intervention record for the lock request; The first update module is used to update the dynamic link library based on the intervention record.
16. A network device, comprising: include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the database deadlock avoidance method as described in any one of claims 1 to 14.
17. A readable storage medium, characterized by include: The readable storage medium stores a program that, when executed by a processor, implements the steps of the database deadlock avoidance method as described in any one of claims 1 to 14.
18. A computer program product, characterised in that, It includes computer instructions that, when executed by a processor, implement the steps of the database deadlock avoidance method as described in any one of claims 1 to 14.