Author: hossman
Date: Fri Jul 13 11:48:50 2007
New Revision: 556099
URL: http://svn.apache.org/viewvc?view=rev&rev=556099
Log:
SOLR-240: New lockType config option supports all Lucene builtin LockFactories
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/example/solr/conf/solrconfig.xml
lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java
lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java
Modified: lucene/solr/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?view=diff&rev=556099&r1=556098&r2=556099
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Fri Jul 13 11:48:50 2007
@@ -94,6 +94,12 @@
in the queryResultCache via queryResultMaxDocsCached solrconfig.xml
entry. (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 behavior
Optimizations
Modified: lucene/solr/trunk/example/solr/conf/solrconfig.xml
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/example/solr/conf/solrconfig.xml?view=diff&rev=556099&r1=556098&r2=556099
==============================================================================
--- lucene/solr/trunk/example/solr/conf/solrconfig.xml (original)
+++ lucene/solr/trunk/example/solr/conf/solrconfig.xml Fri Jul 13 11:48:50 2007
@@ -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 multiple
processes 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>
Modified: lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java?view=diff&rev=556099&r1=556098&r2=556099
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexConfig.java Fri
Jul 13 11:48:50 2007
@@ -39,7 +39,9 @@
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.9
static {
if (writeLockTimeout != -1)
IndexWriter.WRITE_LOCK_TIMEOUT=writeLockTimeout;
@@ -54,6 +56,7 @@
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 @@
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
+}
Modified: lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java?view=diff&rev=556099&r1=556098&r2=556099
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/update/SolrIndexWriter.java Fri
Jul 13 11:48:50 2007
@@ -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 @@
}
}
+
+ 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);
}