Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-14993: Unable to download zookeeper files of 1byte in size

Erick Erickson77a205387f69
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a9b2514e4fb..8db9795c02a 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -204,6 +204,8 @@ Bug Fixes
* SOLR-14983: Fix response returning original score instead of reranked score due to query and filter combining.
(Krishan Goyal, Jason Baik, Christine Poerschke)
+* SOLR-14993: Unable to download zookeeper files of 1byte in size (Erick Erickson, Allen Sooredoo)
+
Other Changes
---------------------
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
index e3e61a44207..04e80ac1947 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
@@ -332,7 +332,7 @@ public class ZkMaintenanceUtils {
private static int copyDataDown(SolrZkClient zkClient, String zkPath, File file) throws IOException, KeeperException, InterruptedException {
byte[] data = zkClient.getData(zkPath, null, null, true);
- if (data != null && data.length > 1) { // There are apparently basically empty ZNodes.
+ if (data != null && data.length > 0) { // There are apparently basically empty ZNodes.
log.info("Writing file {}", file);
Files.write(file.toPath(), data);
return data.length;
diff --git a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java
index 661844afbca..4adb0edf2ba 100644
--- a/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java
+++ b/solr/solrj/src/test/org/apache/solr/common/cloud/TestZkMaintenanceUtils.java
@@ -16,10 +16,12 @@
*/
package org.apache.solr.common.cloud;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -142,6 +144,24 @@ public class TestZkMaintenanceUtils extends SolrTestCaseJ4 {
}
}
+ // SOLR-14993
+ @Test
+ public void testOneByteFile() throws Exception {
+ try (SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), 10000)) {
+ byte[] oneByte = new byte[1];
+ oneByte[0] = 0x30;
+ zkClient.makePath("/test1byte/one", oneByte, true);
+
+ Path tmpDest = Paths.get(createTempDir().toFile().getAbsolutePath(), "MustBeOne");
+ ZkMaintenanceUtils.downloadFromZK(zkClient, "/test1byte/one", tmpDest);
+
+ try (FileInputStream fis = new FileInputStream(tmpDest.toFile())) {
+ byte[] data = fis.readAllBytes();
+ assertEquals("Should have downloaded a one-byte file", data.length, 1);
+ assertEquals("contents of the one-byte file should be 0x30", 0x30, data[0]);
+ }
+ }
+ }
private List<String> getTraverseedZNodes(SolrZkClient zkClient, String path, ZkMaintenanceUtils.VISIT_ORDER visitOrder) throws KeeperException, InterruptedException {
List<String> result = new ArrayList<>();
ZkMaintenanceUtils.traverseZkTree(zkClient, path, visitOrder, new ZkMaintenanceUtils.ZkVisitor() {