如何在 Lucene 中解决/修复 SimpleFSLock
当我更新或添加 lucene documnet 时出现此错误。我知道当索引写入器被其他资源使用时会发生这种情况,我们会得到这个 SimpleFSLock Excetion ,但在我的场景中,我总是关闭我的 IndexWriter,因此没有机会打开索引写入器。
如果我遇到此异常,有没有办法解决这个问题。
编辑:
static object myLock = new object();
public static void AddDocument(//some params)
{
lock (myLock)
{
try
{
//I get the exception thrown on below line [not sure but might be file have been locked due to other resource accessing it : how can i free this lock]
IndexWriter writer = new IndexWriter(GetFileInfo(indexName), analyzer, false);
writer.AddDocument(*//some document //*);
writer.Optimize();
writer.Close();
}
catch (Exception ex)
{
log.LogWarn(null, ex.Message);
}
}
}
I get this error when i do update or add the lucene documnet. I know this happens when indexwriter is being used by other resource we get this SimpleFSLock Excetion , but in my scenario i always close my IndexWriter so there is no chance of indexwriter being opened.
Is there a way if i get this exception i can fix this.
Edit :
static object myLock = new object();
public static void AddDocument(//some params)
{
lock (myLock)
{
try
{
//I get the exception thrown on below line [not sure but might be file have been locked due to other resource accessing it : how can i free this lock]
IndexWriter writer = new IndexWriter(GetFileInfo(indexName), analyzer, false);
writer.AddDocument(*//some document //*);
writer.Optimize();
writer.Close();
}
catch (Exception ex)
{
log.LogWarn(null, ex.Message);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“但在我的场景中,我总是关闭我的 IndexWriter,因此没有机会打开 IndexWriter”
我不太确定!
"but in my scenario i always close my IndexWriter so there is no chance of indexwriter being opened"
I wouldn't be so sure!
您不处理代码中的异常,您应该有一个finaly子句,当发生异常时关闭() IndexWriter以清除“write.lock”文件。
将其添加到您的代码中,然后转到索引目录并手动删除 write.lock 文件。
You dont handles exceptions in your code, you should have a finaly clause that closes() the IndexWriter when an exception occurs to clear the "write.lock" file.
Add that to your code, and then go to your index directory and manually delete the write.lock file.