0

I have an API which creates a file based on user input. I need to distribute this file over a cluster, such that 1 file should be on 1 node only. Can I use zookeeper to achieve this, and how?

A user may want to delete the file. Which means that zookeeper needs to delete the file from the node, when asked to.

I've read through the zookeeper wiki, but it is difficult to understand how/when to use it.

4

1 回答 1

0

是的,您可以使用Apache Curator Recipes做到这一点。Apache Curator 是 Apache Zookeeper 的改进客户端库。

你可以使用 zookeeper watch API 和 Curator 的分布式锁来实现你想要的。

  1. 首先,在创建文件时,在集群中所有节点都在监视的 ZNode 下创建一个 ZNode(可能以文件的内容作为数据)。然后,将通知集群中的所有节点创建文件。
  2. 然后,节点将竞争获取分布式锁,获取它的节点将下载文件(如果需要,您可以删除先前创建的带有文件内容的 ZNode 或引入另一种机制来跟踪已获取的文件)。

希望你有一些想法。

于 2017-08-08T15:43:56.020 回答