Process processing method and device, computer equipment, storage medium and computer program product
By generating lock nodes and judging blocking nodes based on the processing sequence number and node type, the problem of low process processing efficiency in traditional technology is solved, and more efficient process processing is achieved.
Patent Information
- Application Number
- CN202411701257.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-07
AI Technical Summary
In traditional technology, process processing efficiency is low, mainly due to the process priority processing sequentially, which consumes a lot of time.
By generating the lock node of the process to be processed, the blocking node is judged according to the processing sequence number and node type of the lock node, the node status is updated, and processing is performed when the preset node status is reached.
Improves the efficiency of process processing, reduces the idle time of pending processes, and avoids inefficiency caused by dependency priority processing.
Smart Images

Figure CN119576595A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a process processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Art
[0002] At present, in order to ensure the stable operation of computer systems, how to handle processes efficiently is crucial.
[0003] In the traditional technology, in the process of processing a process, each process is generally processed in sequence only according to the priority of the process; however, this method is likely to consume a lot of time, resulting in low efficiency in process processing. Summary of the invention
[0004] Based on this, it is necessary to provide a process processing method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the efficiency of process processing in response to the above technical problems.
[0005] In a first aspect, the present application provides a process processing method, comprising:
[0006] In response to a processing request for a process to be processed, generating a lock node for the process to be processed;
[0007] Obtaining a blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node;
[0008] According to the blocked node judgment result and the node type, the current node state of the lock node is updated to obtain the updated node state of the lock node;
[0009] When the updated node state is the preset node state, the to-be-processed process is processed.
[0010] In one of the embodiments, when the updated node state is the preset node state, after processing the pending process, the method further includes:
[0011] When the node type is a read node, a first monitoring result corresponding to the lock node is obtained; the first monitoring result is used to indicate whether the lock node has a corresponding first target lock node whose node type is a write node within the first time;
[0012] When the first monitoring result satisfies a preset monitoring result, updating the updated node state to a target node state;
[0013] When the first monitoring result does not meet the preset monitoring result, maintaining the updated node state;
[0014] The lock node is deleted according to the updated node status.
[0015] In one embodiment, deleting the lock node according to the updated node state includes:
[0016] When the updated node state is the target node state, deleting the lock node;
[0017] or,
[0018] When the updated node state is the preset node state, obtaining a second monitoring result corresponding to the lock node; the second monitoring result is used to indicate whether the lock node has a corresponding second target lock node whose node type is a write node within the second time;
[0019] When the second monitoring result meets the preset monitoring result, the lock node is deleted.
[0020] In one embodiment, updating the current node state of the lock node according to the blocked node judgment result and the node type to obtain the updated node state of the lock node includes:
[0021] When the blocking node judgment result indicates that the lock node has a blocking node, the current node state of the lock node is updated to obtain an updated node state of the lock node as a waiting state;
[0022] The updated node state is used as the new current node state of the lock node, and the process jumps to the step of obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node, until the blocked node judgment result indicates that there is no blocked node for the lock node, then the current node state of the lock node is updated, and the updated node state of the lock node is the preset node state.
[0023] In one embodiment, obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and the node type corresponding to the lock node includes:
[0024] Determine, according to the node type, a judgment rule corresponding to the processing sequence number;
[0025] The blocked node judgment result is determined according to the processing sequence number and the judgment rule.
[0026] In one of the embodiments, before obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and the node type corresponding to the lock node, the method further includes:
[0027] Obtaining a node identifier of the lock node;
[0028] Identifying a preset separation identifier in the node identifier;
[0029] From the node identifier, identify the sequence number after the preset separation identifier as the processing sequence number.
[0030] In a second aspect, the present application further provides a process processing device, including:
[0031] A node generation module, configured to generate a lock node of a process to be processed in response to a processing request for the process to be processed;
[0032] A result judgment module, used to obtain a blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node;
[0033] A state updating module, used for updating the current node state of the lock node according to the blocking node judgment result and the node type, to obtain the updated node state of the lock node;
[0034] The process processing module is used to process the to-be-processed process when the updated node state is a preset node state.
[0035] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0036] In response to a processing request for a process to be processed, generating a lock node for the process to be processed;
[0037] Obtaining a blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node;
[0038] According to the blocked node judgment result and the node type, the current node state of the lock node is updated to obtain the updated node state of the lock node;
[0039] When the updated node state is the preset node state, the to-be-processed process is processed.
[0040] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0041] In response to a processing request for a process to be processed, generating a lock node for the process to be processed;
[0042] Obtaining a blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node;
[0043] According to the blocked node judgment result and the node type, the current node state of the lock node is updated to obtain the updated node state of the lock node;
[0044] When the updated node state is the preset node state, the to-be-processed process is processed.
[0045] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0046] In response to a processing request for a process to be processed, generating a lock node for the process to be processed;
[0047] Obtaining a blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node;
[0048] According to the blocked node judgment result and the node type, the current node state of the lock node is updated to obtain the updated node state of the lock node;
[0049] When the updated node state is the preset node state, the to-be-processed process is processed.
[0050] The above-mentioned process processing method, device, computer equipment, storage medium and computer program product first respond to the processing request for the process to be processed, generate the lock node of the process to be processed, and then obtain the blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node, and update the current node state of the lock node according to the blocking node judgment result and node type, and obtain the updated node state of the lock node. When the updated node state is the preset node state, the process to be processed is processed. In this way, in the process of processing the process, according to the processing sequence number and node type corresponding to the lock node of the process to be processed, the blocking node judgment result corresponding to the lock node of the process to be processed can be quickly obtained, and then the updated node state of the lock node can be quickly obtained. When the updated node state is the preset node state, the process to be processed is directly processed, which greatly reduces the idle time of the process to be processed and is conducive to improving the efficiency of process processing; moreover, the whole process does not process each process in turn only according to the priority of the process, avoiding the defect that the method of processing each process in turn only according to the priority of the process is easy to consume a lot of time, resulting in low efficiency of process processing, thereby improving the efficiency of process processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0052] Figure 1 A schematic diagram of a process processing method in one embodiment;
[0053] Figure 2 A schematic diagram of a state transition relationship of a distributed read-write lock in one embodiment;
[0054] Figure 3 A schematic diagram of the structure of a node path of a distributed read-write lock in one embodiment;
[0055] Figure 4 A schematic flow chart of a process processing method in another embodiment;
[0056] Figure 5 is a structural block diagram of a process processing device in one embodiment;
[0057] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0058] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0059] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0060] In an exemplary embodiment, Figure 1 As shown, a process processing method is provided. This embodiment uses the method applied to a server as an example for illustration. It can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. Among them, the terminal can be but is not limited to various personal computers, laptops, smart phones and tablet computers; the server can be implemented as an independent server or a server cluster composed of multiple servers. In this embodiment, the method includes the following steps:
[0061] Step S101 : generating a lock node of a process to be processed in response to a processing request for the process to be processed.
[0062] The pending process refers to a process that needs to be processed.
[0063] The processing request is used to indicate the request information corresponding to the operation performed on a process to be processed, such as a write operation (modification, deletion, etc.) on a certain location.
[0064] Among them, the lock node refers to the node corresponding to the distributed read-write lock.
[0065] Exemplarily, the server receives a processing request for a process to be processed sent by a terminal, parses the processing request, and obtains parsing information corresponding to the processing request; then, the server verifies the parsing information and obtains a verification result corresponding to the parsing information; then, if the verification result is passed, the server generates a lock node for the process to be processed.
[0066] Step S102, obtaining a blocking node judgment result corresponding to the locked node according to the processing sequence number and node type corresponding to the locked node.
[0067] The processing sequence number is used to indicate the sequence number information corresponding to the processing sequence of the lock node, such as 03.
[0068] The node type refers to the type information corresponding to the lock node, including read nodes and write nodes.
[0069] The blocking node judgment result is used to indicate whether there is a blocking node on the lock node.
[0070] Exemplarily, the server determines a blocked node judgment result corresponding to the processing sequence number and the node type according to the processing sequence number and the node type corresponding to the lock node, as the blocked node judgment result corresponding to the lock node.
[0071] Step S103, updating the current node state of the locked node according to the blocked node judgment result and the node type, to obtain the updated node state of the locked node.
[0072] Among them, the current node state refers to the node state of the lock node at the current time. It should be noted that the node states of the lock node include Null (the lock has been released or has not been acquired, the start and end states), Waiting (there is a blocking node before acquiring the lock, and the lock can be acquired after waiting for it to be deleted), WriteLock (holding the write lock), RL_Hold (holding the read lock), RL_Releasable (the read lock has been released, but the temporary node has not been deleted), RL_ToRelease (when holding the read lock, receiving a notification of a subsequent request to acquire the write lock), etc. Figure 2 shown.
[0073] The updated node state refers to the current node state after the update.
[0074] Exemplarily, the server updates the current node state of the lock node according to the blocked node judgment result and the node type, and obtains an updated node state corresponding to the blocked node judgment result and the node type as the updated node state of the lock node.
[0075] Step S104: When the updated node state is the preset node state, the process to be processed is processed.
[0076] The preset node state refers to a pre-set node state. In actual scenarios, the preset node state refers to WriteLock or RL_Hold. It should be noted that the preset node state depends on the situation.
[0077] Exemplarily, the server judges the updated node state and obtains a judgment result corresponding to the updated node state; when the judgment result indicates that the updated node state is a preset node state, the server processes the process to be processed.
[0078] In the above process processing method, first respond to the processing request for the process to be processed, generate the lock node of the process to be processed, then obtain the blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node, and update the current node state of the lock node according to the blocking node judgment result and node type, obtain the updated node state of the lock node, and process the process to be processed when the updated node state is the preset node state. In this way, in the process of processing the process, according to the processing sequence number and node type corresponding to the lock node of the process to be processed, the blocking node judgment result corresponding to the lock node of the process to be processed can be quickly obtained, and then the updated node state of the lock node can be quickly obtained. When the updated node state is the preset node state, the process to be processed is directly processed, which greatly reduces the idle time of the process to be processed and is conducive to improving the efficiency of process processing; moreover, the whole process does not process each process in turn only according to the priority of the process, avoiding the defect that the method of processing each process in turn only according to the priority of the process is easy to consume a lot of time, resulting in low efficiency of process processing, thereby improving the efficiency of process processing.
[0079] In an exemplary embodiment, the above step S104, when the updated node state is the preset node state, after processing the process to be processed, specifically includes the following contents: when the node type is a read node, obtain the first monitoring result corresponding to the lock node; the first monitoring result is used to indicate whether the lock node has a corresponding first target lock node with a write node type within the first time; when the first monitoring result meets the preset monitoring result, update the updated node state to the target node state; when the first monitoring result does not meet the preset monitoring result, maintain the updated node state; and delete the lock node according to the updated node state.
[0080] The read node refers to the node corresponding to the process performing the read operation.
[0081] The first monitoring result is used to indicate whether the lock node has a first target lock node whose node type is a write node within the first time.
[0082] The first time may refer to the time when the process to be processed holds the lock.
[0083] The write node refers to the node corresponding to the process performing the write operation.
[0084] The first target lock node is used to indicate the lock node whose processing sequence number is greater than the processing sequence number of the lock node of the process to be processed within the first time. For example, the processing sequence number of the lock node is 03, and the processing sequence number of the first target lock node is 04.
[0085] The preset monitoring result refers to a preset monitoring result. In an actual scenario, the preset monitoring result refers to the lock node having a corresponding node type of a write node. It should be noted that the preset monitoring result depends on the situation.
[0086] The target node state refers to the node state obtained by re-updating the updated node state. In actual scenarios, the target node state refers to RL_ToRelease.
[0087] Exemplarily, when the node type is a read node, the server determines, based on the processing sequence number of the lock node of the process to be processed, whether there is a lock node with a corresponding processing sequence number greater than the processing sequence number of the lock node during the time when the process to be processed holds the lock, as the first monitoring result corresponding to the lock node; then, the server judges the first monitoring result; when the first monitoring result meets the preset monitoring result, the server updates the updated node state to the target node state; when the first monitoring result does not meet the preset monitoring result, the server maintains the updated node state; then, the server deletes the lock node according to the updated node state.
[0088] For example, see Figure 2 When the node type is a read node, the server will also monitor whether there is a subsequent lock node corresponding to the pending process during the time when the pending process holds the lock, as the first monitoring result corresponding to the lock node; when it is found that there is a write node for the subsequent lock node, the updated node state of the pending process changes from RL_Hold to RL_ToRelease; if there is no write node, the updated node state of the pending process remains RL_Hold.
[0089] In this embodiment, when the node type of the lock node is a read node, by monitoring whether there is a first target lock node with a corresponding node type of a write node within the first time, the state change of the lock node can be accurately determined, thereby improving the accuracy of subsequent deletion processing of the lock node.
[0090] In an exemplary embodiment, the lock node is deleted according to the updated node status, which specifically includes the following contents: when the updated node status is the target node status, the lock node is deleted; or, when the updated node status is the preset node status, a second monitoring result corresponding to the lock node is obtained; the second monitoring result is used to indicate whether there is a second target lock node with a corresponding node type of a write node within the second time; when the second monitoring result satisfies the preset monitoring result, the lock node is deleted.
[0091] The second monitoring result is used to indicate whether the lock node has a corresponding second target lock node whose node type is a write node within the second time.
[0092] The second time may refer to the time when the process to be processed releases the lock.
[0093] The second target lock node is used to indicate a lock node whose processing sequence number is greater than the processing sequence number of the lock node of the process to be processed within the second time.
[0094] Exemplarily, the server determines the updated node state of the lock node; when the updated node state is the target node state, the lock node is deleted; when the updated node state is the preset node state, based on the processing sequence number of the lock node of the process to be processed, it is determined whether there is a lock node with a corresponding processing sequence number greater than the processing sequence number of the lock node within the time when the process to be processed releases the lock, as the second monitoring result corresponding to the lock node; when the second monitoring result meets the preset monitoring result, the lock node is deleted.
[0095] For example, see Figure 2 , when the node type is a read node and the pending process releases the read lock, the server determines the updated node state of the lock node; when the updated node state is RL_ToRelease, the lock node is deleted and the updated node state of the lock node is changed from RL_ToRelease to Null; when the updated node state is RL_Hold, the lock node is not deleted and the updated node state of the lock node is changed from RL_Hold to RL_Releasable; when the updated node state of the lock node is RL_Releasable and it is monitored that there is a subsequent lock node corresponding to the pending process within the time when the pending process releases the lock, the lock node is deleted and the updated node state of the lock node is changed from RL_Releasable to Null.
[0096] In this embodiment, by clearly stipulating that the lock node is deleted under specific node status and monitoring result conditions, strict resource lifecycle management principles are followed, thereby ensuring that resources can be correctly released after use, thereby avoiding the risk of resource leakage, which is conducive to ensuring the stability of the system and long-term reliable operation.
[0097] In an exemplary embodiment, the above step S103 updates the current node state of the lock node according to the blocked node judgment result and the node type to obtain the updated node state of the lock node, which specifically includes the following contents: when the blocked node judgment result indicates that there is a blocked node for the lock node, the current node state of the lock node is updated to obtain the updated node state of the lock node as a waiting state; the updated node state is used as the new current node state of the lock node, and the process jumps to the step of obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and the node type corresponding to the lock node, until the blocked node judgment result indicates that there is no blocked node for the lock node, then the current node state of the lock node is updated to obtain the updated node state of the lock node as a preset node state.
[0098] The blocking node is used to represent a lock node that blocks the processing of the process to be processed.
[0099] The waiting state refers to the state in which the lock node is blocked. In actual scenarios, the waiting state refers to Waiting.
[0100] Exemplarily, the server judges the blocked node judgment result corresponding to the lock node; when the blocked node judgment result indicates that there is a blocked node for the lock node, the current node state of the lock node is updated, and the updated node state of the lock node is a waiting state; then, the server uses the updated node state as the new current node state of the lock node, and jumps to the step of obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node, until the blocked node judgment result indicates that there is no blocked node for the lock node, then the current node state of the lock node is updated, and the updated node state of the lock node is a preset node state.
[0101] For example, see Figure 2 , when the blocking node judgment result indicates that there is a blocking node for the lock node, the current node state of the lock node is updated, and the updated node state of the lock node is Waiting; then, the server uses the updated node state as the new current node state of the lock node, and jumps to the step of obtaining the blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node, until the blocking node judgment result indicates that there is no blocking node for the lock node, then the current node state of the lock node is updated, and the updated node state of the lock node is WriteLock / RL_Hold.
[0102] In this embodiment, by allowing the process corresponding to the blocked lock node to enter a waiting state, invalid resource contention is avoided, so that system resources can be allocated preferentially to processes that can execute tasks immediately, which is beneficial to improving the overall resource utilization efficiency and enabling limited system resources to be more reasonably configured and used.
[0103] In an exemplary embodiment, the above step S102 obtains the blocked node judgment result corresponding to the locked node according to the processing sequence number and node type corresponding to the locked node, which specifically includes the following contents: determining the judgment rule corresponding to the processing sequence number according to the node type; determining the blocked node judgment result according to the processing sequence number and the judgment rule.
[0104] The judgment rule refers to a pre-set rule for judging the processing sequence number. It should be noted that for different types of lock nodes, the corresponding judgment rules are different: for a write node, the blocking node is the largest read / write node with a sequence number smaller than it; for a read node, the blocking node is the largest write node with a sequence number smaller than it. For example, Figure 3 As shown, there are three read nodes under ReadLock, and the corresponding processing sequence numbers are 00, 02, and 03 respectively; there are three write nodes under WriteLock, and the corresponding processing sequence numbers are 01 and 04 respectively; for read node 03, the blocking node is write node 01; for write node 04, the blocking node is read node 03.
[0105] Exemplarily, the server queries the correspondence between the node type and the judgment rule based on the node type, and obtains the judgment rule corresponding to the node type as the judgment rule corresponding to the processing sequence number; then, the server determines the blocked node judgment result corresponding to the processing sequence number and the judgment rule based on the processing sequence number and the judgment rule, as the blocked node judgment result corresponding to the lock node.
[0106] In this embodiment, according to the node type, the judgment rule corresponding to the processing sequence number can be accurately determined, and then the blocking node judgment result corresponding to the lock node can be accurately determined, so that it can be clearly judged which processes should wait, thereby effectively avoiding the confusion and efficiency loss caused by resource contention, which is conducive to ensuring the smooth and orderly resource allocation process.
[0107] In an exemplary embodiment, the above-mentioned step S102, before obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node, specifically includes the following contents: obtaining the node identifier of the lock node; identifying the preset separation identifier in the node identifier; and identifying the sequence number after the preset separation identifier from the node identifier as the processing sequence number.
[0108] The node identifier refers to the name of the lock node. It should be noted that the node identifier is composed of a prefix, a separator, and a suffix. The prefix refers to the unique identification code of the process to be processed corresponding to the lock node, the separator can refer to any reserved characters, and the suffix refers to the processing sequence number. Figure 3 As shown, for the node identifier "prefix_03", the prefix is "prefix", the separator is "_", and the suffix is "03".
[0109] The preset separator is a separator.
[0110] Exemplarily, the server obtains the node identifier of the lock node from the database; then, the server performs integrity verification on these node identifiers to obtain integrity verification results corresponding to these node identifiers; then, when the integrity verification results indicate that these node identifiers have passed, the server uses a string processing function to identify a preset separator identifier in the node identifier; then, the server identifies the serial number after the preset separator identifier from the node identifier as the processing sequence number.
[0111] In this embodiment, by accurately extracting the processing sequence number from the node identifier of the lock node, the system can clearly determine the order in which each process obtains resources based on this number, thereby improving the overall resource allocation efficiency and facilitating more reasonable utilization of limited system resources.
[0112] In an exemplary embodiment, Figure 4 As shown, another process processing method is provided, which is described by taking the method applied to a server as an example, and includes the following steps:
[0113] Step S401: In response to a processing request for a process to be processed, a lock node of the process to be processed is generated.
[0114] Step S402, obtaining the node identifier of the lock node; identifying the preset separation identifier in the node identifier; and identifying the sequence number after the preset separation identifier from the node identifier as the processing sequence number.
[0115] Step S403: Determine the judgment rule corresponding to the processing sequence number according to the node type.
[0116] Step S404, determining the blocked node judgment result according to the processing sequence number and the judgment rule.
[0117] Step S405, when the blocking node judgment result indicates that the lock node has a blocking node, the current node state of the lock node is updated, and the updated node state of the lock node is a waiting state.
[0118] Step S406, taking the updated node state as the new current node state of the lock node, and jumping to step S403, until the blocking node judgment result indicates that there is no blocking node for the lock node, then updating the current node state of the lock node, and obtaining the updated node state of the lock node as the preset node state.
[0119] Step S407: When the updated node state is the preset node state, the process to be processed is processed.
[0120] In the above-mentioned process processing method, in the process of processing the process, according to the processing sequence number and node type corresponding to the lock node of the process to be processed, the blocking node judgment result corresponding to the lock node of the process to be processed can be quickly obtained, and then the updated node state of the lock node can be quickly obtained. When the updated node state is the preset node state, the process to be processed is directly processed, which greatly reduces the idle time of the process to be processed and is conducive to improving the efficiency of process processing; moreover, the whole process does not process each process in turn only according to the priority of the process, avoiding the defect that the method of processing each process in turn only according to the priority of the process is easy to consume a lot of time, resulting in low efficiency of process processing, thereby improving the efficiency of process processing.
[0121] In an exemplary embodiment, in order to more clearly illustrate the process processing method provided by the embodiment of the present application, the process processing method is specifically described below with a specific embodiment. In one embodiment, the present application also provides a principle and implementation method of a high-performance distributed read-write lock. In the process of processing a process, a processing request for the process to be processed is first responded to, and a lock node of the process to be processed is generated. Then, according to the processing sequence number and node type corresponding to the lock node, the blocking node judgment result corresponding to the lock node is obtained, and according to the blocking node judgment result and the node type, the current node state of the lock node is updated to obtain the updated node state of the lock node. When the updated node state is the preset node state, the process to be processed is processed. Specifically including the following contents:
[0122] 1. This embodiment is based on a distributed consistency service implementation that meets the following characteristics:
[0123] (1) Based on Paxos (a distributed consistency algorithm) or its simplified protocol, write operations satisfy strong consistency and read operations satisfy sequential consistency.
[0124] (2) Read and write operations carry version numbers and support transaction operations. The client's write operation can only succeed if the version number is consistent with the server's.
[0125] (3) The server supports permanent nodes and temporary nodes. The difference is that permanent nodes will not be automatically deleted after they are created, while temporary nodes will be automatically deleted after the client session that created them expires.
[0126] (4) The client can monitor the server node, and the server will notify the client when the node changes.
[0127] 2. The state transition topology of the lock model can be transformed by simple deletion or equivalent transformation into Figure 2 The state transformation relationship shown.
[0128] 3. When holding the write lock, ensure that the distributed consistency service has a corresponding temporary node. When releasing the write lock, ensure that the corresponding temporary node on the distributed consistency service is deleted successfully.
[0129] 4. When holding a read lock, ensure that the distributed consistency service has a corresponding temporary node. When releasing the read lock, decide whether to delete the corresponding temporary node on the distributed consistency service depending on whether there is a write lock node. That is, there may be a situation where the read lock is not held but the read lock node is not deleted.
[0130] A distributed read-write lock instance corresponds to a specific path on the distributed consistency service, recorded as Root (path), and the directory structure is as follows Figure 3 As shown. Root has two subdirectories ReadLock and WriteLock, which contain all temporary nodes for read and write locks of the distributed read-write lock. Each temporary node name is formed by the concatenation of a prefix, a separator, and a suffix. The prefix is the unique identification code of the process that obtains the distributed read-write lock, the separator can be any reserved character, and the suffix is the sequential number shared by the two subdirectories.
[0131] Each process that wants to obtain a read-write lock will create a lock node in the ReadLock or WriteLock directory and determine whether there is a blocking node for this node based on the blocking rules. For a write lock, a blocking node is the largest read / write node with a sequence number smaller than it; for a read lock, a blocking node is the largest write node with a sequence number smaller than it. If there is no blocking node for this node, the process successfully obtains the read-write lock; if there is a blocking node for this node, the process registers a listener for the blocking node and waits until it receives a notification that the blocking node has been deleted, or gives up waiting because it times out when acquiring the lock.
[0132] By using the monitoring mechanism, when the blocking node of a process's lock node is deleted, the process will receive a callback, so that it can continue to determine whether its lock node has other blocking nodes. If there are no other blocking nodes, the process successfully acquires the read-write lock; if there are other blocking nodes, the above process is repeated until the read-write lock is finally successfully acquired, or the waiting is abandoned due to timeout / other exceptions.
[0133] Among them, a distributed read-write lock has the following six states:
[0134] Null: The lock has been released or has not been acquired. There is no corresponding temporary node for the start and end states.
[0135] Waiting: There is a blocking node before acquiring the lock. The lock can be acquired after waiting for it to be deleted.
[0136] WriteLock: Holds a write lock.
[0137] RL_Hold: Holds the read lock.
[0138] RL_Releasable: The read lock is released, but the temporary node is not deleted.
[0139] RL_ToRelease: When holding a read lock, a subsequent request is received to obtain a write lock.
[0140] Among them, the state machine conversion process is:
[0141] (1) When the lock is not acquired or has been released, the status is Null.
[0142] (2) When trying to obtain a write lock, a write lock node is created. If there is no blocking node, the state changes from Null to WriteLock, and the write lock is successfully obtained. If there is a blocking node, the state changes from Null to Waiting, and the blocking node is deleted through monitoring.
[0143] (3) When trying to obtain a read lock, a read lock node is created. If there is no blocking node, a listener is registered for the WriteLock directory, and the state changes from Null to RL_Hold, indicating that the read lock is successfully obtained. If there is a blocking node, the state changes from Null to Waiting, and the listener waits for the blocking node to be deleted.
[0144] (4) When the blocked node is deleted and there are no other blocked nodes, the state changes from Waiting to WriteLock / RL_Hold, and the write / read lock is acquired successfully.
[0145] (5) When the write lock is released, the write lock node is deleted and the state changes from WriteLock to Null.
[0146] (6) When holding a read lock, if a write lock node is found to be created by monitoring the WriteLock directory, the state changes from RL_Hold to RL_ToRelease.
[0147] (7) When releasing the read lock, if the state is RL_Hold at this time, the read lock node is not deleted and the state changes from RL_Hold to RL_Releasable; if the state is RL_ToRelease at this time, the read lock node is deleted and the state changes from RL_ToRelease to Null.
[0148] (8) When the status is RL_Releasable and a write lock node is found to be created by monitoring the WriteLock directory, the read lock node is deleted and the status changes from RL_Releasable to Null.
[0149] The necessary characteristics of distributed locks satisfied by the distributed read-write locks based on the above scheme are as follows:
[0150] Mutual Exclusion / Exclusiveness / Sharing: Mutual exclusivity is achieved between read-write locks through the sequential number of the lock node. The write lock is an exclusive lock and the read lock is a shared lock.
[0151] Automatic release: When the process holding the lock crashes, the distributed consistency service ensures that the temporary nodes created by the expired session are automatically deleted, so there will be no long-term deadlock caused by inactivated lock nodes.
[0152] Consistency: The consistency of the lock is guaranteed by the specific implementation scheme of the creation, deletion and monitoring of the lock node. At most, it can be the same as the distributed consistency service, that is, writing satisfies strong consistency and reading satisfies sequential consistency. In this case, the distributed write lock can guarantee strong consistency, and the distributed read lock can at most satisfy sequential consistency due to its reliance on monitoring.
[0153] Fairness: The blocking nodes of the lock node are strictly determined according to the ascending order of the sequence number, so the lock meets the fairness and there will be no write lock starvation.
[0154] Reentrancy: Different threads within the same process can repeatedly acquire the lock after the process holds the lock. The process releases the lock only after all threads of the process release the lock, so as to meet the reentrancy of each method. In the specific embodiment, adding a reference counter can support this capability.
[0155] The above is a basic model of a distributed read-write lock that meets features 1 to 4. A specific embodiment is provided below. The final effect of this specific embodiment is that the distributed write lock meets strong consistency, the distributed read lock meets sequential consistency, and when continuously acquiring distributed read locks, the single time consumption is much lower than the traditional solution, and is usually no more than an order of magnitude greater than the time consumption of the local read-write lock to acquire the read lock.
[0156] The specific implementation plan is as follows:
[0157] First, the node version number of the root node determines the sequence number in the read / write lock node name. Before creating the read / write lock node, obtain the root node version number, recorded as v. Then create the read / write lock node transactionally and assign v to the root node. If successful, the sequence number in the read / write lock node name is v; if it fails, repeat the process until it succeeds. In this way, the sequence number in the read / write lock node name is strictly guaranteed to be monotonically increasing and will not be repeated.
[0158] Second, a reference counter that supports atomic read and write is used to solve the problem of multiple threads re-entering the same process to acquire the lock. A reference counter is added to the distributed read-write lock of each process, recorded as LockCnt. When the lock is not acquired or has been released, LockCnt is equal to 0; when a thread successfully changes the state of the distributed read-write lock to WriteLock / RL_Hold, LockCnt increases by 1; when a thread tries to acquire a write / read lock when the lock state is already WriteLock / RL_Hold, LockCnt increases by 1 and returns success; when a thread releases a write / read lock, LockCnt decreases by 1; when LockCnt decreases from a positive value to 0, if the lock state is WriteLock, the lock node is deleted and the state is changed to Null; when LockCnt decreases from a positive value to 0, if the lock state is RL_Hold, the state is changed to RL_Releasable; when LockCnt decreases from a positive value to 0, if the lock state is RL_ToRelease, the lock node is deleted and the state is changed to Null; when the client session is detected to be invalid, LockCnt is reset to 0, the lock node is deleted and the state is changed to Null. The remaining state transition processes not described do not involve the modification of LockCnt.
[0159] Depending on the specific implementation method, the time taken to continuously acquire and release the read lock of the distributed read-write lock using this embodiment can be no more than one order of magnitude greater than the time taken to perform the same operation on the local read-write lock. In scenarios where distributed read-write locks are required, write operations are usually required to sacrifice performance for strong consistency, and read operations are required to ensure high performance but not to satisfy strong consistency, which has high practical value.
[0160] In the above embodiment, in the process of processing the process, according to the processing sequence number and node type corresponding to the lock node of the process to be processed, the blocking node judgment result corresponding to the lock node of the process to be processed can be quickly obtained, and then the updated node state of the lock node can be quickly obtained. When the updated node state is the preset node state, the process to be processed is directly processed, which greatly reduces the idle time of the process to be processed, which is conducive to improving the efficiency of process processing; moreover, the whole process does not process each process in turn only according to the priority of the process, avoiding the defect that the method of processing each process in turn only according to the priority of the process is easy to consume a lot of time, resulting in low efficiency of process processing, thereby improving the efficiency of process processing. At the same time, this embodiment can achieve that the time consumed by multiple threads in the same process to continuously acquire and release the distributed read-write lock and read lock is not more than one order of magnitude of the time consumed by the same operation of the local read-write lock and read lock under the premise of satisfying strong consistency of the write lock and consistent order of the read lock, and has a wide range of application scenarios in the distributed field and has high practical value.
[0161] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0162] Based on the same inventive concept, the embodiment of the present application also provides a process processing device for implementing the process processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more process processing device embodiments provided below can refer to the limitations on the process processing method above, and will not be repeated here.
[0163] In an exemplary embodiment, Figure 5 As shown, a process processing device is provided, including: a node generation module 501, a result judgment module 502, a state update module 503 and a process processing module 504, wherein:
[0164] The node generation module 501 is used to generate a lock node of the process to be processed in response to a processing request for the process to be processed.
[0165] The result judgment module 502 is used to obtain the blocking node judgment result corresponding to the locked node according to the processing sequence number and node type corresponding to the locked node.
[0166] The state updating module 503 is used to update the current node state of the locked node according to the blocked node judgment result and the node type, and obtain the updated node state of the locked node.
[0167] The process processing module 504 is used to process the process to be processed when the node state after update is the preset node state.
[0168] In an exemplary embodiment, the process processing device also includes a node deletion module, which is used to obtain a first monitoring result corresponding to the lock node when the node type is a read node; the first monitoring result is used to indicate whether the lock node has a first target lock node whose corresponding node type is a write node within the first time; when the first monitoring result meets the preset monitoring result, the updated node state is updated to the target node state; when the first monitoring result does not meet the preset monitoring result, the updated node state is maintained; and the lock node is deleted according to the updated node state.
[0169] In an exemplary embodiment, the node deletion module is also used to delete the lock node when the node state after update is the target node state; or, when the node state after update is the preset node state, obtain the second monitoring result corresponding to the lock node; the second monitoring result is used to indicate whether there is a second target lock node with a corresponding node type of a write node within the second time; when the second monitoring result meets the preset monitoring result, the lock node is deleted.
[0170] In an exemplary embodiment, the status update module 503 is also used to update the current node status of the lock node when the blocking node judgment result indicates that there is a blocked node for the lock node, and the updated node status of the lock node is a waiting status; the updated node status is used as the new current node status of the lock node, and the step of obtaining the blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node is jumped to, until the blocking node judgment result indicates that there is no blocked node for the lock node, then the current node status of the lock node is updated, and the updated node status of the lock node is a preset node status.
[0171] In an exemplary embodiment, the result judgment module 502 is further used to determine the judgment rule corresponding to the processing sequence number according to the node type; and determine the blocked node judgment result according to the processing sequence number and the judgment rule.
[0172] In an exemplary embodiment, the process processing device also includes a node identification module, which is used to obtain a node identifier of a lock node; identify a preset separation identifier in the node identifier; and identify a sequence number after the preset separation identifier from the node identifier as a processing sequence number.
[0173] Each module in the above process processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0174] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 6 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data such as processing sequence numbers and node types. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a process processing method is implemented.
[0175] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0176] In an exemplary embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0177] In an exemplary embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0178] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0179] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0180] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0181] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A process processing method, characterized in that: The method comprises: In response to a processing request for a process to be processed, generating a lock node for the process to be processed; Obtaining a blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node; According to the blocked node judgment result and the node type, the current node state of the lock node is updated to obtain the updated node state of the lock node; When the updated node state is the preset node state, the to-be-processed process is processed.
2. The method according to claim 1, characterized in that In the case where the updated node state is the preset node state, after processing the pending process, the method further includes: When the node type is a read node, a first monitoring result corresponding to the lock node is obtained; the first monitoring result is used to indicate whether the lock node has a corresponding first target lock node whose node type is a write node within the first time; When the first monitoring result satisfies a preset monitoring result, updating the updated node state to a target node state; When the first monitoring result does not meet the preset monitoring result, maintaining the updated node state; The lock node is deleted according to the updated node status.
3. The method according to claim 2, characterized in that The deleting process of the lock node according to the updated node state includes: When the updated node state is the target node state, deleting the lock node; or, When the updated node state is the preset node state, obtaining a second monitoring result corresponding to the lock node; the second monitoring result is used to indicate whether the lock node has a corresponding second target lock node whose node type is a write node within the second time; When the second monitoring result meets the preset monitoring result, the lock node is deleted.
4. The method according to claim 1, characterized in that The updating of the current node state of the lock node according to the blocked node judgment result and the node type to obtain the updated node state of the lock node includes: When the blocking node judgment result indicates that the lock node has a blocking node, the current node state of the lock node is updated to obtain an updated node state of the lock node as a waiting state; The updated node state is used as the new current node state of the lock node, and the process jumps to the step of obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node, until the blocked node judgment result indicates that there is no blocked node for the lock node, then the current node state of the lock node is updated, and the updated node state of the lock node is the preset node state.
5. The method according to claim 1, characterized in that: The obtaining, according to the processing sequence number and the node type corresponding to the lock node, a blocking node judgment result corresponding to the lock node includes: Determine, according to the node type, a judgment rule corresponding to the processing sequence number; The blocked node judgment result is determined according to the processing sequence number and the judgment rule.
6. The method according to any one of claims 1 to 5, characterized in that: Before obtaining the blocked node judgment result corresponding to the lock node according to the processing sequence number and the node type corresponding to the lock node, the method further includes: Obtaining a node identifier of the lock node; Identifying a preset separation identifier in the node identifier; From the node identifier, identify the sequence number after the preset separation identifier as the processing sequence number.
7. A process processing device, characterized in that: The device comprises: A node generation module, configured to generate a lock node of a process to be processed in response to a processing request for the process to be processed; A result judgment module, used to obtain a blocking node judgment result corresponding to the lock node according to the processing sequence number and node type corresponding to the lock node; A state updating module, used to update the current node state of the lock node according to the blocking node judgment result and the node type, and obtain the updated node state of the lock node; The process processing module is used to process the to-be-processed process when the updated node state is a preset node state.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.