为什么lucene.net.store.azure抛出indexnotfounexception; quot; quot* no sagments* a zuredirectory中找到的文件。修改索引后例外?

发布于 2025-01-18 11:27:16 字数 1726 浏览 3 评论 0原文

由于某种原因,当我从 Lucene 索引中删除文档时,它会抛出“在 AzureDirectory 中找不到段*文件”异常。仅当尝试加载远程存储在 Azure Blob 存储中的数据时,才会发生这种情况。本地索引更新良好并继续运行,直到本地副本被清除。然后,当尝试从远程 Azure Blob 存储加载索引时出现问题时,就会出现错误。我可以通过修改索引来复制此内容,立即删除本地索引,然后重新读取索引,以便它必须再次从 blob 存储下载。该方法运行后本地和远程路径都有文件。

其次,我还遇到一个问题,本地临时文件上的写锁似乎没有释放 我必须显式调用垃圾收集器。

如果有人对我做错了什么有任何见解,我将不胜感激。

依赖关系:

.Net Core 5.0
Lucene.Net 4.8.0-beta0016
Lucene.Net.QueryParser 4.8.0-beta16
Lucene.Net.Store.Azure 4.8.0-beta15

我尝试将 Lucene.Net 和 Lucene.Net.QueryParser 恢复到 4.8.0-beta15 以匹配 Lucene.Net.Store.Azure,但结果仍然相同。

private void IndexDocument(List<MyModel> toDelete)
{
    string connectionString = "My connection string info.";
    string remotePath = "my/remote/path";
    List<string> excludes = toDelete.Select(o => o.Id).ToList();
    string localPath = @"C:\my\local\path\";
    AzureDirectory folder = new AzureDirectory(connectionString, remotePath, FSDirectory.Open(localPath)); 
    StandardAnalyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);
    IndexWriterConfig config = new IndexWriterConfig(LuceneVersion.LUCENE_48, analyzer);
    IndexWriter writer = new IndexWriter(folder, config); // Create writer
    
    foreach (var exclude in excludes)
    {
        Term term = new Term("MyId", exclude);
        writer.DeleteDocuments(term);
    }
    
    writer.Commit();
    folder.ClearLock("write.lock");
    writer.Dispose();
    folder.Dispose();
    
    // The locks on the local files do not get released until garbage collector is called.
    // https://stackoverflow.com/questions/13262548/delete-a-file-being-used-by-another-process
    GC.Collect();
    GC.WaitForPendingFinalizers();
}

For some reason when I delete a document from a Lucene index it is throwing a "no segments* file found in AzureDirectory" exception. This only happens when trying to load the data stored remotely in Azure blob storage. The local index updates fine and continues to operate until the local copy get cleared. Then when the issue present when it tries to load the index from remote Azure blob storage then the error presents. I am able to duplicate this by making a modification to the index, deleting the local index immediately, then to reread the index so that it has to download from blob storage again. There are files in both the local and remote paths after this method runs.

Secondarily, I am also having an issue where it seems the write locks on local temp files do not release with
out me having to make an explicit call to the garbage collector.

If anyone has any insight as to what I am doing wrong I would greatly appreciate it.

Dependencies:

.Net Core 5.0
Lucene.Net 4.8.0-beta0016
Lucene.Net.QueryParser 4.8.0-beta16
Lucene.Net.Store.Azure 4.8.0-beta15

I tried reverting Lucene.Net and Lucene.Net.QueryParser to 4.8.0-beta15 to match Lucene.Net.Store.Azure but the results are still the same.

private void IndexDocument(List<MyModel> toDelete)
{
    string connectionString = "My connection string info.";
    string remotePath = "my/remote/path";
    List<string> excludes = toDelete.Select(o => o.Id).ToList();
    string localPath = @"C:\my\local\path\";
    AzureDirectory folder = new AzureDirectory(connectionString, remotePath, FSDirectory.Open(localPath)); 
    StandardAnalyzer analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);
    IndexWriterConfig config = new IndexWriterConfig(LuceneVersion.LUCENE_48, analyzer);
    IndexWriter writer = new IndexWriter(folder, config); // Create writer
    
    foreach (var exclude in excludes)
    {
        Term term = new Term("MyId", exclude);
        writer.DeleteDocuments(term);
    }
    
    writer.Commit();
    folder.ClearLock("write.lock");
    writer.Dispose();
    folder.Dispose();
    
    // The locks on the local files do not get released until garbage collector is called.
    // https://stackoverflow.com/questions/13262548/delete-a-file-being-used-by-another-process
    GC.Collect();
    GC.WaitForPendingFinalizers();
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文