manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1642871 - in /manifoldcf/trunk: CHANGES.txt framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockManager.java
Date Tue, 02 Dec 2014 14:00:08 GMT
Author: kwright
Date: Tue Dec  2 14:00:08 2014
New Revision: 1642871

URL: http://svn.apache.org/r1642871
Log:
Fix for CONNECTORS-921.

Modified:
    manifoldcf/trunk/CHANGES.txt
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockManager.java

Modified: manifoldcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/CHANGES.txt?rev=1642871&r1=1642870&r2=1642871&view=diff
==============================================================================
--- manifoldcf/trunk/CHANGES.txt (original)
+++ manifoldcf/trunk/CHANGES.txt Tue Dec  2 14:00:08 2014
@@ -3,6 +3,10 @@ $Id$
 
 ======================= 2.0-dev =====================
 
+CONNECTORS-921: Change Zookeeper paths so all ManifoldCF nodes
+are under one root.
+(Graeme Seaton, Karl Wright)
+
 CONNECTORS-969: Don't use JSON as an output specification format.
 (Karl Wright)
 

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java?rev=1642871&r1=1642870&r2=1642871&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
(original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperConnection.java
Tue Dec  2 14:00:08 2014
@@ -247,30 +247,57 @@ public class ZooKeeperConnection
       try
       {
         //System.out.println("Creating child '"+childName+"' of nodepath '"+nodePath+"'");
-        while (true)
+        createPersistentPath(nodePath + "/" + CHILD_PREFIX + childName, null);
+        break;
+      }
+      catch (KeeperException e)
+      {
+        handleKeeperException(e,true);
+      }
+    }
+  }
+
+  protected void createPersistentPath(String path, byte[] data)
+    throws KeeperException, InterruptedException
+  {
+    // Loop until we've created the entire path, but initially try the whole thing for performance
+    while (true)
+    {
+      try
+      {
+        zookeeper.create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+        // Break on success
+        break;
+      }
+      catch (KeeperException.NoNodeException e)
+      {
+        // Strip off last part of path, and try recursively
+        int lastIndex = path.lastIndexOf("/");
+        // No last path: rethrow because we don't have a clue what is going on
+        if (lastIndex == -1 || lastIndex == 0)
+          throw e;
+        createPersistentPath(path.substring(0,lastIndex),null);
+        // Retry
+      }
+      catch (KeeperException.NodeExistsException e)
+      {
+        // Path is there: someone else beat us to it
+        // But we do have to set the data.
+        // NOTE: This code relies on the fact that only leaf persistent nodes have data.
+        if (data != null)
         {
           try
           {
-            zookeeper.create(nodePath + "/" + CHILD_PREFIX + childName, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
CreateMode.PERSISTENT);
-            break;
+            zookeeper.setData(path, data, -1);
           }
-          catch (KeeperException.NoNodeException e)
+          catch (KeeperException.NoNodeException e2)
           {
-            try
-            {
-              zookeeper.create(nodePath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-            }
-            catch (KeeperException.NodeExistsException e2)
-            {
-            }
+            // Repeat, since we've lost our node
+            continue;
           }
         }
         break;
       }
-      catch (KeeperException e)
-      {
-        handleKeeperException(e,true);
-      }
     }
   }
   
@@ -842,34 +869,21 @@ public class ZooKeeperConnection
           try
           {
             zookeeper.delete(resourcePath, -1);
-            break;
           }
           catch (KeeperException.NoNodeException e)
           {
-            break;
           }
+          break;
         }
         else
         {
-          while (true)
+          try
           {
-            try
-            {
-              zookeeper.setData(resourcePath, data, -1);
-              break;
-            }
-            catch (KeeperException.NoNodeException e)
-            {
-              try
-              {
-                zookeeper.create(resourcePath, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-                break;
-              }
-              catch (KeeperException.NodeExistsException e2)
-              {
-                continue;
-              }
-            }
+            zookeeper.setData(resourcePath, data, -1);
+          }
+          catch (KeeperException.NoNodeException e)
+          {
+            createPersistentPath(resourcePath, data);
           }
           break;
         }
@@ -888,15 +902,8 @@ public class ZooKeeperConnection
     {
       try
       {
-        try
-        {
-          zookeeper.create(flagPath, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
-          break;
-        }
-        catch (KeeperException.NodeExistsException e)
-        {
-          break;
-        }
+        createPersistentPath(flagPath, null);
+        break;
       }
       catch (KeeperException e)
       {
@@ -915,12 +922,11 @@ public class ZooKeeperConnection
         try
         {
           zookeeper.delete(flagPath,-1);
-          break;
         }
         catch (KeeperException.NoNodeException e)
         {
-          break;
         }
+        break;
       }
       catch (KeeperException e)
       {

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockManager.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockManager.java?rev=1642871&r1=1642870&r2=1642871&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockManager.java
(original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/lockmanager/ZooKeeperLockManager.java
Tue Dec  2 14:00:08 2014
@@ -37,14 +37,14 @@ public class ZooKeeperLockManager extend
   protected final static String zookeeperConnectStringParameter = "org.apache.manifoldcf.zookeeper.connectstring";
   protected final static String zookeeperSessionTimeoutParameter = "org.apache.manifoldcf.zookeeper.sessiontimeout";
 
-  private final static String CONFIGURATION_PATH = "/org.apache.manifoldcf.configuration";
-  private final static String RESOURCE_PATH_PREFIX = "/org.apache.manifoldcf.resources-";
-  private final static String FLAG_PATH_PREFIX = "/org.apache.manifoldcf.flags-";
-  private final static String SERVICETYPE_LOCK_PATH_PREFIX = "/org.apache.manifoldcf.servicelock-";
-  private final static String SERVICETYPE_ACTIVE_PATH_PREFIX = "/org.apache.manifoldcf.serviceactive-";
-  private final static String SERVICETYPE_REGISTER_PATH_PREFIX = "/org.apache.manifoldcf.service-";
+  private final static String CONFIGURATION_PATH = "/org.apache.manifoldcf/configuration";
+  private final static String RESOURCE_PATH_PREFIX = "/org.apache.manifoldcf/resources-";
+  private final static String FLAG_PATH_PREFIX = "/org.apache.manifoldcf/flags-";
+  private final static String SERVICETYPE_LOCK_PATH_PREFIX = "/org.apache.manifoldcf/servicelock-";
+  private final static String SERVICETYPE_ACTIVE_PATH_PREFIX = "/org.apache.manifoldcf/serviceactive-";
+  private final static String SERVICETYPE_REGISTER_PATH_PREFIX = "/org.apache.manifoldcf/service-";
   /** Anonymous global variable name prefix, to be followed by the service type */
-  private final static String SERVICETYPE_ANONYMOUS_COUNTER_PREFIX = "/org.apache.manifoldcf.serviceanon-";
+  private final static String SERVICETYPE_ANONYMOUS_COUNTER_PREFIX = "/org.apache.manifoldcf/serviceanon-";
   
   /** Anonymous service name prefix, to be followed by an integer */
   protected final static String anonymousServiceNamePrefix = "_ANON_";



Mime
View raw message