You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2017/08/08 12:14:44 UTC
[31/50] [abbrv] lucene-solr:feature/autoscaling: SOLR-11198:
downconfig downloads empty file as folder
SOLR-11198: downconfig downloads empty file as folder
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/522367cc
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/522367cc
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/522367cc
Branch: refs/heads/feature/autoscaling
Commit: 522367cc4db3b23ddd728b407f2d10326bb9c858
Parents: 1a3295f
Author: Erick Erickson <er...@apache.org>
Authored: Sun Aug 6 09:48:16 2017 -0700
Committer: Erick Erickson <er...@apache.org>
Committed: Sun Aug 6 09:48:16 2017 -0700
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../apache/solr/cloud/SolrCLIZkUtilsTest.java | 76 +++++++++++++++++++-
.../solr/common/cloud/ZkMaintenanceUtils.java | 6 +-
3 files changed, 80 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/522367cc/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index fcff490..f6c0424 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -765,6 +765,8 @@ when using one of Exact*StatsCache (Mikhail Khludnev)
* SOLR-10908: CloudSolrStream.toExpression incorrectly handles fq clauses (Rohit Singh via Erick Erickson)
+* SOLR-11198: downconfig downloads empty file as folder (Erick Erickson)
+
Optimizations
----------------------
* SOLR-10634: JSON Facet API: When a field/terms facet will retrieve all buckets (i.e. limit:-1)
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/522367cc/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java b/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java
index 776075e..579e93d 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SolrCLIZkUtilsTest.java
@@ -106,7 +106,7 @@ public class SolrCLIZkUtilsTest extends SolrCloudTestCase {
@Test
public void testDownconfig() throws Exception {
- Path tmp = createTempDir("downConfigNewPlace");
+ Path tmp = Paths.get(createTempDir("downConfigNewPlace").toAbsolutePath().toString(), "myconfset");
// First we need a configset on ZK to bring down.
@@ -127,6 +127,28 @@ public class SolrCLIZkUtilsTest extends SolrCloudTestCase {
assertEquals("Download should have succeeded.", 0, res);
verifyZkLocalPathsMatch(Paths.get(tmp.toAbsolutePath().toString(), "conf"), "/configs/downconfig1");
+ // Insure that empty files don't become directories (SOLR-11198)
+
+ Path emptyFile = Paths.get(tmp.toAbsolutePath().toString(), "conf", "stopwords", "emptyfile");
+ Files.createFile(emptyFile);
+
+ // Now copy it up and back and insure it's still a file in the new place
+ copyConfigUp(tmp.getParent(), "myconfset", "downconfig2");
+ Path tmp2 = createTempDir("downConfigNewPlace2");
+ downTool = new SolrCLI.ConfigSetDownloadTool();
+ args = new String[]{
+ "-confname", "downconfig2",
+ "-confdir", tmp2.toAbsolutePath().toString(),
+ "-zkHost", zkAddr,
+ };
+
+ res = downTool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(downTool.getOptions()), args));
+ assertEquals("Download should have succeeded.", 0, res);
+ verifyZkLocalPathsMatch(Paths.get(tmp.toAbsolutePath().toString(), "conf"), "/configs/downconfig2");
+ // And insure the empty file is a text file
+ Path destEmpty = Paths.get(tmp2.toAbsolutePath().toString(), "conf", "stopwords", "emptyfile");
+ assertTrue("Empty files should NOT be copied down as directories", destEmpty.toFile().isFile());
+
}
@Test
@@ -373,6 +395,58 @@ public class SolrCLIZkUtilsTest extends SolrCloudTestCase {
content = new String(zkClient.getData("/cp9/conf/stopwords", null, null, true), StandardCharsets.UTF_8);
assertTrue("There should be content in the node! ", content.contains("{Some Arbitrary Data}"));
+ // Copy an individual empty file up and back down and insure it's still a file
+ Path emptyFile = Paths.get(tmp.toAbsolutePath().toString(), "conf", "stopwords", "emptyfile");
+ Files.createFile(emptyFile);
+
+ args = new String[]{
+ "-src", "file:" + emptyFile.toAbsolutePath().toString(),
+ "-dst", "zk:/cp7/conf/stopwords/emptyFile",
+ "-recurse", "false",
+ "-zkHost", zkAddr,
+ };
+
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(cpTool.getOptions()), args));
+ assertEquals("Copy should have succeeded.", 0, res);
+
+ Path tmp2 = createTempDir("cp9");
+ Path emptyDest = Paths.get(tmp2.toAbsolutePath().toString(), "emptyFile");
+ args = new String[]{
+ "-src", "zk:/cp7/conf/stopwords/emptyFile",
+ "-dst", "file:" + emptyDest.toAbsolutePath().toString(),
+ "-recurse", "false",
+ "-zkHost", zkAddr,
+ };
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(cpTool.getOptions()), args));
+ assertEquals("Copy should have succeeded.", 0, res);
+
+ assertTrue("Empty files should NOT be copied down as directories", emptyDest.toFile().isFile());
+
+ // Now with recursive copy
+
+ args = new String[]{
+ "-src", "file:" + emptyFile.getParent().getParent().toString(),
+ "-dst", "zk:/cp10",
+ "-recurse", "true",
+ "-zkHost", zkAddr,
+ };
+
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(cpTool.getOptions()), args));
+ assertEquals("Copy should have succeeded.", 0, res);
+
+ // Now copy it all back and make sure empty file is still a file when recursively copying.
+ tmp2 = createTempDir("cp10");
+ args = new String[]{
+ "-src", "zk:/cp10",
+ "-dst", "file:" + tmp2.toAbsolutePath().toString(),
+ "-recurse", "true",
+ "-zkHost", zkAddr,
+ };
+ res = cpTool.runTool(SolrCLI.processCommandLineArgs(SolrCLI.joinCommonAndToolOptions(cpTool.getOptions()), args));
+ assertEquals("Copy should have succeeded.", 0, res);
+
+ Path locEmpty = Paths.get(tmp2.toAbsolutePath().toString(), "stopwords", "emptyFile");
+ assertTrue("Empty files should NOT be copied down as directories", locEmpty.toFile().isFile());
}
@Test
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/522367cc/solr/solrj/src/java/org/apache/solr/common/cloud/ZkMaintenanceUtils.java
----------------------------------------------------------------------
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 dfdc8cf..6843480 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
@@ -308,13 +308,13 @@ public class ZkMaintenanceUtils {
public static void downloadFromZK(SolrZkClient zkClient, String zkPath, Path file) throws IOException {
try {
List<String> children = zkClient.getChildren(zkPath, null, true);
- // If it has no children, it's a leaf node, write the assoicated data from the ZNode.
+ // If it has no children, it's a leaf node, write the associated data from the ZNode.
// Otherwise, continue recursing, but write the associated data to a special file if any
if (children.size() == 0) {
// If we didn't copy data down, then we also didn't create the file. But we still need a marker on the local
- // disk so create a dir.
+ // disk so create an empty file.
if (copyDataDown(zkClient, zkPath, file.toFile()) == 0) {
- Files.createDirectories(file);
+ Files.createFile(file);
}
} else {
Files.createDirectories(file); // Make parent dir.