gpt4 book ai didi

apache-zookeeper - Zookeeper,数据版本控制

转载 作者:行者123 更新时间:2023-12-05 05:25:22 26 4
gpt4 key购买 nike

场景如下:

  1. Znode 创建:create/config 12345(例如创建于12/12/12)
  2. 更新此配置,设置/config 34567(例如在 2013 年 12 月 12 日修改)
  3. 一个月后再次修改配置,设置/config 567889(例如1/1/13修改)

问题:

  1. “获取”(或维护)版本历史记录的最佳方式是什么与'/config'相关联,即有没有办法让我得到存储在节点中的全部数据历史?
  2. 将当前配置值(即 567889)还原为原始值 12345 的最佳方法是什么? (通过爬取节点历史数据)

我需要一些帮助来解决这个问题。谢谢

最佳答案

我不认为有一种简单的方法可以做到这一点。以下是我将如何实现这一点:

 1. divide the configurations in two znodes [say, /Config and /Config/data-*]
- /config/data-* are the data nodes which will store the configuration
- /config will store the history of all the configs so far
2. /Config/data-* is sequential node
So, every znode will have a strictly increasing number appended to it.
For example, /config/data-1, /config/data-2, and so on. Your configuration object
will be stored in data nodes.
/config/data-1 -> 12345
/config/data-2 -> 34567
/config/data-3 -> 56789
3. /config will look like this:
["/config/data-1","/config/data-2","/config/data-3"] or just
["1", "2", "3"]

这是写入算法:

 1. create a data node with new config. Which will return the the actual path.
say /config/data-4
2. now try to do conditional update on /config with "/config/data-4" or just "4" appended to
the existing data i.e.
["/config/data-1","/config/data-2","/config/data-3","/config/data-4"] or just
["1", "2", "3","4"]
- if update succeeds, end.
- else, someone else was simultaneously trying to update the config and won the race.
So, either quit or try again starting with step1.

注意:如果更新失败,您将在树中拥有有效的孤立节点,这些节点可以通过自动方式定期清理

阅读将是:

1. call sync [if consistency is important]
2. read /config
3. pick the path which is at the last index in the array retrieved from /config
4. read the config from that path

要回滚,要么从存储在/config 中的列表中删除最后一个条目,要么将列表的最后但第二个条目附加到末尾

关于apache-zookeeper - Zookeeper,数据版本控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31521353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com