动物园管理员,数据版本
问题描述:
下面是情形:动物园管理员,数据版本
- Z序节点创建:创建/配置12345(例如在12年12月12日 创建)
- 更新被该结构制成,设置/配置34567 (例如修订于13年12月12日)
- 一个月配置被再次修改之后,设置/配置567889(例如修订于13年1月1日)
问题:
- 什么是“得到”(或维护)以“/配置”相关的版本历史 最好的办法,即有没有办法,我能得到存储在节点数据的 整个历史?
- 什么是最好的方式来恢复我的当前配置值,即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或追加最后一个但列表的第二个条目到最后
您可以添加一个“监视”到znode并跟踪历史记录吗? – LenW