Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
2013-12-20 15:45
441 查看
原文链接:
http://www.javaarch.net/jiagoushi/904.htm
本网站使用了lucene来支持搜索功能,然后定时重建索引,但是最近日志里面出现了下面的异常。
这个异常是因为lucene进入到索引目录中,发现里面就是一个write.lock。而IndexWriter的构造函数在试图获取另外一个IndexWriter已经加锁的索引目录时就会抛出一个LockObtainFailedException。
[ERROR] 2013-06-28 14:00:01,009 [org.springweb.lucene.DataIndex.index] - DataIndex index got error Lock obtain timed out: NativeFSLo
ck@/root/data/write.lock
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/root/data/write.lock
at org.apache.lucene.store.Lock.obtain(Lock.java:84)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:1098)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:926)
at org.springweb.lucene.DataIndex.index(DataIndex.java:36)
之前的代码是这样的
indexwrite.commit();
indexwrite.close();
在close方法里面也会调用unlock方法,就是删除write.lock的锁文件,但是之前在索引过程中抛出了异常,导致这个锁没有被释放,下次再建索引的时候就抛异常了。
所以要么在indexwrite构造方法前调用,要么保证indexwrite.close();能被调用。
// indexwrite.getDirectory().close();
if (IndexWriter.isLocked(directory)) {
IndexWriter.unlock(directory);
}
unlock就是删除public static final String WRITE_LOCK_NAME = "write.lock";这个文件
public static void unlock(Directory directory) throws IOException {
directory.makeLock(IndexWriter.WRITE_LOCK_NAME).release();
}
http://www.javaarch.net/jiagoushi/904.htm
本网站使用了lucene来支持搜索功能,然后定时重建索引,但是最近日志里面出现了下面的异常。
这个异常是因为lucene进入到索引目录中,发现里面就是一个write.lock。而IndexWriter的构造函数在试图获取另外一个IndexWriter已经加锁的索引目录时就会抛出一个LockObtainFailedException。
[ERROR] 2013-06-28 14:00:01,009 [org.springweb.lucene.DataIndex.index] - DataIndex index got error Lock obtain timed out: NativeFSLo
ck@/root/data/write.lock
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/root/data/write.lock
at org.apache.lucene.store.Lock.obtain(Lock.java:84)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:1098)
at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:926)
at org.springweb.lucene.DataIndex.index(DataIndex.java:36)
之前的代码是这样的
indexwrite.commit();
indexwrite.close();
在close方法里面也会调用unlock方法,就是删除write.lock的锁文件,但是之前在索引过程中抛出了异常,导致这个锁没有被释放,下次再建索引的时候就抛异常了。
所以要么在indexwrite构造方法前调用,要么保证indexwrite.close();能被调用。
// indexwrite.getDirectory().close();
if (IndexWriter.isLocked(directory)) {
IndexWriter.unlock(directory);
}
unlock就是删除public static final String WRITE_LOCK_NAME = "write.lock";这个文件
public static void unlock(Directory directory) throws IOException {
directory.makeLock(IndexWriter.WRITE_LOCK_NAME).release();
}
相关文章推荐
- Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
- Lucene的IndexWriter初始化时的LockObtainFailedException的解决方法
- lucene使用IndexWriter时遇到LockObtainFailedException: Lock obtain timed out 异常原因及解决办法
- Lucene的IndexWriter初始化时的LockObtainFailedException
- 求解决 严重: org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
- Lock obtain timed out: Lock@的解决方法(lucene)
- lucene的加锁机制和LockObtainFailedException的异常
- Lucene异常:org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
- Lock obtain timed out: Lock@的解决方法(lucene)
- lucene 异常 Lock obtain timed out 解决方法
- Lock obtain timed out: Lock@的解决方法(lucene)
- `c->xlib.lock' failed错误解决方法
- Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity解决方法
- svn: Failed to lock the file的解决方法
- jython在eclipse控制台出现Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0解决方法
- ognl.MethodFailedException异常解决方法(Struts2)
- Attempted to lock an already-locked dir:org.tigris.subversion.javahl.ClientException-SVN提交报错问题解决方法
- Spring如何加载XSD文件(org.xml.sax.SAXParseException: Failed to read schema document错误的解决方法)
- Spring如何加载XSD文件(org.xml.sax.SAXParseException: Failed to read schema document错误的解决方法)
- Spring如何加载XSD文件(org.xml.sax.SAXParseException: Failed to read schema document错误的解决方法)