Data updating and data releasing method and device

By responding to thread lock requests in a distributed system, updating the timeout of locked data, and determining whether the thread meets the locking conditions, the performance bottlenecks and high maintenance costs of the existing lock mechanism in a distributed system are solved, and high-reliability distributed locked lock data updates are achieved.

CN113760555BActive Publication Date: 2025-04-15BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010673742.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-14
Publication Date
2025-04-15
Estimated Expiration
2040-07-14

AI Technical Summary

Technical Problem

In distributed systems, existing lock mechanisms such as Zookeeper and Redis Redlock have performance bottlenecks and high maintenance costs, and rely heavily on the system clock, making it difficult to solve the disorder problem.

Method used

By responding to the thread's lock request, obtain the timeout moment in the locked data, judge whether there is locked data in the cluster memory, update the timeout moment of the locked data, judge whether the thread meets the locked conditions, and then update the locked data.

Benefits of technology

A low-cost and high-reliability distributed lock-up data update method is realized, which overcomes the performance bottlenecks and high maintenance costs in the prior art, and improves the reliability and orderliness of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760555B_ABST
    Figure CN113760555B_ABST
Patent Text Reader

Abstract

The present application discloses a method and device for updating and releasing data. The specific implementation scheme is as follows: in response to receiving a lock request from a thread, the lock data of the thread is obtained; whether the locked data exists in the cluster memory is determined; in response to the existence of locked data in the cluster memory, the timeout moment of the locked data is obtained to obtain the first moment, and according to the first moment, whether the locked data has timed out is determined; in response to the timeout of the locked data, the timeout moment of the current locked data is obtained to obtain the second moment, and according to the first moment, the second moment and the thread determination method, whether the thread meets the lock-occupying condition is determined; in response to the thread meeting the lock-occupying condition, according to the lock data of the thread, the locked data is updated. This scheme realizes a low-cost, high-reliability method for updating the lock data of a distributed lock.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, specifically to the field of information processing technology, and in particular to methods and devices for data updating and data releasing. Background Art

[0002] In the computer field, when multiple threads of a single machine (server) access a shared resource at the same time, we can use a locking mechanism to achieve resource isolation. That is, when a thread obtains the resource, it immediately locks the resource. After using the resource, it releases it, and other threads can continue to use it, thereby ensuring the orderly execution of the system as a whole. However, in the era of distributed systems, this locking mechanism between threads will not work. In a distributed system, there are generally multiple resources and they are deployed on different machines. These resources are no longer shared between threads, but are resources shared between processes (multi-threads). For example, when B1, a colleague in the B unit on the 10th floor, saw A1 using the printer, he forced the door open to use the printer because he did not know each other. In this case, the overall execution will become disordered, causing various concurrency problems. Based on the above scenario, a locking mechanism used in a distributed scenario becomes particularly important.

[0003] Currently, the lock mechanisms used in distributed scenarios include: Zookeeper distributed lock and Redlock distributed lock in the remote dictionary service Redis distributed system. Among them, Zookeeper distributed lock is implemented based on the file system, frequently deletes / creates file nodes, and has performance bottlenecks under high concurrency; Redlock distributed lock in the remote dictionary service Redis distributed system is complicated to deploy, has high maintenance costs, and is heavily dependent on the system clock. Summary of the invention

[0004] The present application provides a data updating method, apparatus, device and storage medium, and a data releasing method and apparatus.

[0005] According to a first aspect of the present application, a method for updating data is provided, the method comprising: in response to receiving a locking request of a thread, obtaining locking data of the thread, wherein the locking data includes a timeout time; determining whether there is locked data in the cluster memory, wherein the locked data is used to characterize the locked data of different threads that access the same resource as the locked data; in response to the existence of locked data in the cluster memory, obtaining the timeout time of the locked data to obtain a first time, and determining whether the locked data has timed out based on the first time; in response to the timeout of the locked data, obtaining the timeout time of the current locked data to obtain a second time, and determining whether the thread meets the lock-occupying condition based on the first time, the second time and a thread determination method, wherein the lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed; in response to the thread meeting the lock-occupying condition, updating the locked data based on the locking data of the thread.

[0006] In some embodiments, in response to a timeout of locked data, judging whether the thread meets the lock-holding condition based on a first moment, a second moment and a thread determination method, including: in response to a timeout of locked data, executing the following processes in sequence: initializing a thread counter, incrementing the thread counter, updating the timeout time of the locked data based on the timeout time of the locked data, and decrementing the thread counter; judging whether the thread meets the lock-holding condition based on a comparison result of the first moment and the second moment and the thread counter.

[0007] In some embodiments, judging whether the thread meets the lock-holding condition is based on the comparison result of the first moment and the second moment and the thread counter, including: judging whether the first moment is equal to the second moment; in response to the first moment being equal to the second moment, judging whether the thread counter is an initial value and whether the waiting time of the thread has reached a preset threshold; if the thread counter is an initial value or the waiting time of the thread has reached a preset threshold, the thread meets the lock-holding condition; if the thread counter is not an initial value or the waiting time of the thread does not reach the preset threshold, the thread does not meet the lock-holding condition.

[0008] In some embodiments, the method further includes: in response to the first time being unequal to the second time, stopping data updating.

[0009] In some embodiments, before determining whether the locked data has timed out based on the first moment or before determining whether the first moment is equal to the second moment, it also includes: determining whether the timeout moment of the locked data is empty, and in response to the timeout moment of the locked data being not empty, continuing to execute downward; in response to the timeout moment of the locked data being empty, stopping data updating.

[0010] In some embodiments, the method further includes: in response to the locked data not existing in the cluster memory, storing the locked data of the thread into the memory.

[0011] In some embodiments, the method further includes: in response to the locked data not timing out, stopping data updating.

[0012] In some embodiments, the method further includes: in response to the thread not meeting the lock-holding condition, jumping to a determination method based on the first time, the second time and the thread to determine whether the thread meets the lock-holding condition.

[0013] According to a second aspect of the present application, a method for releasing data is provided, the method comprising:

[0014] In response to receiving a release request of a thread, obtaining locking data of the thread, wherein the locking data includes: a timeout moment; determining whether the locking data of the thread exists in the cluster memory; in response to the locking data of the thread existing in the cluster memory, determining whether the timeout moment of the locking data reaches a preset release moment; in response to the timeout moment of the locking data reaching the preset release moment, deleting the locking data of the thread from the memory.

[0015] In some embodiments, the method further includes: in response to the absence of locked data of the thread in the cluster memory or the timeout moment of the locked data not reaching a preset release moment, stopping data release.

[0016] According to a third aspect of the present application, a data updating device is provided, the device comprising: an acquisition unit, configured to acquire the locking data of the thread in response to receiving a locking request of the thread, wherein the locking data includes a timeout moment; a first judgment unit, configured to determine whether there is locked data in the cluster memory, wherein the locked data is used to characterize the locking data of different threads accessing the same resource as the locked data; a second judgment unit, configured to acquire the timeout moment of the locked data in response to the locked data existing in the cluster memory, obtain a first moment, and determine whether the locked data has timed out according to the first moment; a third judgment unit, configured to acquire the timeout moment of the current locked data in response to the timeout of the locked data, obtain a second moment, and determine whether the thread meets the lock-occupying condition according to the first moment, the second moment and a thread determination method, wherein the lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed; an update unit, configured to update the locked data according to the locking data of the thread in response to the thread meeting the lock-occupying condition.

[0017] In some embodiments, the third judgment unit includes: an execution module, which is configured to execute the following processes in sequence in response to the timeout of the locked data: initialize the thread counter, increment the thread counter, update the timeout time of the locked data according to the timeout time of the locked data, and decrement the thread counter; the judgment module is configured to judge whether the thread meets the lock-occupying condition based on the comparison result of the first moment and the second moment and the thread counter.

[0018] In some embodiments, the judgment module is further configured to judge whether the first moment is equal to the second moment; in response to the first moment being equal to the second moment, judge whether the thread counter is the initial value and whether the waiting time of the thread has reached a preset threshold; if the thread counter is the initial value or the waiting time of the thread has reached the preset threshold, the thread meets the lock-holding condition; if the thread counter is not the initial value or the waiting time of the thread does not reach the preset threshold, the thread does not meet the lock-holding condition; in response to the first moment being not equal to the second moment, stop data updating.

[0019] In some embodiments, the device also includes: a fourth judgment unit, configured to judge whether the timeout moment of the locked data is empty, and in response to the timeout moment of the locked data being not empty, continue to execute downward; in response to the timeout moment of the locked data being empty, stop data updating.

[0020] In some embodiments, the apparatus further comprises: a storage unit configured to store the locking data of the thread into the memory in response to the absence of the locked data in the cluster memory.

[0021] In some embodiments, the apparatus further comprises: a stopping unit configured to stop data updating in response to the locked data not timing out.

[0022] In some embodiments, the device further comprises: a jump unit configured to jump to determine whether the thread meets the lock-holding condition according to the first time, the second time and the thread determination method in response to the thread not meeting the lock-holding condition.

[0023] According to a fourth aspect of the present application, a device for releasing data is provided, the device comprising: an acquisition unit, configured to acquire the locking data of the thread in response to receiving a release request of the thread, wherein the locking data comprises: a timeout moment; a first judgment unit, configured to judge whether the locking data of the thread exists in the cluster memory; a second judgment unit, configured to judge whether the timeout moment of the locking data reaches a preset release moment in response to the existence of the locking data of the thread in the cluster memory; and a deletion unit, configured to delete the locking data of the thread from the memory in response to the timeout moment of the locking data reaching the preset release moment.

[0024] In some embodiments, the apparatus further includes: a stopping unit configured to stop releasing data in response to the absence of locked data of the thread in the cluster memory or the timeout moment of the locked data not reaching a preset release moment.

[0025] According to the fifth aspect of the present application, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described in any implementation manner in the first aspect.

[0026] According to the sixth aspect of the present application, the present application provides a non-transitory computer-readable storage medium storing computer instructions, characterized in that the computer instructions are used to enable a computer to execute a method described in any implementation manner in the first aspect.

[0027] The technology of the present application adopts a method of obtaining locking data of a thread in response to receiving a locking request of the thread, wherein the locking data includes a timeout time, determining whether there is locked data in the cluster memory, and in response to the locked data existing in the cluster memory, obtaining the timeout time of the locked data to obtain a first time, and determining whether the locked data has timed out based on the first time, and in response to the timeout of the locked data, obtaining the timeout time of the current locked data to obtain a second time, and determining whether the thread meets the lock-occupying condition based on the first time, the second time and the thread determination method, wherein the lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed, and in response to When a thread meets the lock-occupying conditions, the locked data is updated according to the locked data of the thread, which solves the problem that the Zookeeper distributed lock is based on the file system and frequently deletes / creates file nodes, resulting in performance bottlenecks under high concurrency. It also solves the problem that the Redlock distributed lock in the distributed system of the remote dictionary service Redis is complicated to deploy, costly, and heavily dependent on the system clock, overcomes the disorder problem in the existing distributed system, and implements a low-cost, high-reliability distributed lock lock data update method; it can be seamlessly introduced in the existing distributed memory system, easy to migrate and use, and uses fine control in the case of locked data timeout to improve the reliability of the system.

[0028] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.

[0030] Figure 1 is a schematic diagram of a first embodiment of a method for updating data according to the present application;

[0031] Figure 2 It is a scene diagram of the method for updating data in the embodiment of the present application;

[0032] Figure 3 is a schematic diagram of a second embodiment of a method for updating data according to the present application;

[0033] Figure 4 is a schematic diagram of a first embodiment of a method for data release according to the present application;

[0034] Figure 5 is a structural schematic diagram of an embodiment of a data updating device according to the present application;

[0035] Figure 6 is a structural schematic diagram of an embodiment of a data release device according to the present application;

[0036] Figure 7 It is a block diagram of an electronic device used to implement the data updating method of an embodiment of the present application. DETAILED DESCRIPTION

[0037] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0038] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0039] Figure 1 A schematic diagram 100 of a first embodiment of a method for updating data according to the present application is shown. The method for updating data comprises the following steps:

[0040] Step 101, in response to receiving a thread locking request, obtaining thread locking data.

[0041] In this embodiment, when the execution subject (such as the execution server) receives the thread lock request, the lock request is parsed to obtain the thread lock data. The lock data includes the timeout time of the thread, which is used to represent the final time when the thread is allowed to execute. For example, the lock data is represented as<A,10:00> , where A is the thread identifier and 10:00 is the final time that the thread is allowed to execute.

[0042] Step 102: Determine whether there is locked data in the cluster memory.

[0043] In this embodiment, the execution subject can search in the cluster memory to determine whether there is locked data of other threads. The locked data is used to represent the locked data of different threads that access the same resource as the locked data.

[0044] Step 103, in response to the existence of locked data in the cluster memory, obtain the timeout moment of the locked data to obtain a first moment, and determine whether the locked data has timed out according to the first moment.

[0045] In this embodiment, when the execution subject determines that there is locked data in the cluster memory, the locked data is parsed, the timeout moment of the locked data is obtained, the first moment is obtained, and the first moment is compared with the current moment to determine whether the locked data has timed out. The timeout moment of the locked data will be replaced by the timeout moment of the locked data of different threads.

[0046] Step 104, in response to the locked data timing out, obtain the current timeout time of the locked data, obtain the second time, and determine whether the thread meets the lock-occupying condition according to the first time, the second time and the thread determination method.

[0047] In this embodiment, when the execution subject determines that the locked data has timed out, the current locked data is parsed, the timeout moment of the current locked data is obtained, and a second moment is obtained. The first moment and the second moment are compared and analyzed, and then according to the thread determination method, it is determined whether the thread meets the lock-occupying condition. The lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed. Because the timeout moment of the locked data will be replaced by the timeout moment of the locked data of different threads, the second moment can be the same as the first moment or different from the first moment. The thread determination method is a method for determining whether all threads have been executed.

[0048] Step 105 , in response to the thread meeting the lock-occupying condition, the locked data is updated according to the locking data of the thread.

[0049] In this embodiment, when the execution subject determines that the thread meets the lock-occupying condition, the locked data in the cluster memory is replaced with the lock data of the thread, thereby implementing the update of the lock data of the thread.

[0050] It should be noted that the above data analysis and updating are well-known technologies that are currently widely studied and applied, and will not be elaborated here.

[0051] Continue to see Figure 2 , the data updating method 200 of this embodiment runs in the electronic device 201. When the electronic device 201 receives the locking request of the thread, the electronic device 201 first obtains the locking data of the thread 202, and then the electronic device 201 determines whether there is locked data in the cluster memory 203. When the electronic device 201 determines that there is locked data in the cluster memory, the timeout moment of the locked data is obtained as the first moment, and according to the first moment, it is determined whether the locked data has timed out 204. When the electronic device 201 determines that the locked data has timed out, the timeout moment of the current locked data is obtained as the second moment, and according to the first moment, the second moment and the thread determination method, it is determined whether the thread meets the lock-occupying condition 205. When the electronic device 201 determines that the thread meets the lock-occupying condition, the locked data is updated according to the locking data of the thread 206.

[0052] The data updating method provided by the above-mentioned embodiment of the present application adopts the method of obtaining the locking data of the thread in response to receiving the locking request of the thread, wherein the locking data includes a timeout time, determining whether there is locked data in the cluster memory, and in response to the locked data existing in the cluster memory, obtaining the timeout time of the locked data to obtain a first time, and determining whether the locked data has timed out based on the first time, and in response to the timeout of the locked data, obtaining the timeout time of the current locked data to obtain a second time, and determining whether the thread meets the lock-occupying condition based on the first time, the second time and the thread determination method, wherein the lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed In response to a thread meeting the lock-occupying condition, the locked data is updated according to the thread's locked data, which solves the problem that Zookeeper distributed locks are based on the file system and frequently delete / create file nodes, resulting in performance bottlenecks under high concurrency. It also solves the problem that Redlock distributed locks in the distributed system of the remote dictionary service Redis are complicated to deploy, costly, and heavily dependent on the system clock, overcomes the disorder problem in the existing distributed system, and implements a low-cost, high-reliability distributed lock lock data update method; it can be seamlessly introduced in the existing distributed memory system, easy to migrate and use, and uses fine control in the case of locked data timeout to improve the reliability of the system.

[0053] Further references Figure 3 , which shows a schematic diagram 300 of a second embodiment of a method for updating data. The process of the method includes the following steps:

[0054] Step 301, in response to receiving a thread lock request, obtaining thread lock data.

[0055] Step 302: Determine whether there is locked data in the cluster memory.

[0056] In some optional implementations of this embodiment, the method further includes: in response to the absence of locked data in the cluster memory, storing the locked data of the thread into the memory. This process needs to ensure the atomicity of the operation. When there is no unreleased lock in the thread, the locked data is quickly stored to further achieve the rapid occupation of resources by the thread.

[0057] Step 303, in response to the existence of locked data in the cluster memory, obtain the timeout moment of the locked data to obtain a first moment, and determine whether the locked data has timed out according to the first moment.

[0058] In some optional implementations of this embodiment, before determining whether the locked data has timed out according to the first moment, the method further includes: determining whether the timeout moment of the locked data is empty, and continuing to execute downward in response to the timeout moment of the locked data being not empty; and stopping data update in response to the timeout moment of the locked data being empty. The locked data is verified to determine whether the locked data has been released, thereby realizing a comprehensive and efficient data update process.

[0059] Step 304, in response to the locked data timing out, obtain the current timeout moment of the locked data, initialize the thread counter, and increment the thread counter.

[0060] In this embodiment, when the execution subject determines that the locked data has timed out, the locked data in the current memory is parsed to obtain the timeout moment of the current locked data, and the thread counter is initialized and incremented by 1 after the thread counter is assigned a value.

[0061] In some optional implementations of this embodiment, the method further includes: in response to the locked data not timing out, stopping the data update, immediately stopping the update and restarting a new data update process, thereby improving system efficiency.

[0062] Step 305: Update the timeout time of the locked data according to the timeout time of the locked data, and decrement the thread counter.

[0063] In this embodiment, the execution subject may replace the timeout time of the locked data according to the timeout time of the locked data obtained previously, and decrement the thread counter by 1 after the replacement is completed.

[0064] Step 306: Determine whether the thread meets the lock-occupying condition based on the comparison result between the first moment and the second moment and the thread counter.

[0065] In this embodiment, the execution subject can determine whether the thread meets the condition that the duration of the thread corresponding to the locked data is the shortest based on the comparison result between the first moment and the second moment, analyze the thread counter to determine whether all threads have been executed, and determine whether the thread meets the lock-occupying condition based on the determination result of whether the thread meets the condition that the duration of the thread corresponding to the locked data is the shortest and the determination result of whether all threads have been executed. When the thread meets the condition that the duration of the thread corresponding to the locked data is the shortest and it is determined that all threads have been executed, it is determined that the thread meets the lock-occupying condition, otherwise the thread does not meet the lock-occupying condition.

[0066] In some optional implementations of this embodiment, judging whether the thread meets the lock-occupying condition according to the comparison result of the first moment and the second moment and the thread counter includes: judging whether the first moment and the second moment are equal; in response to the first moment and the second moment being equal, judging whether the thread counter is the initial value and whether the waiting time of the thread has reached the preset threshold; if the thread counter is the initial value or the waiting time of the thread has reached the preset threshold, the thread meets the lock-occupying condition; if the thread counter is not the initial value or the waiting time of the thread has not reached the preset threshold, the thread does not meet the lock-occupying condition. By judging whether the first moment and the second moment are equal, it is determined whether the first moment has been tampered with by other threads. If the first moment and the second moment are equal (that is, no other thread has updated the first moment before the two threads), it indicates that the thread is the thread with the shortest interval between the threads corresponding to the locked data. If the first moment and the second moment are not equal (that is, an earlier thread has updated the first moment before the two threads), it indicates that the thread is not the thread with the shortest interval between the threads corresponding to the locked data. Then, it determines whether the thread counter is the initial value and whether the waiting time of the thread has reached the preset threshold, thus achieving fine control over the process and improving the reliability of the system. By determining whether the waiting time of the thread has reached the preset threshold, it protects against scenarios where the thread occupies the lock for a long time due to anomalies and does not release the lock, thus improving the reliability of the system.

[0067] In some optional implementations of this embodiment, the method further includes: in response to the first time being not equal to the second time being, stopping the data update. Immediately stopping the update and restarting a new data update process improves system efficiency.

[0068] In some optional implementations of this embodiment, before determining whether the first moment is equal to the second moment, the process further includes: determining whether the timeout moment of the locked data is empty, and in response to the timeout moment of the locked data being not empty, continuing to execute downward; and in response to the timeout moment of the locked data being empty, stopping data updating. The locked data is verified to determine whether the locked data has been released, thereby achieving a comprehensive and efficient data update process.

[0069] Step 307: in response to the thread meeting the lock-occupying condition, the locked data is updated according to the locking data of the thread.

[0070] To further illustrate, thread A currently holds the lock in memory and does not release it (the lock data is: <A, 10:00>). Now thread B (the lock data is: <B, 10:05>) and thread C (the lock data is: <C, 10:10>) compete for the lock at the same time at 10:01. A thread counter is set in the memory, and the thread counter num is initialized to make num=0. At 10:01, thread B first obtains the timeout time a(10:00) of the locked data in the current memory (the locked data of thread A), and num is increased by 1. Currently, num=1. At the same time, at 10:01, thread C also obtains the timeout time a(10:00) of the locked data in the current memory, and num is increased by 1. Currently, num=2. Each time a thread stores its own locked data in the memory, num is reduced by 1. At 10:02, B, under the premise of judging that a has timed out, obtains the timeout time b (10:00) of the locked data again and stores its own locked data <B, 10:05> in the memory, and num is reduced by 1, and currently num = 1. At 10:02, C is not executed at this time due to network thread blocking and other reasons. At 10:03, B judges that a = b, because num is not equal to 0 at this time, thread B remains in a waiting state until num = 0. At the same time, at 10:03, the network of thread C suddenly gets better and can continue to execute. C, under the premise of judging that a has timed out, obtains the timeout time b (10:05) of the locked data again and stores its own locked data <C, 10:10> in the memory, and num is reduced by 1, and currently num = 0. At 10:04, B suddenly finds out that num=0 (which means that the "filling memory" steps of other threads have been executed), which meets the lock-occupying condition. However, because its own timeout time 10:05 has been overwritten by C thread as 10:10, it stores its own 10:05 in the memory to overwrite 10:10, ensuring that the timeout time of the locked data in the memory must be 10:05, and returns the lock-occupying success information. At the same time, at 10:04, C determines that a(10:00) is not equal to b(10:05), which means that it does not meet the lock-occupying condition, and returns the lock-occupying failure information. In the end, B succeeds in locking, and C fails in locking.

[0071] In some optional implementations of this embodiment, the method further includes: in response to the thread not meeting the lock-holding condition, jumping to determine whether the thread meets the lock-holding condition based on the first moment, the second moment and the thread determination method. Based on the fast jumping process, the system efficiency is improved.

[0072] In this embodiment, the specific operations of steps 301 to 303 and 307 are the same as Figure 1 The operations of steps 101 to 103 and 105 in the illustrated embodiment are substantially the same and will not be described in detail herein.

[0073] from Figure 3 It can be seen that Figure 1 Compared with the corresponding embodiment, the schematic diagram 300 of the data update method in this embodiment adopts the method of responding to the timeout of the locked data, obtaining the timeout moment of the current locked data, initializing the thread counter, incrementing the thread counter, updating the timeout moment of the locked data according to the timeout moment of the locked data, decrementing the thread counter, judging whether the thread meets the lock-occupying condition according to the comparison result of the first moment and the second moment and the thread counter, and updating the locked data according to the locked data of the thread in response to the thread meeting the lock-occupying condition, and realizing tampering recovery of the timeout time based on the two data updates; the whole process realizes that when multiple threads apply for the cluster lock at the same time, only one thread holds the lock and will not be snatched by other threads, thereby improving the security and stability of the locked data update and making the lock application more orderly.

[0074] Further references Figure 4 , this application provides a method for releasing data, Figure 4 A schematic diagram 400 of a first embodiment of a method for releasing data according to the present application is shown. The method for releasing data comprises the following steps:

[0075] Step 401, in response to receiving a release request of a thread, obtaining locking data of the thread.

[0076] In this embodiment, when the execution subject (eg, the execution server) receives the release request of the thread, the release request is parsed to obtain the locking data of the thread, wherein the locking data includes the timeout time of the thread.

[0077] Step 402: Determine whether there is thread lock data in the cluster memory.

[0078] In this embodiment, the execution subject may search in the cluster memory to determine whether there is locking data of the thread.

[0079] Step 403: In response to the existence of thread lock data in the cluster memory, it is determined whether the timeout moment of the lock data reaches a preset release moment.

[0080] In this embodiment, when the execution subject determines that there is thread lock data in the cluster memory, it is determined whether the timeout moment of the lock data reaches a preset release moment.

[0081] In some optional implementations of this embodiment, the method further includes: in response to the absence of locked data of the thread in the cluster memory or the timeout moment of the locked data not reaching the preset release moment, stopping data release, thereby improving system efficiency.

[0082] Step 404: In response to the timeout moment of the locked data reaching the preset release moment, the locked data of the thread is deleted from the memory.

[0083] In this embodiment, when the execution subject determines that the timeout moment of the lock data has reached the preset release moment, the lock data of the thread is deleted from the memory to complete the lock data release.

[0084] The data release method provided by the above-mentioned embodiment of the present application adopts the method of obtaining the locking data of the thread in response to receiving a release request of the thread, judging whether the locking data of the thread exists in the cluster memory, judging whether the timeout moment of the locking data reaches the preset release moment in response to the locking data of the thread existing in the cluster memory, deleting the locking data of the thread from the memory in response to the timeout moment of the locking data reaching the preset release moment, ensuring that only the lock holder can delete the locking data, thereby improving data security and system efficiency.

[0085] Further references Figure 5 , as a response to the above Figures 1 to 3 In order to realize the method shown in the figure, the present application provides an embodiment of a data updating device, and the device embodiment is similar to Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0086] like Figure 5As shown, the data updating device 500 of this embodiment includes: an acquisition unit 501, a first judgment unit 502, a second judgment unit 503, a third judgment unit 504 and an updating unit 505, wherein the acquisition unit is configured to, in response to receiving a locking request of a thread, acquire the locking data of the thread, wherein the locking data includes a timeout time; the first judgment unit is configured to determine whether there is locked data in the cluster memory, wherein the locked data is used to represent the locking data of different threads accessing the same resource as the locked data; the second judgment unit is configured to, in response to the existence of locked data in the cluster memory , obtain the timeout moment of the locked data, obtain the first moment, and judge whether the locked data has timed out according to the first moment; the third judgment unit is configured to obtain the timeout moment of the current locked data in response to the timeout of the locked data, obtain the second moment, and judge whether the thread meets the lock-occupying condition according to the first moment, the second moment and the thread judgment method, wherein the lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed; the update unit is configured to update the locked data according to the locking data of the thread in response to the thread meeting the lock-occupying condition.

[0087] In this embodiment, the specific processing of the acquisition unit 501, the first judgment unit 502, the second judgment unit 503, the third judgment unit 504 and the updating unit 505 of the data updating device 500 and the technical effects thereof can be referred to respectively. Figure 1 The relevant descriptions of steps 101 to 105 in the corresponding embodiment are not repeated here.

[0088] In some optional implementations of this embodiment, the third judgment unit includes: an execution module, configured to execute the following processes in sequence in response to the timeout of the locked data: initialize the thread counter, increment the thread counter, update the timeout time of the locked data according to the timeout time of the locked data, and decrement the thread counter; a judgment module, configured to judge whether the thread meets the lock-occupying condition based on the comparison result of the first moment and the second moment and the thread counter.

[0089] In some optional implementations of this embodiment, the judgment module is further configured to judge whether the first moment is equal to the second moment; in response to the first moment being equal to the second moment, judge whether the thread counter is the initial value and whether the waiting time of the thread has reached a preset threshold; if the thread counter is the initial value or the waiting time of the thread has reached the preset threshold, the thread meets the lock-occupying condition; if the thread counter is not the initial value or the waiting time of the thread does not reach the preset threshold, the thread does not meet the lock-occupying condition; in response to the first moment being not equal to the second moment, stop data updating.

[0090] In some optional implementations of this embodiment, the device also includes: a fourth judgment unit, configured to judge whether the timeout moment of the locked data is empty, and in response to the timeout moment of the locked data being not empty, continue to execute downward; in response to the timeout moment of the locked data being empty, stop data updating.

[0091] In some optional implementations of this embodiment, the device further includes: a storage unit configured to store the locking data of the thread into the memory in response to the absence of locked data in the cluster memory.

[0092] In some optional implementations of this embodiment, the device further includes: a stopping unit configured to stop data updating in response to the locked data not timing out.

[0093] In some optional implementations of this embodiment, the device also includes: a jump unit, which is configured to jump to determine whether the thread meets the lock-holding condition based on the first moment, the second moment and the thread determination method in response to the thread not meeting the lock-holding condition.

[0094] Further references Figure 6 , as a response to the above Figure 4 The present application provides an embodiment of a data release device, and the device embodiment is similar to Figure 4 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0095] like Figure 6 As shown, the data release device 600 of this embodiment includes: an acquisition unit 601, a first judgment unit 602, a second judgment unit 603 and a deletion unit 604, wherein the acquisition unit is configured to acquire the locking data of the thread in response to receiving a release request of the thread, wherein the locking data includes: a timeout moment; the first judgment unit is configured to determine whether the locking data of the thread exists in the cluster memory; the second judgment unit is configured to determine whether the timeout moment of the locking data reaches a preset release moment in response to the existence of the locking data of the thread in the cluster memory; the deletion unit is configured to delete the locking data of the thread from the memory in response to the timeout moment of the locking data reaching the preset release moment.

[0096] In this embodiment, the specific processing of the acquisition unit 601, the first judgment unit 602, the second judgment unit 603 and the deletion unit 604 of the data release device 600 and the technical effects thereof can be referred to respectively. Figure 4 The relevant descriptions of steps 401 to 404 in the corresponding embodiment are not repeated here.

[0097] In some optional implementations of this embodiment, the device further includes: a stopping unit configured to stop data release in response to the absence of thread lock data in the cluster memory or the timeout moment of the lock data not reaching a preset release moment.

[0098] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.

[0099] like Figure 7 , is a block diagram of an electronic device according to a method for updating data in an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.

[0100] like Figure 7 As shown, the electronic device includes: one or more processors 701, a memory 702, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 701 is taken as an example.

[0101] The memory 702 is a non-transient computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor to enable at least one processor to perform the data updating method provided in the present application. The non-transient computer-readable storage medium of the present application stores computer instructions, which are used to enable a computer to perform the data updating method provided in the present application.

[0102] The memory 702 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions / modules corresponding to the data updating method in the embodiment of the present application (for example, the attached Figure 5 The processor 701 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 702, that is, the data updating method in the above method embodiment is implemented.

[0103] The memory 702 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the electronic device for data update, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 702 may optionally include a memory remotely arranged relative to the processor 701, and these remote memories may be connected to the electronic device for data update via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0104] The electronic device of the data updating method may further include: an input device 703 and an output device 704. The processor 701, the memory 702, the input device 703 and the output device 704 may be connected via a bus or other means. Figure 7 The example of connecting through bus is taken in the following.

[0105] The input device 703 can receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device for data update, such as input devices such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator rod, one or more mouse buttons, a trackball, a joystick, etc. The output device 704 may include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor), etc. The display device may include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display, and a plasma display. In some embodiments, the display device may be a touch screen.

[0106] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0107] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or means (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.

[0108] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0109] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0110] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.

[0111] According to the technical solution of the embodiment of the present application, in response to receiving a lock request from a thread, the lock data of the thread is obtained, wherein the lock data includes a timeout time, and it is determined whether there is locked data in the cluster memory. In response to the locked data existing in the cluster memory, the timeout time of the locked data is obtained to obtain a first time, and according to the first time, it is determined whether the locked data has timed out. In response to the timeout of the locked data, the timeout time of the current locked data is obtained to obtain a second time, and according to the first time, the second time and the thread determination method, it is determined whether the thread meets the lock-occupying condition, wherein the lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed. When a thread meets the lock-occupying condition, the locked data is updated according to the locking data of the thread, which solves the problem that Zookeeper distributed locks are based on the file system and frequently delete / create file nodes, resulting in performance bottlenecks under high concurrency. It also solves the problem that the Redlock distributed lock in the distributed system of the remote dictionary service Redis is complicated to deploy, costly, and heavily dependent on the system clock, overcomes the disorder problem in the existing distributed system, and realizes a low-cost, high-reliability distributed lock locking data update method; it can be seamlessly introduced in the existing distributed memory system, easy to migrate and use, and uses fine control in the case of locked data timeout to improve the reliability of the system. In response to the timeout of locked data, the timeout moment of the current locked data is obtained, the thread counter is initialized, the thread counter is incremented, the timeout moment of the locked data is updated according to the timeout moment of the locked data, the thread counter is decremented, and whether the thread meets the lock-occupying condition is determined according to the comparison result of the first moment and the second moment and the thread counter. In response to the thread meeting the lock-occupying condition, the locked data is updated according to the locked data of the thread. Based on the two data updates, the tampering recovery of the timeout time is realized; the whole process realizes that when multiple threads apply for cluster locks at the same time, only one thread holds the lock and will not be snatched by other threads, which improves the security and stability of the lock data update and makes the lock application more orderly.

[0112] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.

[0113] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.

Claims

1. A method for updating data, the method comprising: In response to receiving a thread lock request, acquiring lock data of the thread, wherein the lock data includes a timeout time; Determine whether there is locked data in the cluster memory, wherein the locked data is used to represent locked data of different threads that access the same resource as the locked data; In response to the existence of locked data in the cluster memory, obtaining a timeout moment of the locked data to obtain a first moment, and judging whether the locked data has timed out according to the first moment; In response to the locked data timeout, the current timeout moment of the locked data is obtained to obtain a second moment, and according to the first moment, the second moment and the thread determination method, whether the thread meets the lock-occupying condition is determined, including: in response to the locked data timeout, the following processes are sequentially performed: initializing a thread counter, increasing the thread counter, updating the timeout moment of the locked data according to the timeout moment of the locked data, and decreasing the thread counter; Determining whether the first moment is equal to the second moment; In response to the first moment being equal to the second moment, determining whether the thread counter is an initial value and whether the waiting time of the thread has reached a preset threshold; If the thread counter is at an initial value or the waiting time of the thread has reached a preset threshold, the thread meets the lock-occupying condition; If the thread counter is not the initial value or the waiting time of the thread does not reach the preset threshold, the thread does not meet the lock-occupying condition, wherein the lock-occupying condition is used to indicate that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed; In response to the first time being not equal to the second time, stopping the data update; In response to the thread meeting the lock-occupying condition, the locked data is updated according to the locking data of the thread.

2. The method according to claim 1, wherein: Before determining whether the locked data has timed out according to the first moment or before determining whether the first moment is equal to the second moment, the method further includes: Determine whether the timeout time of the locked data is empty, and in response to the timeout time of the locked data being not empty, continue to execute downward; in response to the timeout time of the locked data being empty, stop the data update.

3. The method according to claim 1, further comprising: In response to the absence of locked data in the cluster memory, storing the locked data of the thread in the memory.

4. The method according to claim 1, further comprising: In response to the locked data not timing out, stopping the data update.

5. The method according to claim 1, further comprising: In response to the thread not meeting the lock-holding condition, the process jumps to determining whether the thread meets the lock-holding condition according to the first time, the second time and a thread determination method.

6. A method for releasing data, the method comprising: In response to receiving a release request of a thread, acquiring locking data of the thread according to the method of any one of claims 1 to 5, wherein the locking data includes: a timeout time; Determine whether there is locked data of the thread in the cluster memory; In response to the existence of locking data of the thread in the cluster memory, determining whether a timeout moment of the locking data reaches a preset release moment; In response to the timeout moment of the locking data reaching a preset release moment, the locking data of the thread is deleted from the memory.

7. The method according to claim 6, further comprising: In response to the fact that the locked data of the thread does not exist in the cluster memory or the timeout moment of the locked data does not reach the preset release moment, the data release is stopped.

8. A data updating device, comprising: an acquisition unit, configured to acquire locking data of the thread in response to receiving a locking request of the thread, wherein the locking data includes a timeout time; A first determination unit is configured to determine whether there is locked data in the cluster memory, wherein the locked data is used to represent locked data of different threads accessing the same resource as the locked data; A second judgment unit is configured to, in response to the existence of locked data in the cluster memory, obtain a timeout moment of the locked data to obtain a first moment, and judge whether the locked data has timed out according to the first moment; The third judgment unit includes: The execution module is configured to, in response to the timeout of the locked data, obtain the current timeout time of the locked data, obtain a second time, and determine whether the thread meets the lock-occupying condition according to the first time, the second time and the thread determination method, including: in response to the timeout of the locked data, sequentially perform the following processes: initialize a thread counter, increment the thread counter, update the timeout time of the locked data according to the timeout time of the locked data, and decrement the thread counter; The judgment module is configured to judge whether the first moment is equal to the second moment; in response to the first moment being equal to the second moment, judge whether the thread counter is an initial value and whether the waiting time of the thread has reached a preset threshold; if the thread counter is an initial value or the waiting time of the thread has reached a preset threshold, the thread meets the lock-occupying condition; if the thread counter is not an initial value or the waiting time of the thread has not reached the preset threshold, the thread does not meet the lock-occupying condition; in response to the first moment being not equal to the second moment, stop the data update, wherein the lock-occupying condition is used to characterize that the interval between the thread and the thread corresponding to the locked data is the shortest and all threads have been executed; The updating unit is configured to update the locked data according to the locking data of the thread in response to the thread meeting the lock occupying condition.

9. The apparatus according to claim 8, further comprising: The fourth judgment unit is configured to judge whether the timeout moment of the locked data is empty, and in response to the timeout moment of the locked data being not empty, continue to execute downward; in response to the timeout moment of the locked data being empty, stop the data update.

10. The apparatus according to claim 8, further comprising: The storage unit is configured to store the locking data of the thread into the memory in response to the absence of locked data in the cluster memory.

11. The apparatus according to claim 8, further comprising: The stopping unit is configured to stop the data update in response to the locked data not timing out.

12. The apparatus according to claim 8, further comprising: The jump unit is configured to jump to determine whether the thread meets the lock-holding condition according to the first time, the second time and a thread determination method in response to the thread not meeting the lock-holding condition.

13. A data release device, the device comprising: An acquisition unit is configured to, in response to receiving a release request of a thread, acquire the locking data of the thread according to the method according to any one of claims 1 to 5, wherein the locking data includes: a timeout time; A first determination unit is configured to determine whether there is locking data of the thread in the cluster memory; A second judgment unit is configured to judge whether a timeout moment of the locking data reaches a preset release moment in response to the locking data of the thread existing in the cluster memory; The deleting unit is configured to delete the locking data of the thread from the memory in response to the timeout moment of the locking data reaching a preset release moment.

14. The apparatus according to claim 13, further comprising: The stopping unit is configured to stop releasing the data in response to the fact that the locking data of the thread does not exist in the cluster memory or the timeout time of the locking data does not reach the preset release time.

15. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.

16. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Control method and device of distributed-type lock

    CN107818018A