Evict stale partition mappings for vanished/detached relations in Partitions.handle_relation/2
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Inizia da packages/sync-service/lib/electric/shapes/partitions.ex, leggendo handle_relation/2 e expand_change/2 ed esaminando la semantica di clean_up_partitions/1. Esamina i test esistenti per le partizioni e ShapeLogCollector prima di aggiungere una regressione che copra drop o detach, la ricreazione con lo stesso nome come tabella semplice e l’espansione delle modifiche. Il lavoro è completato quando le mappature obsolete vengono rimosse senza desincronizzare la proprietà delle partizioni o i conteggi attivi, e la modifica della tabella ricreata non viene inviata alla vecchia root shape.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- TypeScript
- Stelle
- 10.4k
- Fork
- 399
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di electric-sql/electric
-
camelToSnake and snakeCamelMapper() drop the underscore when a digit precedes a camelCase boundaryAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
electric-sql/electric#4855 ·
-
ShapeStream does not notify subscribers when it gives up on a non-Error valueForse già presa @Tyagiquamar l’ha presa 19 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
electric-sql/electric#4830 ·
-
@electric-sql/client throws SecurityError on import when the browser blocks site storage (typeof localStorage outside try)Forse già presa @mohanedmoh l’ha presa 37 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
electric-sql/electric#4826 · 1 commento ·
-
agents-chat-starter: spawn PUT goes to the durable-streams proxy, so no entity is created and agents never wakeForse già presa @adityavkk l’ha presa 133 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
electric-sql/electric#4687 ·
-
Listen IP addressApertafeature request triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
electric-sql/electric#4150 · 1 commento ·
Tutte le issue di electric-sql/electric
Issue simili
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openclaw/openclaw#199885 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
feature needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BoardGamesEmpire/board-games-empire-backend#1306 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
sequant-io/sequant#1689 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100