azure-contrib / AzureDirectory

A Lucene Directory Provider for Azure Blob Storage
Microsoft Public License
77 stars 57 forks source link

IsLocked doesn't work properly #24

Closed ghost closed 7 years ago

ghost commented 7 years ago

AzureLock.IsLocked method returns incorrect result. If directory is locked it returns FALSE, if not locked it returns TRUE.

Looks like this line has wrong condition: https://github.com/azure-contrib/AzureDirectory/blob/master/AzureDirectory/AzureLock.cs#L43

See example code below, which outputs to:

//Console output
Writer created.
IsLocked: False
Writer disposed
IsLocked: True
Writer 2 created.
IsLocked: False
Directory unlocked
IsLocked: True
var cloudAccount = GetStorageAccount();

var localCache = new DirectoryInfo("c:\\isLockedTest.txt");
var azureContainer = "azurelocktest";

var cacheDirectory = new SimpleFSDirectory(localCache);
var azureDirectory =
    new AzureDirectory(cloudAccount, azureContainer, cacheDirectory);

var analyzer = new StandardAnalyzer(Version.LUCENE_30);

var indexWriter = new IndexWriter(azureDirectory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);

Console.WriteLine("Writer 2 created.");
Console.WriteLine($"IsLocked: {IndexWriter.IsLocked(azureDirectory)}");
indexWriter.Dispose();
Console.WriteLine("Writer disposed");
Console.WriteLine($"IsLocked: {IndexWriter.IsLocked(azureDirectory)}");         

indexWriter = new IndexWriter(azureDirectory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);

Console.WriteLine("Writer 2 created.");
Console.WriteLine($"IsLocked: {IndexWriter.IsLocked(azureDirectory)}");
IndexWriter.Unlock(azureDirectory);
Console.WriteLine("Directory unlocked");
Console.WriteLine($"IsLocked: {IndexWriter.IsLocked(azureDirectory)}");
richorama commented 7 years ago

I think you're right. I'll fix it now