You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2014/12/24 22:00:55 UTC

svn commit: r1647842 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/CHANGES.txt solr/core/ solr/core/src/java/org/apache/solr/cloud/ZkCLI.java solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java

Author: thelabdude
Date: Wed Dec 24 21:00:54 2014
New Revision: 1647842

URL: http://svn.apache.org/r1647842
Log:
SOLR-6397: zkcli script put/putfile should allow overwriting an existing znode's data

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1647842&r1=1647841&r2=1647842&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Wed Dec 24 21:00:54 2014
@@ -321,6 +321,9 @@ Bug Fixes
 * SOLR-6873: Lib relative path is incorrect for techproduct configset
   (Alexandre Rafalovitch via Erick Erickson)
 
+* SOLR-6397: zkcli script put/putfile should allow overwriting an existing znode's data
+  (Timothy Potter)
+
 Optimizations
 ----------------------
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java?rev=1647842&r1=1647841&r2=1647842&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkCLI.java Wed Dec 24 21:00:54 2014
@@ -254,16 +254,27 @@ public class ZkCLI {
             System.out.println("-" + PUT + " requires two args - the path to create and the data string");
             System.exit(1);
           }
-          zkClient.create(arglist.get(0).toString(), arglist.get(1).toString().getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true);
+          String path = arglist.get(0).toString();
+          if (zkClient.exists(path, true)) {
+            zkClient.setData(path, arglist.get(1).toString().getBytes(StandardCharsets.UTF_8), true);
+          } else {
+            zkClient.create(path, arglist.get(1).toString().getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true);
+          }
         } else if (line.getOptionValue(CMD).equals(PUT_FILE)) {
           List arglist = line.getArgList();
           if (arglist.size() != 2) {
             System.out.println("-" + PUT_FILE + " requires two args - the path to create in ZK and the path to the local file");
             System.exit(1);
           }
+
+          String path = arglist.get(0).toString();
           InputStream is = new FileInputStream(arglist.get(1).toString());
           try {
-            zkClient.create(arglist.get(0).toString(), IOUtils.toByteArray(is), CreateMode.PERSISTENT, true);
+            if (zkClient.exists(path, true)) {
+              zkClient.setData(path, IOUtils.toByteArray(is), true);
+            } else {
+              zkClient.create(path, IOUtils.toByteArray(is), CreateMode.PERSISTENT, true);
+            }
           } finally {
             IOUtils.closeQuietly(is);
           }

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java?rev=1647842&r1=1647841&r2=1647842&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java Wed Dec 24 21:00:54 2014
@@ -144,6 +144,13 @@ public class ZkCLITest extends SolrTestC
     zkClient.getData("/data.txt", null, null, true);
 
     assertArrayEquals(zkClient.getData("/data.txt", null, null, true), data.getBytes(StandardCharsets.UTF_8));
+
+    // test re-put to existing
+    data = "my data deux";
+    args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
+        "put", "/data.txt", data};
+    ZkCLI.main(args);
+    assertArrayEquals(zkClient.getData("/data.txt", null, null, true), data.getBytes(StandardCharsets.UTF_8));
   }
 
   @Test