You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2016/10/31 14:05:59 UTC

[06/37] lucene-solr:jira/solr-8542-v2: SOLR-9533: Reload core config when a core is reloaded

SOLR-9533: Reload core config when a core is reloaded


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/2ee72314
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/2ee72314
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/2ee72314

Branch: refs/heads/jira/solr-8542-v2
Commit: 2ee723140c5377a4507cdaf5c877d9f0d47d82fc
Parents: 53507b4
Author: Joel Bernstein <jb...@apache.org>
Authored: Wed Oct 26 17:38:13 2016 -0400
Committer: Joel Bernstein <jb...@apache.org>
Committed: Wed Oct 26 20:19:40 2016 -0400

----------------------------------------------------------------------
 .../src/java/org/apache/solr/core/SolrCore.java |  4 +-
 .../solr/core/TestCorePropertiesReload.java     | 71 ++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2ee72314/solr/core/src/java/org/apache/solr/core/SolrCore.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java
index a2dc1c4..96f8738 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrCore.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java
@@ -585,9 +585,11 @@ public final class SolrCore implements SolrInfoMBean, Closeable {
     boolean success = false;
     SolrCore core = null;
     try {
+      CoreDescriptor cd = new CoreDescriptor(coreDescriptor.getName(), coreDescriptor);
+      cd.loadExtraProperties(); //Reload the extra properties
       core = new SolrCore(getName(), getDataDir(), coreConfig.getSolrConfig(),
           coreConfig.getIndexSchema(), coreConfig.getProperties(),
-          coreDescriptor, updateHandler, solrDelPolicy, currentCore);
+          cd, updateHandler, solrDelPolicy, currentCore);
       
       // we open a new IndexWriter to pick up the latest config
       core.getUpdateHandler().getSolrCoreState().newIndexWriter(core, false);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/2ee72314/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java b/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java
new file mode 100644
index 0000000..bb7aaa0
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/core/TestCorePropertiesReload.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.core;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.Properties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.solr.SolrTestCaseJ4;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestCorePropertiesReload extends SolrTestCaseJ4 {
+
+  private final File solrHomeDirectory = createTempDir().toFile();
+
+  public void setMeUp() throws Exception {
+    FileUtils.copyDirectory(new File(TEST_HOME()), solrHomeDirectory);
+    Properties props = new Properties();
+    props.setProperty("test", "Before reload");
+    writeProperties(props);
+    initCore("solrconfig.xml", "schema.xml", solrHomeDirectory.getAbsolutePath());
+  }
+
+  @Test
+  public void testPropertiesReload() throws Exception {
+    setMeUp();
+    SolrCore core = h.getCore();
+    CoreDescriptor coreDescriptor = core.getCoreDescriptor();
+    String testProp = coreDescriptor.getCoreProperty("test", null);
+    assertTrue(testProp.equals("Before reload"));
+
+    //Re-write the properties file
+    Properties props = new Properties();
+    props.setProperty("test", "After reload");
+    writeProperties(props);
+
+    h.reload();
+    core = h.getCore();
+    coreDescriptor = core.getCoreDescriptor();
+
+    testProp = coreDescriptor.getCoreProperty("test", null);
+    assertTrue(testProp.equals("After reload"));
+  }
+
+  private void writeProperties(Properties props) throws Exception {
+    FileWriter out = null;
+    try {
+      File confDir = new File(new File(solrHomeDirectory, "collection1"), "conf");
+      out = new FileWriter(new File(confDir, "solrcore.properties"));
+      props.store(out, "Reload Test");
+    } finally {
+      out.close();
+    }
+  }
+}