Apache Solr open-source search software
SOLR-240: New lockType config option supports all Lucene builtin LockFactories
Chris M. Hostetterebaeb6443ca3
diff --git a/CHANGES.txt b/CHANGES.txtindex 39fcb480818..6fc64e7bddc 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -94,6 +94,12 @@ New Featuresin the queryResultCache via queryResultMaxDocsCached solrconfig.xmlentry. (Koji Sekiguchi via yonik)+16. SOLR-240: New <lockType> configuration setting in <mainIndex> and+ <indexDefaults> blocks supports all Lucene builtin LockFactories.+ 'single' is recommended setting, but 'simple' is default for total+ backwards compatibility.+ (Will Johnson via hossman)+Changes in runtime behaviorOptimizationsdiff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xmlindex 54ad03d26b6..e58778fa3e3 100755--- a/example/solr/conf/solrconfig.xml+++ b/example/solr/conf/solrconfig.xml@@ -41,6 +41,20 @@<maxFieldLength>10000</maxFieldLength><writeLockTimeout>1000</writeLockTimeout><commitLockTimeout>10000</commitLockTimeout>+ <!--+ As long as Solr is the only process modifying your index, it is+ safe to use Lucene's in process locking mechanism. But you may+ specify one of the other Lucene LockFactory implementations in+ the event that you have a custom situation.++ none = NoLockFactory (typically only used with read only indexes)+ single = SingleInstanceLockFactory (suggested)+ native = NativeFSLockFactory+ simple = SimpleFSLockFactory++ ('simple' is the default for backwards compatibility with Solr 1.2)+ -->+ <lockType>single</lockType></indexDefaults><mainIndex>@@ -54,7 +68,9 @@<!-- If true, unlock any held write or commit locks on startup.This defeats the locking mechanism that allows multipleprocesses to safely access a lucene index, and should be- used with care. -->+ used with care.+ This is not needed if lock type is 'none' or 'single'+ --><unlockOnStartup>false</unlockOnStartup></mainIndex>diff --git a/src/java/org/apache/solr/update/SolrIndexConfig.java b/src/java/org/apache/solr/update/SolrIndexConfig.javaindex c8b420d7f60..d7ea19b0aaf 100644--- a/src/java/org/apache/solr/update/SolrIndexConfig.java+++ b/src/java/org/apache/solr/update/SolrIndexConfig.java@@ -39,7 +39,9 @@ public class SolrIndexConfig {public static final int defMaxFieldLength=SolrConfig.config.getInt(defaultsName +"/maxFieldLength", -1);public static final int defWriteLockTimeout=SolrConfig.config.getInt(defaultsName +"/writeLockTimeout", -1);public static final int defCommitLockTimeout=SolrConfig.config.getInt(defaultsName +"/commitLockTimeout", -1);-+ public static final String defLockType=SolrConfig.config.get(defaultsName +"/lockType", null);++/*** These are "final" in lucene 1.9static {if (writeLockTimeout != -1) IndexWriter.WRITE_LOCK_TIMEOUT=writeLockTimeout;@@ -54,6 +56,7 @@ public class SolrIndexConfig {public final int maxFieldLength;public final int writeLockTimeout;public final int commitLockTimeout;+ public final String lockType;public SolrIndexConfig(String prefix) {useCompoundFile=SolrConfig.config.getBool(prefix+"/useCompoundFile", defUseCompoundFile);@@ -63,5 +66,6 @@ public class SolrIndexConfig {maxFieldLength= SolrConfig.config.getInt(prefix+"/maxFieldLength",defMaxFieldLength);writeLockTimeout= SolrConfig.config.getInt(prefix+"/writeLockTimeout", defWriteLockTimeout);commitLockTimeout= SolrConfig.config.getInt(prefix+"/commitLockTimeout", defCommitLockTimeout);+ lockType=SolrConfig.config.get(prefix+"/lockType", defLockType);}-}\ No newline at end of file+}diff --git a/src/java/org/apache/solr/update/SolrIndexWriter.java b/src/java/org/apache/solr/update/SolrIndexWriter.javaindex 1af9f153861..0efe2dad30d 100644--- a/src/java/org/apache/solr/update/SolrIndexWriter.java+++ b/src/java/org/apache/solr/update/SolrIndexWriter.java@@ -18,6 +18,13 @@package org.apache.solr.update;import org.apache.lucene.index.IndexWriter;+import org.apache.lucene.store.Directory;+import org.apache.lucene.store.FSDirectory;+import org.apache.lucene.store.NativeFSLockFactory;+import org.apache.lucene.store.NoLockFactory;+import org.apache.lucene.store.SimpleFSLockFactory;+import org.apache.lucene.store.SingleInstanceLockFactory;+import org.apache.solr.common.SolrException;import org.apache.solr.schema.IndexSchema;import java.util.logging.Logger;@@ -54,14 +61,40 @@ public class SolrIndexWriter extends IndexWriter {}}++ private static Directory getDirectory(String path, SolrIndexConfig config) throws IOException {+ Directory d = FSDirectory.getDirectory(path);++ String rawLockType = (null == config) ? null : config.lockType;+ if (null == rawLockType) {+ // we default to "simple" for backwards compatiblitiy+ log.warning("No lockType configured for "+path+" assuming 'simple'");+ rawLockType = "simple";+ }+ final String lockType = rawLockType.toLowerCase().trim();++ if ("simple".equals(lockType)) {+ d.setLockFactory(new SimpleFSLockFactory(path));+ } else if("native".equals(lockType)) {+ d.setLockFactory(new NativeFSLockFactory(path));+ } else if("single".equals(lockType)) {+ d.setLockFactory(new SingleInstanceLockFactory());+ } else if("none".equals(lockType)) {+ d.setLockFactory(new NoLockFactory());+ } else {+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,+ "Unrecognized lockType: " + rawLockType);+ }+ return d;+ }public SolrIndexWriter(String name, String path, boolean create, IndexSchema schema) throws IOException {- super(path, schema.getAnalyzer(), create);+ super(getDirectory(path, null), schema.getAnalyzer(), create);init(name, schema, null);}public SolrIndexWriter(String name, String path, boolean create, IndexSchema schema, SolrIndexConfig config) throws IOException {- super(path, schema.getAnalyzer(), create);+ super(getDirectory(path, config), schema.getAnalyzer(), create);init(name, schema,config);}