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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1419720 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-12-10 20:19:53 +00:00
parent 6f6211d310
commit ef21415d6c
9 changed files with 139 additions and 2 deletions

View File

@ -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
----------------------

View File

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

View File

@ -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) {

View File

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

View File

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

View File

@ -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";

View File

@ -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. -->

View File

@ -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" />

View File

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