fix(sqlite-persistence): make every persisted hydration wait for a reserved commit #2265
Merged
KyleAMathewsmerged 30 commits into
main fromrefs/pull/2265/head·merged by KyleAMathews Showing 17 changed files with 19 additions and 0 deletions (loading 14).
x
@@ -0,0 +1,5 @@
+---
+'@tanstack/db-sqlite-persistence-core': patch
+---
+
+Keep a persisted Collection's status when another tab's commit reloads its rows. Before, a reload from durable rows could mark a tab `ready` while its own source was still loading, or move a tab whose initial sync failed from `error` to `ready`. Now only the Collection's own source changes its status.
@@ -0,0 +1,13 @@
+---
+'@tanstack/db-sqlite-persistence-core': patch
+'@tanstack/db': patch
+'@tanstack/electric-db-collection': patch
+---
+
+Keep a sync transaction that reserved its commit turn from failing when a persisted hydration starts while it is open. Before, only a subset load admitted during the reservation waited for the commit. A subset load admitted earlier, a reload or reset from a peer tab's notice, sequence-gap recovery, or a hydration that a shared scheduler held past its turn advanced the hydration cycle, and the commit then rejected with `a persisted sync transaction cannot cross a hydration cycle`. Electric reserves every stream transaction, so a deploy that made several tabs refetch at once could put their Collections into `error`. Each of these hydrations now waits outside the apply mutex until the reserved transaction commits, then starts. While it waits, readers keep the rows from before it. The `reserveCommitTurn` contract now covers every persisted hydration.
+
+A peer reset now applies in arrival order with peer commit notices, so a commit from before the reset can no longer publish a row that the reset removed.
+
+Electric now abandons its open transaction when its stream stops for good, so hydrations that wait for that transaction can run.
+
+An abandoned reservation now releases the subset loads that waited for it, as a commit does, so they run. Before, a load admitted while the turn was reserved rejected with `SyncTransactionAbortedError` when the source abandoned the transaction.