-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make sure that Postgres always get a consistent snapshot #929
Open
judahrand
wants to merge
9
commits into
transferwise:master
Choose a base branch
from
thread:postgres-snapshot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
judahrand
force-pushed
the
postgres-snapshot
branch
from
April 4, 2022 18:26
2e18c58
to
535f236
Compare
@Samira-El This PR is ready for review, I believe. |
judahrand
force-pushed
the
postgres-snapshot
branch
4 times, most recently
from
April 5, 2022 09:07
b9ee0f5
to
ce27325
Compare
Merged
judahrand
force-pushed
the
postgres-snapshot
branch
from
April 5, 2022 14:32
0b98a99
to
d59e5d5
Compare
judahrand
force-pushed
the
postgres-snapshot
branch
3 times, most recently
from
April 19, 2022 08:47
04eaffb
to
c04292a
Compare
This change ensures that the LSN at which the replication slot is first consistent is availiable to the caller of the method.
There is a replication lag between a primary and replica database. We get information about what data the replication slot can provide from the primary but perform the initial data snapshot on the replica. Therefore, we must make sure that the replica has caught up to at least the LSN which we are going to begin streaming from the replication slot.
judahrand
force-pushed
the
postgres-snapshot
branch
from
April 19, 2022 08:50
c04292a
to
f795486
Compare
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.
Problem
It is currently possible for PipelineWise to select an LSN to stream from which will result in missing data once the initial snapshot has been conducted.
This is due to the current mechanism of just selecting either the most recent LSN on the primary or the most recent LSN which has been replayed on the replica: https://github.com/thread/pipelinewise/blob/cfd2c2091eb60a5b71ea38486594ccfb91a4fe1c/pipelinewise/fastsync/commons/tap_postgres.py#L297-L322
This is not a safe thing to do as it does not guarantee a consistent view of the database.
Fixes: #930
Proposed changes
Inspired by how Debezium (another CDC tool written in Java) deals with initial snapshots of Postgres databases we will take advantage of two behaviours:
confirmed_flush_lsn
to this value). We will stream from that point forward but use the current state of the database as the snapshot.confirmed_flush_lsn
to be the point at which we will start streaming.In both of these cases, we may have data which will also be streamed to us by the replication slot but this should not be an issue as we are relying on an 'at least once' delivery mechanism already.
Types of changes
What types of changes does your code introduce to PipelineWise?
Put an
x
in the boxes that applyChecklist
setup.py
is an individual PR and not mixed with feature or bugfix PRs[AP-NNNN]
(if applicable. AP-NNNN = JIRA ID)AP-NNN
(if applicable. AP-NNN = JIRA ID)