You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by "tisonkun (via GitHub)" <gi...@apache.org> on 2023/03/31 15:12:02 UTC

[GitHub] [curator] tisonkun opened a new pull request, #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

tisonkun opened a new pull request, #453:
URL: https://github.com/apache/curator/pull/453

   See https://issues.apache.org/jira/browse/CURATOR-665 for details.


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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] tisonkun commented on a diff in pull request #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #453:
URL: https://github.com/apache/curator/pull/453#discussion_r1154606534


##########
curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java:
##########
@@ -333,26 +341,49 @@ public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode
             String subPath = path.substring(0, pos);
             if ( zookeeper.exists(subPath, false) == null )
             {
-                try
+                List<ACL> acl = null;
+                if ( aclProvider != null )
                 {
-                    List<ACL> acl = null;
-                    if ( aclProvider != null )
-                    {
-                        acl = aclProvider.getAclForPath(subPath);
-                        if ( acl == null )
-                        {
-                            acl = aclProvider.getDefaultAcl();
-                        }
-                    }
+                    acl = aclProvider.getAclForPath(subPath);
                     if ( acl == null )
                     {
-                        acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
+                        acl = aclProvider.getDefaultAcl();
                     }
-                    zookeeper.create(subPath, new byte[0], acl, getCreateMode(asContainers));
                 }
-                catch ( KeeperException.NodeExistsException e )
+                if ( acl == null )
+                {
+                    acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
+                }
+
+                CompletableFuture<KeeperException> f = new CompletableFuture<>();
+
+                zookeeper.create(subPath, new byte[0], acl, getCreateMode(asContainers), new AsyncCallback.Create2Callback()
+                {
+                    @Override
+                    public void processResult(int rc, String path, Object ctx, String name, Stat stat)
+                    {
+                        if ( rc == KeeperException.Code.OK.intValue() )
+                        {
+                            f.complete(null);
+                            return;
+                        }
+
+                        if ( rc == KeeperException.Code.NODEEXISTS.intValue() )
+                        {
+                            // ignore... someone else has created it since we checked
+                            f.complete(null);
+                            return;
+                        }
+
+                        callback.processResult(rc, path, ctx, name, stat);
+                        f.complete(KeeperException.create(KeeperException.Code.get(rc)));
+                    }
+                }, null);
+
+                KeeperException ke = f.join();

Review Comment:
   I'm not sure if we can still interrupt properly here.



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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] tisonkun commented on pull request #453: CURATOR-665: Convey mkdirs exception to create backgorund

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #453:
URL: https://github.com/apache/curator/pull/453#issuecomment-1493232151

   @kezhuw You're right. Updated.


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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] tisonkun commented on pull request #453: CURATOR-665: Convey mkdirs exception to create backgorund

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on PR #453:
URL: https://github.com/apache/curator/pull/453#issuecomment-1493889881

   Thanks for your review! Merging...


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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] kezhuw commented on pull request #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on PR #453:
URL: https://github.com/apache/curator/pull/453#issuecomment-1493225830

   Nit: the commit title sounds outdated now.


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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] tisonkun merged pull request #453: CURATOR-665: Convey mkdirs exception to create backgorund

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun merged PR #453:
URL: https://github.com/apache/curator/pull/453


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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] kezhuw commented on a diff in pull request #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on code in PR #453:
URL: https://github.com/apache/curator/pull/453#discussion_r1155140954


##########
curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java:
##########
@@ -770,14 +790,24 @@ static <T> void backgroundCreateParentsThenNode(final CuratorFrameworkImpl clien
             @Override
             public void performBackgroundOperation(OperationAndData<T> dummy) throws Exception
             {
+                AtomicReference<CuratorEvent> event = new AtomicReference<>();
+                AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback()
+                {
+                    @Override
+                    public void processResult(int rc, String path, Object ctx, String name, Stat stat)
+                    {
+                        event.set(createResponseEvent(client, rc, path, ctx, name, stat));
+                    }
+                };
                 try
                 {
-                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers);
+                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers, callback);
                 }
                 catch ( KeeperException e )
                 {
                     if ( !client.getZookeeperClient().getRetryPolicy().allowRetry(e) )
                     {
+                        client.processBackgroundOperation(mainOperationAndData, event.get());

Review Comment:
   Sounds like all we need in exceptional case is `rc` and `path`. `KeeperException` already covers these two `KeeperException::code` and `KeeperException::getPath`. So I think we could construct `CuratorEvent` without resorting to a callback.



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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] tisonkun commented on a diff in pull request #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #453:
URL: https://github.com/apache/curator/pull/453#discussion_r1154600433


##########
curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java:
##########
@@ -333,26 +341,49 @@ public static void mkdirs(ZooKeeper zookeeper, String path, boolean makeLastNode
             String subPath = path.substring(0, pos);
             if ( zookeeper.exists(subPath, false) == null )
             {
-                try
+                List<ACL> acl = null;
+                if ( aclProvider != null )
                 {
-                    List<ACL> acl = null;
-                    if ( aclProvider != null )
-                    {
-                        acl = aclProvider.getAclForPath(subPath);
-                        if ( acl == null )
-                        {
-                            acl = aclProvider.getDefaultAcl();
-                        }
-                    }
+                    acl = aclProvider.getAclForPath(subPath);
                     if ( acl == null )
                     {
-                        acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
+                        acl = aclProvider.getDefaultAcl();
                     }
-                    zookeeper.create(subPath, new byte[0], acl, getCreateMode(asContainers));
                 }
-                catch ( KeeperException.NodeExistsException e )
+                if ( acl == null )
+                {
+                    acl = ZooDefs.Ids.OPEN_ACL_UNSAFE;
+                }
+
+                CompletableFuture<KeeperException> f = new CompletableFuture<>();
+
+                zookeeper.create(subPath, new byte[0], acl, getCreateMode(asContainers), new AsyncCallback.Create2Callback()

Review Comment:
   The callback-completable-future-mixed style is not quite elegant, but this is the best solution I find now.



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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] tisonkun commented on a diff in pull request #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #453:
URL: https://github.com/apache/curator/pull/453#discussion_r1155235873


##########
curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java:
##########
@@ -770,14 +790,24 @@ static <T> void backgroundCreateParentsThenNode(final CuratorFrameworkImpl clien
             @Override
             public void performBackgroundOperation(OperationAndData<T> dummy) throws Exception
             {
+                AtomicReference<CuratorEvent> event = new AtomicReference<>();
+                AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback()
+                {
+                    @Override
+                    public void processResult(int rc, String path, Object ctx, String name, Stat stat)
+                    {
+                        event.set(createResponseEvent(client, rc, path, ctx, name, stat));
+                    }
+                };
                 try
                 {
-                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers);
+                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers, callback);
                 }
                 catch ( KeeperException e )
                 {
                     if ( !client.getZookeeperClient().getRetryPolicy().allowRetry(e) )
                     {
+                        client.processBackgroundOperation(mainOperationAndData, event.get());

Review Comment:
   @kezhuw Thanks for your insight!
   
   I checked that on exception, `stat` should be `null`, `ctx` we passed is `null`, and since we don't create sequential node here, `path == name`. So you're right that I can tidy the code a lot.



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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] tisonkun commented on a diff in pull request #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

Posted by "tisonkun (via GitHub)" <gi...@apache.org>.
tisonkun commented on code in PR #453:
URL: https://github.com/apache/curator/pull/453#discussion_r1155236420


##########
curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java:
##########
@@ -770,14 +790,24 @@ static <T> void backgroundCreateParentsThenNode(final CuratorFrameworkImpl clien
             @Override
             public void performBackgroundOperation(OperationAndData<T> dummy) throws Exception
             {
+                AtomicReference<CuratorEvent> event = new AtomicReference<>();
+                AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback()
+                {
+                    @Override
+                    public void processResult(int rc, String path, Object ctx, String name, Stat stat)
+                    {
+                        event.set(createResponseEvent(client, rc, path, ctx, name, stat));
+                    }
+                };
                 try
                 {
-                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers);
+                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers, callback);
                 }
                 catch ( KeeperException e )
                 {
                     if ( !client.getZookeeperClient().getRetryPolicy().allowRetry(e) )
                     {
+                        client.processBackgroundOperation(mainOperationAndData, event.get());

Review Comment:
   Updated.



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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [curator] kezhuw commented on a diff in pull request #453: CURATOR-665: ZKPaths.mkdirs should complete background on exception

Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on code in PR #453:
URL: https://github.com/apache/curator/pull/453#discussion_r1155239661


##########
curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java:
##########
@@ -770,14 +790,24 @@ static <T> void backgroundCreateParentsThenNode(final CuratorFrameworkImpl clien
             @Override
             public void performBackgroundOperation(OperationAndData<T> dummy) throws Exception
             {
+                AtomicReference<CuratorEvent> event = new AtomicReference<>();
+                AsyncCallback.Create2Callback callback = new AsyncCallback.Create2Callback()
+                {
+                    @Override
+                    public void processResult(int rc, String path, Object ctx, String name, Stat stat)
+                    {
+                        event.set(createResponseEvent(client, rc, path, ctx, name, stat));
+                    }
+                };
                 try
                 {
-                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers);
+                    ZKPaths.mkdirs(client.getZooKeeper(), path, false, aclProvider, createParentsAsContainers, callback);
                 }
                 catch ( KeeperException e )
                 {
                     if ( !client.getZookeeperClient().getRetryPolicy().allowRetry(e) )
                     {
+                        client.processBackgroundOperation(mainOperationAndData, event.get());

Review Comment:
   @tisonkun On exception, `name` should be `null` as no node is created. But this won't affect final result as `KeeperException` needs only `CuratorEvent::getResultCode` and `CuratorEvent::getPath` to reconstruct itself.



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

To unsubscribe, e-mail: commits-unsubscribe@curator.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org