Evict stale partition mappings for vanished/detached relations in Partitions.handle_relation/2
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 68/100
调研方向
从 packages/sync-service/lib/electric/shapes/partitions.ex 开始,阅读 handle_relation/2 和 expand_change/2,并检查 clean_up_partitions/1 的语义。在添加涵盖 drop 或 detach、以普通表的形式使用相同名称重新创建,以及变更扩展的回归测试之前,先检查现有的 partition 和 ShapeLogCollector 测试。完成的标准是:移除过时的映射,同时不使 partition 所有权或活动计数失去同步,并且重新创建的表的变更不会发送到旧的 root shape。
由索引模型根据 Issue 内容生成。
描述
Summary
Electric.Shapes.Partitions.handle_relation/2 does not evict stale entries from the partitions map when a relation stops being a tracked partition. Because handle_txn_fragment/2 expands changes by {schema, table} name, a stale mapping can silently mis-route changes to the wrong root shape after a drop/detach + same-name recreation.
Surfaced by a Codex review on #4565 (commit a4dcc7d61), but the behavior is pre-existing — that PR only made the :table_not_found path reachable without crashing.
The bug
The partition map maps partition_table → [root_table], and expansion looks it up by name:
defp expand_change(%{relation: relation} = change, state) do
[change | state.partitions |> Map.get(relation, []) |> Enum.map(&%{change | relation: &1})]
end
Two branches of handle_relation/2 return the state unchanged without clearing a previously-tracked entry for that name:
# packages/sync-service/lib/electric/shapes/partitions.ex
{:ok, _} ->
{:ok, state} # relation no longer has a parent (detached / never partitioned)
:table_not_found ->
# the table was dropped (or dropped and recreated under a new oid) ...
{:ok, state} # added in #4565
If a tracked partition P of root R is dropped (or detached) and a new table with the same {schema, table} name is later created as a non-partition, the stale partitions[P] = [R] entry persists. Changes to the new P then get duplicated onto the old root shape R, which is incorrect.
Why it's narrow
It requires all of:
- an active shape on the partitioned root
R, - partition
Pdropped/detached, - a new relation recreated with the exact same schema-qualified name,
- recreated as a plain/non-partition table (if recreated as a partition, the
{:ok, %{parent: ...}}branch overwrites the stale entry, so no bug), - changes flowing to the recreated table.
Fix considerations
-
Evict the vanished/detached relation from
partitionsin both the:table_not_foundand the no-parent{:ok, _}branches — fixing only one (as the inline suggestion did) leaves the identical hole in the other. -
Eviction must be ownership-aware. Entries in
partitionscome from two places with different bookkeeping:add_shape/3— also tracked inpartition_ownershipand counted inactive,handle_relation/2discovery — not tracked inpartition_ownership.
A blind
Map.delete/2on a relation message could desyncpartitionsfrompartition_ownership/activefor shape-owned children, so the cleanup needs to account for ownership (likely reuse / extendclean_up_partitions/1semantics rather than delete directly). -
Add a regression test that reproduces drop/detach → recreate-as-plain-table → asserts the change is not duplicated to the old root shape.
References
- PR #4565 — "Don't crash ShapeLogCollector on introspection failures in the replication path"
- File:
packages/sync-service/lib/electric/shapes/partitions.ex(handle_relation/2,expand_change/2)
- 主要语言
- TypeScript
- 星标
- 10.4k
- 派生
- 399
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
electric-sql/electric 的其他 Issue
-
camelToSnake and snakeCamelMapper() drop the underscore when a digit precedes a camelCase boundary未关闭
难度 2/5 1-3 小时 新手友好度 85/100
electric-sql/electric#4855 ·
-
ShapeStream does not notify subscribers when it gives up on a non-Error value可能已有人在做 @Tyagiquamar 于 19 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
electric-sql/electric#4830 ·
-
@electric-sql/client throws SecurityError on import when the browser blocks site storage (typeof localStorage outside try)可能已有人在做 @mohanedmoh 于 37 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
electric-sql/electric#4826 · 1 条评论 ·
-
agents-chat-starter: spawn PUT goes to the durable-streams proxy, so no entity is created and agents never wake可能已有人在做 @adityavkk 于 133 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
electric-sql/electric#4687 ·
-
feature request triage
难度 2/5 1-3 小时 新手友好度 68/100
electric-sql/electric#4150 · 1 条评论 ·
查看 electric-sql/electric 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
software-mansion/argent#1946 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 63/100
podman-desktop/podman-desktop#20216 ·
维护者通常 1 天内回复
-
[Type] Bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
omdsh-dev/DSH-better-sidebar#1205 ·
维护者通常 3 天内回复