SOLR-6397: zkcli script put/putfile should allow overwriting an existing znode's data

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1647828 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy Potter 2014-12-24 18:44:02 +00:00
parent 1a494d6384
commit 007a6a1610
3 changed files with 23 additions and 2 deletions

View File

@ -357,6 +357,9 @@ Bug Fixes
* SOLR-6850: AutoAddReplicas makes a call to wait to see live replicas that times
out after 30 milliseconds instead of 30 seconds. (Varun Thacker via Mark Miller)
* SOLR-6397: zkcli script put/putfile should allow overwriting an existing znode's data
(Timothy Potter)
Optimizations
----------------------

View File

@ -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);
}

View File

@ -144,6 +144,13 @@ public class ZkCLITest extends SolrTestCaseJ4 {
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