Apache Solr open-source search software
SOLR-8484: refactor update/SolrIndexConfig.LOCK_TYPE_* into core/DirectoryFactory.LOCK_TYPE_*
Christine Poerschke33fc06036fad
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a93d167319e..162c6bb99cc 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -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 releasediff --git a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.javaindex 0993768fad0..e3bbd026876 100644--- a/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/DirectoryFactory.java@@ -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 countdiff --git a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.javaindex 79f80407202..b516ee69e21 100644--- a/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/HdfsDirectoryFactory.java@@ -162,9 +162,9 @@ public class HdfsDirectoryFactory extends CachingDirectoryFactory implements Solswitch (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,diff --git a/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.javaindex 73a1e0acf66..1fd526b03a2 100644--- a/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/RAMDirectoryFactory.java@@ -33,9 +33,9 @@ public class RAMDirectoryFactory extends EphemeralDirectoryFactory {@Overrideprotected 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();}diff --git a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.javaindex 6a0e85d06ec..73d6e6eec55 100644--- a/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java+++ b/solr/core/src/java/org/apache/solr/core/StandardDirectoryFactory.java@@ -56,19 +56,18 @@ public class StandardDirectoryFactory extends CachingDirectoryFactory {@Overrideprotected 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,diff --git a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.javaindex 2ccdc36ef00..ab37d8a194f 100644--- a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java+++ b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java@@ -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();diff --git a/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.javaindex 842bc66749c..121732c5b6f 100644--- a/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java+++ b/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java@@ -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();}diff --git a/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.javanew file mode 100755index 00000000000..e0f13765300--- /dev/null+++ b/solr/core/src/test/org/apache/solr/core/DirectoryFactoryTest.java@@ -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);+ }++}diff --git a/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.javaindex 66e25dd2699..aa30b613140 100644--- a/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java+++ b/solr/core/src/test/org/apache/solr/core/RAMDirectoryFactoryTest.java@@ -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);diff --git a/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java b/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.javaindex 509c74c9903..1c1fb44c6e8 100644--- a/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java+++ b/solr/core/src/test/org/apache/solr/core/SolrCoreCheckLockOnStartupTest.java@@ -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 indexinitCore("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 indexinitCore("solrconfig-basic.xml", "schema.xml");CoreContainer cc = h.getCoreContainer();diff --git a/solr/core/src/test/org/apache/solr/core/TestConfig.java b/solr/core/src/test/org/apache/solr/core/TestConfig.javaindex 96ade4554e5..d115b61ca51 100644--- a/solr/core/src/test/org/apache/solr/core/TestConfig.java+++ b/solr/core/src/test/org/apache/solr/core/TestConfig.java@@ -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);diff --git a/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.javaindex d2a3be58ea2..59672802bed 100644--- a/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java+++ b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java@@ -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);