helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: HELIX-57: new File(path).getParent() is problematic on Windows platform
Date Tue, 05 Mar 2013 22:01:23 GMT
Updated Branches:
  refs/heads/master f80938e15 -> aa056d289


HELIX-57: new File(path).getParent() is problematic on Windows platform


Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/aa056d28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/aa056d28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/aa056d28

Branch: refs/heads/master
Commit: aa056d2890a8a96f40e63b40430f2d0c4565969f
Parents: f80938e
Author: zzhang <zzhang5@uci.edu>
Authored: Tue Mar 5 14:01:08 2013 -0800
Committer: zzhang <zzhang5@uci.edu>
Committed: Tue Mar 5 14:01:08 2013 -0800

----------------------------------------------------------------------
 .../java/org/apache/helix/manager/zk/Cache.java    |    5 +-
 .../apache/helix/manager/zk/WriteThroughCache.java |   22 +--------
 .../helix/manager/zk/ZkBaseDataAccessor.java       |    5 +-
 .../apache/helix/manager/zk/ZkCallbackCache.java   |   11 +++--
 .../main/java/org/apache/helix/util/HelixUtil.java |   36 +++++++++++----
 5 files changed, 41 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/aa056d28/helix-core/src/main/java/org/apache/helix/manager/zk/Cache.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/Cache.java b/helix-core/src/main/java/org/apache/helix/manager/zk/Cache.java
index 2613885..06650a2 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/Cache.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/Cache.java
@@ -28,6 +28,7 @@ import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.helix.store.zk.ZNode;
+import org.apache.helix.util.HelixUtil;
 import org.apache.zookeeper.data.Stat;
 
 
@@ -116,8 +117,8 @@ public abstract class Cache<T>
     {
       _lock.writeLock().lock();
 
-      String parentPath = new File(path).getParent();
-      String name = new File(path).getName();
+      String parentPath = HelixUtil.getZkParentPath(path);
+      String name = HelixUtil.getZkName(path);
       removeFromParentChildSet(parentPath, name);
 
       ZNode znode = _cache.remove(path);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/aa056d28/helix-core/src/main/java/org/apache/helix/manager/zk/WriteThroughCache.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/WriteThroughCache.java b/helix-core/src/main/java/org/apache/helix/manager/zk/WriteThroughCache.java
index e051ad5..1dcd2a3 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/WriteThroughCache.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/WriteThroughCache.java
@@ -27,6 +27,7 @@ import org.I0Itec.zkclient.exception.ZkNoNodeException;
 import org.apache.helix.AccessOption;
 import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.store.zk.ZNode;
+import org.apache.helix.util.HelixUtil;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.data.Stat;
 
@@ -55,8 +56,8 @@ public class WriteThroughCache<T> extends Cache<T>
   @Override
   public void update(String path, T data, Stat stat)
   {
-    String parentPath = new File(path).getParent();
-    String childName = new File(path).getName();
+    String parentPath = HelixUtil.getZkParentPath(path);
+    String childName = HelixUtil.getZkName(path);
     addToParentChildSet(parentPath, childName);
     
     ZNode znode = _cache.get(path);
@@ -83,29 +84,12 @@ public class WriteThroughCache<T> extends Cache<T>
     {
       _lock.writeLock().lock();
 
-//      // update parent's childSet
-//      String parentPath = new File(path).getParent();
-//      String name = new File(path).getName();
-//      addToParentChildSet(parentPath, name);
-
       // update this node
       Stat stat = new Stat();
       T readData = _accessor.get(path, stat, AccessOption.THROW_EXCEPTION_IFNOTEXIST);
 
       update(path, readData, stat);
       
-//      ZNode znode = _cache.get(path);
-//      if (znode == null)
-//      {
-//        znode = new ZNode(path, readData, stat);
-//        _cache.put(path, znode);
-//      }
-//      else
-//      {
-//        znode.setData(readData);
-//        znode.setStat(stat);
-//      }
-
       // recursively update children nodes if not exists
       ZNode znode = _cache.get(path);
       List<String> childNames = _accessor.getChildNames(path, 0);

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/aa056d28/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
index 77f33ce..77e2b5a 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
@@ -42,6 +42,7 @@ import org.apache.helix.manager.zk.ZkAsyncCallbacks.ExistsCallbackHandler;
 import org.apache.helix.manager.zk.ZkAsyncCallbacks.GetDataCallbackHandler;
 import org.apache.helix.manager.zk.ZkAsyncCallbacks.SetDataCallbackHandler;
 import org.apache.helix.store.zk.ZNode;
+import org.apache.helix.util.HelixUtil;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException.Code;
@@ -101,7 +102,7 @@ public class ZkBaseDataAccessor<T> implements BaseDataAccessor<T>
       catch (ZkNoNodeException e)
       {
         // this will happen if parent node does not exist
-        String parentPath = new File(path).getParent();
+        String parentPath = HelixUtil.getZkParentPath(path);
         try
         {
           RetCode rc = create(parentPath, null, pathCreated, AccessOption.PERSISTENT);
@@ -581,7 +582,7 @@ public class ZkBaseDataAccessor<T> implements BaseDataAccessor<T>
 
         if (Code.get(cb.getRc()) == Code.NONODE)
         {
-          String parentPath = new File(path).getParent();
+          String parentPath = HelixUtil.getZkParentPath(path);
           parentPaths.set(i, parentPath);
           failOnNoNode = true;
         }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/aa056d28/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackCache.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackCache.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackCache.java
index 04ee662..05c1243 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackCache.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkCallbackCache.java
@@ -35,6 +35,7 @@ import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.manager.zk.ZkCacheEventThread.ZkCacheEvent;
 import org.apache.helix.store.HelixPropertyListener;
 import org.apache.helix.store.zk.ZNode;
+import org.apache.helix.util.HelixUtil;
 import org.apache.log4j.Logger;
 import org.apache.zookeeper.Watcher.Event.EventType;
 import org.apache.zookeeper.Watcher.Event.KeeperState;
@@ -78,8 +79,8 @@ public class ZkCallbackCache<T> extends Cache<T> implements
   @Override
   public void update(String path, T data, Stat stat)
   {
-    String parentPath = new File(path).getParent();
-    String childName = new File(path).getName();
+    String parentPath = HelixUtil.getZkParentPath(path);
+    String childName = HelixUtil.getZkName(path);
 
     addToParentChildSet(parentPath, childName);
     ZNode znode = _cache.get(path);
@@ -241,8 +242,8 @@ public class ZkCallbackCache<T> extends Cache<T> implements
       _accessor.unsubscribeDataChanges(dataPath, this);
       _accessor.unsubscribeChildChanges(dataPath, this);
 
-      String parentPath = new File(dataPath).getParent();
-      String name = new File(dataPath).getName();
+      String parentPath = HelixUtil.getZkParentPath(dataPath);
+      String name = HelixUtil.getZkName(dataPath);
       removeFromParentChildSet(parentPath, name);
       _cache.remove(dataPath);
 
@@ -360,7 +361,7 @@ public class ZkCallbackCache<T> extends Cache<T> implements
         }
       }
 
-      tmpPath = new File(tmpPath).getParent();
+      tmpPath = HelixUtil.getZkParentPath(tmpPath);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/aa056d28/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java b/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
index 811aa4b..1d41f8f 100644
--- a/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
+++ b/helix-core/src/main/java/org/apache/helix/util/HelixUtil.java
@@ -60,16 +60,6 @@ public final class HelixUtil
     return getPropertyPath(clusterName, PropertyType.LIVEINSTANCES);
   }
 
-  // public static String getConfigPath(String clusterName)
-  // {
-  // return getPropertyPath(clusterName, PropertyType.PARTICIPANT_CONFIGS);
-  // }
-
-  // public static String getConfigPath(String clusterName, String instanceName)
-  // {
-  // return getConfigPath(clusterName) + "/" + instanceName;
-  // }
-
   public static String getMessagePath(String clusterName, String instanceName)
   {
     return getInstancePropertyPath(clusterName, instanceName, PropertyType.MESSAGES);
@@ -182,4 +172,30 @@ public final class HelixUtil
   {
     return PropertyPathConfig.getPath(type, clusterName);
   }
+  
+  /**
+   * get the parent-path of given path
+   * return "/" string if path = "/xxx", null if path = "/"
+   * 
+   * @param path
+   * @return
+   */
+  public static String getZkParentPath(String path) {
+      if (path.equals("/")) {
+          return null;
+      }
+      
+      int idx = path.lastIndexOf('/');
+      return idx == 0? "/" : path.substring(0, idx);
+  }
+  
+  /**
+   * get the last part of the zk-path
+   * 
+   * @param path
+   * @return
+   */
+  public static String getZkName(String path) {
+      return path.substring(path.lastIndexOf('/') + 1);
+  }
 }


Mime
View raw message