fix(localdb): apply upserts on the primary key, not INSERT OR REPLACE (scadaproj#38)

INSERT OR REPLACE resolved a secondary UNIQUE conflict by deleting a
different row (another PK) with capture suppressed and its ledger left live,
so a pair diverged silently (LocalDb-003). The applier now uses
INSERT ... ON CONFLICT(<pk>) DO UPDATE (DO NOTHING when every column is PK):
a clash on another unique key aborts the entry, which is dead-lettered, and
each node keeps its own row. Side effect: a remote update of a parent with
ON DELETE RESTRICT children now applies instead of being dead-lettered.

Also waits for the snapshot watermark in WipedPeer_SnapshotLiftsItsWatermark,
which raced SnapshotComplete under full-suite load.

Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
Joseph Doherty
2026-11-09 14:58:34 -05:00
parent 4af0ea8152
commit 15a6c7c710
10 changed files with 250 additions and 22 deletions
@@ -317,7 +317,11 @@ public sealed class SnapshotResyncTests : IDisposable
{
var run1A = a.Session.RunAsync(d1A, cts1.Token);
var run1B = b.Session.RunAsync(d1B, cts1.Token);
await WaitForAsync(async () => (await ReadOrders(b.Db)).Count == 3, RunTimeout);
// Rows land per SnapshotBatch; the watermark moves on the later SnapshotComplete. Waiting
// on the rows alone let cts1 cancel the session between the two (an intermittent failure
// of the assert below under full-suite load), so wait for the watermark to move at all.
await WaitForAsync(
async () => (await ReadOrders(b.Db)).Count == 3 && await LastAppliedRemoteSeq(b.Db) > 0, RunTimeout);
cts1.Cancel();
await SwallowAsync(run1A);
await SwallowAsync(run1B);