Java org.apache.lucene.store.lockOcctainFailedException:锁获取超时:
我试图为从tomcat服务器获得的一大组日志文件编制索引。我已经编写了代码来打开每个文件,为每一行创建一个索引,然后使用ApacheLucene存储每一行。所有这些都是使用多线程完成的 当我尝试删除此代码时,我得到了此异常的提示Java org.apache.lucene.store.lockOcctainFailedException:锁获取超时:,java,solr,lucene,Java,Solr,Lucene,我试图为从tomcat服务器获得的一大组日志文件编制索引。我已经编写了代码来打开每个文件,为每一行创建一个索引,然后使用ApacheLucene存储每一行。所有这些都是使用多线程完成的 当我尝试删除此代码时,我得到了此异常的提示 org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: 代码 现在我想,由于我每次都提交索引,这可能会导致写锁定。所以我删除了indexWriter.commit(): 现在我
org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out:
代码
现在我想,由于我每次都提交索引,这可能会导致写锁定。所以我删除了indexWriter.commit()代码>:
现在我也不例外
所以我的问题是为什么indexWriter.commit();导致异常。即使我删除了indexWriter.commit();我在搜索时没有遇到任何问题。那就是我得到了我想要的确切结果。那么为什么要使用indexWriter.commit()简而言之,它类似于DB commit,除非您提交事务,否则添加到Solr的文档只保存在内存中。只有在提交时,文档才会保留在索引中。
如果文档在内存中时Solr崩溃,您可能会丢失这些文档
:-
从第一天开始,Lucene的原则之一就是写一次
政策。我们从不写两次文件。通过添加文档时
IndexWriter它被编入内存,一旦我们到达
我们编写的特定阈值(最大缓冲文档或RAM缓冲区大小)
从主存到磁盘的所有文件;你可以找到更多
关于这里和这里。将文档写入磁盘会产生一个完整的
新索引称为段。现在,当你索引一堆文档时
或者在生产环境中运行增量索引,您可以在此处看到
频繁更改的段数。但是,一旦调用commit
Lucene将其整个RAM缓冲区刷新为段,并对其进行同步
将属于此提交的所有段的指针写入
段文件
如果该文档已经存在于Solr中,它将被覆盖(由唯一id确定)。
因此,您的搜索可能仍然可以正常工作,但除非您提交,否则最新文档无法用于搜索
此外,一旦您打开和indexwriter,它将获得索引上的锁,您应该关闭写入程序以释放锁
if (indexWriter.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE)
{
// New index, so we just add the document (no old document can be there):
System.out.println("adding " + path);
indexWriter.addDocument(doc);
} else {
// Existing index (an old copy of this document may have been indexed) so
// we use updateDocument instead to replace the old one matching the exact
// path, if present:
System.out.println("updating " + path);
indexWriter.updateDocument(new Term("path", path), doc);
}
indexWriter.commit();
indexWriter.close();
if (indexWriter.getConfig().getOpenMode() == IndexWriterConfig.OpenMode.CREATE)
{
// New index, so we just add the document (no old document can be there):
System.out.println("adding " + path);
indexWriter.addDocument(doc);
} else {
// Existing index (an old copy of this document may have been indexed) so
// we use updateDocument instead to replace the old one matching the exact
// path, if present:
System.out.println("updating " + path);
indexWriter.updateDocument(new Term("path", path), doc);
}
indexWriter.close();