Zookeeper错过了连续更改中的事件 [英] Zookeeper missed events on successive changes
问题描述
我目前有一个带有单个Zookeeper节点和Curator的设置来访问数据.读取数据是通过Curator TreeCache完成的.
I currently have a setup with a single zookeeper node and Curator to access the data. Reading data is done through a Curator TreeCache.
我进行了以下测试:
public void test_callback_successive_changes_success_global_new_version() throws InterruptedException {
ZookeeperTestsHelper.createNewNodeInZookeeperSingleCommand("/my/path/new_node", "some string4", curator);
ZookeeperTestsHelper.createNewNodeInZookeeperSingleCommand("/my/path/new_node", "some string5", curator);
Thread.sleep(1000);
assertThat(<check what events the listener heard>);
}
请注意,执行测试之前"new_node"不存在.
Note that "new_node" does not exists before the test is executed.
public static void createNewNodeInZookeeperSingleCommand(final String fullPathOfValueInZookeeper, final String valueToSet, final CuratorFramework curator) {
try {
if (curator.checkExists().forPath(fullPathOfValueInZookeeper) != null) {
System.out.println("E: " + valueToSet);
//Node already exists just set it
curator.setData().forPath(fullPathOfValueInZookeeper, valueToSet.getBytes());
} else {
System.out.println("N: " + valueToSet);
//Node needs to be created
curator.create().creatingParentsIfNeeded().forPath(fullPathOfValueInZookeeper, valueToSet.getBytes());
}
} catch (Exception e) {
throw new IllegalStateException("Error", e);
}
}
我期望缓存侦听器将首先听到添加了某些字符串4"的节点的事件,然后听到了另外发生了由某些字符串5"更新的节点的事件.
I'm expecting that the cache listener will first heard the event of a node added with "some string 4" and then heard another event of node updated with "some string 5".
相反,我只收到添加了值"some string 5"的节点的事件
Instead I am only receiving the event for a node added with value "some string 5"
查看日志,两个命令都正在执行.即记录"N:某些字符串4"和"E:某些字符串5".而且Zookeeper中的最终值是正确的(一些字符串5"),但是我不明白为什么馆长缓存只看到一个事件?
Looking at the logs both commands are being executed. i.e. "N: some string 4" and "E: some string 5" are both logged. And the final value in Zookeeper is correct ("some string 5") but I do not understand why the Curator cache is only seeing a single event?
推荐答案
ZooKeeper(或馆长的TreeCache)不保证您不会错过连续更改的事件.保证是您不会看到与其他客户看到的顺序不同的连续更改.
ZooKeeper (or Curator's TreeCache) don't guarantee that you will not miss events on successive changes. The guarantee is that you won't see successive changes in a different order from what other clients would see.
这篇关于Zookeeper错过了连续更改中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!