【问题标题】:Exception when updating Lucene index更新 Lucene 索引时出现异常
【发布时间】:2009-05-08 03:33:53
【问题描述】:

我是 Lucene 搜索 API 的新手。 更新 Lucene 索引时不断出现以下异常...为什么会出现此错误以及如何避免它?

System.IO.IOException: Lock obtain timed out: SimpleFSLock@C:\Indexes\write.lock
   at Lucene.Net.Store.Lock.Obtain(Int64 lockWaitTimeout)
   at Lucene.Net.Index.IndexWriter.Init(Directory d, Analyzer a, Boolean create, Boolean closeDir)
   at Lucene.Net.Index.IndexWriter.Init(String path, Analyzer a, Boolean create)
   at Lucene.Net.Index.IndexWriter..ctor(String path, Analyzer a, Boolean create)

感谢阅读。

【问题讨论】:

    标签: c# lucene lucene.net


    【解决方案1】:

    Lucene 在以写模式打开索引时创建锁定文件。当您完全关闭索引时,此锁定文件将被删除。在写入索引时,如果程序在没有关闭 lucene IndexWriter 的情况下退出,下次尝试写入时会出现此异常。如果您从索引目录中删除锁定文件,您将不会看到此异常。

    您可以选择使用FSDirectory.setDisableLocks(false) 禁用锁定,但不建议这样做,因为错误会被静默忽略。

    【讨论】:

      【解决方案2】:

      我认为,如果索引写入所用的时间超过超时值,并且在锁定到期后和索引写入完成之前发生了另一个索引写入,那么您也会收到此错误 - 至少看起来是这样的。

      当我开始接近单个 Windows 目录中最大文件数的 50% 左右时,我开始遇到同样的问题。这减慢了写入速度,足以导致问题。 (Win2k3)

      相信你可以重新编译Lucene来改变超时值。

      【讨论】:

      【解决方案3】:

      尝试以下方法:

      try
      {
          writer = new IndexWriter(directory, new StandardAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
      }
      catch (LockObtainFailedException ex)
      {
          DirectoryInfo indexDirInfo = new DirectoryInfo(directory);
          FSDirectory indexFSDir = FSDirectory.Open(indexDirInfo, new Lucene.Net.Store.SimpleFSLockFactory(indexDirInfo));
          IndexWriter.Unlock(indexFSDir);
          writer = new IndexWriter(directory, new StandardAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
      }
      

      【讨论】:

      • 你能先修复这段代码吗? DirectoryInfo 构造函数在构造函数中不采用 AzureDirectory 对象。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-16
      • 2023-03-19
      相关资源
      最近更新 更多