Hi there,
I am using Apache Curator 4.1.0  with Zk 3.4.10 (Open JDK 1.8)
openjdk version "1.8.0_191"


I am PersistentNode recipe and I am receiving this exception


java.lang.IllegalStateException: initial create has not been processed. Call 
waitForInitialCreate() to ensure.        at 
org.apache.curator.shaded.com.google.common.base.Preconditions.checkState(Preconditions.java:444)
        at 
org.apache.curator.framework.recipes.nodes.PersistentNode.setData(PersistentNode.java:392)
        at 
com.cheva.udr.sm.RemoteReporter.reportToRemote(RemoteReporter.java:67)        
at com.cheva.udr.sm.RemoteReporter.lambda$2(RemoteReporter.java:84)        at 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)        
at java.util.concurrent.FutureTask.run(FutureTask.java:266)        at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 
       at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 
       at java.lang.Thread.run(Thread.java:748)


My class RemoteReporter.java (assumes that PersistentNode is thread safe)
// The class is final, and the attribute is private final so allow safe 
publicationprivate final Persistent pn;

Constrcutor() {...PersistentNode pn = new PersistentNode(cf, 
CreateMode.EPHEMERAL, false, path, dataToReport());
}
// Class has also an start methodstart() {...79            pn.start();...// 
Create new thread and execute the follwoing code84          
pn.waitForInitialCreate(1000, TimeUnit.DAYS);85          pn.setData("XXx");86   
       statusCache.getListenable().addListener(listener);}

I was checking the PersistentNode code and the excepction happens because 
nodePath.get()==null  variable. I am not 100% sure if the problem is in my code 
or in the recipe...
- My code is using the waitForinitial as suggested- The recipe uses a 
CountDownLatch, but there are 2 different paths for the latch to be countDown 
(via initalisationComplete() method), and I am not sure that one of them 
assures that nodePath.get() != null

In this code snippet, you can see that the latch is countDown, but I am not 
sure that nodePath.set(whatever) is called, so I guess there could be a race 
condition
    private final BackgroundCallback setDataCallback = new BackgroundCallback() 
   {
        @Override        public void processResult(CuratorFramework dummy, 
CuratorEvent event)            throws Exception        {            //If the 
result is ok then initialisation is complete (if we're still initialising)      
      //Don't retry on other errors as the only recoverable cases will be 
connection loss            //and the node not existing, both of which are 
already handled by other watches.            if ( event.getResultCode() == 
KeeperException.Code.OK.intValue() )            {                //Update is 
ok, mark initialisation as complete if required.                
initialisationComplete();            }            else if ( 
event.getResultCode() == KeeperException.Code.NOAUTH.intValue() )            {  
              log.warn("Client does not have authorisation to write node at 
path {}", event.getPath());                authFailure.set(true);            }  
      }    };
Thanks in adavance for the help,
Evaristo

Reply via email to