CN109753364A - A kind of implementation method, equipment and the medium of network-based distributed lock - Google Patents

A kind of implementation method, equipment and the medium of network-based distributed lock Download PDF

Info

Publication number
CN109753364A
CN109753364A CN201811617626.1A CN201811617626A CN109753364A CN 109753364 A CN109753364 A CN 109753364A CN 201811617626 A CN201811617626 A CN 201811617626A CN 109753364 A CN109753364 A CN 109753364A
Authority
CN
China
Prior art keywords
client
request
locking
resource
queue
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201811617626.1A
Other languages
Chinese (zh)
Inventor
丁波
喻波
王志海
刘旺
韩振国
安鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Wondersoft Technology Co Ltd
Original Assignee
Beijing Wondersoft Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Wondersoft Technology Co Ltd filed Critical Beijing Wondersoft Technology Co Ltd
Priority to CN201811617626.1A priority Critical patent/CN109753364A/en
Publication of CN109753364A publication Critical patent/CN109753364A/en
Pending legal-status Critical Current

Links

Abstract

Implementation method, equipment and the medium of network-based distributed lock provided by the invention, the locking operation request for the distributed lock that at least one client is sent is received first, at least one client is added in client queue and is ranked up, it can be ranked up based on time or priority, then the active client for carrying out locking operation request first is obtained, judges that the locking request of the active client is synchronous locking request or asynchronous locking request;Different locking strategies is used according to different locking requests, so that the corresponding locking request of the active client for meeting condition obtains distributed lock, and resource information is accessed, is unsatisfactory for condition, then returns to locking failure information.Content according to the present invention realizes effective access of shared resource, solves the problems, such as distributed lock reentry property, the dependence of the Single Point of Faliure problem and distributed lock service of distributed lock service to third party software.

Description

A kind of implementation method, equipment and the medium of network-based distributed lock
Technical field
This application involves field of computer technology, and in particular to Internet technical field more particularly to network-based point Implementation method, equipment and the medium of cloth lock.
Background technique
The deployment of current almost all of large-scale website and application is all distributed.The one of data in distributed scene Cause property is an important topic.Distributed CAP theory teaches that " any one distributed system all can not be simultaneously Meet consistency (Consistency), availability (Availability), be distributed fault-tolerance (Partition Tolerance), Two can only at most be met simultaneously.".So being just made that choice to this three at the beginning of many system designs.In most of interconnections It requires to sacrifice strong consistency, Lai Huanqu high availability in net system, system often only needs to guarantee final consistency.
Include the implementation of three kinds of distributed locks in the scheme of the prior art:
(1) based on the distributed lock of database: using the major key field of field in relational database table uniqueness about Beam, using the number-mark of shared resource as major key.The data for applying for insertion corresponding resource number when shared lock, are inserted into successfully then Application is locked successfully, and lock failure is then applied in insertion failure.
(2) distributed lock based on caching (Redis): by the insertion to key-value key-value pair, modification is deleted real Existing distributed lock.Application lock is insertion data, is inserted into successfully then to lock and apply successfully, and lock failure is then applied in insertion failure.By The timeout mechanism of key-value key-value pair prevents deadlock.Using finishing, then delete release is locked.
(3) based on the distributed lock of zookeeper: the Node based on Zookeeper, Watcher, temporal order's Node station System realizes distributed lock.It when application lock, is monitored to the Node registry for representing related shared resource, and creation is interim suitable in its lower section Sequence node.When receiving node Notification of Changes, judge whether oneself is the smallest node of number, if it is, being locked, no It is then to continue waiting for notifying.After completing the access to related resource, the node of oneself creation is deleted.
In order to guarantee that an attribute or a method synchronization can only passed by a thread accesses under high concurrent situation It unites in the case where the deployment of monomer applications single machine, the relevant API of some con current controls can be used.But with the need of business development It wants, former monomer applications evolve into after distributed system, and multithreading originally, multi-process has been distributed on different systems, The Analysis of Concurrency Control of monomer system will fail at this time.Just one kind is needed to overstate process at this time, overstates that the mechanism of system is shared to control The access of resource, here it is it is to be solved the problem of.
Summary of the invention
In order to solve the above technical problems, the invention proposes implementation method, the equipment of a kind of network-based distributed lock And medium, to solve the technical issues of background section above is mentioned.
According to one embodiment of present invention, the present invention provides a kind of implementation method of network-based distributed lock, Applied to the host node of server end, including
The host node receives the locking operation request for the distributed lock that at least one client is sent;
By at least one corresponding described client of the locking operation request of at least one client, it is added to It in the client queue of the current distributed lock and is ranked up, obtains the existing customer for carrying out locking operation request first End;
The locking request for judging the active client is synchronous locking request or asynchronous locking request;
Different locking strategies is used according to different locking requests, so that the active client for meeting condition is corresponding Locking request obtain distributed lock, and access resource information, be unsatisfactory for condition, then return to locking failure information.
Preferably, described that different locking strategies is used according to different locking requests, so that meeting the client of condition Corresponding locking request obtains distributed lock, and accesses resource information, is unsatisfactory for condition, then returns to locking failure information, specifically Including if the active client initiates asynchronous locking request, the host node checks whether resource request queue is sky, such as Fruit is sky, then the asynchronous locking request directly initiated the active client is added in the resource request queue, returns and adds It locks successfully, if being not sky, checks in the resource request queue whether there is the active client, if there is then what is all It does not do, the resource request queue tail is added in the asynchronous locking request for then not initiating the active client, described After the lock holder of the head of the queue of resource request queue has used certain resource, lock release operation is initiated, at this time the lock holder of head of the queue Team out, the new application for being located at head of the queue obtain the lock of the resource;If the active client initiates synchronous locking request, described Host node checks whether resource request queue is sky, if it is sky, directly synchronizes locking for what the active client was initiated Request is added in the resource request queue, and return locks successfully, if be not it is empty, check the active client whether be Otherwise the current holder of the lock of resource returns to failure if it is, returning successfully.
Preferably, at least one corresponding described visitor of the locking operation request by least one client Family end is added in the client queue of the current distributed lock and is ranked up, including the request initiated according to client Time be ranked up, alternatively, according to client initiate request priority be ranked up.
Preferably, the server end further includes from node, and the host node is in the operation for carrying out distributed lock realization Cheng Zhong, push data into it is described from node, it is described receive the data from node after update and save it is data cached so that institute It is synchronous with the data from node to state host node.
Preferably, described periodically to send heartbeat detection, monitoring master from node in the normal situation of the host node Node, when the host node is abnormal, it is described from node according to synchronous data, start externally service, periodically send wide It broadcasts, while electing new from node, and keep new slave node synchronous with instead of the data of slave node of host node.
Preferably, pass through network to the host node cycle, broadcast is externally sent in a manner of UDP, participate in contention for resources At least one described client receive broadcast after, then registered to server in a manner of TCP, server receives information of registering Afterwards, the information of registering of internal each client is updated, then server is according to the information of registering of each client to each Client in a resource waiting list checks, waiting list of the client that those long periods are not registered from resource Middle deletion prevents deadlock with this.
According to one embodiment of present invention, the present invention also provides a kind of realization sides of network-based distributed lock Method is applied to client, comprising:
The host node of at least one user end to server sends locking operation request,
According to the sortord in the client queue of the server, obtains and carry out the current of locking operation request first Client;
The locking request that the active client is sent to server end is synchronous locking request or asynchronous locking request;
It is described current if meeting condition according to the different locking strategies that server end uses different locking requests Client obtains distributed lock from server end and accesses resource information, if being unsatisfactory for condition, the active client is from clothes Business device termination receives locking failure information.
According to one embodiment of present invention, the present invention also provides a kind of host node device, the host node device packets It includes:
Reception device, the locking operation for receiving the distributed lock that at least one client is sent are requested;
Collator, for by the request of the locking operation of at least one client it is corresponding it is described at least one Client is added in the client queue of the current distributed lock and is ranked up, and obtains progress locking operation first and asks The active client asked;
Judgment means, for judging that the locking request of the active client is that synchronous locking request or asynchronous locking are asked It asks;
Processing unit, for using different locking strategies according to different locking requests, so that meeting the described of condition The corresponding locking request of active client obtains distributed lock, and accesses resource information, is unsatisfactory for condition, then returns to locking failure Information.
Preferably, the host node device further include:
Sending device, it is real carrying out distributed lock for by network, broadcast externally to be sent in a manner of UDP periodically In existing operating process, push data into from node, it is described receive the data from node after update and save it is data cached, So that the host node is synchronous with the data from node.
According to one embodiment of present invention, the present invention also provides a kind of computer readable storage mediums, comprising:
Processor;And
It is arranged to the memory of storage computer executable instructions, the executable instruction makes the place when executed The step of managing the method for the above-mentioned realization distributed lock of device.
Implementation method, equipment and the medium of network-based distributed lock provided by the invention, receive at least one first The locking operation for the distributed lock that client is sent is requested, at least one client is added in client queue and is arranged Sequence can be ranked up based on time or priority, then obtained the active client for carrying out locking operation request first, sentenced The locking request of the active client of breaking is synchronous locking request or asynchronous locking request;Made according to different locking requests With different locking strategies, so that the corresponding locking request of the active client for meeting condition obtains distributed lock, and visit It asks resource information, is unsatisfactory for condition, then return to locking failure information.Content according to the present invention, realize shared resource has Effect access solves the problems, such as distributed lock reentry property, the Single Point of Faliure problem of distributed lock service and distributed lock service pair The dependence of third party software.
Detailed description of the invention
Fig. 1 is the implementation method overview flow chart of network-based distributed lock proposed by the present invention;
Fig. 2, which is that the implementation method of network-based distributed lock proposed by the present invention is synchronous, locks flow chart;
Fig. 3 is the asynchronous locking flow chart of implementation method of network-based distributed lock proposed by the present invention;
Fig. 4 is the equipment overall framework figure of network-based distributed lock proposed by the present invention;
Fig. 5 is the host node device frame diagram of network-based distributed lock proposed by the present invention.
Specific embodiment
Below in conjunction with the attached drawing in the embodiment of the present application, technical solutions in the embodiments of the present application carries out clear, complete Site preparation description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on Embodiment in the present invention, those of ordinary skill in the art without making creative work it is obtained it is all its Its embodiment, shall fall within the protection scope of the present invention.
Core of the invention is to provide a kind of method, equipment and readable storage medium storing program for executing for obtaining distributed lock, distribution The dependence of lock reentry property problem, the Single Point of Faliure problem and distributed lock service of distributed lock service to third party software.
Scheme in order to enable those skilled in the art to better understand the present invention, with reference to the accompanying drawing and specific embodiment party The present invention is described in further detail for formula.
Fig. 1 is the implementation method overview flow chart of network-based distributed lock proposed by the present invention, as shown in Figure 1, answering Host node for server end, wherein server end further include from node, host node and between node carry out data friendship Mutually.The concrete methods of realizing of distributed lock proposed by the present invention, includes following content:
The host node receives the locking operation request for the distributed lock that at least one client is sent, as shown in Figure 1, objective This block of family end just includes APP1, APP2, APP3, APP4, APP5, host node externally provides service, the different moneys of internal maintenance The request queue in source.
Distributed lock is obtained based on different APP application request in the present invention, when application APP1, APP2, APP3, When APP4, APP5 send distributed lock request to server host node, different applications can enter in a queue, then right The application for initially entering queue carries out the distribution of distributed lock.And in application acquisition request, and the difference including different application Request method, such as asynchronous locking request or synchronous locking request, then with regard to needing to divide different locking requests respectively The different distribution of cloth lock.
Meanwhile in the present invention, a client can request that an application may also request multiple applications, and different The request of different applications can also occur for client, then then needing when multiple client carries out the request of distributed lock to more A client carries out the adjustment of queue.
The mode of adjustment is, by the locking operation request corresponding described at least one of at least one client A client is added in the client queue of the current distributed lock and is ranked up, and obtains and carries out locking operation first The active client of request;
As shown in figure 4, at least one client includes one or more than one client, when being that client is visited When asking that server end carries out resource request, does not need to be ranked up, directly be sentenced by server end according to resource queue's information It is disconnected, it is how to carry out the realization of distributed lock, when there is more than one client, while accesses server end, or successively Server end is accessed, server end needs the client to multiple access to be ranked up processing, according to time sequencing or preferentially Grade sequence, performs corresponding processing.After sequence, than if any the first client, the second client ..., N client, then One client is handled first, then successively the second client, until N client, herein, the progress first of acquisition The client of processing is active client.
The locking request for judging the active client is synchronous locking request or asynchronous locking request;
In the present invention, different locking requests is that have the corresponding mode for obtaining distributed lock, therefore, in the present invention In, different locking strategies is used according to different locking requests, is added so that the active client for meeting condition is corresponding Lock request obtains distributed lock, and accesses resource information, is unsatisfactory for condition, then returns to locking failure information.
Specific strategy are as follows:
As shown in Figures 2 and 3, if the active client initiates asynchronous locking request, the host node checks resource Whether request queue is sky, and if it is sky, the money is added in the asynchronous locking request for directly initiating the active client In the request queue of source, return is locked successfully, and whether if being not sky, checking has the current visitor in the resource request queue Family end, if there is then doing nothing, the resource is added in the asynchronous locking request for then not initiating the active client Lock release operation is initiated after the lock holder of the head of the queue of the resource request queue has used certain resource in request queue tail portion, The lock holder of head of the queue goes out team at this time, and the new application for being located at head of the queue obtains the lock of the resource;If the active client hair Synchronous locking request is played, the host node checks whether resource request queue is sky, if it is sky, directly by the current visitor The synchronization locking request that family end is initiated is added in the resource request queue, and return locks successfully, if being not sky, checks institute State whether active client is otherwise the current holder of lock of resource returns to failure if it is, return successfully.
Based on above content, then the Different Strategies setting of different locking requests is realized, point of different clients is realized The acquisition process of cloth lock, after active client has obtained resource, server end deletes it in client sequence list, And it is operated by next client to carry out resource acquisition, for example, after the first client completes resource acquisition, then the second client End carries out resource acquisition operation, carries out according to the queue sequence of setting.
In the present invention, there is exception during the work time in host node in order to prevent, causes system problem, and the present invention also exists Server end is provided with from node, and the host node pushes data into institute in the operating process for carrying out distributed lock realization State from node, it is described receive the data from node after update and save it is data cached so that the host node and described from section The data of point are synchronous.It is described periodically to send heartbeat detection from node in the normal situation of the host node, monitor main section Point, when the host node is abnormal, it is described from node according to synchronous data, start externally service, periodically send broadcast, It elects simultaneously new from node, and keeps new slave node synchronous with instead of the data of slave node of host node.
Meanwhile in order to prevent deadlock the problem of, in method proposed by the present invention, further includes: lead to the host node cycle Cross network, broadcast externally sent in a manner of UDP, participate in contention for resources at least one described client receive broadcast after, Registered in a manner of TCP to server again, server receives register information after, update registering for internal each client Information, then server checks the client in each resource waiting list according to the information of registering of each client, will The client that those long periods do not register deletes from the waiting list of resource, prevents deadlock with this.
Above content belongs to the implementation method of the distributed lock applied to server end, and the present invention also provides a kind of applications In the implementation method of the distributed lock of client, comprising: the host node of at least one user end to server, which is sent, to lock Operation requests,
According to the sortord in the client queue of the server, obtains and carry out the current of locking operation request first Client;
The locking request that the active client is sent to server end is synchronous locking request or asynchronous locking request;
It is described current if meeting condition according to the different locking strategies that server end uses different locking requests Client obtains distributed lock from server end and accesses resource information, if being unsatisfactory for condition, the active client is from clothes Business device termination receives locking failure information.
Herein, the data interaction between server end and client is two-way, and locking strategy herein is also based on What server end was made, it is that identical content is realized, does not do state more herein.
According to an embodiment of the invention, as shown in figure 5, the present invention also provides the host nodes that a kind of distributed lock is realized to set Standby, the host node device includes:
Reception device, the locking operation for receiving the distributed lock that at least one client is sent are requested;
Collator, for by the request of the locking operation of at least one client it is corresponding it is described at least one Client is added in the client queue of the current distributed lock and is ranked up, and obtains progress locking operation first and asks The active client asked;
Judgment means, for judging that the locking request of the active client is that synchronous locking request or asynchronous locking are asked It asks;
Processing unit, for using different locking strategies according to different locking requests, so that meeting the described of condition The corresponding locking request of active client obtains distributed lock, and accesses resource information, is unsatisfactory for condition, then returns to locking failure Information.
The processing unit, is also used to, if the active client initiates asynchronous locking request, the processing unit inspection Look into whether resource request queue is sky, if it is sky, the asynchronous locking request for directly initiating the active client is added Whether in the resource request queue, return is locked successfully, if being not sky, check described in having in the resource request queue Active client, if there is then doing nothing, institute is added in the asynchronous locking request for then not initiating the active client Resource request queue tail is stated, after the lock holder of the head of the queue of the resource request queue has used certain resource, lock is initiated and releases Operation is put, the lock holder of head of the queue goes out team at this time, and the new application for being located at head of the queue obtains the lock of the resource;If the current visitor Synchronous locking request is initiated at family end, and the processing unit checks whether resource request queue is sky, if it is sky, directly by institute The synchronization locking request for stating active client initiation is added in the resource request queue, and return locks successfully, if being not sky, Then check whether the active client is otherwise the current holder of lock of resource is returned and lost if it is, return successfully It loses.
The host node device further include:
Sending device, it is real carrying out distributed lock for by network, broadcast externally to be sent in a manner of UDP periodically In existing operating process, push data into from node, it is described receive the data from node after update and save it is data cached, So that the host node is synchronous with the data from node.
Content according to the present invention, the present invention also provides a kind of computer readable storage mediums, comprising:
Processor;And
It is arranged to the memory of storage computer executable instructions, the executable instruction makes the place when executed The step of reason device realizes the method for the present invention for realizing distributed lock.
Implementation method, equipment and the medium of network-based distributed lock provided by the invention, receive at least one first The locking operation for the distributed lock that client is sent is requested, at least one client is added in client queue and is arranged Sequence can be ranked up based on time or priority, then obtained the active client for carrying out locking operation request first, sentenced The locking request of the active client of breaking is synchronous locking request or asynchronous locking request;Made according to different locking requests With different locking strategies, so that the corresponding locking request of the active client for meeting condition obtains distributed lock, and visit It asks resource information, is unsatisfactory for condition, then return to locking failure information.Content according to the present invention, realize shared resource has Effect access solves the problems, such as distributed lock reentry property, the Single Point of Faliure problem of distributed lock service and distributed lock service pair The dependence of third party software.
It is obvious to a person skilled in the art that the embodiment of the present invention is not limited to the details of above-mentioned exemplary embodiment, And without departing substantially from the spirit or essential attributes of the embodiment of the present invention, this hair can be realized in other specific forms Bright embodiment.Therefore, in all respects, the present embodiments are to be considered as illustrative and not restrictive, this The range of inventive embodiments is indicated by the appended claims rather than the foregoing description, it is intended that being equal for claim will be fallen in All changes in the meaning and scope of important document are included in the embodiment of the present invention.It should not be by any attached drawing mark in claim Note is construed as limiting the claims involved.Furthermore, it is to be understood that one word of " comprising " does not exclude other units or steps, odd number is not excluded for Plural number.Multiple units, module or the device stated in system, device or terminal claim can also be by the same units, mould Block or device are implemented through software or hardware.The first, the second equal words are used to indicate names, and are not offered as any specific Sequence.
Finally it should be noted that embodiment of above is only to illustrate the technical solution of the embodiment of the present invention rather than limits, Although the embodiment of the present invention is described in detail referring to the above better embodiment, those skilled in the art should Understand, can modify to the technical solution of the embodiment of the present invention or equivalent replacement should not all be detached from the skill of the embodiment of the present invention The spirit and scope of art scheme.

Claims (14)

1. a kind of implementation method of network-based distributed lock, which is characterized in that applied to the host node of server end, packet It includes:
The host node receives the locking operation request for the distributed lock that at least one client is sent;
By at least one corresponding described client of the locking operation request of at least one client, it is added to described It in the client queue of current distributed lock and is ranked up, obtains the active client for carrying out locking operation request first;
The locking request for judging the active client is synchronous locking request or asynchronous locking request;
Different locking strategies is used according to different locking requests, is added so that the active client for meeting condition is corresponding Lock request obtains distributed lock, and accesses resource information, is unsatisfactory for condition, then returns to locking failure information.
2. the implementation method of network-based distributed lock according to claim 1, which is characterized in that described according to difference Locking request use different locking strategies so that the corresponding locking request of the client for meeting condition obtains distributed lock, And resource information is accessed, it is unsatisfactory for condition, then returns to locking failure information, specifically includes, if the active client is initiated Asynchronous locking request, the host node check whether resource request queue is sky, if it is sky, directly by the existing customer The asynchronous locking request of end initiation is added in the resource request queue, and return locks successfully, if being not sky, described in inspection Whether the active client is had in resource request queue, if there is then doing nothing, not then by the active client The resource request queue tail is added in the asynchronous locking request initiated, in the lock holder of the head of the queue of the resource request queue After having used certain resource, lock release operation is initiated, the lock holder of head of the queue goes out team at this time, and the new application for being located at head of the queue is somebody's turn to do The lock of resource;If the active client initiates synchronous locking request, the host node check resource request queue whether be Sky, if it is sky, the synchronization locking request for directly initiating the active client is added in the resource request queue, is returned Return and lock successfully, if be not it is empty, check the active client whether be resource lock current holder, if so, Success is then returned, failure is otherwise returned.
3. the implementation method of network-based distributed lock according to claim 2, which is characterized in that the general is described extremely At least one corresponding described client of the locking operation request of a few client, is added to the current distributed lock Client queue in and be ranked up, the time of the request including being initiated according to client is ranked up, alternatively, according to client The priority that request is initiated at end is ranked up.
4. the implementation method of network-based distributed lock according to claim 1, which is characterized in that the server end Further include from node, the host node in the operating process for carrying out distributed lock realization, push data into it is described from node, It is described receive the data from node after update and save it is data cached so that the host node and the data from node are same Step.
5. the implementation method of network-based distributed lock according to claim 3 or 4, which is characterized in that in the master It is described periodically to send heartbeat detection from node in the normal situation of node, host node is monitored, when host node generation is different Chang Shi, it is described from node according to synchronous data, start externally service, periodically send broadcast, at the same elect it is new from node, And keep slave node newly synchronous with the data of slave node of host node are replaced.
6. the implementation method of network-based distributed lock according to claim 5, which is characterized in that the host node week Pass through network to phase, broadcast is externally sent in a manner of UDP, at least one the described client for participating in contention for resources receives extensively After broadcasting, then registered to server in a manner of TCP, server receives register information after, update internal each client Information of registering, then server examines the client in each resource waiting list according to the information of registering of each client It looks into, the client that those long periods do not register is deleted from the waiting list of resource, deadlock is prevented with this.
7. a kind of implementation method of network-based distributed lock, which is characterized in that be applied to client, comprising:
The host node of at least one user end to server sends locking operation request, according to the client of the server Sortord in queue obtains the active client for carrying out locking operation request first;
The locking request that the active client is sent to server end is synchronous locking request or asynchronous locking request;
According to the different locking strategies that server end uses different locking requests, if meeting condition, the existing customer End obtains distributed lock from server end and accesses resource information, if being unsatisfactory for condition, the active client is from server Termination receives locking failure information.
8. the implementation method of network-based distributed lock according to claim 7, which is characterized in that described according to service Device end for different locking requests use it is different lock strategy, if meeting condition, the active client is from server end It obtains distributed lock and accesses resource information, if being unsatisfactory for condition, the active client is from received server-side to locking Failure information specifically includes, if the active client initiates asynchronous locking request, the host node checks resource request team Whether column are sky, and if it is sky, the resource request is added in the asynchronous locking request for directly initiating the active client In queue, return is locked successfully, if being not sky, checks in the resource request queue whether there is the active client, If there is then doing nothing, the resource request team is added in the asynchronous locking request for then not initiating the active client Tail portion is arranged, after the lock holder of the head of the queue of the resource request queue has used certain resource, initiates lock release operation, at this time team First lock holder goes out team, and the new application for being located at head of the queue obtains the lock of the resource;If the active client initiates to synchronize Locking request, the host node check whether resource request queue is sky, if it is sky, directly send out the active client The synchronization locking request risen is added in the resource request queue, and return locks successfully, if being not sky, checks described current Whether client is otherwise the current holder of lock of resource returns to failure if it is, return successfully.
9. the implementation method of network-based distributed lock according to claim 8, which is characterized in that the host node week Pass through network to phase, broadcast is externally sent in a manner of UDP, at least one the described client for participating in contention for resources receives extensively After broadcasting, then registered to server in a manner of TCP, server receives register information after, update internal each client Information of registering, then server examines the client in each resource waiting list according to the information of registering of each client It looks into, the client that those long periods do not register is deleted from the waiting list of resource, deadlock is prevented with this.
10. the implementation method of network-based distributed lock according to claim 9, which is characterized in that the client Synchronous or asynchronous locking request is sent to server, when transmission be synchronous locking request when, client obstruction waits clothes The response at business end;When transmission be asynchronous locking request when, client realizes non-obstruction locking request by registered callbacks.
11. the host node device that a kind of distributed lock is realized, wherein the host node device includes:
Reception device, the locking operation for receiving the distributed lock that at least one client is sent are requested;
Collator, for the locking operation of at least one client to be requested at least one corresponding described client End, is added in the client queue of the current distributed lock and is ranked up, and obtains and carries out locking operation request first Active client;
Judgment means, for judging that the locking request of the active client is synchronous locking request or asynchronous locking request;
Processing unit, for using different locking strategies according to different locking requests, so that meeting the described current of condition The corresponding locking request of client obtains distributed lock, and accesses resource information, is unsatisfactory for condition, then returns to locking and unsuccessfully believe Breath.
12. host node device according to claim 11, which is characterized in that the processing unit is also used to, if described Active client initiates asynchronous locking request, and the processing unit checks whether resource request queue is sky, if it is sky, directly The asynchronous locking request for initiating the active client is connect to be added in the resource request queue, return locks successfully, if For sky, then check in the resource request queue whether there is the active client, if there is then doing nothing, it is no then The resource request queue tail is added in the asynchronous locking request that the active client is initiated, in the resource request queue Head of the queue lock holder used certain resource after, initiate lock release operation, the lock holder of head of the queue goes out team at this time, and new is located at The application of head of the queue obtains the lock of the resource;If the active client initiates synchronous locking request, the processing unit inspection Whether resource request queue is sky, and if it is sky, institute is added in the synchronization locking request for directly initiating the active client State in resource request queue, return locks successfully, if be not it is empty, check the active client whether be resource lock Otherwise current holder returns to failure if it is, returning successfully.
13. host node device according to claim 11, which is characterized in that the host node device further include:
Sending device is carrying out distributed lock realization for by network, broadcast externally to be sent in a manner of UDP periodically In operating process, push data into from node, it is described receive the data from node after update and save it is data cached so that The host node is synchronous with the data from node;
Reception device, for receiving the information of registering of client transmission.
14. a kind of computer readable storage medium, comprising:
Processor;And
It is arranged to the memory of storage computer executable instructions, the executable instruction makes the processor when executed The step of realizing the method that distributed lock is realized as described in claims 1 to 10 any one.
CN201811617626.1A 2018-12-28 2018-12-28 A kind of implementation method, equipment and the medium of network-based distributed lock Pending CN109753364A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811617626.1A CN109753364A (en) 2018-12-28 2018-12-28 A kind of implementation method, equipment and the medium of network-based distributed lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811617626.1A CN109753364A (en) 2018-12-28 2018-12-28 A kind of implementation method, equipment and the medium of network-based distributed lock

Publications (1)

Publication Number Publication Date
CN109753364A true CN109753364A (en) 2019-05-14

Family

ID=66404273

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811617626.1A Pending CN109753364A (en) 2018-12-28 2018-12-28 A kind of implementation method, equipment and the medium of network-based distributed lock

Country Status (1)

Country Link
CN (1) CN109753364A (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110381124A (en) * 2019-06-28 2019-10-25 苏州浪潮智能科技有限公司 A kind of application method and device for locking resource
CN111124697A (en) * 2020-01-02 2020-05-08 中国航空工业集团公司西安航空计算技术研究所 Task synchronization and execution method facing distributed platform
CN111930503A (en) * 2020-08-05 2020-11-13 浪潮云信息技术股份公司 Resource lock acquisition method based on ETCD
CN112099961A (en) * 2020-09-21 2020-12-18 天津神舟通用数据技术有限公司 Realization method of distributed lock manager based on lock state cache
CN112486696A (en) * 2020-12-11 2021-03-12 上海悦易网络信息技术有限公司 Method and equipment for acquiring distributed lock
CN112835722A (en) * 2021-01-29 2021-05-25 卓望数码技术(深圳)有限公司 Service processing method, electronic device and computer readable storage medium
CN113778697A (en) * 2021-09-14 2021-12-10 福建天晴数码有限公司 Method and system for realizing high availability of redis distribution lock
CN113810479A (en) * 2021-08-31 2021-12-17 山石网科通信技术股份有限公司 Service coordination system and service coordination method
WO2022105804A1 (en) * 2020-11-18 2022-05-27 花瓣云科技有限公司 Synchronization processing method, device and medium
CN114926935A (en) * 2022-05-07 2022-08-19 中国银行股份有限公司 Negotiation signing queuing number-taking method and device and computer equipment
CN115113994A (en) * 2021-08-30 2022-09-27 腾讯科技(深圳)有限公司 Request processing method and device, computing equipment and storage medium
CN115277379A (en) * 2022-07-08 2022-11-01 北京城市网邻信息技术有限公司 Distributed lock disaster tolerance processing method and device, electronic equipment and storage medium
WO2023029519A1 (en) * 2021-08-30 2023-03-09 康键信息技术(深圳)有限公司 Data synchronization method and apparatus, computer device, and storage medium
CN112835722B (en) * 2021-01-29 2024-04-26 卓望数码技术(深圳)有限公司 Service processing method, electronic device and computer readable storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170163762A1 (en) * 2012-06-20 2017-06-08 Amazon Technologies, Inc. Asynchronous and idempotent distributed lock interfaces
CN107181789A (en) * 2017-03-31 2017-09-19 北京奇艺世纪科技有限公司 A kind of distributed lock implementation method and device
CN107783842A (en) * 2016-08-31 2018-03-09 阿里巴巴集团控股有限公司 A kind of distributed lock implementation method, equipment and storage device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170163762A1 (en) * 2012-06-20 2017-06-08 Amazon Technologies, Inc. Asynchronous and idempotent distributed lock interfaces
CN107783842A (en) * 2016-08-31 2018-03-09 阿里巴巴集团控股有限公司 A kind of distributed lock implementation method, equipment and storage device
CN107181789A (en) * 2017-03-31 2017-09-19 北京奇艺世纪科技有限公司 A kind of distributed lock implementation method and device

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
谭玉靖: "基于ZooKeeper的分布式处理框架的研究与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *

Cited By (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110381124A (en) * 2019-06-28 2019-10-25 苏州浪潮智能科技有限公司 A kind of application method and device for locking resource
CN111124697A (en) * 2020-01-02 2020-05-08 中国航空工业集团公司西安航空计算技术研究所 Task synchronization and execution method facing distributed platform
CN111124697B (en) * 2020-01-02 2023-09-08 中国航空工业集团公司西安航空计算技术研究所 Task synchronization and execution method for distributed platform
CN111930503A (en) * 2020-08-05 2020-11-13 浪潮云信息技术股份公司 Resource lock acquisition method based on ETCD
CN112099961A (en) * 2020-09-21 2020-12-18 天津神舟通用数据技术有限公司 Realization method of distributed lock manager based on lock state cache
CN112099961B (en) * 2020-09-21 2024-02-06 天津神舟通用数据技术有限公司 Method for realizing distributed lock manager based on lock state cache
WO2022105804A1 (en) * 2020-11-18 2022-05-27 花瓣云科技有限公司 Synchronization processing method, device and medium
CN112486696A (en) * 2020-12-11 2021-03-12 上海悦易网络信息技术有限公司 Method and equipment for acquiring distributed lock
CN112835722A (en) * 2021-01-29 2021-05-25 卓望数码技术(深圳)有限公司 Service processing method, electronic device and computer readable storage medium
CN112835722B (en) * 2021-01-29 2024-04-26 卓望数码技术(深圳)有限公司 Service processing method, electronic device and computer readable storage medium
CN115113994A (en) * 2021-08-30 2022-09-27 腾讯科技(深圳)有限公司 Request processing method and device, computing equipment and storage medium
WO2023029519A1 (en) * 2021-08-30 2023-03-09 康键信息技术(深圳)有限公司 Data synchronization method and apparatus, computer device, and storage medium
WO2023029837A1 (en) * 2021-08-30 2023-03-09 腾讯科技(深圳)有限公司 Request processing method and apparatus, computing device and storage medium
CN115113994B (en) * 2021-08-30 2023-06-20 腾讯科技(深圳)有限公司 Request processing method, device, computing equipment and storage medium
CN113810479A (en) * 2021-08-31 2021-12-17 山石网科通信技术股份有限公司 Service coordination system and service coordination method
CN113810479B (en) * 2021-08-31 2023-11-07 山石网科通信技术股份有限公司 Service coordination system and service coordination method
CN113778697A (en) * 2021-09-14 2021-12-10 福建天晴数码有限公司 Method and system for realizing high availability of redis distribution lock
CN114926935A (en) * 2022-05-07 2022-08-19 中国银行股份有限公司 Negotiation signing queuing number-taking method and device and computer equipment
CN115277379A (en) * 2022-07-08 2022-11-01 北京城市网邻信息技术有限公司 Distributed lock disaster tolerance processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN109753364A (en) A kind of implementation method, equipment and the medium of network-based distributed lock
EP3490224B1 (en) Data synchronization method and system
CN110196856B (en) Distributed data reading method and device
EP0926608A2 (en) Distributed persistent storage for intermittently connected clients
US9055065B2 (en) Managing participant order in distributed transactions
JP7389793B2 (en) Methods, devices, and systems for real-time checking of data consistency in distributed heterogeneous storage systems
US9417906B2 (en) Transaction participant registration with caveats
CN103036717A (en) Consistency maintenance system and methods for distributed-type data
US20230106118A1 (en) Distributed processing of transactions in a network using timestamps
CN110990200B (en) Flow switching method and device based on multiple active data centers
CN109815248B (en) Zookeeper-based distributed architecture data consistency method
CN108989391B (en) Consistency processing method and system
CN112597249B (en) Synchronous distribution storage method and system for service data
CN109783151B (en) Method and device for rule change
CN109173270B (en) Game service system and implementation method
CN103488526A (en) System and method for locking business resource in distributed system
CN105959349A (en) Distributed service end operation system and method
WO2023093641A1 (en) User relationship chain storage method, apparatus and system, electronic device, and storage medium
CN104881444B (en) The method and system of cache server are updated in website
CN107465725B (en) Heterogeneous long transaction processing system and method based on client information control system
CN109257396B (en) Distributed lock scheduling method and device
CN112632093A (en) Work order processing method, device, system, storage medium and program product
CN101751292B (en) Method for realizing consistency function of multimachine core data in ATC (automatic timing corrector) system
WO2022206426A1 (en) Distributed transaction processing method and system, and related device
US7748010B1 (en) Global attribute uniqueness (GAU) using an ordered message service (OMS)

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20190514