Repository: knox
Updated Branches:
  refs/heads/master 85ccaae92 -> 12eac267e


KNOX-1621 - CuratorClientService#createEntry - Avoid race condition when 
creating znodes

Signed-off-by: Kevin Risden <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/12eac267
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/12eac267
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/12eac267

Branch: refs/heads/master
Commit: 12eac267e14d1d4fe6e160858b159533332eae7a
Parents: 85ccaae
Author: Kevin Risden <[email protected]>
Authored: Wed Nov 21 14:36:22 2018 -0500
Committer: Kevin Risden <[email protected]>
Committed: Mon Nov 26 14:18:05 2018 -0500

----------------------------------------------------------------------
 .../config/remote/zk/CuratorClientService.java  | 22 +++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/12eac267/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
----------------------------------------------------------------------
diff --git 
a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
 
b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
index 5662e64..a8c5448 100644
--- 
a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
+++ 
b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
@@ -117,7 +117,6 @@ class CuratorClientService implements 
ZooKeeperClientService {
         return clients.get(name);
     }
 
-
     private RemoteConfigurationRegistryClient 
createClient(RemoteConfigurationRegistryConfig config) {
         ACLProvider aclProvider;
         if (config.isSecureRegistry()) {
@@ -279,13 +278,7 @@ class CuratorClientService implements 
ZooKeeperClientService {
 
         @Override
         public void createEntry(String path) {
-            try {
-                if (delegate.checkExists().forPath(path) == null) {
-                    delegate.create().forPath(path);
-                }
-            } catch (Exception e) {
-                log.errorInteractingWithRemoteConfigRegistry(e);
-            }
+            createEntry(path, null);
         }
 
         @Override
@@ -296,8 +289,17 @@ class CuratorClientService implements 
ZooKeeperClientService {
         @Override
         public void createEntry(String path, String data, String encoding) {
             try {
-                createEntry(path);
-                setEntryData(path, data, encoding);
+                byte[] dataBytes;
+                if(data == null) {
+                    // Match default znode value like curator
+                    // {@see CuratorFrameworkImpl#getDefaultData}
+                    dataBytes = new byte[0];
+                } else {
+                    dataBytes = data.getBytes(encoding);
+                }
+                if (delegate.checkExists().forPath(path) == null) {
+                    delegate.create().forPath(path, dataBytes);
+                }
             } catch (Exception e) {
                 log.errorInteractingWithRemoteConfigRegistry(e);
             }

Reply via email to