Skip to content

Commit

Permalink
Merge pull request #9 from dotJEM/issues/GH-6
Browse files Browse the repository at this point in the history
Don't return directory outside of lock, this is not optimal and inste…
  • Loading branch information
jeme authored May 24, 2024
2 parents 77af588 + 3af6759 commit ece9ce7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/DotJEM.Json.Index2.Management/Writer/IJsonIndexWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@ private void Commit()
if (callsRead < 1)
return;

using ILease<IndexWriter> lease = target.WriterLease;
try
{
using ILease<IndexWriter> lease = target.WriterLease;
lease.Value.Commit();
}
catch (Exception e)
{
target.infoStream.WriteError("Failed to commit indexed data to storage.", e);
bool leaseExpired = lease.IsExpired;

target.infoStream.WriteError($"Failed to commit indexed data to storage. {leaseExpired}", e);
// SWALLOW FOR NOW
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/DotJEM.Json.Index2/IO/JsonIndexWriterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public IndexWriter Value
}
}

public bool IsExpired => DateTime.Now - leaseTime > TimeSpan.FromSeconds(5);
public bool IsExpired => (DateTime.Now - leaseTime > TimeSpan.FromSeconds(5)) || IsDisposed;

public TimeLimitedIndexWriterLease(IndexWriterManager manager, Action<TimeLimitedIndexWriterLease> onReturned)
{
Expand All @@ -181,9 +181,6 @@ protected override void Dispose(bool disposing)

public void Wait()
{
if (IsDisposed)
return;

if (IsExpired)
return;

Expand Down
5 changes: 2 additions & 3 deletions src/DotJEM.Json.Index2/Storage/IJsonIndexStorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public Directory Directory
{
get
{
if (directory != null)
return directory;

lock (padlock)
{
if (directory != null)
Expand Down Expand Up @@ -83,6 +80,8 @@ public void Delete()
foreach (string file in directory.ListAll())
directory.DeleteFile(file);
provider.Delete();


}
}
}

0 comments on commit ece9ce7

Please sign in to comment.