-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clean cached column information on delete (#1562)
Fixes #1550. This PR extends the shape log collector to also clean the cached column information from ETS when a relation changes. This ensures that when a table is migrated, we don't re-use the old table information from ETS but instead load it from Postgres and re-populate the cache with the new column info. **There's one corner case that this PR does not address:** - Create table, insert data - Sync a shape containing that table - Drop the table - Delete the shape - Recreate the table but with a different schema - Insert some data into the new table - Sync a shape containing the newly recreated table In the above scenario, when syncing the newly recreated table, we get the new data but in the old schema (so we only get the columns that also existed in the old schema). This is because Postgres logical replication stream does not inform us when a table is dropped. As a result, we can't detect that a table was dropped and thus don't know that we need to clean the cached column information. It's only when we get a Relation message that we know this. But Postgres only sends a Relation message the first time the data in the table changes and **we're subscribed to that table in the replication stream** (and that's only after syncing the shape). So, the data that was inserted before we synced the table in the last step, does not lead to a Relation message. Only if we insert data into the table after that sync step, will Postgres send a Relation message that will make us clean the cached column information. But note that at that point the row that was inserted in the previous step is already stored in storage in the format of the old schema.
- Loading branch information
Showing
13 changed files
with
373 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@core/sync-service": patch | ||
--- | ||
|
||
Clean cached column info on relation changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Electric.PersistentKV.Mock do | ||
defstruct [] | ||
|
||
@type t() :: %__MODULE__{} | ||
|
||
@spec new() :: t() | ||
def new() do | ||
%__MODULE__{} | ||
end | ||
|
||
defimpl Electric.PersistentKV do | ||
def set(_memory, _key, _value) do | ||
:ok | ||
end | ||
|
||
def get(_memory, _key) do | ||
{:ok, 42} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 21 additions & 1 deletion
22
packages/sync-service/lib/electric/shape_cache/shape_status.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.