helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zzh...@apache.org
Subject git commit: [HELIX-465] ZkCopy skips paths already exist in destination namespace, rb=23184
Date Tue, 01 Jul 2014 00:29:52 GMT
Repository: helix
Updated Branches:
  refs/heads/helix-0.6.2-release c5bb31269 -> 79a6b92aa


[HELIX-465] ZkCopy skips paths already exist in destination namespace, rb=23184


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

Branch: refs/heads/helix-0.6.2-release
Commit: 79a6b92aa08e443110dfc6132481d4f904bf2ee0
Parents: c5bb312
Author: zzhang <zzhang5@uci.edu>
Authored: Mon Jun 30 17:27:36 2014 -0700
Committer: zzhang <zzhang5@uci.edu>
Committed: Mon Jun 30 17:29:33 2014 -0700

----------------------------------------------------------------------
 .../java/org/apache/helix/tools/ZkCopy.java     | 13 ++++--
 .../java/org/apache/helix/tools/TestZkCopy.java | 46 ++++++++++++++++++++
 2 files changed, 56 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/79a6b92a/helix-core/src/main/java/org/apache/helix/tools/ZkCopy.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/ZkCopy.java b/helix-core/src/main/java/org/apache/helix/tools/ZkCopy.java
index 69369a5..3991c09 100644
--- a/helix-core/src/main/java/org/apache/helix/tools/ZkCopy.java
+++ b/helix-core/src/main/java/org/apache/helix/tools/ZkCopy.java
@@ -23,6 +23,7 @@ import java.net.URI;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.I0Itec.zkclient.exception.ZkNodeExistsException;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.GnuParser;
@@ -119,12 +120,18 @@ public class ZkCopy {
       String fromPath = concatenate(srcPath, path);
       Object data = srcClient.readDataAndStat(fromPath, stat, false);
       if (stat.getEphemeralOwner() != 0) {
-        logger.info("Skip copying ephemeral znode: " + fromPath);
+        logger.warn("Skip copying ephemeral znode: " + fromPath);
         continue;
       }
       String toPath = concatenate(dstPath, path);
-      System.out.println("Copy " + fromPath + " to " + toPath);
-      dstClient.createPersistent(toPath, data);
+      try {
+        dstClient.createPersistent(toPath, data);
+        System.out.println("Copy " + fromPath + " to " + toPath);
+
+      } catch (ZkNodeExistsException e) {
+        logger.warn("Skip copying znode: " + fromPath + ", " + toPath + " already exists");
+      }
+
       List<String> children = srcClient.getChildren(fromPath);
       if (children != null && children.size() > 0) {
         for (String child : children) {

http://git-wip-us.apache.org/repos/asf/helix/blob/79a6b92a/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java b/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java
index 21a1ad5..ee3d2bd 100644
--- a/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java
+++ b/helix-core/src/test/java/org/apache/helix/tools/TestZkCopy.java
@@ -21,9 +21,11 @@ package org.apache.helix.tools;
 
 import java.util.Date;
 
+import org.apache.helix.InstanceType;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.manager.zk.ZKUtil;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -64,4 +66,48 @@ public class TestZkCopy extends ZkUnitTestBase {
 
     System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
   }
+
+  @Test
+  public void testSkipCopyExistZnode() throws Exception {
+    String className = TestHelper.getTestClassName();
+    String methodName = TestHelper.getTestMethodName();
+    String testName = className + "_" + methodName;
+
+    System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));
+    String srcClusterName = testName + "_src";
+    String dstClusterName = testName + "_dst";
+    int n = 5;
+
+    TestHelper.setupCluster(srcClusterName, ZK_ADDR, 12918, // participant port
+        "localhost", // participant name prefix
+        "TestDB", // resource name prefix
+        1, // resources
+        32, // partitions per resource
+        n, // number of nodes
+        2, // replicas
+        "MasterSlave", true); // do rebalance
+
+    TestHelper.setupEmptyCluster(_gZkClient, dstClusterName);
+
+    String fromPath = String.format("/%s/INSTANCES", srcClusterName);
+    String toPath = String.format("/%s/INSTANCES", dstClusterName);
+    ZkCopy.main(new String[] {
+        "--src", "zk://" + ZK_ADDR + fromPath, "--dst", "zk://" + ZK_ADDR + toPath
+    });
+
+    fromPath = String.format("/%s/CONFIGS/PARTICIPANT", srcClusterName);
+    toPath = String.format("/%s/CONFIGS/PARTICIPANT", dstClusterName);
+    ZkCopy.main(new String[] {
+        "--src", "zk://" + ZK_ADDR + fromPath, "--dst", "zk://" + ZK_ADDR + toPath
+    });
+
+    for (int i = 0; i < n; i++) {
+      String instanceName = "localhost_" + (12918 + i);
+      boolean ret =
+          ZKUtil
+              .isInstanceSetup(_gZkClient, dstClusterName, instanceName, InstanceType.PARTICIPANT);
+      Assert.assertTrue(ret);
+    }
+    System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
+  }
 }


Mime
View raw message