English 中文(简体)
zookeeper - locking one-of-many
原标题:

I have a set of resources each of which has a unique identifier, and each resource element must be locked before it is used, and unlocked afterwards. The logic of the application is:

lock any one element;
if (none locked) then 
   exit with error;
else
   get resource-id from lock
   use resource
   unlock resource
end

Zookeeper looks like a good candidate for managing these locks, being fast and resilient, and it seems quite simple to recover from client failure.

Can anyone think how I could use Zookeeper to achieve this ?

最佳回答

How about this-

you have resources in the a directory (say /locks)

each process which needs to lock, lists all the children of this directory and then creates an ephemeral node called /locks/resource1/lock depending on which resource it wants to lock. It could be randomized on the set of resources.

This ephemeral node will be deleted by the process as soon as its done using the resource. A process should only use to resource_{i} if its been able to create /locks/resource_{i}/locks.

Would that work?

Thanks mahadev

问题回答

暂无回答




相关问题
iPhone app running while screen locked

Here is something I am trying desperately to get to work: I have an app that polls the GPS module in specified intervals and then sends out coords out to a server using Unix calls such as write(); It ...

Threading and un-safe variables

I have code listed here: Threading and Sockets. The answer to that question was to modify isListening with volatile. As I remarked, that modifier allowed me to access the variable from another thread....

mySQL - Apply a row level lock using mysqli

Using PHP s mysqli how do you apply a row level lock? Row level locks stop anyone editing currently present rows that match your criteria right? but do they stop a user inserting a row which matches ...

How are mutex and lock structures implemented?

I understand the concept of locks, mutex and other synchronization structures, but how are they implemented? Are they provided by the OS, or are these structures dependent on special CPU instructions ...

Determine thread which holds the lock on file

I know there is no WINAPI which would do it, but if a thread is hung and holds an open handle of file. how do we determine the thread id and Terminate it within our processes. I m not talking about ...

xml Column update and Locking in Sql Server

I have a few windwos services. They get xml column from Sql server manipulate and update it. Service A- Gets XML Service B- Gets XML Service A- Updates XML (it will be lost) Service B- Updates XML I ...

热门标签