fix(pglite-sync): don't filter move-in messages by LSN#883
Open
jbingen wants to merge 2 commits intoelectric-sql:mainfrom
Open
fix(pglite-sync): don't filter move-in messages by LSN#883jbingen wants to merge 2 commits intoelectric-sql:mainfrom
jbingen wants to merge 2 commits intoelectric-sql:mainfrom
Conversation
Move-in messages from Electric's tagged_subqueries feature don't have an LSN header because they come from direct DB queries, not replication. Previously these messages were incorrectly skipped as "already seen" because the missing LSN defaulted to 0. This checks for the is_move_in header and bypasses LSN filtering for move-in messages, ensuring rows moving into a shape due to subquery condition changes are properly synced. Fixes electric-sql/electric#3769
Move-in data from tagged_subqueries can overlap with initial sync data, causing duplicate key errors. This adds ON CONFLICT DO UPDATE handling specifically for move-in inserts. - Add primaryKey param to applyInsertsToTable - Use ON CONFLICT DO UPDATE for move-in inserts - Update changeset description
Author
|
Added a second commit to handle duplicate key errors that can occur when move-in data overlaps with initial sync data. When a row "moves in" to a shape, the server sends an INSERT. But if that row was already synced during initial sync, we get a duplicate key error. For move-in inserts specifically, use |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Move-in messages from Electric's
tagged_subqueriesfeature don't have anlsnheader because they come from direct database queries, not from the PostgreSQL replication stream. Previously, these messages were incorrectly skipped as "already seen" because the missing LSN defaulted to 0.This fix checks for the
is_move_inheader and bypasses LSN filtering for move-in messages, ensuring that rows moving into a shape due to subquery condition changes are properly synced to the client.Problem
When using shapes with subqueries (e.g.,
WHERE id IN (SELECT user_id FROM workspace_members WHERE workspace_id = $1)), new rows that "move in" to match the subquery weren't being synced:headers.is_move_in: truebut NOheaders.lsn(since it's from a query, not replication)lsn <= lastCommittedLsnForShapeevaluates to0 <= Xwhich is true after initial syncSolution
Test case
id IN (SELECT user_id FROM workspace_members WHERE workspace_id = ...))