Unione dell'ondata 1; lo scrittore unico non esegue più un'operazione annullata mentre il lotto è in corso; decisioni consolidate
verifica / prove (push) Successful in 9m24s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 16:14:03 +00:00
1 parent 4f55fbed8e
commit e2c987873b
2 files changed
+56 -10

No files matched your search

+28 -10
View File
@@ -160,24 +160,28 @@ internal sealed class SqliteWriter : IDisposable
private void ProcessBatch(List<WorkItem> batch)
{
var started = new List<WorkItem>(batch.Count);
// Drop items already cancelled before opening a transaction; the others are started one by one,
// right before they run, so a cancellation that arrives while an earlier item of the same batch
// is executing is still honoured.
var pending = new List<WorkItem>(batch.Count);
foreach (var item in batch)
{
if (item.TryStart())
{
started.Add(item);
}
else
if (item.IsCancelled)
{
item.Dispose(); // cancelled while queued
}
else
{
pending.Add(item);
}
}
if (started.Count == 0)
if (pending.Count == 0)
{
return;
}
var started = new List<WorkItem>(pending.Count);
var succeeded = new List<WorkItem>(started.Count);
SqliteTransaction? transaction = null;
WriteContext? context = null;
@@ -185,8 +189,15 @@ internal sealed class SqliteWriter : IDisposable
{
transaction = _connection.BeginTransaction(deferred: false);
context = new WriteContext(_connection, transaction);
foreach (var item in started)
foreach (var item in pending)
{
if (!item.TryStart())
{
item.Dispose(); // cancelled while an earlier item of this batch was running
continue;
}
started.Add(item);
transaction.Save(Savepoint);
var executing = Interlocked.Increment(ref _executing);
UpdateMax(executing);
@@ -224,9 +235,13 @@ internal sealed class SqliteWriter : IDisposable
{
}
foreach (var item in started)
foreach (var item in pending)
{
item.Fail(ex); // no effect on items that already failed on their own
// Items not reached yet fail too, so no caller waits forever; failing twice has no effect.
if (started.Contains(item) || item.TryStart())
{
item.Fail(ex);
}
}
return;
@@ -279,6 +294,9 @@ internal sealed class SqliteWriter : IDisposable
/// <summary>Queued → started. False when the caller cancelled first.</summary>
public bool TryStart() => Interlocked.CompareExchange(ref _state, Started, Queued) == Queued;
/// <summary>True when the caller cancelled before the item started.</summary>
public bool IsCancelled => Volatile.Read(ref _state) == Cancelled;
public abstract void Execute(WriteContext context);
public abstract void Complete();