Lucene.NET --> 对段的访问被拒绝

发布于 2024-07-08 17:05:33 字数 366 浏览 6 评论 0原文

我在使用 Lucene.NET 时遇到问题。 在索引期间,我收到错误“访问路径段被拒绝”。 或者有时“访问可删除的路径被拒绝”。 我最终给了“Everyone”对索引目录的完全安全权限,但问题仍然存在。

然后我发现在索引运行期间,lucene 将段文件重命名为“segments.new”,然后发生此错误。 我猜想某些进程在重命名后仍然尝试从旧的段文件中读取? 我不知道为什么会发生这种情况,也不知道如何解决这个问题。 奇怪的是,我的合作开发人员可以毫无问题地在他们的计算机上运行索引。

该错误发生在 Lucene.Net.Index.IndexModifier.AddDocument(Document) 中。

任何想法将不胜感激。

I have a problem with Lucene.NET. During an index, I receive the error 'Access to the path segments is denied'. Or sometimes 'Access to the path deletable is denied'. I eventually gave 'Everyone' full security rights to the index directory, but the problem still existed.

I then found out that during the index run, lucene renames the segments file to 'segments.new', and then this error happens. I guess some process still tries to read from the old segments file after it has been renamed? I have no clue as to why this happens, or how to fix this. Strangely enough, my co-developers can run the index on their computer without a problem.

The error happens at happens in Lucene.Net.Index.IndexModifier.AddDocument(Document).

Any ideas would be much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

撩起发的微风 2024-07-15 17:05:33

我怀疑您的 IndexModifier 与搜索器存在争用。

以下是我如何在我的 错误跟踪 应用程序中使用 Lucene.Net,BugTracker.NET,似乎工作正常。

我在应用程序启动时创建索引。

我创建了一个搜索器并保留它,以便每次搜索时都不会重新加载索引。 所有线程共享同一个搜索器。 当搜索器搜索时,它会获取一个锁,搜索,然后释放锁,以便另一个线程可以搜索。 在我的应用程序中强制搜索到单个文件是可行的,因为 Lucene.NET 速度很快并且错误跟踪系统也不是那么忙。

同时,我有一个 IndexWriter,可以在数据更改时更新索引。 它只是发生了一点变化,所以它也很快完成了任务。 当它需要运行时,它会获取相同的锁,销毁搜索器,更新索引,然后重新创建搜索器。 新的搜索者会一直保留到下一次索引更新为止。 搜索者始终使用最新的索引。

您可以获取 BugTracker.NET 源代码并查看文件 my_lucene.cs 和 search_text.aspx。 全部都在这两个文件中,并且没有那么多代码。

I suspect that your IndexModifier is in contention with a Searcher.

Here's how I use Lucene.Net in my bug tracking app, BugTracker.NET, which seems to be working ok.

I create the index at app startup.

I create a searcher and keep it around so that the index isn't reloaded with each search. All threads share the same searcher. When the searcher searches, it grabs a lock, searches, then releases the lock, so that another thread can search. Forces the searches into single file is doable in my app because Lucene.NET is quick and a bug tracking system isn't THAT busy.

Meanwhile, I have an IndexWriter that updates the index when there is a data change. It is just changing a little bit so it does its task quick too. When it needs to run, it grabs the same lock, destroys the searcher, updates the index, and the re-recreates the searcher. The new searcher stays around until the next update of the index. The searcher always is working with an up-to-date index.

You can get the BugTracker.NET source and look at the files my_lucene.cs and search_text.aspx. It's all in those two files, and there isn't that much code.

末が日狂欢 2024-07-15 17:05:33

此问题是由在线病毒扫描程序锁定段(.new)文件引起的。 我必须编写一个自定义 Lucene Directory 实现来解决这个问题。

This problem is caused by an online virus scanner locking the segments(.new) file. I have had to write a custom Lucene Directory implementation to work around this.

向日葵 2024-07-15 17:05:33

我想我找到了一个解决方案..至少它对我有用..
我正在测试“segments.new”问题,下面有代码..所以正如你在循环中看到的那样,我创建了数千个lucene文档(6000)..在大约1360个文档时出现错误,说他不能t 重命名 blablabla .. 代码是用 c# 编写的 .. 基本上你只需为错误插入一个 try catch (在循环内),当错误弹出时,你只需再次尝试将 int 循环编号(y)减去 1 (y = y - 1) ..

//-----------------问题 -------------- -----------------------

for (int y = 0; y < 6000; y++)
{
文档 doc = new Document();

 doc.Add(new Field("URL", "C:/Users/blabla/(convert-csharp)/IMssg", Field.Store.YES, Field.Index.TOKENIZED));

 writer.AddDocument(doc);

}

//--------------------解决方案-------------------- ---------------------

IndexWriter writer = new IndexWriter("C:/Users/blabla/(convert-csharp)/IMssg", new StandardAnalyzer(), false );

for (int y = 0; y < 6000; y++)
{
尝试
{

 Document doc = new Document();

 doc.Add(new Field("URL", "C:/Users/blabla/(convert-csharp)/IMssg", Field.Store.YES, Field.Index.TOKENIZED));

 writer.AddDocument(doc);

  }
   catch (Exception t) 
  {

   y = (y < 0) ? 0 : y - 1;

   string gfff = t.Message.ToString();

   }

}

writer.Close();

我不是英国人,所以如果某些单词有任何错误,我很抱歉......
目前为止
问候伊曼纽尔

I think i found a solution.. well at least it worked for me..
I was testing for the "segments.new" problem and below you have the code .. so as you can see in a loop i created thousands of lucene documents (6000).. At about 1360 document an error appears saying that he couldn´t rename blablabla.. The code is written in c#.. basically you just have to insert a try catch (inside the loop) for the error and when the error pops up you just try again subtracting the int loop nunmber(y) by one (y = y - 1) ..

//-----------------Problem -------------------------------------

for (int y = 0; y < 6000; y++)
{
Document doc = new Document();

 doc.Add(new Field("URL", "C:/Users/blabla/(convert-csharp)/IMssg", Field.Store.YES, Field.Index.TOKENIZED));

 writer.AddDocument(doc);

}

//--------------------Solution----------------------------------------

IndexWriter writer = new IndexWriter("C:/Users/blabla/(convert-csharp)/IMssg", new StandardAnalyzer(), false);

for (int y = 0; y < 6000; y++)
{
try
{

 Document doc = new Document();

 doc.Add(new Field("URL", "C:/Users/blabla/(convert-csharp)/IMssg", Field.Store.YES, Field.Index.TOKENIZED));

 writer.AddDocument(doc);

  }
   catch (Exception t) 
  {

   y = (y < 0) ? 0 : y - 1;

   string gfff = t.Message.ToString();

   }

}

writer.Close();

Im not a english guy so im sory if there´s any error in some word...
by now
regards immanouel

他是夢罘是命 2024-07-15 17:05:33

我赞同伊玛的解决方案。 我也有这个问题。 对我来说,解决方法是将 try/catch 放在 IndexWriter.AddDocument(doc) 周围:

 int attemptNo = 0;
 while (attemptNo < 2)
 {
    try
    {
       writer.AddDocument(doc);
       break;
    }
    catch (Exception e)
    {
       String ErrMsg = String.Format("{0} ({1}): While adding Document {2}/{3}, caught {4}", DateTime.Now, attemptNo, doc.GetField("kanji").StringValue(), doc.GetField("kana").StringValue(), e.Message);
       attemptNo++;
       System.Threading.Thread.Sleep(30);
       Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate()
       {
          ViewModel.Log.Add(ErrMsg);
       });
    }

参考: http://issues.apache.org/jira/browse/LUCENE-665

“问题的要点是:在 Windows 上,您有时会看到间歇性的
重命名段时出现“访问被拒绝”错误。将新段重命名为段或
deletable.new 到 deletable 等 Lucene 一般会先写入文件
到 X.new,然后重命名为 X。”

I second Imma's solution. I had this problem also. The fix for me was to put the try/catch around IndexWriter.AddDocument(doc):

 int attemptNo = 0;
 while (attemptNo < 2)
 {
    try
    {
       writer.AddDocument(doc);
       break;
    }
    catch (Exception e)
    {
       String ErrMsg = String.Format("{0} ({1}): While adding Document {2}/{3}, caught {4}", DateTime.Now, attemptNo, doc.GetField("kanji").StringValue(), doc.GetField("kana").StringValue(), e.Message);
       attemptNo++;
       System.Threading.Thread.Sleep(30);
       Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate()
       {
          ViewModel.Log.Add(ErrMsg);
       });
    }

reference: http://issues.apache.org/jira/browse/LUCENE-665:

"The gist of the issue is: on Windows, you sometimes see intermittant
"Access Denied" errors in renaming segments.new to segments or
deletable.new to deletable, etc. Lucene typically writes files first
to X.new and then renames then to X."

メ斷腸人バ 2024-07-15 17:05:33

我读到过这个。 但是,我没有运行任何病毒扫描程序。 我还禁用了索引目录的 Vista 搜索索引,从任务管理器中终止了搜索索引进程,以确保没有其他进程锁定该文件。 不幸的是,无济于事。 此外,问题似乎更在于它尝试访问的“segments”文件已经消失(因为 lucene 将其重命名为segments.new)。 我不确定它们是否是同样的问题......

I read about this. However, I do not have any virus scanners running. I also disabled Vista Search Index for the index directory, killed the search index process from the task manager, to make sure no other process is locking the file. Unfortunately, to no avail. Moreover, the problem seems more to be that the 'segments' file it tries to access, is gone (since lucene renamed it to segments.new). I'm not sure if they are the same problems...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文