Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4124: You should be able to set the update log directory with the CoreAdmin API the same way as the data directory.

Mark Robert Milleref21415d6cb0
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index def50826415..afdee6beb8f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -122,6 +122,8 @@ New Features
will be a total of 3 replicas (one of which will normally be
designated as the leader.) (yonik)
+* SOLR-4124: You should be able to set the update log directory with the
+ CoreAdmin API the same way as the data directory. (Mark Miller)
Optimizations
----------------------
diff --git a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
index 53fbc6002f7..99435d5b238 100644
--- a/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
+++ b/solr/core/src/java/org/apache/solr/core/CoreDescriptor.java
@@ -31,6 +31,7 @@ public class CoreDescriptor {
protected String name;
protected String instanceDir;
protected String dataDir;
+ protected String ulogDir;
protected String configName;
protected String propertiesName;
protected String schemaName;
@@ -225,4 +226,12 @@ public class CoreDescriptor {
public void setSwappable(boolean swappable) {
this.swappable = swappable;
}
+
+ public String getUlogDir() {
+ return ulogDir;
+ }
+
+ public void setUlogDir(String ulogDir) {
+ this.ulogDir = ulogDir;
+ }
}
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
index 7aefe03bb8b..4aa4cc14cac 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
@@ -40,7 +40,6 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocRouter;
-import org.apache.solr.common.cloud.DocRouter;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
@@ -479,6 +478,10 @@ public class CoreAdminHandler extends RequestHandlerBase {
opts = params.get(CoreAdminParams.DATA_DIR);
if (opts != null)
dcore.setDataDir(opts);
+
+ opts = params.get(CoreAdminParams.ULOG_DIR);
+ if (opts != null)
+ dcore.setUlogDir(opts);
CloudDescriptor cd = dcore.getCloudDescriptor();
if (cd != null) {
diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.java
index ef1f3053c5a..df0742dfcda 100644
--- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java
+++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java
@@ -183,6 +183,12 @@ public class UpdateLog implements PluginInfoInitialized {
}
public void init(UpdateHandler uhandler, SolrCore core) {
+ // ulogDir from CoreDescriptor overrides
+ String ulogDir = core.getCoreDescriptor().getUlogDir();
+ if (ulogDir != null) {
+ dataDir = ulogDir;
+ }
+
if (dataDir == null || dataDir.length()==0) {
dataDir = core.getDataDir();
}
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
index 3124800f016..9afa3d1b533 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/CoreAdminRequest.java
@@ -50,6 +50,7 @@ public class CoreAdminRequest extends SolrRequest
protected String configName = null;
protected String schemaName = null;
protected String dataDir = null;
+ protected String ulogDir = null;
protected String collection;
private Integer numShards;
private String shardId;
@@ -63,6 +64,7 @@ public class CoreAdminRequest extends SolrRequest
public void setSchemaName(String schema) { this.schemaName = schema; }
public void setConfigName(String config) { this.configName = config; }
public void setDataDir(String dataDir) { this.dataDir = dataDir; }
+ public void setUlogDir(String ulogDir) { this.ulogDir = ulogDir; }
public void setCollection(String collection) { this.collection = collection; }
public void setNumShards(int numShards) {this.numShards = numShards;}
public void setShardId(String shardId) {this.shardId = shardId;}
@@ -72,6 +74,7 @@ public class CoreAdminRequest extends SolrRequest
public String getSchemaName() { return schemaName; }
public String getConfigName() { return configName; }
public String getDataDir() { return dataDir; }
+ public String getUlogDir() { return ulogDir; }
public String getCollection() { return collection; }
public String getShardId() { return shardId; }
public String getRoles() { return roles; }
@@ -98,6 +101,9 @@ public class CoreAdminRequest extends SolrRequest
if (dataDir != null) {
params.set( CoreAdminParams.DATA_DIR, dataDir);
}
+ if (ulogDir != null) {
+ params.set( CoreAdminParams.ULOG_DIR, ulogDir);
+ }
if (collection != null) {
params.set( CoreAdminParams.COLLECTION, collection);
}
diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java
index 2c529eac319..09ef414faa2 100644
--- a/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java
+++ b/solr/solrj/src/java/org/apache/solr/common/params/CoreAdminParams.java
@@ -36,6 +36,8 @@ public interface CoreAdminParams
/** If you rename something, what is the new name **/
public final static String DATA_DIR = "dataDir";
+
+ public final static String ULOG_DIR = "ulogDir";
/** Name of the other core in actions involving 2 cores **/
public final static String OTHER = "other";
diff --git a/solr/solrj/src/test-files/solrj/solr/shared/conf/schema.xml b/solr/solrj/src/test-files/solrj/solr/shared/conf/schema.xml
index 6f6e3db88db..103c997daa9 100644
--- a/solr/solrj/src/test-files/solrj/solr/shared/conf/schema.xml
+++ b/solr/solrj/src/test-files/solrj/solr/shared/conf/schema.xml
@@ -47,6 +47,7 @@
<filter class="solr.RemoveDuplicatesTokenFilterFactory"/>
</analyzer>
</fieldType>
+ <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
</types>
<fields>
@@ -55,6 +56,7 @@
<field name="type" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="name" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="${ctlField:}" type="text-${l10n:EN}" indexed="true" stored="true" multiValued="true"/>
+ <field name="_version_" type="long" indexed="true" stored="true"/>
</fields>
<!-- field to use to determine and enforce document uniqueness. -->
diff --git a/solr/solrj/src/test-files/solrj/solr/shared/conf/solrconfig.xml b/solr/solrj/src/test-files/solrj/solr/shared/conf/solrconfig.xml
index 6d30c1603fb..8cda0e68d0d 100644
--- a/solr/solrj/src/test-files/solrj/solr/shared/conf/solrconfig.xml
+++ b/solr/solrj/src/test-files/solrj/solr/shared/conf/solrconfig.xml
@@ -25,7 +25,11 @@
<dataDir>${tempDir}/data/${l10n:}-${version:}</dataDir>
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/>
- <updateHandler class="solr.DirectUpdateHandler2" />
+ <updateHandler class="solr.DirectUpdateHandler2">
+ <updateLog>
+ <str name="dir">${solr.data.dir:}</str>
+ </updateLog>
+ </updateHandler>
<requestDispatcher handleSelect="true" >
<requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" />
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
new file mode 100644
index 00000000000..0bf531ab9e6
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestCoreAdmin.java
@@ -0,0 +1,103 @@
+/*
+ * 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.client.solrj.request;
+
+import java.io.File;
+
+import org.apache.derby.iapi.services.io.FileUtil;
+import org.apache.solr.SolrIgnoredThreadsFilter;
+import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.embedded.AbstractEmbeddedSolrServerTestCase;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.core.SolrCore;
+import org.apache.solr.util.FileUtils;
+import org.junit.After;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
+
+@ThreadLeakFilters(defaultFilters = true, filters = {SolrIgnoredThreadsFilter.class})
+public class TestCoreAdmin extends AbstractEmbeddedSolrServerTestCase {
+ protected static Logger log = LoggerFactory.getLogger(TestCoreAdmin.class);
+
+ private static final String SOLR_XML = "solr.xml";
+
+ @Override
+ protected File getSolrXml() throws Exception {
+ // This test writes on the directory where the solr.xml is located. Better
+ // to copy the solr.xml to
+ // the temporary directory where we store the index
+ File origSolrXml = new File(SOLR_HOME, SOLR_XML);
+ File solrXml = new File(tempDir, SOLR_XML);
+ FileUtils.copyFile(origSolrXml, solrXml);
+ return solrXml;
+ }
+
+ protected SolrServer getSolrAdmin() {
+ return new EmbeddedSolrServer(cores, "core0");
+ }
+
+ @Test
+ public void testCustomUlogDir() throws Exception {
+
+ SolrServer server = getSolrAdmin();
+
+
+ File tmp = new File(TEMP_DIR, "solrtest-" + getTestClass().getSimpleName() + "-" + System.currentTimeMillis());
+ tmp.mkdirs();
+
+ File dataDir = new File(tmp, this.getTestName()
+ + System.currentTimeMillis() + "-" + "data");
+
+ File newCoreInstanceDir = new File(tmp, this.getTestName()
+ + System.currentTimeMillis() + "-" + "instance");
+
+ File instanceDir = new File(cores.getSolrHome());
+ FileUtil.copyDirectory(instanceDir, new File(newCoreInstanceDir,
+ "newcore"));
+
+ CoreAdminRequest.Create req = new CoreAdminRequest.Create();
+ req.setCoreName("newcore");
+ req.setInstanceDir(newCoreInstanceDir.getAbsolutePath() + File.separator + "newcore");
+ req.setDataDir(dataDir.getAbsolutePath());
+ req.setUlogDir(new File(dataDir, "ulog").getAbsolutePath());
+ req.process(server);
+
+ SolrCore core = cores.getCore("newcore");
+ File logDir;
+ try {
+ logDir = core.getUpdateHandler().getUpdateLog().getLogDir();
+ } finally {
+ core.close();
+ }
+ assertEquals(new File(dataDir, "ulog" + File.separator + "tlog").getAbsolutePath(), logDir.getAbsolutePath());
+ server.shutdown();
+
+ }
+
+ @After
+ public void after() {
+ // wtf?
+ System.setProperty("tempDir", ".");
+
+ System.clearProperty("solr.solr.home");
+ }
+
+}