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