Titano: time-lapse ecosystem (client, server, uploader) — in progress #1
@@ -36,6 +36,7 @@ public sealed class SqliteDatabase : IDatabase
|
||||
|
||||
internal const int BusyTimeoutMs = 5000;
|
||||
private const string LogCategory = "Data.Sqlite";
|
||||
private static readonly TimeSpan WriteLockTimeout = TimeSpan.FromSeconds(60);
|
||||
|
||||
private readonly string _filename;
|
||||
private readonly bool _memory;
|
||||
@@ -196,7 +197,15 @@ public sealed class SqliteDatabase : IDatabase
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
internal Task AcquireWriteAsync(CancellationToken cancellationToken) => _writeLock.WaitAsync(cancellationToken);
|
||||
/// <summary>
|
||||
/// Queues for the write lock. The wait is bounded so a transaction left open by mistake surfaces as a transient
|
||||
/// SQLITE_BUSY instead of hanging every writer; the bound is generous because bulk imports hold the lock for long.
|
||||
/// </summary>
|
||||
internal async Task AcquireWriteAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!await _writeLock.WaitAsync(WriteLockTimeout, cancellationToken).ConfigureAwait(false))
|
||||
throw new SqliteException($"database is locked: no write lock within {WriteLockTimeout.TotalSeconds} s", SQLITE_BUSY);
|
||||
}
|
||||
|
||||
internal void ReleaseWrite() => _writeLock.Release();
|
||||
|
||||
|
||||
Reference in new issue
Block a user