Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't return directory outside of lock, this is not optimal and inste… #9

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -51,7 +51,7 @@
{
return writer = Open(index);
}
catch (Exception e)

Check warning on line 54 in src/DotJEM.Json.Index2/IO/JsonIndexWriterManager.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'e' is declared but never used
{
Debug.WriteLine("ACTIVE LEASES: " +leases.Count);
throw;
Expand Down Expand Up @@ -165,7 +165,7 @@
}
}

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

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


}
}
}
Loading