[ 
https://issues.apache.org/jira/browse/CURATOR-540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16930234#comment-16930234
 ] 

HonglunChen commented on CURATOR-540:
-------------------------------------

[~randgalt] 

In my zk:

!image-2019-09-16-12-43-01-588.png!

Test case as follows:
{code:java}
// code placeholder
package org.apache.curator.framework.recipes.cache;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class TestPathChildrenCache {
    private static Logger LOGGER = 
LoggerFactory.getLogger(TestPathChildrenCache.class);

    public static void main(String[] args) throws IOException, Exception {

        String PATH = "/test/cache";
        CuratorFramework client = CuratorFrameworkFactory.newClient(
                "test.zk.host:2181",
                new ExponentialBackoffRetry(1000, 3));
        client.start();
        PathChildrenCache cache = new PathChildrenCache(client, PATH, true);
        cache.getListenable()
                .addListener(new TestPathChildrenCacheListener());
        cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE);

        Thread.sleep(20 * 1000);

    }

    public static class TestPathChildrenCacheListener
            implements PathChildrenCacheListener {

        @Override
        public synchronized void childEvent(CuratorFramework client, 
PathChildrenCacheEvent event) throws Exception {
            switch (event.getType()) {
                case CHILD_ADDED:
                    System.out.println(event.getData().getPath());
                    break;
                case INITIALIZED:
                case CHILD_UPDATED:
                case CHILD_REMOVED:
                    break;
                case CONNECTION_RECONNECTED:
                    // resume the node
                    break;
                case CONNECTION_SUSPENDED:
                case CONNECTION_LOST:
                    // suspend the node
                    break;
                default:
                    break;
            }
        }
    }

}
{code}
Run the test case above and we will get the result: 
{code:java}
// code placeholder
2019-09-16 12:37:33,002  INFO 
org.apache.curator.framework.state.ConnectionStateManager:228 - State change: 
CONNECTED
/test/cache/1
/test/cache/2
/test/cache/3
/test/cache/4
/test/cache/5
{code}
But the mode "StartMode.BUILD_INITIAL_CACHE" should not send history, right?    
     

 

> BUILD_INITIAL_CACHE mode will post history child on start
> ---------------------------------------------------------
>
>                 Key: CURATOR-540
>                 URL: https://issues.apache.org/jira/browse/CURATOR-540
>             Project: Apache Curator
>          Issue Type: Bug
>          Components: Recipes
>    Affects Versions: 2.12.0, 2.13.0
>            Reporter: HonglunChen
>            Priority: Major
>         Attachments: image-2019-09-16-12-43-01-588.png
>
>
> I debugged and found the root cause : In PathChildrenCache, CONNECTED state 
> is triggered before currentData initializes.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)

Reply via email to