You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ke...@apache.org on 2023/04/19 14:39:41 UTC
[curator] branch master updated: CURATOR-666: Fix twice unfixForNamespace in background create (#454)
This is an automated email from the ASF dual-hosted git repository.
kezhuw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git
The following commit(s) were added to refs/heads/master by this push:
new 9aea8ff9 CURATOR-666: Fix twice unfixForNamespace in background create (#454)
9aea8ff9 is described below
commit 9aea8ff99df5e807a8004a294dd1dde8f93d48dd
Author: Kezhu Wang <ke...@apache.org>
AuthorDate: Wed Apr 19 22:39:32 2023 +0800
CURATOR-666: Fix twice unfixForNamespace in background create (#454)
Previously, `unfixForNamespace` was called twice in background create.
This will accidentally unfix node path if it happens to contain
namespace in its prefix. Say, creating "/zoo/a" in namespace "/zoo" will
get path "/a".
---
.../curator/framework/imps/CreateBuilderImpl.java | 12 ++++------
.../curator/framework/imps/CuratorEventImpl.java | 2 +-
.../curator/framework/imps/TestFramework.java | 27 ++++++++++++++++++++++
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index 6b52e662..ea31ef53 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@ -797,8 +797,7 @@ public class CreateBuilderImpl implements CreateBuilder, CreateBuilder2, Backgro
{
if ( !client.getZookeeperClient().getRetryPolicy().allowRetry(e) )
{
- final CuratorEvent event = makeCuratorEvent(client, e.code().intValue(), e.getPath(), null, e.getPath(), null);
- client.processBackgroundOperation(mainOperationAndData, event);
+ sendBackgroundResponse(client, e.code().intValue(), e.getPath(), null, null, null, mainOperationAndData);
throw e;
}
// otherwise safe to ignore as it will get retried
@@ -895,14 +894,13 @@ public class CreateBuilderImpl implements CreateBuilder, CreateBuilder2, Backgro
private void sendBackgroundResponse(int rc, String path, Object ctx, String name, Stat stat, OperationAndData<PathAndBytes> operationAndData)
{
- client.processBackgroundOperation(operationAndData, makeCuratorEvent(client, rc, path, ctx, name, stat));
+ sendBackgroundResponse(client, rc, path, ctx, name, stat, operationAndData);
}
- private static CuratorEvent makeCuratorEvent(CuratorFrameworkImpl client, int rc, String path, Object ctx, String name, Stat stat)
+ private static <T> void sendBackgroundResponse(CuratorFrameworkImpl client, int rc, String path, Object ctx, String name, Stat stat, OperationAndData<T> operationAndData)
{
- path = client.unfixForNamespace(path);
- name = client.unfixForNamespace(name);
- return new CuratorEventImpl(client, CuratorEventType.CREATE, rc, path, name, ctx, stat, null, null, null, null, null);
+ CuratorEvent event = new CuratorEventImpl(client, CuratorEventType.CREATE, rc, path, name, ctx, stat, null, null, null, null, null);
+ client.processBackgroundOperation(operationAndData, event);
}
private ACLCreateModePathAndBytesable<String> asACLCreateModePathAndBytesable()
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorEventImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorEventImpl.java
index e5623510..4e316cd6 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorEventImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorEventImpl.java
@@ -133,7 +133,7 @@ class CuratorEventImpl implements CuratorEvent
this.resultCode = resultCode;
this.opResults = (opResults != null) ? ImmutableList.copyOf(opResults) : null;
this.path = client.unfixForNamespace(path);
- this.name = name;
+ this.name = client.unfixForNamespace(name);
this.context = context;
this.stat = stat;
this.data = data;
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
index 5c285fbe..5eb632f9 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFramework.java
@@ -1031,6 +1031,33 @@ public class TestFramework extends BaseClassForTests
}
}
+ @Test
+ public void testBackgroundPathWithNamespace() throws Exception {
+ CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
+ try (CuratorFramework client = builder
+ .connectString(server.getConnectString())
+ .retryPolicy(new RetryOneTime(1))
+ .build()) {
+ client.start();
+ CuratorFramework namespaceZoo = client.usingNamespace("zoo");
+ BlockingQueue<CuratorEvent> events = new LinkedBlockingQueue<>();
+ BackgroundCallback callback = (CuratorFramework ignored, CuratorEvent event) -> {
+ events.add(event);
+ };
+
+ namespaceZoo.create().creatingParentsIfNeeded().inBackground(callback).forPath("/zoo/a");
+ CuratorEvent event = events.poll(10, TimeUnit.SECONDS);
+ assertNotNull(event);
+ assertEquals("/zoo/a", event.getPath());
+ assertEquals("/zoo/a", event.getName());
+
+ client.checkExists().inBackground(callback).forPath("/zoo/zoo/a");
+ event = events.poll(10, TimeUnit.SECONDS);
+ assertNotNull(event);
+ assertEquals("/zoo/zoo/a", event.getPath());
+ }
+ }
+
@Test
public void testCreateModes() throws Exception
{