Zookeeper - 锁定多个之一

发布于 2024-08-22 19:14:06 字数 329 浏览 11 评论 0原文

我有一组资源,每个资源都有一个唯一的标识符,并且每个资源元素必须在使用之前锁定,并在使用之后解锁。该应用程序的逻辑是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

睡美人的小仙女 2024-08-29 19:14:06

怎么样-

您在一个目录(例如/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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文