Lucene.NET - >拒绝访问段

时间:2021-10-10 03:09:26

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.

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

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.

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

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

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

Any ideas would be much appreciated.

任何想法将不胜感激。

5 个解决方案

#1


1  

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

我怀疑你的IndexModifier与搜索者争论不休。

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

以下是我在我的bug跟踪应用程序BugTracker.NET中使用Lucene.Net的方法,该应用程序看起来运行正常。

I create the index at app startup.

我在app启动时创建索引。

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.

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

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.

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

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.

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

#2


1  

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) ..

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

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

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

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);

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

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

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

我不是一个英国人,所以如果在某些词中有任何错误,那么即时...现在关于immanouel

#3


1  

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

我是伊玛的第二个解决方案。我也有这个问题。对我来说,修复是将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);
       });
    }

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."

“问题的关键在于:在Windows上,你有时会在重命名段时看到间歇性的”拒绝访问“错误。更新到段或者删除。删除等等.Lucene通常首先将文件写入X.new,然后重命名为X。”

#4


0  

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.

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

#5


0  

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...

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

#1


1  

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

我怀疑你的IndexModifier与搜索者争论不休。

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

以下是我在我的bug跟踪应用程序BugTracker.NET中使用Lucene.Net的方法,该应用程序看起来运行正常。

I create the index at app startup.

我在app启动时创建索引。

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.

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

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.

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

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.

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

#2


1  

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) ..

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

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

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

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);

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

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

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

我不是一个英国人,所以如果在某些词中有任何错误,那么即时...现在关于immanouel

#3


1  

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

我是伊玛的第二个解决方案。我也有这个问题。对我来说,修复是将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);
       });
    }

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."

“问题的关键在于:在Windows上,你有时会在重命名段时看到间歇性的”拒绝访问“错误。更新到段或者删除。删除等等.Lucene通常首先将文件写入X.new,然后重命名为X。”

#4


0  

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.

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

#5


0  

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...

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