CN107656815A - Method and apparatus for controlling distributed lock - Google Patents

Method and apparatus for controlling distributed lock Download PDF

Info

Publication number
CN107656815A
CN107656815A CN201610597208.5A CN201610597208A CN107656815A CN 107656815 A CN107656815 A CN 107656815A CN 201610597208 A CN201610597208 A CN 201610597208A CN 107656815 A CN107656815 A CN 107656815A
Authority
CN
China
Prior art keywords
distributed lock
time
lock
expired
distributed
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
CN201610597208.5A
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 Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201610597208.5A priority Critical patent/CN107656815A/en
Publication of CN107656815A publication Critical patent/CN107656815A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

This application discloses the method and apparatus for controlling distributed lock.One embodiment of methods described includes:The locking request for the distributed lock that client is sent is received, the locking request includes:The mark of the distributed lock;Judge whether the distributed lock is occupied;If the distributed lock is unoccupied,:Determine the expired time of the distributed lock;The distributed lock is distributed into the client;The client is sent to using the mark of the distributed lock and the expired time of the distributed lock as success message is locked, the business operation protected for the client executing by the distributed lock.The embodiment realizes the quick locking of distributed lock.

Description

Method and apparatus for controlling distributed lock
Technical field
The application is related to field of computer technology, and in particular to Internet technical field, more particularly, to control distribution The method and apparatus of formula lock.
Background technology
In the epoch of cloud computing, major applications are deployed on distributed server.The service that these applications provide Some are very strict to coherence request, absolutely not allow same resource allocation to different Internet users in concurrent. At this time generally effective processing mode is exactly to lock.If basic thought is exactly to need to change or occupy in an issued transaction Some resource, then need first to obtain the related unique lock of this resource, this resource could be operated by having obtained lock, work as office With regard to discharging the lock occupied after the completion of reason.At present, have some solutions for realizing distributed lock both at home and abroad.Such as Google Chubby, Apache Zookeeper, based on the transactional lock of relevant database realization, and some use NoSql databases The solution that the atomic operation of offer is realized.
However, the current solution for realizing distributed lock is present, locking and unlocked time are partially long, it is general to be applicable scale Small-scale cluster within 10, during distributed timing tasks carrying because the distributed computer of each request resource is deposited It is asynchronous in clock and the problem of cause timed task to repeat.These problems cause the existing solution for realizing distributed lock The quick application of large-scale cluster and the scene of quick release are (for example, the business of e-commerce website on the unsuitable internet of scheme Product second execution ground scape).
The content of the invention
The purpose of the application is to propose a kind of improved method and apparatus for controlling distributed lock, more than solving The technical problem that background section is mentioned.
In a first aspect, this application provides a kind of method for controlling distributed lock, methods described includes:Receive client The locking request for the distributed lock sent is held, the locking request includes:The mark of the distributed lock;Judge the distribution Whether lock is occupied;If the distributed lock is unoccupied,:Determine the expired time of the distributed lock;Will be described point Cloth lock distributes to the client;Using the mark of the distributed lock and the expired time of the distributed lock as locking Success message is sent to the client, the business operation protected for the client executing by the distributed lock.
Second aspect, this application provides a kind of device for being used to control distributed lock, described device includes:Locking request Receiving unit, is configured to receive the locking request for the distributed lock that client is sent, and the locking request includes:The distribution The mark of formula lock;First judging unit, it is configured to judge whether the distributed lock is occupied;First locks unit, configuration If unoccupied for the distributed lock,:Determine the expired time of the distributed lock;The distributed lock is distributed To the client;Sent out using the mark of the distributed lock and the expired time of the distributed lock as success message is locked The client is given, the business operation protected for the client executing by the distributed lock.
The method and apparatus for controlling distributed lock that the application provides, the distributed lock sent by receiving client Locking request, then judge whether distributed lock occupied, then if distributed lock is unoccupied, determine the mistake of distributed lock Time phase, and distributed lock is distributed into client, then the mark of distributed lock and the expired time of distributed lock are made Client is sent to lock success message, for the business operation that client executing is protected by distributed lock, so as to effectively sharp With the expired time data of distributed lock, the quick locking of distributed lock is realized.
Brief description of the drawings
By reading the detailed description made to non-limiting example made with reference to the following drawings, the application's is other Feature, objects and advantages will become more apparent upon:
Fig. 1 is that the application can apply to exemplary system architecture figure therein;
Fig. 2 is the flow chart for being used to control one embodiment of the method for distributed lock according to the application;
Fig. 3 is the flow chart for being used to control another embodiment of the method for distributed lock according to the application;
Fig. 4 is one embodiment for handling unlocking request immediately according to the method for being used to control distributed lock of the application Flow chart;
Fig. 5 is one embodiment according to the processing delay unlocking request of the method for being used to control distributed lock of the application Flow chart;
Fig. 6 is the structural representation for being used to control one embodiment of the device of distributed lock according to the application;
Fig. 7 is adapted for the structural representation of the computer system of the server for realizing the embodiment of the present application.
Embodiment
The application is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched The specific embodiment stated is used only for explaining related invention, rather than the restriction to the invention.It also should be noted that in order to Be easy to describe, illustrate only in accompanying drawing to about the related part of invention.
It should be noted that in the case where not conflicting, the feature in embodiment and embodiment in the application can phase Mutually combination.Describe the application in detail below with reference to the accompanying drawings and in conjunction with the embodiments.
Fig. 1 shows the method for being used to control distributed lock that can apply the application or the dress for controlling distributed lock The exemplary system architecture 100 for the embodiment put.
As shown in figure 1, system architecture 100 can include terminal device 101,102,103, network 104 and server 105. Network 104 between terminal device 101,102,103 and server 105 provide communication link medium.Network 104 can be with Including various connection types, such as wired, wireless communication link or fiber optic cables etc..
User can be interacted with using terminal equipment 101,102,103 by network 104 with server 105, to receive or send out Send message etc..Various client applications can be installed, such as distributed resource request class should on terminal device 101,102,103 With, web browser applications, the application of shopping class, searching class application, JICQ, mailbox client, social platform software Deng.
Terminal device 101,102,103 can be the various electronic equipments for having processor, including but not limited to intelligent hand Machine, tablet personal computer, E-book reader, MP3 player (Moving Picture Experts Group Audio Layer III, dynamic image expert's compression standard audio aspect 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic image expert's compression standard audio aspect 4) player, pocket computer on knee and desktop computer etc. Deng.
Server 105 can be to provide the server of various services, such as to being installed on terminal device 101,102,103 Distributed resource request class application provides the distributed lock control server supported.Distributed lock control server can be to receiving To the locking request that sends of terminal device, the data such as unlocking request analyze etc. processing, and result (such as are locked Success message, unblock success message) feed back to terminal device.
It should be noted that the method for controlling distributed lock that the embodiment of the present application is provided is typically by server 105 are performed, and correspondingly, the device for controlling distributed lock is generally positioned in server 105.
It should be understood that the number of the terminal device, network and server in Fig. 1 is only schematical.According to realizing need Will, can have any number of terminal device, network and server.
With continued reference to Fig. 2, the stream for being used to control one embodiment of the method for distributed lock according to the application is shown Journey 200.The described method for controlling distributed lock, comprises the following steps:
Step 201, the locking request for the distributed lock that client is sent is received.
In the present embodiment, the method for controlling distributed lock runs electronic equipment thereon (such as shown in Fig. 1 Server) can by wired connection mode or radio connection from client (terminal 101 as shown in Figure 1,102, 103) locking request of distributed lock is received, wherein, locking request includes the mark that client to be asked the distributed lock of locking Know.Here, the mark of distributed lock can be the data of unique mark distributed lock, for example, the mark of distributed lock can be Character string of numeral, numeral and/or letter composition etc..
Step 202, judge whether distributed lock is occupied, if unoccupied, go to step 203.
In the present embodiment, above-mentioned electronic equipment can receive the distributed lock that client is sent locking request it Afterwards, judge whether above-mentioned distributed lock is occupied.If above-mentioned distributed lock is unoccupied, step 203 is gone to.
Step 203, the expired time of distributed lock is determined.
In the present embodiment, above-mentioned electronic equipment can judge the unappropriated feelings of above-mentioned distributed lock in step 202 Under condition, the expired time of above-mentioned distributed lock is determined.
In some optional implementations of the present embodiment, the locking request for the distributed lock that above-mentioned client is sent is also It can include:The maximum duration of holder lock, so, above-mentioned electronic equipment can determine the expired of distributed lock as follows Time:First, above-mentioned electronic equipment can obtain current time, and above-mentioned current time then is added into holding in locking request Expired time of the time of gained as distributed lock after the maximum duration of lock.
In some optional implementations of the present embodiment, the locking request for the distributed lock that above-mentioned client is sent The maximum duration of holder lock can not be included, so, above-mentioned electronic equipment can be with, obtains current time first, then, will be above-mentioned Current time is plus expired time of the time as distributed lock after the time of acquiescence obtained by (for example, 10 seconds or 20 seconds).
Step 204, distributed lock is distributed into client.
In the present embodiment, above-mentioned electronic equipment can be after the expired time that step 203 determines distributed lock, will be upper State distributed lock and distribute to above-mentioned client.
Step 205, it is sent to using the mark of distributed lock and the expired time of distributed lock as success message is locked Client, the business operation protected for client executing by distributed lock.
In the present embodiment, above-mentioned electronic equipment can be after above-mentioned client be distributed to by above-mentioned distributed lock, will The mark of distributed lock and the expired time of distributed lock are sent to client as success message is locked, so that client is held The business operation that row is protected by distributed lock.
As an example, the above-mentioned business operation by distributed lock protection can be:The above-mentioned electronic equipment of client request The available information resources such as computing resource, storage resource, data resource.Specifically, can be internal memory, the network of computer Data, virtual objects etc. include the resource of effective information.The resource of client request can be the intrinsic letter of above-mentioned electronic equipment Data, such as amount of ram are ceased, can also be pre-stored in above-mentioned electronic equipment, such as the data in internal memory, can also be by above-mentioned electricity Sub- equipment passes through the picture in Network Capture, such as virtual objects, network data, word etc..Specifically, resource request can be with It is that the computational resource allocation request in data analysis process or the resources of virtual machine for handling order are asked, may be used also To be the request for getting the virtual objects configured in website.For example, the second in e-commerce website kills commodity, reward voucher etc..
The method and apparatus for controlling distributed lock that the application provides, the distributed lock sent by receiving client Locking request, then judge whether distributed lock occupied, then if distributed lock is unoccupied, determine the mistake of distributed lock Time phase, and distributed lock is distributed into client, then the mark of distributed lock and the expired time of distributed lock are made Client is sent to lock success message, for the business operation that client executing is protected by distributed lock, so as to effectively sharp With the expired time data of distributed lock, the quick locking of distributed lock is realized.
With continued reference to Fig. 3, Fig. 3 is another embodiment for being used to control the method for distributed lock according to the present embodiment Flow chart.
Step 301, the locking request for the distributed lock that client is sent is received.
In the present embodiment, the method for controlling distributed lock runs electronic equipment thereon (such as shown in Fig. 1 Server) can by wired connection mode or radio connection from client (terminal 101 as shown in Figure 1,102, 103) receive the locking request of distributed lock, wherein, the mark of locking request including the distributed lock to be asked of client with Locking request time-out duration.
Step 302, judge whether locking request time-out duration is more than zero, if it is, step 303 is gone to, if not, going to Step 304.
In the present embodiment, above-mentioned electronic equipment can receive the distributed lock that client is sent in step 301 After after locking request or locking request time-out duration is subtracted into preset time in step 312, judge that locking request surpasses Whether Shi Shichang is more than zero.If locking request time-out duration is more than zero, illustrates that locking request is also not timed-out, then go to step 303 judge whether distributed lock is occupied;If locking request time-out duration is not more than zero, illustrate that locking request has timed, out, Then go to step 304 and send locking request failed message to client.
Step 303, judge whether distributed lock is occupied, if unoccupied, go to step 305, if occupied, turn To step 308.
In the present embodiment, above-mentioned electronic equipment can judge that locking request time-out duration is more than zero in step 302 In the case of, judge whether distributed lock is occupied, if unoccupied, go to step 305, if occupied, go to step 308。
Step 304, locking request failed message is sent to client.
In the present embodiment, above-mentioned electronic equipment can judge that locking request time-out duration is not more than zero in step 302 In the case of, send locking request failed message to client.
Step 305, the expired time of distributed lock is determined.
Step 306, distributed lock is distributed into above-mentioned client.
Step 307, it is sent to using the mark of distributed lock and the expired time of distributed lock as success message is locked Client, the business operation protected for client executing by distributed lock.
The concrete operations of above-mentioned steps 305- steps 307 are essentially identical with the operation in step 203- steps 205 respectively, This is repeated no more.
Step 308, current time and the expired time of above-mentioned distributed lock are obtained.
In the present embodiment, in the case of above-mentioned electronic equipment can judge that distributed lock is occupied in step 303, obtain Take current time and the expired time of above-mentioned distributed lock.Wherein, the expired time of above-mentioned distributed lock is that above-mentioned electronics is set It is standby be currently take it is set expired when the client application of above-mentioned distributed lock locks to above-mentioned distributed lock Time.
Step 309, judge whether current time exceedes the expired time of above-mentioned distributed lock.If it is, go to step 310, if not, going to step 311.
In the present embodiment, above-mentioned electronic equipment can get current time and above-mentioned distribution in step 308 After the expired time of lock, judge whether current time exceedes the expired time of above-mentioned distributed lock.
If current time exceedes the expired time of above-mentioned distributed lock, show that current distributed lock is accounted for by other client With and take the client of the distributed lock and exceed the time limit to take because the machine of delaying, deadlock or other reasonses cause the distributed lock to be in State, therefore when avoiding the distributed lock from being exceeded the time limit to take and cause to ask other clients of the distributed lock to wait oversize Between, step 310 can be gone in this case releases the distributed lock.
If current time is not above the expired time of above-mentioned distributed lock, show current distributed lock by other client End takes and the distributed lock does not exceed the time limit also, then go to step 311 carry out etc. it is to be operated.
Step 310, above-mentioned distributed lock is released.
In the present embodiment, above-mentioned electronic equipment can release above-mentioned distributed lock, then go to step 305.
Step 311, preset time is waited.
In the present embodiment, above-mentioned electronic equipment can judge the above-mentioned distribution in occupied state in step 309 In the case that formula lock does not exceed the time limit also, preset time is waited.Above-mentioned preset time can be above-mentioned electronic equipment default setting, example Such as 2 seconds.
Step 312, locking request time-out duration is subtracted into preset time, then goes to step 302.
In the present embodiment, above-mentioned electronic equipment can be after step 311 waits preset time, during by locking request time-out Length subtracts preset time, then goes to step 302 and continues to judge whether locking request time-out duration is more than zero.
From figure 3, it can be seen that compared with embodiment corresponding to Fig. 2, being used in the present embodiment controls distributed lock The flow 300 of method is highlighted how to be locked in the case of distributed lock is occupied the step of.Thus, the present embodiment describes Scheme can realize the locking for more comprehensively, faster controlling distributed lock.
With further reference to Fig. 4, it illustrates one that handles unlocking request immediately of the method for controlling distributed lock The flow 400 of embodiment.This is used for the flow 400 for controlling the method for distributed lock, comprises the following steps:
Step 401, client end response is received to stand in what the execution for the business operation protected by distributed lock was completed and sent That is unlocking request.
In the present embodiment, the method for controlling distributed lock runs electronic equipment thereon (such as shown in Fig. 1 Server) can by wired connection mode or radio connection from client (terminal 101 as shown in Figure 1,102, 103) unlocking request immediately that client end response is completed and sent in the execution for the business operation protected by distributed lock is received.Its In, unlocking request can include immediately:The mark of distributed lock to be unlocked and the first expired time, here, first it is expired when Between be client receive lock success message in distributed lock expired time.
Step 402, the expired time of distributed lock corresponding with the mark of distributed lock to be unlocked is obtained, as second Expired time.
In the present embodiment, above-mentioned electronic equipment can obtain after the unlocking request immediately that client is sent is received The expired time of distributed lock corresponding with the mark of distributed lock to be unlocked is taken, as the second expired time.Here, with treating The expired time of distributed lock corresponding to the mark of the distributed lock of unblock is that above-mentioned electronic equipment is currently to take above-mentioned distribution The client application of formula lock expired time set when being locked to above-mentioned distributed lock.
Step 403, judge whether the first expired time is identical with the second expired time, if it is, going to step 404.
In the present embodiment, above-mentioned electronic equipment may determine that first in the unlocking request immediately obtained in step 401 Whether expired time and the second expired time obtained in step 402 are identical, if identical, show to send unlocking request immediately The client distributed lock indicated with taking the distributed lock mark to be unlocked in above-mentioned unlocking request immediately client End is same client, can go to step 404 and be unlocked operation immediately, so as to ensure that the correct of unblock operation.
Step 404, the distributed lock indicated by the mark of distributed lock to be unlocked is released.
In the present embodiment, above-mentioned electronic equipment can confirm in step 403 the first expired time with second it is expired when Between in the case of identical, the distributed lock indicated by the mark of distributed lock to be unlocked is released, by the occupancy of the distributed lock State is arranged to unoccupied.
With further reference to Fig. 5, it illustrates one of the processing delay unlocking request of the method for controlling distributed lock The flow 500 of embodiment.This is used for the flow 500 for controlling the method for distributed lock, comprises the following steps:
Step 501, receive that client end response is completed in the execution for the business operation protected by distributed lock and what is sent prolong Slow unlocking request.
In the present embodiment, the method for controlling distributed lock runs electronic equipment thereon (such as shown in Fig. 1 Server) can by wired connection mode or radio connection from client (terminal 101 as shown in Figure 1,102, 103) the delay unlocking request that client end response is completed and sent in the execution for the business operation protected by distributed lock is received.This In, delay unlocking request includes:The mark of distributed lock to be unlocked, the first expired time and delay unlocked time, wherein, the One expired time is the expired time for locking the distributed lock in success message that client receives.
Step 502, the expired time of distributed lock corresponding with the mark of distributed lock to be unlocked is obtained, as second Expired time.
In the present embodiment, above-mentioned electronic equipment can obtain after the delay unlocking request that client is sent is received The expired time of distributed lock corresponding with the mark of distributed lock to be unlocked is taken, as the second expired time.Here, with treating The expired time of distributed lock corresponding to the mark of the distributed lock of unblock is that above-mentioned electronic equipment is currently to take above-mentioned distribution The client application of formula lock expired time set when being locked to above-mentioned distributed lock.
Step 503, judge whether the first expired time is identical with the second expired time, if it is, going to step 504.
In the present embodiment, above-mentioned electronic equipment may determine that first in the delay unlocking request obtained in step 501 Whether expired time and the second expired time obtained in step 502 are identical, if identical, show to send delay unlocking request The client distributed lock indicated with taking the distributed lock mark to be unlocked in above-mentioned delay unlocking request client End is same client, can go to step 504 and carry out delay unblock operation, so as to ensure the correct of delay unblock operation.
Step 504, the distributed lock indicated by the mark of distributed lock to be unlocked is released after unlocked time is postponed.
In the present embodiment, above-mentioned electronic equipment can confirm in step 503 the first expired time with second it is expired when Between in the case of identical, the distributed lock indicated by the mark of distributed lock to be unlocked is released after unlocked time is postponed, The seizure condition of the distributed lock is arranged to unoccupied.
In some optional implementations of the present embodiment, above-mentioned electronic equipment can also be prolonged as follows Unblock late:Current time is obtained, and distribution to be unlocked is updated plus the time obtained by delay unlocked time with current time The expired time of distributed lock indicated by the mark of formula lock.So, even if directly not unlocking the distribution, but should The expired time of distributed lock is modified, and can also be realized when other client application distributed locks, is found Current time alreadys exceed expired time and releases the effect of the distributed lock, specifically can be referring to the step 309 in embodiment 300 Explanation, will not be repeated here.
With further reference to Fig. 6, as the realization to method shown in above-mentioned each figure, it is used to control this application provides one kind and divides One embodiment of the device of cloth lock, the device embodiment is corresponding with the embodiment of the method shown in Fig. 2, and the device specifically may be used With applied in various electronic equipments.
As shown in fig. 6, described in the present embodiment be used for control the device 600 of distributed lock to include:Locking request receives single The 601, first judging unit of member 602 and first locks unit 603.Wherein, locking request receiving unit 601, it is configured to receive The locking request for the distributed lock that client is sent, above-mentioned locking request include:The mark of above-mentioned distributed lock;First judges list Member 602, is configured to judge whether above-mentioned distributed lock is occupied;First locks unit 603, if being configured to above-mentioned distribution Formula lock is unoccupied, then:Determine the expired time of above-mentioned distributed lock;Above-mentioned distributed lock is distributed into above-mentioned client;Will The mark of above-mentioned distributed lock and the expired time of above-mentioned distributed lock are sent to above-mentioned client as success message is locked, The business operation protected for above-mentioned client executing by above-mentioned distributed lock.
In the present embodiment, the locking request receiving unit 601, first of the device 600 for controlling distributed lock judges Unit 602 and first lock unit 603 specific processing can respectively with reference to figure 2 correspondence embodiment in step 201, step 202 with And the related description of step 203- steps 206, it will not be repeated here.
In some optional implementations of the present embodiment, when above-mentioned locking request can also include locking request time-out It is long;And above-mentioned first judging unit 602 can include:First judge module 6021, it is configured to judge above-mentioned locking request Whether overtime duration is more than zero;Sending module 6022, if being configured to above-mentioned locking request time-out duration no more than zero, to Above-mentioned client, which is sent, locks failed message;Second judge module 6023, if being configured to above-mentioned locking request time-out duration More than zero, then judge whether above-mentioned distributed lock is occupied.First judge module 6021 of the first judging unit 602, send mould The specific processing of the judge module 6023 of block 6022 and second can be respectively with reference to step 302, step 304 in the corresponding embodiment of figure 3 And the related description of step 303, it will not be repeated here.
In some optional implementations of the present embodiment, the device for being used to control distributed lock of the present embodiment offer 600 can also include:Second judging unit 604, if it is occupied to be configured to above-mentioned distributed lock,:Obtain current time And the expired time of above-mentioned distributed lock;Judge whether above-mentioned current time exceedes the expired time of above-mentioned distributed lock;The Two lock unit 605, if being configured to the expired time that above-mentioned current time exceedes above-mentioned distributed lock,:Release above-mentioned Distributed lock;Determine the expired time of above-mentioned distributed lock;Above-mentioned distributed lock is distributed into above-mentioned client;By above-mentioned distribution The mark of formula lock and the expired time of above-mentioned distributed lock are sent to above-mentioned client as success message is locked, for above-mentioned The business operation that client executing is protected by above-mentioned distributed lock;Unit 606 is waited, if being configured to above-mentioned current time not More than the expired time of above-mentioned distributed lock, then preset time is waited, above-mentioned locking request time-out duration is subtracted above-mentioned default Time, and continue to judge whether above-mentioned locking request time-out duration is more than zero.Second judging unit 604, second locks unit 605 Specific processing with wait unit 606 can be respectively with reference to step 308- steps 309, step 310 and step in the corresponding embodiment of figure 3 The related description of 305- steps 307 and step 311 and step 312, will not be repeated here.
In some optional implementations of the present embodiment, the device for being used to control distributed lock of the present embodiment offer 600 can also include:Unlocking request receiving unit 607 immediately, it is configured to receive above-mentioned client end response in by above-mentioned distribution The unlocking request immediately that the execution of the business operation of formula lock protection is completed and sent, above-mentioned unlocking request immediately include:Wait to unlock Distributed lock mark and the first expired time, wherein, above-mentioned first expired time be the locking that receives of above-mentioned client into The expired time of above-mentioned distributed lock in work(message;First acquisition unit 608, it is configured to obtain and above-mentioned point to be unlocked The expired time of distributed lock corresponding to the mark of cloth lock, as the second expired time;3rd judging unit 609, configuration are used In judging whether above-mentioned first expired time is identical with above-mentioned second expired time;First unlocking unit 610, if be configured to It is then to release the distributed lock indicated by the mark of above-mentioned distributed lock to be unlocked.Immediately unlocking request receiving unit 607, The specific processing of first acquisition unit 608, the 3rd judging unit 609 and the first unlocking unit 610 can be respectively with reference to the correspondence of figure 4 Step 401 in embodiment, step 402, the related description of step 403 and step 404, will not be repeated here.
In some optional implementations of the present embodiment, the device for being used to control distributed lock of the present embodiment offer 600 can also include:First delay unlocking request receiving unit 611, is configured to receive above-mentioned client end response in by above-mentioned The delay unlocking request that the execution of the business operation of distributed lock protection is completed and sent, above-mentioned delay unlocking request include:Treat The mark of the distributed lock of unblock, the first expired time and delay unlocked time, above-mentioned first expired time is above-mentioned client What is received locks the expired time of the above-mentioned distributed lock in success message;Second acquisition unit 612, be configured to obtain with it is upper The expired time of distributed lock corresponding to the mark of distributed lock to be unlocked is stated, as the second expired time;4th judges list Member 613, is configured to judge whether above-mentioned first expired time is identical with above-mentioned second expired time;Second unlocking unit 614, It is configured to if it is, being released after above-mentioned delay unlocked time indicated by the mark of above-mentioned distributed lock to be unlocked Distributed lock.First delay unlocking request receiving unit 611, second acquisition unit 612, the 4th judging unit 613 and second The specific processing of unlocking unit 614 can be respectively with reference to step 501, step 502, step 503 and step in the corresponding embodiment of figure 5 504 related description, will not be repeated here.
In some optional implementations of the present embodiment, the device for being used to control distributed lock of the present embodiment offer 600 can also include:Second delay unlocking request receiving unit 615, is configured to receive above-mentioned client end response in by above-mentioned The delay unlocking request that the execution of the business operation of distributed lock protection is completed and sent, above-mentioned delay unlocking request include:Treat The mark of the distributed lock of unblock, the first expired time and delay unlocked time, above-mentioned first expired time is above-mentioned client What is received locks the expired time of the above-mentioned distributed lock in success message;3rd acquiring unit 616, be configured to obtain with it is upper The expired time of distributed lock corresponding to the mark of distributed lock to be unlocked is stated, as the second expired time;The single without judging Member 617, is configured to judge whether above-mentioned first expired time is identical with above-mentioned second expired time;3rd unlocking unit 618, Be configured to if it is, obtain current time, and with above-mentioned current time add obtained by above-mentioned delay unlocked time when Between update the expired time of distributed lock indicated by the mark of above-mentioned distributed lock to be unlocked.Second delay unlocking request connects Receiving the specific processing of unit 615, the 3rd acquiring unit 616, the 5th judging unit 617 and the 3rd unlocking unit 618 can distinguish The related description of step 501 in embodiment, step 502, step 503 and step 504 is corresponded to reference to figure 5, will not be repeated here.
In some optional implementations of the present embodiment, above-mentioned locking request also includes:The maximum duration of holder lock; And above-mentioned first locking unit 603 is further configured to:Current time is obtained, above-mentioned current time is held plus above-mentioned Expired time of the time of gained as above-mentioned distributed lock after the maximum duration of lock.
Below with reference to Fig. 7, it illustrates suitable for for realizing the computer system 700 of the server of the embodiment of the present application Structural representation.
As shown in fig. 7, computer system 700 includes CPU (CPU) 701, it can be read-only according to being stored in Program in memory (ROM) 702 or be loaded into program in random access storage device (RAM) 703 from storage part 706 and Perform various appropriate actions and processing.In RAM 703, also it is stored with system 700 and operates required various programs and data. CPU 701, ROM 702 and RAM 703 are connected with each other by bus 704.Input/output (I/O) interface 705 is also connected to always Line 704.
I/O interfaces 705 are connected to lower component:Storage part 706 including hard disk etc.;And including such as LAN card, tune The communications portion 707 of the NIC of modulator-demodulator etc..Communications portion 707 performs mailing address via the network of such as internet Reason.Driver 708 is also according to needing to be connected to I/O interfaces 705.Detachable media 709, such as disk, CD, magneto-optic disk, half Conductor memory etc., it is arranged on as needed on driver 708, in order to which the computer program read from it is as needed It is mounted into storage part 706.
Especially, in accordance with an embodiment of the present disclosure, it may be implemented as computer above with reference to the process of flow chart description Software program.For example, embodiment of the disclosure includes a kind of computer program product, it includes being tangibly embodied in machine readable Computer program on medium, the computer program include the program code for being used for the method shown in execution flow chart.At this In the embodiment of sample, the computer program can be downloaded and installed by communications portion 707 from network, and/or from removable Medium 709 is unloaded to be mounted.When the computer program is performed by CPU (CPU) 701, perform in the present processes The above-mentioned function of limiting.
Flow chart and block diagram in accompanying drawing, it is illustrated that according to the system of the various embodiments of the application, method and computer journey Architectural framework in the cards, function and the operation of sequence product.At this point, each square frame in flow chart or block diagram can generation The part of one module of table, program segment or code, a part for the module, program segment or code include one or more For realizing the executable instruction of defined logic function.It should also be noted that some as replace realization in, institute in square frame The function of mark can also be with different from the order marked in accompanying drawing generation.For example, two square frames succeedingly represented are actual On can perform substantially in parallel, they can also be performed in the opposite order sometimes, and this is depending on involved function.Also It is noted that the combination of each square frame and block diagram in block diagram and/or flow chart and/or the square frame in flow chart, Ke Yiyong Function as defined in execution or the special hardware based system of operation are realized, or can be referred to specialized hardware and computer The combination of order is realized.
Being described in unit involved in the embodiment of the present application can be realized by way of software, can also be by hard The mode of part is realized.Described unit can also be set within a processor, for example, can be described as:A kind of processor bag Include locking request receiving unit, the first judging unit and first locks unit.Wherein, the title of these units is under certain conditions Do not form the restriction in itself to the unit, for example, the first judging unit be also described as " judge distributed lock whether by The unit of occupancy ".
As on the other hand, present invention also provides a kind of nonvolatile computer storage media, the non-volatile calculating Machine storage medium can be the nonvolatile computer storage media included in device described in above-described embodiment;Can also be Individualism, without the nonvolatile computer storage media in supplying terminal.Above-mentioned nonvolatile computer storage media is deposited One or more program is contained, when one or more of programs are performed by an equipment so that the equipment:Receive The locking request for the distributed lock that client is sent, above-mentioned locking request include:The mark of above-mentioned distributed lock;Judge above-mentioned point Whether cloth lock is occupied;If above-mentioned distributed lock is unoccupied,:Determine the expired time of above-mentioned distributed lock;Will be upper State distributed lock and distribute to above-mentioned client;Using the mark of above-mentioned distributed lock and the expired time of above-mentioned distributed lock as Lock success message and be sent to above-mentioned client, the business operation protected for above-mentioned client executing by above-mentioned distributed lock.
Above description is only the preferred embodiment of the application and the explanation to institute's application technology principle.People in the art Member should be appreciated that invention scope involved in the application, however it is not limited to the technology that the particular combination of above-mentioned technical characteristic forms Scheme, while should also cover in the case where not departing from the inventive concept, carried out by above-mentioned technical characteristic or its equivalent feature The other technical schemes for being combined and being formed.Such as features described above has similar work(with (but not limited to) disclosed herein The technical scheme that the technical characteristic of energy is replaced mutually and formed.

Claims (14)

  1. A kind of 1. method for controlling distributed lock, it is characterised in that methods described includes:
    The locking request for the distributed lock that client is sent is received, the locking request includes:The mark of the distributed lock;
    Judge whether the distributed lock is occupied;
    If the distributed lock is unoccupied,:Determine the expired time of the distributed lock;The distributed lock is distributed To the client;Sent out using the mark of the distributed lock and the expired time of the distributed lock as success message is locked The client is given, the business operation protected for the client executing by the distributed lock.
  2. 2. according to the method for claim 1, it is characterised in that the locking request also includes locking request time-out duration;
    And
    It is described to judge whether the distributed lock is occupied, including:
    Judge whether the locking request time-out duration is more than zero;
    If the locking request time-out duration is not more than zero, is sent to the client and lock failed message;
    If the locking request time-out duration is more than zero, judge whether the distributed lock is occupied.
  3. 3. according to the method for claim 2, it is characterised in that methods described also includes:
    If the distributed lock is occupied,:Obtain current time and the expired time of the distributed lock;Described in judgement Whether current time exceedes the expired time of the distributed lock;
    If the current time exceedes the expired time of the distributed lock,:Release the distributed lock;It is determined that described point The expired time of cloth lock;The distributed lock is distributed into the client;By the mark of the distributed lock and described The expired time of distributed lock is sent to the client as success message is locked, so that the client executing is by described point The business operation of cloth lock protection;
    If the current time waits preset time, the locking is asked not less than the expired time of the distributed lock Ask overtime duration to subtract the preset time, and continue to judge whether the locking request time-out duration is more than zero.
  4. 4. according to the method for claim 1, it is characterised in that methods described also includes:
    Receive the solution immediately that the client end response is completed and sent in the execution for the business operation protected by the distributed lock Lock request, the unlocking request immediately include:The mark of distributed lock to be unlocked and the first expired time, wherein, described One expired time is the expired time for locking the distributed lock in success message that the client receives;
    Obtain the expired time of corresponding with the mark of the distributed lock to be unlocked distributed lock, as second it is expired when Between;
    Judge whether first expired time is identical with second expired time;
    If it is, the distributed lock indicated by the mark of distributed lock to be unlocked described in releasing.
  5. 5. according to the method for claim 1, it is characterised in that methods described also includes:
    Receive the delay solution that the client end response is completed and sent in the execution for the business operation protected by the distributed lock Lock request, the delay unlocking request include:When mark, the first expired time and delay wait the distributed lock unlocked unlock Between, first expired time is the expired time for locking the distributed lock in success message that the client receives;
    Obtain the expired time of corresponding with the mark of the distributed lock to be unlocked distributed lock, as second it is expired when Between;
    Judge whether first expired time is identical with second expired time;
    If it is, the distribution indicated by the mark of distributed lock to be unlocked described in being released after the delay unlocked time Formula is locked.
  6. 6. according to the method for claim 3, it is characterised in that methods described also includes:
    Receive the delay solution that the client end response is completed and sent in the execution for the business operation protected by the distributed lock Lock request, the delay unlocking request include:When mark, the first expired time and delay wait the distributed lock unlocked unlock Between, first expired time is the expired time for locking the distributed lock in success message that the client receives;
    Obtain the expired time of corresponding with the mark of the distributed lock to be unlocked distributed lock, as second it is expired when Between;
    Judge whether first expired time is identical with second expired time;
    If it is, obtain current time, and with the current time plus it is described postpone unlocked time obtained by time more The expired time of distributed lock indicated by the mark of the new distributed lock to be unlocked.
  7. 7. according to the method for claim 1, it is characterised in that the locking request also includes:The maximum duration of holder lock; And
    If the distributed lock is unoccupied, the expired time of the distributed lock is determined, including:
    Current time is obtained, time of the current time plus gained after the maximum duration of the holder lock is divided as described The expired time of cloth lock.
  8. 8. a kind of device for being used to control distributed lock, it is characterised in that described device includes:
    Locking request receiving unit, it is configured to receive the locking request for the distributed lock that client is sent, the locking request Including:The mark of the distributed lock;
    First judging unit, it is configured to judge whether the distributed lock is occupied;
    First locks unit, if it is unoccupied to be configured to the distributed lock,:Determine the distributed lock it is expired when Between;The distributed lock is distributed into the client;By the expired of the mark of the distributed lock and the distributed lock Time is sent to the client as success message is locked, the industry protected for the client executing by the distributed lock Business operation.
  9. 9. device according to claim 8, it is characterised in that the locking request also includes locking request time-out duration;
    And first judging unit includes:
    First judge module, it is configured to judge whether the locking request time-out duration is more than zero;
    Sending module, if being configured to the locking request time-out duration no more than zero, send and lock to the client Failed message;
    Second judge module, if being configured to the locking request time-out duration more than zero, judge that the distributed lock is It is no occupied.
  10. 10. device according to claim 9, it is characterised in that described device also includes:
    Second judging unit, if it is occupied to be configured to the distributed lock,:Obtain current time and the distribution The expired time of lock;Judge whether the current time exceedes the expired time of the distributed lock;
    Second locks unit, if being configured to the expired time that the current time exceedes the distributed lock,:Release institute State distributed lock;Determine the expired time of the distributed lock;The distributed lock is distributed into the client;Will be described point The mark of cloth lock and the expired time of the distributed lock are sent to the client as success message is locked, for institute State the business operation that client executing is protected by the distributed lock;
    Unit is waited, if being configured to expired time of the current time not less than the distributed lock, is waited default Time, the locking request time-out duration is subtracted into the preset time, and continue to judge that the locking request time-out duration is It is no to be more than zero.
  11. 11. device according to claim 8, it is characterised in that described device also includes:
    Unlocking request receiving unit immediately, it is configured to receive the client end response in the business protected by the distributed lock The unlocking request immediately that the execution of operation is completed and sent, the unlocking request immediately include:The mark of distributed lock to be unlocked Knowledge and the first expired time, wherein, first expired time is described in the locking success message that the client receives The expired time of distributed lock;
    First acquisition unit, it is configured to obtain the expired of distributed lock corresponding with the mark of the distributed lock to be unlocked Time, as the second expired time;
    3rd judging unit, it is configured to judge whether first expired time is identical with second expired time;
    First unlocking unit, it is configured to the distribution if it is, indicated by the mark of distributed lock to be unlocked described in releasing Formula is locked.
  12. 12. device according to claim 8, it is characterised in that described device also includes:
    The first delay unlocking request receiving unit, it is configured to receive the client end response in being protected by the distributed lock The delay unlocking request that the execution of business operation is completed and sent, the delay unlocking request include:Distributed lock to be unlocked Mark, the first expired time and delay unlocked time, first expired time be the client receive locking success The expired time of the distributed lock in message;
    Second acquisition unit, it is configured to obtain the expired of distributed lock corresponding with the mark of the distributed lock to be unlocked Time, as the second expired time;
    4th judging unit, it is configured to judge whether first expired time is identical with second expired time;
    Second unlocking unit, it is configured to the distribution if it is, to be unlocked described in being released after the delay unlocked time Distributed lock indicated by the mark of formula lock.
  13. 13. device according to claim 10, it is characterised in that described device also includes:
    The second delay unlocking request receiving unit, it is configured to receive the client end response in being protected by the distributed lock The delay unlocking request that the execution of business operation is completed and sent, the delay unlocking request include:Distributed lock to be unlocked Mark, the first expired time and delay unlocked time, first expired time be the client receive locking success The expired time of the distributed lock in message;
    3rd acquiring unit, it is configured to obtain the expired of distributed lock corresponding with the mark of the distributed lock to be unlocked Time, as the second expired time;
    5th judging unit, it is configured to judge whether first expired time is identical with second expired time;
    3rd unlocking unit, it is configured to if it is, obtaining current time, and solved plus the delay with the current time The expired time of distributed lock described in time renewal obtained by the lock time indicated by the mark of distributed lock to be unlocked.
  14. 14. device according to claim 8, it is characterised in that the locking request also includes:Holder lock it is most long when Between;And
    The first locking unit is further configured to:
    Current time is obtained, time of the current time plus gained after the maximum duration of the holder lock is divided as described The expired time of cloth lock.
CN201610597208.5A 2016-07-26 2016-07-26 Method and apparatus for controlling distributed lock Pending CN107656815A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610597208.5A CN107656815A (en) 2016-07-26 2016-07-26 Method and apparatus for controlling distributed lock

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610597208.5A CN107656815A (en) 2016-07-26 2016-07-26 Method and apparatus for controlling distributed lock

Publications (1)

Publication Number Publication Date
CN107656815A true CN107656815A (en) 2018-02-02

Family

ID=61126702

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610597208.5A Pending CN107656815A (en) 2016-07-26 2016-07-26 Method and apparatus for controlling distributed lock

Country Status (1)

Country Link
CN (1) CN107656815A (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium
CN109324877A (en) * 2018-08-15 2019-02-12 北京天元创新科技有限公司 The method and server of data access
CN110097330A (en) * 2019-03-27 2019-08-06 深圳市佰仟金融服务有限公司 A kind of service request processing method, device and computer readable storage medium
CN110677465A (en) * 2019-09-09 2020-01-10 北京信安世纪科技股份有限公司 Control method and device of distributed lock
CN111258976A (en) * 2018-12-03 2020-06-09 北京京东尚科信息技术有限公司 Distributed lock implementation method, system, device and storage medium
CN111400324A (en) * 2019-11-08 2020-07-10 杭州海康威视系统技术有限公司 Method and device for locking object in cloud storage and server
CN112035269A (en) * 2020-09-10 2020-12-04 蔡国凤 Multi-node locking method for distributed system
CN113535416A (en) * 2021-06-30 2021-10-22 北京百度网讯科技有限公司 Method and device for realizing reentrant distributed lock, electronic equipment and storage medium
CN113568760A (en) * 2020-04-28 2021-10-29 北京国双科技有限公司 Distributed lock processing method and device based on database

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103634347A (en) * 2012-08-24 2014-03-12 腾讯科技(深圳)有限公司 Parallel service processing method, device and system
CN103678122A (en) * 2013-11-29 2014-03-26 华为技术有限公司 Deadlock detecting method, equipment and system
US20140236913A1 (en) * 2013-02-20 2014-08-21 Nec Laboratories America, Inc. Accelerating Distributed Transactions on Key-Value Stores Through Dynamic Lock Localization
CN104486328A (en) * 2014-12-10 2015-04-01 小米科技有限责任公司 Access control method and device
CN105550052A (en) * 2015-12-28 2016-05-04 东软集团股份有限公司 Distributed lock realization method and apparatus

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103634347A (en) * 2012-08-24 2014-03-12 腾讯科技(深圳)有限公司 Parallel service processing method, device and system
US20140236913A1 (en) * 2013-02-20 2014-08-21 Nec Laboratories America, Inc. Accelerating Distributed Transactions on Key-Value Stores Through Dynamic Lock Localization
CN103678122A (en) * 2013-11-29 2014-03-26 华为技术有限公司 Deadlock detecting method, equipment and system
CN104486328A (en) * 2014-12-10 2015-04-01 小米科技有限责任公司 Access control method and device
CN105550052A (en) * 2015-12-28 2016-05-04 东软集团股份有限公司 Distributed lock realization method and apparatus

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
李静瑶: "基于Redis实现分布式锁,Redisson使用及源码分析", 《数据分析与开发》 *

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium
CN108874552B (en) * 2018-06-28 2021-09-21 杭州云毅网络科技有限公司 Distributed lock execution method, device and system, application server and storage medium
CN109324877A (en) * 2018-08-15 2019-02-12 北京天元创新科技有限公司 The method and server of data access
CN111258976A (en) * 2018-12-03 2020-06-09 北京京东尚科信息技术有限公司 Distributed lock implementation method, system, device and storage medium
CN110097330A (en) * 2019-03-27 2019-08-06 深圳市佰仟金融服务有限公司 A kind of service request processing method, device and computer readable storage medium
CN110677465A (en) * 2019-09-09 2020-01-10 北京信安世纪科技股份有限公司 Control method and device of distributed lock
CN111400324A (en) * 2019-11-08 2020-07-10 杭州海康威视系统技术有限公司 Method and device for locking object in cloud storage and server
CN111400324B (en) * 2019-11-08 2023-05-02 杭州海康威视系统技术有限公司 Method, device and server for locking object in cloud storage
CN113568760A (en) * 2020-04-28 2021-10-29 北京国双科技有限公司 Distributed lock processing method and device based on database
CN112035269A (en) * 2020-09-10 2020-12-04 蔡国凤 Multi-node locking method for distributed system
CN113535416A (en) * 2021-06-30 2021-10-22 北京百度网讯科技有限公司 Method and device for realizing reentrant distributed lock, electronic equipment and storage medium
CN113535416B (en) * 2021-06-30 2024-02-27 北京百度网讯科技有限公司 Implementation method and device of reentrant distributed lock, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN107656815A (en) Method and apparatus for controlling distributed lock
CN107818018A (en) The control method and device of distributed lock
CN105471759B (en) The network traffics dispatching method and device of data center
CN102576354B (en) Support that difference disposes the extensible framework of framework
US9069870B2 (en) Client-side aggregation of context-sensitive request results where results for aggregation are asynchronously produced by multiple servers
CN107341051A (en) Cluster task coordination approach, system and device
CN107544850A (en) Method and apparatus for controlling distributed lock
US20090287768A1 (en) Management apparatus and management method for computer system
CN107301091A (en) Resource allocation methods and device
CN107590188A (en) A kind of reptile crawling method and its management system for automating vertical subdivision field
CN111400344B (en) Electronic bill printing method, device, equipment and storage medium
CN105740332A (en) Data sorting method and device
CN106101256A (en) Method and apparatus for synchrodata
CN109313675A (en) Software license management system and management method
CN107291769A (en) The method and apparatus for handling concurrent order
CN108764902A (en) Method, node and block catenary system for storing data
Salibindla Microservices API security
CN108112268A (en) Management and the relevant load balancer of automatic expanded set
CN113434311B (en) Service data interaction method, device, equipment and storage medium
CN110366724A (en) Computer system, licence managing method and program
Goecke The evolution of online booking systems
CN107657155A (en) Method and apparatus for identifying user's operating right
CN111200645A (en) Service request processing method, device, equipment and readable storage medium
CN107770227A (en) The distribution processing method and device of service request
CN106130757B (en) Information acquisition method and device

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

Application publication date: 20180202

RJ01 Rejection of invention patent application after publication