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);
}
}
我期望缓存侦听器会首先听到添加了some string 4"的节点的事件,然后听到更新了some string 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 中的最终值是正确的(some string 5"),但我不明白为什么 Curator 缓存只看到一个事件?
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(或 Curator 的 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屋!