Zookeeper - 锁定多个之一
我有一组资源,每个资源都有一个唯一的标识符,并且每个资源元素必须在使用之前锁定,并在使用之后解锁。该应用程序的逻辑是:
lock any one element;
if (none locked) then
exit with error;
else
get resource-id from lock
use resource
unlock resource
end
Zookeeper 看起来是管理这些锁的良好候选者,速度快且有弹性,并且从客户端故障中恢复似乎非常简单。
谁能想到我如何使用 Zookeeper 来实现这一目标?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样-
您在一个目录(例如/locks)中有资源,
每个需要锁定的进程都会列出该目录的所有子进程
然后创建一个名为 /locks/resource1/lock 的临时节点,具体取决于
它想要锁定哪个资源。它可以在资源集上随机化。
该临时节点将在完成后立即被进程删除
资源。一个进程应该只使用resource_{i},如果它能够
创建/locks/resource_{i}/locks。
那行得通吗?
谢谢
马哈德夫
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