Skip to content

Commit 3af6759

Browse files
author
jmd
committed
Don't return directory outside of lock, this is not optimal and instead we should have a lease system instead, but it seems to fix the concurency issues for now.
1 parent 95bf8a4 commit 3af6759

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/DotJEM.Json.Index2.Management/Writer/IJsonIndexWriter.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,16 @@ private void Commit()
150150
if (callsRead < 1)
151151
return;
152152

153+
using ILease<IndexWriter> lease = target.WriterLease;
153154
try
154155
{
155-
using ILease<IndexWriter> lease = target.WriterLease;
156156
lease.Value.Commit();
157157
}
158158
catch (Exception e)
159159
{
160-
target.infoStream.WriteError("Failed to commit indexed data to storage.", e);
160+
bool leaseExpired = lease.IsExpired;
161+
162+
target.infoStream.WriteError($"Failed to commit indexed data to storage. {leaseExpired}", e);
161163
// SWALLOW FOR NOW
162164
}
163165
}

src/DotJEM.Json.Index2/IO/JsonIndexWriterManager.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public IndexWriter Value
165165
}
166166
}
167167

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

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

182182
public void Wait()
183183
{
184-
if (IsDisposed)
185-
return;
186-
187184
if (IsExpired)
188185
return;
189186

src/DotJEM.Json.Index2/Storage/IJsonIndexStorageManager.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ public Directory Directory
3636
{
3737
get
3838
{
39-
if (directory != null)
40-
return directory;
41-
4239
lock (padlock)
4340
{
4441
if (directory != null)
@@ -83,6 +80,8 @@ public void Delete()
8380
foreach (string file in directory.ListAll())
8481
directory.DeleteFile(file);
8582
provider.Delete();
83+
84+
8685
}
8786
}
8887
}

0 commit comments

Comments
 (0)