Zookeeper missed events on successive changes

筅森魡賤 提交于 2019-12-12 20:56:31

问题


I currently have a setup with a single zookeeper node and Curator to access the data. Reading data is done through a Curator TreeCache.

I have the following test:

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>);
}

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);
    }
}

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".

Instead I am only receiving the event for a node added with value "some string 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?


回答1:


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.



来源:https://stackoverflow.com/questions/38806413/zookeeper-missed-events-on-successive-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!