Re: Skipping logical replication transactions on subscriber side
Amit Kapila <amit.kapila16@gmail.com>
On Mon, Dec 13, 2021 at 8:28 AM Masahiko Sawada <sawada.mshk@gmail.com> wrote: > > On Sat, Dec 11, 2021 at 3:29 PM Amit Kapila <amit.kapila16@gmail.com> wrote: > > > > 3. > > + * Also, we don't skip receiving the changes in streaming cases, > > since we decide > > + * whether or not to skip applying the changes when starting to apply changes. > > > > But why so? Can't we even skip streaming (and writing to file all such > > messages)? If we can do this then we can avoid even collecting all > > messages in a file. > > IIUC in streaming cases, a transaction can be sent to the subscriber > while splitting into multiple chunks of changes. In the meanwhile, > skip_xid can be changed. If the user changed or cleared skip_xid after > the subscriber skips some streamed changes, the subscriber won't able > to have complete changes of the transaction. > Yeah, I think if we want we can handle this by writing into the stream xid file whether the changes need to be skipped and then the consecutive streams can check that in the file or may be in some way don't allow skip_xid to be changed in worker if it is already skipping some xact. If we don't want to do anything for this then it is better to at least reflect this reasoning in the comments. > > > > 4. > > + * Also, one might think that we can skip preparing the skipped transaction. > > + * But if we do that, PREPARE WAL record won’t be sent to its physical > > + * standbys, resulting in that users won’t be able to find the prepared > > + * transaction entry after a fail-over. > > + * > > .. > > + */ > > + if (skipping_changes) > > + stop_skipping_changes(false); > > > > Why do we need such a Prepare's entry either at current subscriber or > > on its physical standby? I think it is to allow Commit-prepared. If > > so, how about if we skip even commit prepared as well? Even on > > physical standby, we would be having the value of skip_xid which can > > help us to skip there as well after failover. > > It's true that skip_xid would be set also on physical standby. When it > comes to preparing the skipped transaction on the current subscriber, > if we want to skip commit-prepared I think we need protocol changes in > order for subscribers to know prepare_lsn and preppare_timestampso > that it can lookup the prepared transaction when doing > commit-prepared. I proposed this idea before. This change would be > benefical as of now since the publisher sends even empty transactions. > But considering the proposed patch[1] that makes the puslisher not > send empty transaction, this protocol change would be an optimization > only for this feature. > I was thinking to compare the xid received as part of the commit_prepared message with the value of skip_xid to skip the commit_prepared but I guess the user would change it between prepare and commit prepare and then we won't be able to detect it, right? I think we can handle this and the streaming case if we disallow users to change the value of skip_xid when we are already skipping changes or don't let the new skip_xid to reflect in the apply worker if we are already skipping some other transaction. What do you think? -- With Regards, Amit Kapila.
Commits
-
Test ALIGNOF_DOUBLE==4 compatibility under ALIGNOF_DOUBLE==8.
- c1da0acbb06e 15.0 landed
-
Reorder subskiplsn in pg_subscription to avoid alignment issues.
- 79b716cfb7a1 15.0 landed
-
Add ALTER SUBSCRIPTION ... SKIP.
- 208c5d65bbd6 15.0 landed
-
Optionally disable subscriptions on error.
- 705e20f8550c 15.0 cited
-
Update docs of logical replication for commit 8d74fc96db.
- 85c61ba8920b 15.0 landed
-
Respect permissions within logical replication.
- a2ab9c06ea15 15.0 cited
-
Fix regression test failure caused by commit 8d74fc96db.
- 41e66fee0516 15.0 landed
-
Add a view to show the stats of subscription workers.
- 8d74fc96db5f 15.0 landed
-
Add logical change details to logical replication worker errcontext.
- abc0910e2e0a 15.0 landed
-
Rename LOGICAL_REP_MSG_STREAM_END to LOGICAL_REP_MSG_STREAM_STOP.
- 4cd7a1896871 15.0 landed
-
Fix typo in protocol.sgml.
- e1915646658d 14.0 landed
- 0ac1aee0d7d8 15.0 landed
-
Remove unused argument in apply_handle_commit_internal().
- f4b939f1a372 14.0 landed
- 16bd4becee32 15.0 landed
-
Fix replication of in-progress transactions in tablesync worker.
- 0926e96c4934 14.0 cited
-
Reorder pg_sequence columns to avoid alignment issue
- f3b421da5f4a 10.0 cited