mirror of https://github.com/apache/lucene.git
SOLR-8484: refactor update/SolrIndexConfig.LOCK_TYPE_* into core/DirectoryFactory.LOCK_TYPE_*
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1723564 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c87b01af02
commit
33fc06036f
|
@ -442,6 +442,9 @@ Other Changes
|
|||
|
||||
* SOLR-8498: Improve error message when a large value is stored in an indexed string field. (shalin)
|
||||
|
||||
* SOLR-8484: refactor update/SolrIndexConfig.LOCK_TYPE_* into core/DirectoryFactory.LOCK_TYPE_*
|
||||
(Christine Poerschke)
|
||||
|
||||
================== 5.4.0 ==================
|
||||
|
||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release
|
||||
|
|
|
@ -54,6 +54,12 @@ public abstract class DirectoryFactory implements NamedListInitializedPlugin,
|
|||
public enum DirContext {DEFAULT, META_DATA}
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
// Available lock types
|
||||
public final static String LOCK_TYPE_SIMPLE = "simple";
|
||||
public final static String LOCK_TYPE_NATIVE = "native";
|
||||
public final static String LOCK_TYPE_SINGLE = "single";
|
||||
public final static String LOCK_TYPE_NONE = "none";
|
||||
|
||||
/**
|
||||
* Indicates a Directory will no longer be used, and when its ref count
|
||||
|
|
|
@ -162,9 +162,9 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Sol
|
|||
switch (lockType) {
|
||||
case "hdfs":
|
||||
return HdfsLockFactory.INSTANCE;
|
||||
case "single":
|
||||
case DirectoryFactory.LOCK_TYPE_SINGLE:
|
||||
return new SingleInstanceLockFactory();
|
||||
case "none":
|
||||
case DirectoryFactory.LOCK_TYPE_NONE:
|
||||
return NoLockFactory.INSTANCE;
|
||||
default:
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||
|
|
|
@ -33,9 +33,9 @@ public class RAMDirectoryFactory extends EphemeralDirectoryFactory {
|
|||
|
||||
@Override
|
||||
protected LockFactory createLockFactory(String rawLockType) throws IOException {
|
||||
if (!(rawLockType == null || "single".equalsIgnoreCase(rawLockType.trim()))) {
|
||||
if (!(rawLockType == null || DirectoryFactory.LOCK_TYPE_SINGLE.equalsIgnoreCase(rawLockType.trim()))) {
|
||||
throw new SolrException(ErrorCode.FORBIDDEN,
|
||||
"RAMDirectory can only be used with the 'single' lock factory type.");
|
||||
"RAMDirectory can only be used with the '"+DirectoryFactory.LOCK_TYPE_SINGLE+"' lock factory type.");
|
||||
}
|
||||
return new SingleInstanceLockFactory();
|
||||
}
|
||||
|
|
|
@ -56,19 +56,18 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {
|
|||
@Override
|
||||
protected LockFactory createLockFactory(String rawLockType) throws IOException {
|
||||
if (null == rawLockType) {
|
||||
// we default to "native"
|
||||
log.warn("No lockType configured, assuming 'native'.");
|
||||
rawLockType = "native";
|
||||
rawLockType = DirectoryFactory.LOCK_TYPE_NATIVE;
|
||||
log.warn("No lockType configured, assuming '"+rawLockType+"'.");
|
||||
}
|
||||
final String lockType = rawLockType.toLowerCase(Locale.ROOT).trim();
|
||||
switch (lockType) {
|
||||
case "simple":
|
||||
case DirectoryFactory.LOCK_TYPE_SIMPLE:
|
||||
return SimpleFSLockFactory.INSTANCE;
|
||||
case "native":
|
||||
case DirectoryFactory.LOCK_TYPE_NATIVE:
|
||||
return NativeFSLockFactory.INSTANCE;
|
||||
case "single":
|
||||
case DirectoryFactory.LOCK_TYPE_SINGLE:
|
||||
return new SingleInstanceLockFactory();
|
||||
case "none":
|
||||
case DirectoryFactory.LOCK_TYPE_NONE:
|
||||
return NoLockFactory.INSTANCE;
|
||||
default:
|
||||
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.lucene.util.InfoStream;
|
|||
import org.apache.lucene.util.Version;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
import org.apache.solr.common.util.Utils;
|
||||
import org.apache.solr.core.DirectoryFactory;
|
||||
import org.apache.solr.core.MapSerializable;
|
||||
import org.apache.solr.core.PluginInfo;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
|
@ -68,12 +69,6 @@ public class SolrIndexConfig implements MapSerializable {
|
|||
|
||||
public InfoStream infoStream = InfoStream.NO_OUTPUT;
|
||||
|
||||
// Available lock types
|
||||
public final static String LOCK_TYPE_SIMPLE = "simple";
|
||||
public final static String LOCK_TYPE_NATIVE = "native";
|
||||
public final static String LOCK_TYPE_SINGLE = "single";
|
||||
public final static String LOCK_TYPE_NONE = "none";
|
||||
|
||||
/**
|
||||
* Internal constructor for setting defaults based on Lucene Version
|
||||
*/
|
||||
|
@ -86,7 +81,7 @@ public class SolrIndexConfig implements MapSerializable {
|
|||
mergeFactor = -1;
|
||||
ramBufferSizeMB = 100;
|
||||
writeLockTimeout = -1;
|
||||
lockType = LOCK_TYPE_NATIVE;
|
||||
lockType = DirectoryFactory.LOCK_TYPE_NATIVE;
|
||||
mergePolicyInfo = null;
|
||||
mergeSchedulerInfo = null;
|
||||
defaultMergePolicyClassName = TieredMergePolicy.class.getName();
|
||||
|
|
|
@ -193,10 +193,10 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {
|
|||
if (tracker == null) {
|
||||
tracker = new Tracker();
|
||||
tracker.path = path;
|
||||
tracker.dir = df.get(path, DirContext.DEFAULT, "single");
|
||||
tracker.dir = df.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
|
||||
dirs.put(path, tracker);
|
||||
} else {
|
||||
tracker.dir = df.get(path, DirContext.DEFAULT, "single");
|
||||
tracker.dir = df.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
|
||||
}
|
||||
tracker.refCnt.incrementAndGet();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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 org.apache.lucene.util.LuceneTestCase;
|
||||
|
||||
public class DirectoryFactoryTest extends LuceneTestCase {
|
||||
|
||||
public void testLockTypesUnchanged() throws Exception {
|
||||
assertEquals("simple", DirectoryFactory.LOCK_TYPE_SIMPLE);
|
||||
assertEquals("native", DirectoryFactory.LOCK_TYPE_NATIVE);
|
||||
assertEquals("single", DirectoryFactory.LOCK_TYPE_SINGLE);
|
||||
assertEquals("none", DirectoryFactory.LOCK_TYPE_NONE);
|
||||
}
|
||||
|
||||
}
|
|
@ -44,8 +44,8 @@ public class RAMDirectoryFactoryTest extends LuceneTestCase {
|
|||
}
|
||||
};
|
||||
String path = "/fake/path";
|
||||
Directory dir1 = factory.get(path, DirContext.DEFAULT, "single");
|
||||
Directory dir2 = factory.get(path, DirContext.DEFAULT, "single");
|
||||
Directory dir1 = factory.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
|
||||
Directory dir2 = factory.get(path, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
|
||||
assertEquals("RAMDirectoryFactory should not create new instance of RefCntRamDirectory " +
|
||||
"every time open() is called for the same path", dir1, dir2);
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class RAMDirectoryFactoryTest extends LuceneTestCase {
|
|||
|
||||
private void dotestOpenSucceedForEmptyDir() throws IOException {
|
||||
RAMDirectoryFactory factory = new RAMDirectoryFactory();
|
||||
Directory dir = factory.get("/fake/path", DirContext.DEFAULT, "single");
|
||||
Directory dir = factory.get("/fake/path", DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_SINGLE);
|
||||
assertNotNull("RAMDirectoryFactory should create RefCntRamDirectory even if the path doen't lead " +
|
||||
"to index directory on the file system", dir);
|
||||
factory.release(dir);
|
||||
|
|
|
@ -59,7 +59,7 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
|||
|
||||
ignoreException("locked");
|
||||
try {
|
||||
System.setProperty("solr.tests.lockType","simple");
|
||||
System.setProperty("solr.tests.lockType",DirectoryFactory.LOCK_TYPE_SIMPLE);
|
||||
//opening a new core on the same index
|
||||
initCore("solrconfig-basic.xml", "schema.xml");
|
||||
if (checkForCoreInitException(LockObtainFailedException.class))
|
||||
|
@ -85,7 +85,7 @@ public class SolrCoreCheckLockOnStartupTest extends SolrTestCaseJ4 {
|
|||
|
||||
ignoreException("locked");
|
||||
try {
|
||||
System.setProperty("solr.tests.lockType","native");
|
||||
System.setProperty("solr.tests.lockType",DirectoryFactory.LOCK_TYPE_NATIVE);
|
||||
//opening a new core on the same index
|
||||
initCore("solrconfig-basic.xml", "schema.xml");
|
||||
CoreContainer cc = h.getCoreContainer();
|
||||
|
|
|
@ -124,7 +124,7 @@ public class TestConfig extends SolrTestCaseJ4 {
|
|||
|
||||
++numDefaultsTested; assertEquals("default ramBufferSizeMB", 100.0D, sic.ramBufferSizeMB, 0.0D);
|
||||
++numDefaultsTested; assertEquals("default writeLockTimeout", -1, sic.writeLockTimeout);
|
||||
++numDefaultsTested; assertEquals("default LockType", SolrIndexConfig.LOCK_TYPE_NATIVE, sic.lockType);
|
||||
++numDefaultsTested; assertEquals("default LockType", DirectoryFactory.LOCK_TYPE_NATIVE, sic.lockType);
|
||||
|
||||
++numDefaultsTested; assertEquals("default infoStream", InfoStream.NO_OUTPUT, sic.infoStream);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.index.IndexWriterConfig;
|
|||
import org.apache.lucene.index.SimpleMergedSegmentWarmer;
|
||||
import org.apache.lucene.index.TieredMergePolicy;
|
||||
import org.apache.solr.SolrTestCaseJ4;
|
||||
import org.apache.solr.core.DirectoryFactory;
|
||||
import org.apache.solr.core.SolrConfig;
|
||||
import org.apache.solr.core.TestMergePolicyConfig;
|
||||
import org.apache.solr.schema.IndexSchema;
|
||||
|
@ -129,10 +130,10 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
|
|||
++mSizeExpected; assertTrue(m.get("lockType") instanceof String);
|
||||
{
|
||||
final String lockType = (String)m.get("lockType");
|
||||
assertTrue(SolrIndexConfig.LOCK_TYPE_SIMPLE.equals(lockType) ||
|
||||
SolrIndexConfig.LOCK_TYPE_NATIVE.equals(lockType) ||
|
||||
SolrIndexConfig.LOCK_TYPE_SINGLE.equals(lockType) ||
|
||||
SolrIndexConfig.LOCK_TYPE_NONE.equals(lockType));
|
||||
assertTrue(DirectoryFactory.LOCK_TYPE_SIMPLE.equals(lockType) ||
|
||||
DirectoryFactory.LOCK_TYPE_NATIVE.equals(lockType) ||
|
||||
DirectoryFactory.LOCK_TYPE_SINGLE.equals(lockType) ||
|
||||
DirectoryFactory.LOCK_TYPE_NONE.equals(lockType));
|
||||
}
|
||||
|
||||
++mSizeExpected; assertTrue(m.get("infoStreamEnabled") instanceof Boolean);
|
||||
|
|
Loading…
Reference in New Issue