eolivelli commented on a change in pull request #376:
URL: https://github.com/apache/curator/pull/376#discussion_r566630026



##########
File path: 
curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
##########
@@ -210,6 +230,47 @@ public Stat forPath(String path) throws Exception
         return this;
     }
 
+    private void backgroundCheckIdempotent(final CuratorFrameworkImpl client, 
final OperationAndData<PathAndBytes> mainOperationAndData, final String path, 
final Backgrounding backgrounding)
+    {
+        final AsyncCallback.DataCallback dataCallback = new 
AsyncCallback.DataCallback()
+        {
+            @Override
+            public void processResult(int rc, String path, Object ctx, byte[] 
data, Stat stat)
+            {
+                    if ( rc == KeeperException.Code.OK.intValue() )
+                    {
+                        if ( failNextIdempotentCheckForTesting )
+                        {
+                            failNextIdempotentCheckForTesting = false;
+                            rc = 
KeeperException.Code.CONNECTIONLOSS.intValue();
+                        }
+                        else if ( !idempotentSetMatches(stat.getVersion(), 
mainOperationAndData.getData().getData(), data) )
+                        {
+                            rc = KeeperException.Code.BADVERSION.intValue();
+                        }
+                    }
+                    CuratorEvent event = new CuratorEventImpl(client, 
CuratorEventType.SET_DATA, rc, path, null, ctx, stat, null, null, null, null, 
null);
+                    client.processBackgroundOperation(mainOperationAndData, 
event);
+            }
+        };
+        BackgroundOperation<PathAndBytes> operation = new 
BackgroundOperation<PathAndBytes>()
+        {
+            @Override
+            public void 
performBackgroundOperation(OperationAndData<PathAndBytes> op) throws Exception
+            {
+                try
+                {
+                    client.getZooKeeper().getData(path, false, dataCallback, 
backgrounding.getContext());
+                }
+                catch ( KeeperException e )
+                {
+                    // ignore

Review comment:
       log ?

##########
File path: 
curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
##########
@@ -807,6 +826,53 @@ public void 
performBackgroundOperation(OperationAndData<PathAndBytes> op) throws
         client.queueOperation(new OperationAndData<>(operation, null, null, 
null, null, null));
     }
 
+    private void backgroundCheckIdempotent(final CuratorFrameworkImpl client, 
final OperationAndData<PathAndBytes> mainOperationAndData, final String path, 
final Backgrounding backgrounding)
+    {
+        final AsyncCallback.DataCallback dataCallback = new 
AsyncCallback.DataCallback()
+        {
+            @Override
+            public void processResult(int rc, String path, Object ctx, byte[] 
data, Stat stat)
+            {
+                if ( rc == KeeperException.Code.NONODE.intValue() )
+                {
+                    client.queueOperation(mainOperationAndData);    // try to 
create it again
+                }
+                else
+                {
+                    if ( rc == KeeperException.Code.OK.intValue() )
+                    {
+                        if ( failNextIdempotentCheckForTesting )
+                        {
+                            failNextIdempotentCheckForTesting = false;
+                            rc = 
KeeperException.Code.CONNECTIONLOSS.intValue();
+                        }
+                        else if ( !IdempotentUtils.matches(0, 
mainOperationAndData.getData().getData(), stat.getVersion(), data) )
+                        {
+                            rc = KeeperException.Code.NODEEXISTS.intValue();
+                        }
+                    }
+                    sendBackgroundResponse(rc, path, ctx, path, stat, 
mainOperationAndData);
+                }
+            }
+        };
+        BackgroundOperation<PathAndBytes> operation = new 
BackgroundOperation<PathAndBytes>()
+        {
+            @Override
+            public void 
performBackgroundOperation(OperationAndData<PathAndBytes> op) throws Exception
+            {
+                try
+                {
+                    client.getZooKeeper().getData(path, false, dataCallback, 
backgrounding.getContext());
+                }
+                catch ( KeeperException e )
+                {
+                    // ignore

Review comment:
       log ?

##########
File path: pom.xml
##########
@@ -68,7 +68,7 @@
 
         <!-- versions -->
         <zookeeper-version>3.6.0</zookeeper-version>
-        <maven-bundle-plugin-version>4.1.0</maven-bundle-plugin-version>
+        <maven-bundle-plugin-version>5.1.1</maven-bundle-plugin-version>

Review comment:
       It should be fine to make the upgrade

##########
File path: 
curator-framework/src/main/java/org/apache/curator/framework/imps/IdempotentUtils.java
##########
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.framework.imps;
+
+/*
+ * Utilties Class for idempotent operatons. 
+ */
+class IdempotentUtils
+{
+
+    /**
+     * Returns whether the version and data currently in the node match what 
would be expected in the idempotent retry case. 
+     */
+    static boolean matches(int expectedVersion, byte[] expectedData, int 
actualVersion, byte[] actualData)
+    {
+        return expectedVersion == actualVersion && matches(expectedData, 
actualData);
+    }
+
+    /**
+     * Returns whether the data currently in the node matches what would be 
expected in the idempotent retry case (ignoring version).
+     */
+    static boolean matches(byte[] expectedData, byte[] actualData)
+    {
+        if ( expectedData.length != actualData.length )

Review comment:
       can we use java.util.Arrays.equals ?

##########
File path: 
curator-framework/src/main/java/org/apache/curator/framework/imps/SetDataBuilderImpl.java
##########
@@ -51,6 +62,8 @@ public SetDataBuilderImpl(CuratorFrameworkImpl client, 
Backgrounding backgroundi
         this.backgrounding = backgrounding;
         this.version = version;
         this.compress = compress;
+        // TODO jslocum - this is only public for x-async api. Should I add 
idempotent there too?

Review comment:
       can we link a JIRA ?

##########
File path: 
curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
##########
@@ -87,6 +93,7 @@ public CreateBuilderImpl(CuratorFrameworkImpl client, 
CreateMode createMode, Bac
         this.createParentsAsContainers = createParentsAsContainers;
         this.compress = compress;
         this.setDataIfExists = setDataIfExists;
+        this.idempotent = false; // TODO should I add this to async framework 
as well? Looks like that's the reason this is a public constructor

Review comment:
       can we please remove TODO and create an issue ? 
   or we can leave here the TODO but put the link to the JIRA




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to