mirror of https://github.com/apache/lucene.git
SOLR-240: New lockType config option supports all Lucene builtin LockFactories
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@556099 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b6ca445deb
commit
ebaeb6443c
|
@ -94,6 +94,12 @@ New Features
|
|||
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
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -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.9
|
||||
static {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue