Electric progressive: apply and confirm changes to visible rows during the background full sync
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
Start with packages/electric-db-collection/src/electric.ts and the progressive witnesses in electric-live-query.test.ts; trace how buffered changes, snapshot metadata, txid evidence, and the atomic swap interact. Use the recovery and descriptor-isolation oracles to check ordering around snapshot xmin, xmax, and xip, then inspect persistence and reset behavior. Done means visible-row changes and their txids are applied before the swap, with no stale rollback or duplicate application, and the stated evidence passes.
由索引模型根据 Issue 内容生成。
描述
Summary
During a progressive collection's background full sync, Electric buffers stream changes and their txids until the atomic swap. #2115 makes a live query over a progressive source ready as soon as its own subset loads. A user can now edit a visible row while the full sync is still running. That mutation's awaitTxId cannot resolve until the swap. If the full sync takes longer than the awaitTxId timeout, the handler throws and the optimistic change rolls back.
The stream starts at once, so Electric receives the confirming change long before the swap. Electric could apply that change and its txid during buffering for rows that the client already shows.
Current behavior
In packages/electric-db-collection/src/electric.ts:
- While
isBufferingInitialSync()is true, change messages go tobufferedMessages. Their txids are not added tonewTxids. The comment says "txids will be extracted during atomic swap". - The atomic swap on the first
up-to-dateapplies the buffered changes, extracts their txids, and then resolves txid waiters throughpublishEvidence.
As a result:
- Confirmation waits for the full sync.
awaitTxId(txid)for a write to a visible row resolves only at the swap. - Visible rows go stale. A ready progressive query shows its subset snapshot rows unchanged until the swap. #2115 records this as a known limit, and
electric-live-query.test.tspins it ("a ready query's rows update only when the full sync completes").
Before #2115, useLiveQuery already rendered rows in this window. Suspense users now reach it too.
Proposal
Apply stream changes during buffering for keys that a subset snapshot already loaded, when the change is newer than that snapshot. Record their txids when the change applies. Keep buffering every other change until the swap.
Electric has the needed pieces:
progressiveSnapshotRowskeeps the snapshot row for a key when a later stream update needs that row as its baseline.- Each
fetchSnapshotreturns snapshot metadata, andisVisibleInSnapshotcan order a txid against it.
The txid must resolve only when its change is visible. If Electric confirms a change that it still buffers, the optimistic state drops and the old snapshot row shows again until the swap.
Questions to settle
- Ordering. A change can be older than, or included in, the snapshot that loaded its key. Use the snapshot's xmin, xmax, and xip list to decide whether to apply the change, skip it as already included, or keep buffering it.
- The swap. The swap must not apply an early-applied change a second time, and it must not move a row back to an older value.
- Keys outside any subset. Changes to keys that no subset loaded stay buffered, so their txids stay unconfirmed until the swap. Decide whether
awaitTxIdshould report this case, or whether a write to a row the client never loaded is outside scope. - Must-refetch. A reset during buffering discards the subset rows. Changes applied early before the reset must follow the reset's truncate rules.
- Persistence. Early-applied changes go through the same commit and receipt path. Check resume metadata and
seenTxidsevidence for persisted collections.
Evidence to add
- Extend the progressive witnesses in
electric-live-query.test.ts. A write to a visible row during buffering must become visible, and itsawaitTxIdmust resolve before the swap. - Flip the pinned freshness test on purpose, and update the limit in
packages/db/src/query/live/ARCHITECTURE.mdand in the #2115 review record. - Add an ordering lane with changes before, inside, and after the loading snapshot, checked against an independent model. The Electric recovery and descriptor-isolation oracles already generate progressive histories and are a good place to start.
- A hostile control: a design that confirms a txid without applying its change must fail at the first checkpoint after confirmation.
Related: #2113, #2115, #2118.
- 主要语言
- TypeScript
- 星标
- 3.9k
- 派生
- 272
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 235
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/db 的其他 Issue
-
难度 3/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 8/100
维护者通常 1 天内回复
-
难度 3/5 半天 新手友好度 58/100
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 5/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
维护者通常 1 天内回复
相似的 Issue
-
afk-ok area:data-quality importer size:S
难度 2/5 1-3 小时 新手友好度 74/100
enorm-labs/event-junkie#3301 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
one-zero-eight/apply-bot#39 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
bigbluebutton/bbb-ui-components-react#108 ·
维护者通常 2 天内回复
-
area: app type: bug
难度 2/5 1-3 小时 新手友好度 70/100
ExpidetGames/code-reviewer#308 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复