-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
There's a race condition between beginBarrier and the user's database write. The current implementation uses seq ranges to identify which undolog entries belong to a barrier:
beginBarrierreadsmax(seq)as startSeq⚠️ Another write could happen here → undolog entries created- User's write happens → undolog entries created
endBarrierreadsmax(seq)as endSeq, captures range [startSeq+1, endSeq]
If concurrent writes occur between steps 1 and 3, those unrelated undolog entries are incorrectly included in the barrier's range.
Proposed Solution
Tag undolog entries with a barrier ID rather than relying on seq ranges.
Schema change:
-- Add barrierId column to undolog
ALTER TABLE undolog ADD COLUMN barrierId TEXT;
-- Add currentBarrierId to undoState
ALTER TABLE undoState ADD COLUMN currentBarrierId TEXT;Trigger change:
INSERT INTO undolog(barrierId, tableName, sql)
VALUES((SELECT currentBarrierId FROM undoState WHERE id = 1), ...);API change:
beginBarriersetscurrentBarrierIdin undoStateendBarrierqueriesWHERE barrierId = ?instead of seq range- Entries with
barrierId = NULLare ignored (written outside a barrier)
Benefits
- Eliminates race condition entirely
- Works correctly with concurrent database access
- No change to public API
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels